Create and Browse Unitpackage’s

Create and Browse Unitpackage’s#

The unitpackage API can be used to create unitpackages or browse such packages. The unitpackage is based on the frictionless framework, which has been adapted to meet the requirements to annotate scientific data. Read more in the unitpackage documentation.

Create unitpackages#

The creation of unitpackages with the unitpackage API is described in the documentation. They can be created from local CSV files but also directly from pandas dataframes.

The following example illustrates how a unitpackage can be created from a CSV and YAML (containing information on the column names in the CSV and additional metadata)

from unitpackage.entry import Entry
import yaml

with open("../files/data/data.csv.meta.yaml", "rb") as f:
    metadata = yaml.load(f, Loader=yaml.SafeLoader)

fields = metadata["figure description"]["fields"]

entry = Entry.from_csv(csvname="../files/data/data.csv", metadata=metadata, fields=fields)
entry.save(outdir="../generated/files/data/generated/")

In case your original data is not standard CSV, we recommend writing a loader that creates a pandas dataframe, which can be stored along with measured metadata as unitpackage, as described in the unitpackage documentation on how to load unitpackages. A modular loader and converter is currently developed in echemdb-converters.

Exploring data#

A collection of unitpackages can be loaded with the unitpackage API to browse, explore, modify or visualize the entries. A detailed description and usage examples can be found in the unitpackage documentation. Here we collect a demo unitpackage.

from unitpackage.collection import Collection

db = Collection.from_local('../files/data')
db
[Entry('data_demo')]

If units were provided to the fields, you can simply transform the units and create a plot with these units.

entry = db['data_demo']
entry.rescale({'t':'ms', 'U':'V'}).plot('t', 'U')

Other metadata as accessible as attributes from each package.

entry.research_question
'Resistance of a resistor connected in series to a power supply.'