SDF.data_model package

class AnonymousParameterSet(items: typing.Optional[typing.Iterable[SDF.data_model.parameter.ParameterType]] = None)[source]

Bases: SDF.data_model.element_set.ElementSet[SDF.data_model.parameter.ParameterType]

Create an empty ElementSet.

Parameters
  • key_func – Function to get a string key from an item (e.g. lambda item: item.name)

  • check_func – Function to check if an item is valid for this ElementSet (e.g. lambda item: hasattr(item, ‘name’) or lambda item: isinstance(item, …)). If it returns True, everything is fine. If it returns False, a default exception is raised. To raise a more specific exception, raise an exception instead of returning False.

add(item: T, as_first: bool = False)None

Add an item to the collection. If as_first, the item is added at the beginning, else at the end.

add_from_structure(structure: typing.Sequence, parse_names_from_dicts: bool = False)[source]
clear()None

Like dict.clear

copy()SDF.data_model.element_set.ElementSet[T]

Return a shallow copy of this collection

items()typing.ItemsView[str, T]

Like dict.items

keys()typing.KeysView[str]

Like dict.keys

pop(key: typing.Optional[typing.Union[str, int]] = None)T

Like dict.pop if key is str, else like list.pop

remove(item: typing.Union[str, T])None

Remove the item. If key is a string, remove the item specified by key

update(*items: typing.Union[T, typing.Iterable[T]])None

Like set.update

values()typing.ValuesView[T]

Like dict.values

class ArrayData1D(data: numpy.ndarray, try_hex_transformation: bool = False)[source]

Bases: SDF.data_model.abstract.Data

Wraps a 1-dimensional Numpy ndarray, represents SDF <data> tags of dataset type ‘sc’

property data

The wrapped array

static from_linearly_transformed_array(array: numpy.ndarray, multiplier: float, offset: float)SDF.data_model.array_data_1d.ArrayData1D[source]

Instantiate from a non-negative integer array with multiplier and offset

classmethod from_xml_element(element: xml.etree.ElementTree.Element)SDF.data_model.array_data_1d.ArrayData1D[source]

Generates an instance of this class from an Element

to_xml_element()xml.etree.ElementTree.Element[source]

Returns an Element object that contains all information needed to export this object as XML.

property type_for_xml

The ‘type’ attribute the wrapping <dataset> element has to have

class ArrayData2D(data: numpy.ndarray)[source]

Bases: SDF.data_model.abstract.Data

Wraps a 2-dimensional Numpy ndarray, represents SDF <data> elements of dataset type ‘mc’

property data

The wrapped array

classmethod from_xml_element(element: xml.etree.ElementTree.Element)SDF.data_model.array_data_2d.ArrayData2D[source]

Generates an instance of this class from an Element

to_xml_element()xml.etree.ElementTree.Element[source]

Returns an Element object that contains all information needed to export this object as XML.

property type_for_xml

The ‘type’ attribute the wrapping <dataset> element has to have

class ArrayDataset1D(name: typing.Union[str, SDF.data_model.name.NameElement], data: typing.Union[SDF.data_model.array_data_1d.ArrayData1D, numpy.ndarray], *, unit: typing.Optional[str] = None, owner: typing.Optional[typing.Union[str, SDF.data_model.owner.Owner]] = None, date: typing.Optional[typing.Union[datetime.datetime, SDF.data_model.date.Date]] = None, comment: typing.Optional[typing.Union[str, SDF.data_model.comment.Comment]] = None, samples: typing.Optional[typing.Iterable[SDF.data_model.sample.Sample]] = None, parameters: typing.Optional[typing.Iterable[SDF.data_model.parameter.ParameterType]] = None, instruments: typing.Optional[typing.Iterable[SDF.data_model.instrument.Instrument]] = None)[source]

Bases: SDF.data_model.dataset.Dataset

Represents an SDF <dataset> element

property comment
property data

Data array

property date
classmethod from_xml_element(element: xml.etree.ElementTree.Element)SDF.data_model.array_dataset_1d.ArrayDataset1D[source]

Reads the ‘type’ attribute of a <dataset type=…> element, delegates to the associated Dataset subclass

