Data types

Metadata

Metadata describing EVERY object within the data structure.

Attributes

  • name .. Name of an attribute (str)

  • value .. Value of an attribute

  • dtype .. data type of the attribute (default: str)

  • unit .. physical unit of an attribute (optional)

  • description .. a description of an attribute (optional)

  • label .. a fancy label of an attribute , e.g. for plotting (optional)

  • required .. a boolean attribute for attribute checks (optional)

1import sdata
2attribute1 = sdata.Attribute("color", "blue")
3attribute1
(Attr'color':blue(str))
1attribute2 = sdata.Attribute(name="answer",
2                             value=42,
3                             dtype="int",
4                             unit="-",
5                             description="""The Answer to the Ultimate Question of Life, The Universe, and Everything""",
6                             label="Die Antwort")
7attribute2.to_dict()
{'name': 'answer',
 'value': 42,
 'unit': '-',
 'dtype': 'int',
 'description': 'The Answer to the Ultimate Question of Life, The Universe, and Everything',
 'label': 'Die Antwort'}

dtypes for attributes

  • int, (int64)

  • float, (float32, float64, float128)

  • str, (unicode)

  • bool

  • timestamp (datetime.isoformat with timezone)

  • (uuid planed)

sdata.metadata

1metadata = sdata.Metadata()
2metadata.add(attribute1)
3metadata.add(attribute2)
4print(metadata)
5metadata.df
                        name  value dtype unit                                        description        label
key
sdata_version  sdata_version  0.8.4   str    -
Augenfarbe             color   blue   str    -
answer                answer     42   int    -  The Answer to the Ultimate Question of Life, T...  Die Antwort
1data = sdata.Data(name="basic example", uuid="38b26864e7794f5182d38459bab85842", table=df)
2data.metadata.add("Temperatur",
3                  value=25.4,
4                  dtype="float",
5                  unit="degC",
6                  description="Temperatur",
7                  label="Temperatur T [°C]")
8data.metadata.df
                        name                             value  dtype  unit  description              label
key
sdata_version  sdata_version                             0.8.4    str     -
name                    name                     basic example    str     -
uuid                    uuid  38b26864e7794f5182d38459bab85842    str     -
Temperatur        Temperatur                              25.4  float  degC   Temperatur  Temperatur T [°C]

Core data types

Data

The Data class is the Base class for all classes within the sdata family. It provides a uuid, a name and the metadata functionality. It can group other Data objects. A Data object can store one pandas.DataFrame.

1import sdata
2data = sdata.Data(name="my data name", table=df, description="my data description")
 1df = pd.DataFrame({"time": [1.1, 2.1, 3.5],
 2                   "temperature": [2.4, 5.2, 2.2]},
 3
 4data_name = "Temperaturmessung-001"
 5data = sdata.Data(name=data_name,
 6                  uuid=sdata.uuid_from_str(data_name),
 7                  table=df,
 8                  description="Messergebnis Temperatur")
 9data.metadata.add("time",
10                  value=None,
11                  dtype="float",
12                  unit="s",
13                  description="Zeitachse",
14                  label="time $t$")
15data.metadata.add("temperature",
16                  value=None,
17                  dtype="float",
18                  unit="°C",
19                  description="Zeitachse",
20                  label="temperature $T$")
21data.describe()
 1import matplotlib.pyplot as plt
 2fig, ax = plt.subplots()
 3
 4x_var = "time"
 5y_var = "temperature"
 6
 7x_attr = data.metadata.get(x_var)
 8y_attr = data.metadata.get(y_var)
 9
10ax.plot(data.df[x_var], data.df[y_var], label=data.name)
11ax.legend(loc="best")
12ax.set_xlabel("{0.label} [{0.unit}]".format(x_attr))
13ax.set_ylabel("{0.label} [{0.unit}]".format(y_attr))
14print("plot")