labcore.measurement.record#

Module Attributes

ds

shorter notation for constructing DataSpec objects

DataSpecFromTupleType

The type for creating a ds from a tuple (i.e., what can be passed to the constructor of DataSpec)

DataSpecFromDictType

The type for creating a ds from a dict (i.e., what can be passed to the constructor of DataSpec as keywords)

DataSpecCreationType

The type from which we can create a DataSpec.

Functions

combine_data_specs(*specs)

Create a tuple of DataSpecs from the inputs.

data_specs_label(*dspecs)

Create a readable label for multiple data specs.

dep(name[, depends_on, unit, type])

Create a the spec for a dependent parameter.

dependent(name[, depends_on, unit, type])

Create a the spec for a dependent parameter.

get_parameter(param)

indep(name[, unit, type])

Create a the spec for an independent parameter.

independent(name[, unit, type])

Create a the spec for an independent parameter.

make_data_spec(value)

Instantiate a DataSpec object.

make_data_specs(*specs)

Create a tuple of DataSpec instances.

produces_record(obj)

Check if obj is annotated to generate records.

record_as(obj, *specs)

Annotate produced data as records.

recording(*data_specs)

Returns a decorator that allows adding data parameter specs to a function.

Classes

DataSpec(name[, depends_on, type, unit])

Specification for data parameters to be recorded.

DataType(value)

Valid options for data types used in DataSpec

FunctionToRecords(func, *data_specs)

A wrapper that converts a function return to a record.

IteratorToRecords(iterable, *data_specs)

A wrapper that converts the iteration values to records.

ds

shorter notation for constructing DataSpec objects

class labcore.measurement.record.DataSpec(name: str, depends_on: None | List[str] | Tuple[str] = None, type: str | DataType = 'scalar', unit: str = '')[source]#

Bases: object

Specification for data parameters to be recorded.

copy() DataSpec[source]#

return a deep copy of the DataSpec instance.

depends_on: None | List[str] | Tuple[str] = None#

dependencies. if None, it is independent.

name: str#

name of the parameter

type: str | DataType = 'scalar'#

information about data format

unit: str = ''#

physical unit of the data

labcore.measurement.record.DataSpecCreationType#

The type from which we can create a DataSpec.

alias of str | Tuple[str, None | List[str] | Tuple[str], str, str] | Dict[str, str | None | List[str] | Tuple[str]] | DataSpec

labcore.measurement.record.DataSpecFromDictType#

The type for creating a ds from a dict (i.e., what can be passed to the constructor of DataSpec as keywords)

alias of Dict[str, str | None | List[str] | Tuple[str]]

labcore.measurement.record.DataSpecFromTupleType#

The type for creating a ds from a tuple (i.e., what can be passed to the constructor of DataSpec)

alias of Tuple[str, None | List[str] | Tuple[str], str, str]

class labcore.measurement.record.DataType(value)[source]#

Bases: Enum

Valid options for data types used in DataSpec

array = 'array'#

multi-valued data. typically numpy-arrays.

scalar = 'scalar'#

scalar (single-valued) data. typically numeric, but also bool, etc.

class labcore.measurement.record.FunctionToRecords(func, *data_specs)[source]#

Bases: object

A wrapper that converts a function return to a record.

get_data_specs()[source]#
using(*args, **kwargs) FunctionToRecords[source]#

Set the default positional and keyword arguments that will be used when the function is called.

Returns:

a copy of the object. This is to allow setting different defaults to multiple uses of the function.

class labcore.measurement.record.IteratorToRecords(iterable: Iterable, *data_specs: str | Tuple[str, None | List[str] | Tuple[str], str, str] | Dict[str, str | None | List[str] | Tuple[str]] | DataSpec)[source]#

Bases: object

A wrapper that converts the iteration values to records.

get_data_specs()[source]#
labcore.measurement.record.combine_data_specs(*specs: DataSpec) Tuple[DataSpec, ...][source]#

Create a tuple of DataSpecs from the inputs. Removes duplicates.

labcore.measurement.record.data_specs_label(*dspecs: DataSpec) str[source]#

Create a readable label for multiple data specs.

Format:

{data_name_1 (dep_1, dep_2), data_name_2 (dep_3), etc.}

Parameters:

dspecs – data specs as positional arguments.

Returns:

label as string.

labcore.measurement.record.dep(name: str, depends_on: List[str] = [], unit: str = '', type: str = 'scalar')#

Create a the spec for a dependent parameter. All arguments are forwarded to the DataSpec constructor. depends_on may not be set to None.

labcore.measurement.record.dependent(name: str, depends_on: List[str] = [], unit: str = '', type: str = 'scalar')[source]#

Create a the spec for a dependent parameter. All arguments are forwarded to the DataSpec constructor. depends_on may not be set to None.

labcore.measurement.record.ds#

shorter notation for constructing DataSpec objects

labcore.measurement.record.get_parameter(param: Parameter)[source]#
labcore.measurement.record.indep(name: str, unit: str = '', type: str = 'scalar') DataSpec#

Create a the spec for an independent parameter. All arguments are forwarded to the DataSpec constructor. depends_on is set to None.

labcore.measurement.record.independent(name: str, unit: str = '', type: str = 'scalar') DataSpec[source]#

Create a the spec for an independent parameter. All arguments are forwarded to the DataSpec constructor. depends_on is set to None.

labcore.measurement.record.make_data_spec(value: str | Tuple[str, None | List[str] | Tuple[str], str, str] | Dict[str, str | None | List[str] | Tuple[str]] | DataSpec) DataSpec[source]#

Instantiate a DataSpec object.

Parameters:

value

May be one of the following with the following behavior:

  • A string create a dependent with name given by the string

  • A tuple of values that can be used to pass to the constructor of DataSpec

  • A dictionary entries of which will be passed as keyword arguments to the constructor of DataSpec

  • A DataSpec instance

labcore.measurement.record.make_data_specs(*specs: str | Tuple[str, None | List[str] | Tuple[str], str, str] | Dict[str, str | None | List[str] | Tuple[str]] | DataSpec) Tuple[DataSpec, ...][source]#

Create a tuple of DataSpec instances.

Parameters:

specs – will be passed individually to make_data_spec()

labcore.measurement.record.produces_record(obj: Any) bool[source]#

Check if obj is annotated to generate records.

labcore.measurement.record.record_as(obj: Callable | Iterable | Iterator, *specs: str | Tuple[str, None | List[str] | Tuple[str], str, str] | Dict[str, str | None | List[str] | Tuple[str]] | DataSpec)[source]#

Annotate produced data as records.

Parameters:
  • obj – a function that returns data or an iterable/iterator that produces data at each iteration step

  • specs – specs for the data produced (see make_data_specs())

labcore.measurement.record.recording(*data_specs: str | Tuple[str, None | List[str] | Tuple[str], str, str] | Dict[str, str | None | List[str] | Tuple[str]] | DataSpec) Callable[source]#

Returns a decorator that allows adding data parameter specs to a function.