property instruments
property name
property owner
property parameters
property samples
to_xml_element()xml.etree.ElementTree.Element[source]

Returns an Element object that contains all information needed to export this object as XML.

property unit

Unit of data

class ArrayDataset2D(name: typing.Union[str, SDF.data_model.name.NameElement], data: typing.Union[SDF.data_model.array_data_2d.ArrayData2D, numpy.ndarray], *, owner: typing.Optional[typing.Union[str, SDF.data_model.owner.Owner]] = None, date: typing.Optional[typing.Union[datetime.datetime, SDF.data_model.date.Date]] = None, comment: typing.Optional[typing.Union[str, SDF.data_model.comment.Comment]] = None, samples: typing.Optional[typing.Iterable[SDF.data_model.sample.Sample]] = None, parameters: typing.Optional[typing.Iterable[SDF.data_model.parameter.ParameterType]] = None, instruments: typing.Optional[typing.Iterable[SDF.data_model.instrument.Instrument]] = None)[source]

Bases: SDF.data_model.dataset.Dataset

Represents an SDF <dataset> element

property comment
property data
property date
classmethod from_xml_element(element: xml.etree.ElementTree.Element)SDF.data_model.array_dataset_2d.ArrayDataset2D[source]

Reads the ‘type’ attribute of a <dataset type=…> element, delegates to the associated Dataset subclass

property instruments
property name
property owner
property parameters
property samples
to_xml_element()xml.etree.ElementTree.Element[source]

Returns an Element object that contains all information needed to export this object as XML.

class Comment(comment: str)[source]

Bases: SDF.data_model.abstract.XMLWritable

Represents an SDF <comment> element

property comment
classmethod from_xml_element(element: xml.etree.ElementTree.Element)SDF.data_model.comment.Comment[source]

Generates an instance of this class from an Element

to_xml_element()xml.etree.ElementTree.Element[source]

Returns an Element object that contains all information needed to export this object as XML.

class Data[source]

Bases: SDF.data_model.abstract.XMLWritable

Abstract class for all SDF objects representing <data> elements

abstract classmethod from_xml_element(element: xml.etree.ElementTree.Element)SDF.data_model.abstract.XMLWritable

Generates an instance of this class from an Element

abstract to_xml_element()xml.etree.ElementTree.Element

Returns an Element object that contains all information needed to export this object as XML.

abstract property type_for_xml

The ‘type’ attribute the wrapping <dataset> element has to have

class Dataset(name: typing.Union[str, SDF.data_model.name.NameElement], *, owner: typing.Optional[typing.Union[str, SDF.data_model.owner.Owner]] = None, date: typing.Optional[typing.Union[datetime.datetime, SDF.data_model.date.Date]] = None, comment: typing.Optional[typing.Union[str, SDF.data_model.comment.Comment]] = None, samples: typing.Optional[typing.Union[typing.Iterable[SDF.data_model.sample.Sample], typing.Mapping[str, str]]] = None, parameters: typing.Optional[typing.Iterable[SDF.data_model.parameter.ParameterType]] = None, instruments: typing.Optional[typing.Iterable[SDF.data_model.instrument.Instrument]] = None)[source]

Bases: SDF.data_model.sdf_object.SDFObject, SDF.data_model.abstract.XMLWritable

Abstract class. Dataset implementations must inherit from it.

property comment
property date
static from_xml_element(element: xml.etree.ElementTree.Element)SDF.data_model.dataset.Dataset[source]

Reads the ‘type’ attribute of a <dataset type=…> element, delegates to the associated Dataset subclass

property instruments
property name
property owner
property parameters
property samples
abstract to_xml_element()xml.etree.ElementTree.Element

Returns an Element object that contains all information needed to export this object as XML.

class Date(date: datetime.datetime, dateformat: typing.Optional[str] = None)[source]

Bases: SDF.data_model.abstract.XMLWritable

Wraps a datetime.datetime object. Represents an SDF <date> element.

classmethod from_xml_element(element: xml.etree.ElementTree.Element)SDF.data_model.date.Date[source]

Generates an instance of this class from an Element

to_xml_element()xml.etree.ElementTree.Element[source]

Returns an Element object that contains all information needed to export this object as XML.

