Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions doc/news/refactor-create-examples.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
**Added:**

* Added ``Entry.create_example(name=None)`` which returns a single example entry. Defaults to ``'alves_2011_electrochemistry_6010_f1a_solid'`` when no name is provided.

**Changed:**

* Changed ``Collection.create_example`` to use ``Collection.from_local`` internally.

**Removed:**

* Removed ``Entry.create_examples``. Use ``Entry.create_example`` instead.
17 changes: 3 additions & 14 deletions unitpackage/collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
# along with unitpackage. If not, see <https://www.gnu.org/licenses/>.
# ********************************************************************
import logging
import os.path

from frictionless import Package

Expand Down Expand Up @@ -121,21 +122,9 @@ def create_example(cls):
Entry('no_bibliography')]

"""
example_dir = os.path.join(os.path.dirname(__file__), "..", "examples", "local")

entries = (
cls.Entry.create_examples("alves_2011_electrochemistry_6010")
+ cls.Entry.create_examples("engstfeld_2018_polycrystalline_17743")
+ cls.Entry.create_examples("no_bibliography")
)

package = Package()

for entry in entries:
package.add_resource(entry.resource)

return cls(
package=package,
)
return cls.from_local(example_dir)

def filter(self, predicate):
r"""
Expand Down
24 changes: 12 additions & 12 deletions unitpackage/database/echemdb_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def __repr__(self):

EXAMPLES::

>>> entry = EchemdbEntry.create_examples()[0]
>>> entry = EchemdbEntry.create_example()
>>> entry
Echemdb('alves_2011_electrochemistry_6010_f1a_solid')

Expand All @@ -109,14 +109,14 @@ def bibliography(self):

EXAMPLES::

>>> entry = EchemdbEntry.create_examples()[0]
>>> entry = EchemdbEntry.create_example()
>>> entry.bibliography # doctest: +NORMALIZE_WHITESPACE
Entry('article',
fields=[
('title', ...
...

>>> entry_no_bib = EchemdbEntry.create_examples(name="no_bibliography")[0]
>>> entry_no_bib = EchemdbEntry.create_example(name="no_bibliography")
>>> entry_no_bib.bibliography
''

Expand Down Expand Up @@ -144,7 +144,7 @@ def citation(self, backend="text"):

EXAMPLES::

>>> entry = EchemdbEntry.create_examples()[0]
>>> entry = EchemdbEntry.create_example()
>>> entry.citation(backend='text')
'O. B. Alves et al. Electrochemistry at Ru(0001) in a flowing CO-saturated electrolyte—reactive and inert adlayer phases. Physical Chemistry Chemical Physics, 13(13):6010–6021, 2011.'
>>> print(entry.citation(backend='md'))
Expand Down Expand Up @@ -210,7 +210,7 @@ def get_electrode(self, name):

EXAMPLES::

>>> entry = EchemdbEntry.create_examples()[0]
>>> entry = EchemdbEntry.create_example()
>>> entry.get_electrode('WE') # doctest: +NORMALIZE_WHITESPACE
{'name': 'WE', 'function': 'workingElectrode', 'type': 'single crystal',
'crystallographicOrientation': '0001', 'material': 'Ru',
Expand Down Expand Up @@ -245,7 +245,7 @@ def rescale(self, units):
These units must be defined in the metadata of the resource,
within the key ``figureDescription.fields``::

>>> entry = EchemdbEntry.create_examples()[0]
>>> entry = EchemdbEntry.create_example()
>>> rescaled_entry = entry.rescale(units='original')
>>> rescaled_entry.fields # doctest: +NORMALIZE_WHITESPACE
[{'name': 't', 'type': 'number', 'unit': 's'},
Expand All @@ -270,7 +270,7 @@ def scan_rate(self):

EXAMPLES::

>>> entry = EchemdbEntry.create_examples()[0]
>>> entry = EchemdbEntry.create_example()
>>> entry.scan_rate
<Quantity 0.05 V / s>

Expand All @@ -297,7 +297,7 @@ def rescale_scan_rate(self, field_name=None, *, value, unit):

EXAMPLES::

>>> entry = EchemdbEntry.create_examples()[0]
>>> entry = EchemdbEntry.create_example()
>>> entry.scan_rate
<Quantity 0.05 V / s>

Expand Down Expand Up @@ -361,7 +361,7 @@ def _normalize_field_name(self, field_name):

EXAMPLES::

>>> entry = EchemdbEntry.create_examples()[0]
>>> entry = EchemdbEntry.create_example()
>>> entry._normalize_field_name('j')
'j'
>>> entry._normalize_field_name('x')
Expand All @@ -382,7 +382,7 @@ def thumbnail(self, width=96, height=72, dpi=72, **kwds):

EXAMPLES::

>>> entry = EchemdbEntry.create_examples()[0]
>>> entry = EchemdbEntry.create_example()
>>> thumb = entry.thumbnail()
>>> thumb.startswith(b'\x89PNG')
True
Expand Down Expand Up @@ -432,7 +432,7 @@ def plot(self, x_label="E", y_label="j", name=None):

EXAMPLES::

>>> entry = EchemdbEntry.create_examples()[0]
>>> entry = EchemdbEntry.create_example()
>>> entry.plot()
Figure(...)

Expand Down Expand Up @@ -496,7 +496,7 @@ def rescale_reference(self, new_reference=None, field_name=None, ph=None):

EXAMPLES::

>>> entry = EchemdbEntry.create_examples()[0]
>>> entry = EchemdbEntry.create_example()
>>> entry.resource.schema.get_field('E') # doctest: +NORMALIZE_WHITESPACE
{'name': 'E', 'type': 'number', 'unit': 'V', 'reference': 'RHE'}

Expand Down
6 changes: 3 additions & 3 deletions unitpackage/descriptor.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ class QuantityDescriptor(GenericDescriptor):
EXAMPLES::

>>> from unitpackage.entry import Entry
>>> entry = Entry.create_examples()[0]
>>> entry = Entry.create_example()
>>> temperature = entry.echemdb.system.electrolyte.temperature
>>> temperature
298.15 K
Expand All @@ -187,7 +187,7 @@ def quantity(self):
EXAMPLES::

>>> from unitpackage.entry import Entry
>>> entry = Entry.create_examples()[0]
>>> entry = Entry.create_example()
>>> temperature = entry.echemdb.system.electrolyte.temperature
>>> temperature.quantity
<Quantity 298.15 K>
Expand All @@ -204,7 +204,7 @@ def __repr__(self):
EXAMPLES::

>>> from unitpackage.entry import Entry
>>> entry = Entry.create_examples()[0]
>>> entry = Entry.create_example()
>>> temperature = entry.echemdb.system.electrolyte.temperature
>>> temperature
298.15 K
Expand Down
Loading