class ElementSet(key_func: typing.Callable[T, str], check_func: typing.Callable[T, bool], items: typing.Optional[typing.Iterable[T]] = None)[source]

Bases: typing.Generic[typing.T]

Strictly typed collection that mostly resembles an ordered set, but borrows some behavior of list and dict.

Items must be representable by a str key (like item.name), allowing dict-like access.

Create an empty ElementSet.

Parameters
  • key_func – Function to get a string key from an item (e.g. lambda item: item.name)

  • check_func – Function to check if an item is valid for this ElementSet (e.g. lambda item: hasattr(item, ‘name’) or lambda item: isinstance(item, …)). If it returns True, everything is fine. If it returns False, a default exception is raised. To raise a more specific exception, raise an exception instead of returning False.

add(item: T, as_first: bool = False)None[source]

Add an item to the collection. If as_first, the item is added at the beginning, else at the end.

clear()None[source]

Like dict.clear

copy()SDF.data_model.element_set.ElementSet[T][source]

Return a shallow copy of this collection

items()typing.ItemsView[str, T][source]

Like dict.items

keys()typing.KeysView[str][source]

Like dict.keys

pop(key: typing.Optional[typing.Union[str, int]] = None)T[source]

Like dict.pop if key is str, else like list.pop

remove(item: typing.Union[str, T])None[source]

Remove the item. If key is a string, remove the item specified by key

update(*items: typing.Union[T, typing.Iterable[T]])None[source]

Like set.update

values()typing.ValuesView[T][source]

Like dict.values

class ImageData(data: PIL.Image.Image)[source]

Bases: SDF.data_model.abstract.Data

Wraps a PIL Image. Represents an SDF <data> element of type ‘img’.

static base64_to_image(base64_str: str)PIL.Image.Image[source]

Read base64-encoded PNG image

property data
classmethod from_xml_element(element: xml.etree.ElementTree.Element)SDF.data_model.image_data.ImageData[source]

Generates an instance of this class from an Element

static image_to_base64(image: PIL.Image.Image)str[source]

Return base64-encoded PNG representation of image

to_xml_element()xml.etree.ElementTree.Element[source]

Returns an Element object that contains all information needed to export this object as XML.

property type_for_xml

The ‘type’ attribute the wrapping <dataset> element has to have

class ImageDataset(name: typing.Union[str, SDF.data_model.name.NameElement], data: typing.Union[SDF.data_model.image_data.ImageData, PIL.Image.Image], *, owner: typing.Optional[typing.Union[str, SDF.data_model.owner.Owner]] = None, date: typing.Optional[typing.Union[datetime.datetime, SDF.data_model.date.Date]] = None, comment: typing.Optional[typing.Union[str, SDF.data_model.comment.Comment]] = None, samples: typing.Optional[typing.Iterable[SDF.data_model.sample.Sample]] = None, parameters: typing.Optional[typing.Iterable[SDF.data_model.parameter.ParameterType]] = None, instruments: typing.Optional[typing.Iterable[SDF.data_model.instrument.Instrument]] = None)[source]

Bases: SDF.data_model.dataset.Dataset

Represents an SDF <dataset> element

property comment
property data
property date
classmethod from_xml_element(element: xml.etree.ElementTree.Element)SDF.data_model.image_dataset.ImageDataset[source]

Reads the ‘type’ attribute of a <dataset type=…> element, delegates to the associated Dataset subclass

property instruments
property name
property owner
property parameters
property samples
to_xml_element()xml.etree.ElementTree.Element[source]

Returns an Element object that contains all information needed to export this object as XML.

class Instrument(name: typing.Optional[typing.Union[str, SDF.data_model.name.NameElement]] = None, parameters: typing.Optional[typing.Iterable[SDF.data_model.parameter.ParameterType]] = None)[source]

Bases: SDF.data_model.parameter.AnonymousParameterSet, SDF.data_model.abstract.XMLWritable

Represents an SDF <instrument> element

Create an empty ElementSet.

Parameters
  • key_func – Function to get a string key from an item (e.g. lambda item: item.name)

  • check_func – Function to check if an item is valid for this ElementSet (e.g. lambda item: hasattr(item, ‘name’) or lambda item: isinstance(item, …)). If it returns True, everything is fine. If it returns False, a default exception is raised. To raise a more specific exception, raise an exception instead of returning False.

add(item: T, as_first: bool = False)None

Add an item to the collection. If as_first, the item is added at the beginning, else at the end.

add_from_structure(structure: typing.Sequence, parse_names_from_dicts: bool = False)
clear()None

Like dict.clear

copy()SDF.data_model.element_set.ElementSet[T]

Return a shallow copy of this collection

classmethod from_xml_element(element: xml.etree.ElementTree.Element)SDF.data_model.instrument.Instrument[source]

Generates an instance of this class from an Element

items()typing.ItemsView[str, T]

Like dict.items

keys()typing.KeysView[str]

Like dict.keys

property name
pop(key: typing.Optional[typing.Union[str, int]] = None)T

Like dict.pop if key is str, else like list.pop

remove(item: typing.Union[str, T])None

Remove the item. If key is a string, remove the item specified by key

to_xml_element()xml.etree.ElementTree.Element[source]

Returns an Element object that contains all information needed to export this object as XML.

update(*items: typing.Union[T, typing.Iterable[T]])None

Like set.update

values()typing.ValuesView[T]

Like dict.values

class InstrumentSet(items: typing.Optional[typing.Iterable[SDF.data_model.instrument.Instrument]] = None)[source]

Bases: SDF.data_model.element_set.ElementSet[SDF.data_model.instrument.Instrument]

Extends ElementSet[Instrument] to allow adding parameters more intuitively

Create an empty ElementSet.

Parameters
  • key_func – Function to get a string key from an item (e.g. lambda item: item.name)

  • check_func – Function to check if an item is valid for this ElementSet (e.g. lambda item: hasattr(item, ‘name’) or lambda item: isinstance(item, …)). If it returns True, everything is fine. If it returns False, a default exception is raised. To raise a more specific exception, raise an exception instead of returning False.

add(item: T, as_first: bool = False)None

Add an item to the collection. If as_first, the item is added at the beginning, else at the end.

clear()None

Like dict.clear

copy()SDF.data_model.element_set.ElementSet[T]

Return a shallow copy of this collection

items()typing.ItemsView[str, T]

Like dict.items

keys()typing.KeysView[str]

Like dict.keys

pop(key: typing.Optional[typing.Union[str, int]] = None)T

Like dict.pop if key is str, else like list.pop

remove(item: typing.Union[str, T])None

Remove the item. If key is a string, remove the item specified by key

update(*items: typing.Union[T, typing.Iterable[T]])None

Like set.update

values()typing.ValuesView[T]

Like dict.values

class Name(name: str)[source]

Bases: object

Represents an SDF <name> element

property name
class NameElement(name: str)[source]

Bases: SDF.data_model.name.Name, SDF.data_model.abstract.XMLWritable

classmethod from_xml_element(element: xml.etree.ElementTree.Element)SDF.data_model.name.NameElement[source]

Generates an instance of this class from an Element

property name
to_xml_element()xml.etree.ElementTree.Element[source]

Returns an Element object that contains all information needed to export this object as XML.

class Owner(name: str)[source]

Bases: SDF.data_model.abstract.XMLWritable

Represents an SDF <owner> element

classmethod from_xml_element(element: xml.etree.ElementTree.Element)SDF.data_model.owner.Owner[source]

Generates an instance of this class from an Element

to_xml_element()xml.etree.ElementTree.Element[source]

Returns an Element object that contains all information needed to export this object as XML.

class Parameter(name: typing.Union[str, SDF.data_model.name.Name], value: typing.Any, unit: typing.Optional[str] = None)[source]

Bases: SDF.data_model.parameter.ParameterType

Represents a single-valued SDF <par> element

classmethod from_xml_element(element: xml.etree.ElementTree.Element)SDF.data_model.parameter.Parameter[source]

Generates an instance of this class from an Element

property name
property parsed_value

Try to parse self.value as a Python literal (e.g. int, float, list, tuple, str, bytes)

to_xml_element()xml.etree.ElementTree.Element[source]

Returns an Element object that contains all information needed to export this object as XML.

class ParameterSet(name: typing.Union[str, SDF.data_model.name.Name], items: typing.Optional[typing.Iterable[SDF.data_model.parameter.ParameterType]] = None)[source]

Bases: SDF.data_model.parameter.AnonymousParameterSet, SDF.data_model.parameter.ParameterType

Create an empty ElementSet.

Parameters
  • key_func – Function to get a string key from an item (e.g. lambda item: item.name)

  • check_func – Function to check if an item is valid for this ElementSet (e.g. lambda item: hasattr(item, ‘name’) or lambda item: isinstance(item, …)). If it returns True, everything is fine. If it returns False, a default exception is raised. To raise a more specific exception, raise an exception instead of returning False.

add(item: T, as_first: bool = False)None

Add an item to the collection. If as_first, the item is added at the beginning, else at the end.

add_from_structure(structure: typing.Sequence, parse_names_from_dicts: bool = False)
clear()None

Like dict.clear

copy()SDF.data_model.parameter.ParameterSet[source]

Return a shallow copy of this collection

classmethod from_xml_element(element: xml.etree.ElementTree.Element)SDF.data_model.parameter.ParameterSet[source]

Generates an instance of this class from an Element

items()typing.ItemsView[str, T]

Like dict.items

keys()typing.KeysView[str]

Like dict.keys

property name
pop(key: typing.Optional[typing.Union[str, int]] = None)T

Like dict.pop if key is str, else like list.pop

remove(item: typing.Union[str, T])None

Remove the item. If key is a string, remove the item specified by key

to_xml_element()xml.etree.ElementTree.Element[source]

Returns an Element object that contains all information needed to export this object as XML.

update(*items: typing.Union[T, typing.Iterable[T]])None

Like set.update

values()typing.ValuesView[T]

Like dict.values

class ParameterType[source]

Bases: SDF.data_model.abstract.XMLWritable

static from_xml_element(element: xml.etree.ElementTree.Element)SDF.data_model.parameter.ParameterType[source]

Generates an instance of this class from an Element

abstract to_xml_element()xml.etree.ElementTree.Element

Returns an Element object that contains all information needed to export this object as XML.

class SDFObject(name: typing.Union[str, SDF.data_model.name.NameElement], *, owner: typing.Optional[typing.Union[str, SDF.data_model.owner.Owner]] = None, date: typing.Optional[typing.Union[datetime.datetime, SDF.data_model.date.Date]] = None, comment: typing.Optional[typing.Union[str, SDF.data_model.comment.Comment]] = None, samples: typing.Optional[typing.Union[typing.Iterable[SDF.data_model.sample.Sample], typing.Mapping[str, str]]] = None, parameters: typing.Optional[typing.Iterable[SDF.data_model.parameter.ParameterType]] = None, instruments: typing.Optional[typing.Iterable[SDF.data_model.instrument.Instrument]] = None)[source]

Bases: object

Superclass for datasets and workspaces

property comment
property date
property instruments
property name
property owner
property parameters
property samples
class Sample(name: typing.Union[str, SDF.data_model.name.NameElement], comment: typing.Optional[typing.Union[str, SDF.data_model.comment.Comment]] = None)[source]

Bases: SDF.data_model.abstract.XMLWritable

Represents an SDF <sample> element

property comment
classmethod from_xml_element(element: xml.etree.ElementTree.Element)SDF.data_model.sample.Sample[source]

Generates an instance of this class from an Element

property name
to_xml_element()xml.etree.ElementTree.Element[source]

Returns an Element object that contains all information needed to export this object as XML.

class SampleSet(items: typing.Optional[typing.Iterable[SDF.data_model.sample.Sample]] = None)[source]

Bases: SDF.data_model.element_set.ElementSet[SDF.data_model.sample.Sample]

Behaves like Dict[str, str], where the keys are sample names and the values are the associated comments

Create an empty ElementSet.

Parameters
  • key_func – Function to get a string key from an item (e.g. lambda item: item.name)

  • check_func – Function to check if an item is valid for this ElementSet (e.g. lambda item: hasattr(item, ‘name’) or lambda item: isinstance(item, …)). If it returns True, everything is fine. If it returns False, a default exception is raised. To raise a more specific exception, raise an exception instead of returning False.

add(item: T, as_first: bool = False)None

Add an item to the collection. If as_first, the item is added at the beginning, else at the end.

clear()None

Like dict.clear

copy()SDF.data_model.element_set.ElementSet[T]

Return a shallow copy of this collection

items()typing.ItemsView[str, T]

Like dict.items

keys()typing.KeysView[str]

Like dict.keys

pop(key: typing.Optional[typing.Union[str, int]] = None)T

Like dict.pop if key is str, else like list.pop

remove(item: typing.Union[str, T])None

Remove the item. If key is a string, remove the item specified by key

update(*items: typing.Union[T, typing.Iterable[T]])None

Like set.update

values()typing.ValuesView[T]

Like dict.values

class SourceParameters(converter_name: typing.Optional[str] = None, source_file: typing.Optional[str] = None, source_file_type: typing.Optional[str] = None)[source]

Bases: SDF.data_model.parameter.ParameterSet

Represents an <par name=”source-of-sdf-file”> element. Carries information about the origin of the SDF file.

Create an empty ElementSet.

Parameters
  • key_func – Function to get a string key from an item (e.g. lambda item: item.name)

  • check_func – Function to check if an item is valid for this ElementSet (e.g. lambda item: hasattr(item, ‘name’) or lambda item: isinstance(item, …)). If it returns True, everything is fine. If it returns False, a default exception is raised. To raise a more specific exception, raise an exception instead of returning False.

add(item: T, as_first: bool = False)None

Add an item to the collection. If as_first, the item is added at the beginning, else at the end.

add_from_structure(structure: typing.Sequence, parse_names_from_dicts: bool = False)
clear()None

Like dict.clear

copy()SDF.data_model.parameter.ParameterSet

Return a shallow copy of this collection

classmethod from_xml_element(element: xml.etree.ElementTree.Element)SDF.data_model.parameter.ParameterSet

Generates an instance of this class from an Element

items()typing.ItemsView[str, T]

Like dict.items

keys()typing.KeysView[str]

Like dict.keys

property name
pop(key: typing.Optional[typing.Union[str, int]] = None)T

Like dict.pop if key is str, else like list.pop

remove(item: typing.Union[str, T])None

Remove the item. If key is a string, remove the item specified by key

to_xml_element()xml.etree.ElementTree.Element

Returns an Element object that contains all information needed to export this object as XML.

update(*items: typing.Union[T, typing.Iterable[T]])None

Like set.update

values()typing.ValuesView[T]

Like dict.values

class Workspace(name: typing.Union[str, SDF.data_model.name.NameElement], *, owner: typing.Optional[typing.Union[str, SDF.data_model.owner.Owner]] = None, date: typing.Optional[typing.Union[datetime.datetime, SDF.data_model.date.Date]] = None, comment: typing.Optional[typing.Union[str, SDF.data_model.comment.Comment]] = None, samples: typing.Optional[typing.Iterable[SDF.data_model.sample.Sample]] = None, parameters: typing.Optional[typing.Iterable[SDF.data_model.parameter.ParameterType]] = None, instruments: typing.Optional[typing.Iterable[SDF.data_model.instrument.Instrument]] = None, datasets: typing.Optional[typing.Iterable[SDF.data_model.dataset.Dataset]] = None, workspaces: typing.Optional[typing.Iterable[SDF.data_model.workspace.Workspace]] = None)[source]

Bases: SDF.data_model.sdf_object.SDFObject, SDF.data_model.abstract.XMLWritable

Represents an SDF <workspace> element

property comment
property datasets
property date
classmethod from_xml_element(element: xml.etree.ElementTree.Element)SDF.data_model.workspace.Workspace[source]

Generates an instance of this class from an Element

property instruments
property name
property owner
property parameters
property samples
to_xml_element()xml.etree.ElementTree.Element[source]

Returns an Element object that contains all information needed to export this object as XML.

property workspaces
class XMLWritable[source]

Bases: abc.ABC

Abstract class for all SDF objects that are directly mappable to XML elements

abstract classmethod from_xml_element(element: xml.etree.ElementTree.Element)SDF.data_model.abstract.XMLWritable[source]

Generates an instance of this class from an Element

abstract to_xml_element()xml.etree.ElementTree.Element[source]

Returns an Element object that contains all information needed to export this object as XML.