Data Management
|
Enum for dimensionality representation of data |
|
Enum for source of data |
|
Enum for distribution of data |
|
Object holding info and data about physical axis of some data |
|
Base object to store homogeneous data and metadata generated by pymodaq's objects. |
|
Specialized DataWithAxes set with source as 'raw'. |
|
Specialized DataWithAxes set with source as 'calculated'. |
|
Specialized DataWithAxes set with source as 'calculated'. |
|
Object to store all raw and calculated DataWithAxes data for later exporting, saving, sending signal... |
Axes
Created the 28/10/2022
@author: Sebastien Weber
- class pymodaq_data.data.Axis(label='', units='', data=None, index=0, scaling=None, offset=None, size=None, spread_order=0)[source]
Object holding info and data about physical axis of some data
In case the axis’s data is linear, store the info as a scale and offset else store the data
- Parameters:
label (
str) – The label of the axis, for instance ‘time’ for a temporal axisunits (
str) – The units of the data in the object, for instance ‘s’ for secondsdata (
ndarray) – A 1D ndarray holding the data of the axisindex (
int) – an integer representing the index of the Data object this axis is related toscaling (
float) – The scaling to apply to a linspace version in order to obtain the proper scalingoffset (
float) – The offset to apply to a linspace/scaled version in order to obtain the proper axissize (
int) – The size of the axis array (to be specified if data is None)spread_order (
int) – An integer needed in the case where data has a spread DataDistribution. It refers to the index along the data’s spread_index dimension
Examples
>>> axis = Axis('myaxis', units='seconds', data=np.array([1,2,3,4,5]), index=0)
- static deserialize(bytes_str)[source]
Convert bytes into an Axis object
Convert the first bytes into an Axis reading first information about the Axis
- static serialize(axis)[source]
Convert an Axis object into a bytes message together with the info to convert it back
- Parameters:
axis (
Axis)- Returns:
bytes
- Return type:
the total bytes messagetoserialize the Axis
Notes
The bytes sequence is constructed as:
serialize the axis label
serialize the axis units
serialize the axis array
serialize the axis
serialize the axis spread_order
- create_linear_data(nsteps)[source]
replace the axis data with a linear version using scaling and offset
- get_data()[source]
Convenience method to obtain the axis data (usually None because scaling and offset are used)
- Return type:
ndarray
- get_quantity()[source]
Convenience method to obtain the numerical data as a quantity array
- Return type:
Quantity
- get_scale_offset_from_data(data=None)[source]
Get the scaling and offset from the axis’s data
If data is not None, extract the scaling and offset
- Parameters:
data (
ndarray)
- property data
get/set the data of Axis
- Type:
np.ndarray
DataObjects
Created the 28/10/2022
@author: Sebastien Weber
- class pymodaq_data.data.DataBase(name, source=None, dim=None, distribution=DataDistribution.uniform, data=None, labels=None, origin='', units='', **kwargs)[source]
Base object to store homogeneous data and metadata generated by pymodaq’s objects.
To be inherited for real data
- Parameters:
name (
str) – the identifier of these datasource (
DataSource) – Enum specifying if data are raw or processed (for instance from roi)dim (
DataDim) – The identifier of the data typedistribution (
DataDistribution) – The distribution type of the data: uniform if distributed on a regular grid or spread if on specific unordered pointsdata (
List[ndarray]) – The data the object is storing. In case of Quantities, the object units attribute will be forced to the unit of this quantity, ignoring the units argument.origin (
str) – An identifier of the element where the data originated, for instance the DAQ_Viewer’s name. Used when appending DataToExport in DAQ_Scan to disintricate from which origin data comes from when scanning multiple detectors.units (
str) – A unit string identifier as specified in the UnitRegistry of the pint modulekwargs (
named parameters) – All other parameters are stored dynamically using the name/value pair. The name of these extra parameters are added into the extra_attributes attribute
- source
Enum specifying if data are raw or processed (for instance from roi)
- Type:
DataSourceorstr
- distribution
The distribution type of the data: uniform if distributed on a regular grid or spread if on specific unordered points
- Type:
- origin
An identifier of the element where the data originated, for instance the DAQ_Viewer’s name. Used when appending DataToExport in DAQ_Scan to disintricate from which origin data comes from when scanning multiple detectors.
- Type:
- shape
The shape of the underlying data
- Type:
Tuple[int]
- extra_attributes
list of string giving identifiers of the attributes added dynamically at the initialization (for instance to save extra metadata using the DataSaverLoader
- Type:
List[str]
See also
DataWithAxes,DataFromPlugins,DataRaw,DataSaverLoaderExamples
>>> import numpy as np >>> from pymodaq.utils.data import DataBase, DataSource, DataDim, DataDistribution >>> data = DataBase('mydata', source=DataSource['raw'], dim=DataDim['Data1D'], distribution=DataDistribution.uniform, data=[np.array([1.,2.,3.]), np.array([4.,5.,6.])], labels=['channel1', 'channel2'], origin='docutils code') >>> data.dim <DataDim.Data1D: 1> >>> data.source <DataSource.raw: 0> >>> data.shape (3,) >>> data.length 2 >>> data.size 3
- append(data)[source]
Append data content if the underlying arrays have the same shape and compatible units
- as_dte(name='mydte')[source]
Convenience method to wrap the DataWithAxes object into a DataToExport
- Return type:
- get_data_index(index=0)[source]
Get the data by its index in the list, same as self[index]
- Return type:
ndarray
- get_full_name()[source]
Get the data ful name including the origin attribute into the returned value
- Returns:
str
- Return type:
Examples
d0 = DataBase(name=’datafromdet0’, origin=’det0’)
- set_dim(dim)[source]
Addhoc modification of dim independantly of the real data shape, should be used with extra care
- stack_as_array(axis=0, dtype=None)[source]
Stack all data arrays in a single numpy array
- Parameters:
- Return type:
ndarray
See also
np.stack()
- units_as(units, inplace=True, context=None, **context_kwargs)[source]
Set the object units to the new one (if possible)
- value(units=None)[source]
Returns the underlying float value (of the first elt in the data list) if this data holds only a float otherwise returns a mean of the underlying data
- values(units=None)[source]
Returns the underlying float value (for each data array in the data list) if this data holds only a float otherwise returns a mean of the underlying data
- property data: List[ndarray]
get/set (and check) the data the object is storing
- Type:
List[np.ndarray]
- property distribution
the enum representing the distribution of the stored data
- Type:
- property length
The length of data. This is the length of the list containing the nd-arrays
- property shape
The shape of the nd-arrays
- property size
The size of the nd-arrays
- property source
the enum representing the source of the data
- Type:
- class pymodaq_data.data.DataCalculated(name, dim=None, distribution=DataDistribution.uniform, data=None, labels=None, origin='', units='', axes=[], nav_indexes=(), errors=None, **kwargs)[source]
Specialized DataWithAxes set with source as ‘calculated’. To be used for processed/calculated data
- class pymodaq_data.data.DataFromRoi(name, dim=None, distribution=DataDistribution.uniform, data=None, labels=None, origin='', units='', axes=[], nav_indexes=(), errors=None, **kwargs)[source]
Specialized DataWithAxes set with source as ‘calculated’. To be used for processed data from region of interest
- class pymodaq_data.data.DataRaw(name, dim=None, distribution=DataDistribution.uniform, data=None, labels=None, origin='', units='', axes=[], nav_indexes=(), errors=None, **kwargs)[source]
Specialized DataWithAxes set with source as ‘raw’. To be used for raw data
- class pymodaq.utils.data.DataActuator(*args, **kwargs)[source]
Specialized DataWithAxes set with source as ‘raw’. To be used for raw data generated by actuator plugins
- class pymodaq.utils.data.DataFromPlugins(*args, **kwargs)[source]
Specialized DataWithAxes set with source as ‘raw’. To be used for raw data generated by Detector plugins
It introduces by default to extra attributes, do_plot and do_save. Their presence can be checked in the extra_attributes list.
- Parameters:
Data Characteristics
Created the 28/10/2022
@author: Sebastien Weber
Union of Data
When exporting multiple set of Data objects, one should use a DataToExport
Created the 28/10/2022
@author: Sebastien Weber
- class pymodaq_data.data.DataToExport(name, data=[], **kwargs)[source]
Object to store all raw and calculated DataWithAxes data for later exporting, saving, sending signal…
Includes methods to retrieve data from dim, source… Stored data have a unique identifier their name. If some data is appended with an existing name, it will replace the existing data. So if you want to append data that has the same name
- Parameters:
name (
str) – The identifier of the exporting objectdata (
List[DataWithAxes]) – All the raw and calculated data to be exported
- name
- timestamp
- data
- classmethod deserialize(bytes_str)[source]
Convert bytes into a DataToExport object
Convert the first bytes into a DataToExport reading first information about the underlying data
- Return type:
- Returns:
DataToExport (
the decoded DataToExport)bytes (
the remaining bytes if any)
- static serialize(dte)[source]
Convert a DataToExport into a bytes string
- Parameters:
dte (
DataToExport)- Returns:
bytes
- Return type:
the total bytes messagetoserialize the DataToExport
Notes
The bytes sequence is constructed as:
serialize the string type: ‘DataToExport’
serialize the timestamp: float
serialize the name
serialize the list of DataWithAxes
- affect_name_to_origin_if_none()[source]
Affect self.name to all DataWithAxes children’s attribute origin if this origin is not defined
- average(other, weight)[source]
Compute the weighted average between self and other DataToExport and attributes it to self
- Parameters:
other (
DataToExport)weight (
int) – The weight the ‘other_data’ holds with respect to self
- Return type:
- get_data_from_Naxes(Naxes, deepcopy=False)[source]
Get the data matching the given number of axes
- Parameters:
Naxes (
int) – Number of axes in the DataWithAxes objects- Returns:
DataToExport
- Return type:
- get_data_from_attribute(attribute, attribute_value, deepcopy=False, sort_by_name=False)[source]
Get the data matching a given attribute value
- Parameters:
- Returns:
DataToExport
- Return type:
- get_data_from_dim(dim, deepcopy=False, sort_by_name=False)[source]
Get the data matching the given DataDim
- Returns:
DataToExport
- Return type:
- get_data_from_dims(dims, deepcopy=False, sort_by_name=False)[source]
Get the data matching the given DataDim
- Returns:
DataToExport
- Return type:
- get_data_from_full_name(full_name, deepcopy=False)[source]
Get the DataWithAxes with matching full name
- Return type:
- get_data_from_missing_attribute(attribute, deepcopy=False)[source]
Get the data matching a given attribute value
- Parameters:
- Returns:
DataToExport
- Return type:
- get_data_from_name_origin(name, origin='')[source]
Get the data matching the given name and the given origin
- Return type:
- get_data_from_sig_axes(Naxes, deepcopy=False)[source]
Get the data matching the given number of signal axes
- Parameters:
Naxes (
int) – Number of signal axes in the DataWithAxes objects- Returns:
DataToExport
- Return type:
- get_data_from_source(source, deepcopy=False, sort_by_name=False)[source]
Get the data matching the given DataSource
- Returns:
DataToExport
- Return type:
- get_data_with_naxes_lower_than(n_axes=2, deepcopy=False)[source]
Get the data with n axes lower than the given number
- Parameters:
Naxes (
int) – Number of axes in the DataWithAxes objects- Returns:
DataToExport
- Return type:
- get_full_names(dim=None)[source]
Get the ful names including the origin attribute into the returned value, eventually filtered by dim
- Parameters:
dim (
DataDim)- Returns:
list of str
- Return type:
the namesof the (filtered) DataWithAxes data constructed as :origin/name
Examples
d0 = DataWithAxes(name=’datafromdet0’, origin=’det0’)
- get_origins(dim=None)[source]
Get the origins of the underlying data into the returned value, eventually filtered by dim
- Parameters:
dim (
DataDim)- Returns:
list of str
- Return type:
the originsofthe (filtered) DataWithAxes data
Examples
d0 = DataWithAxes(name=’datafromdet0’, origin=’det0’)
- index(data)[source]
Here use a comparison to assert data is equal to one element in the list
But the __eq__ method is not checking the name while it is the main issue for elt finding Hence here I’m doing both checks
- index_from_name_origin(name, origin='')[source]
Get the index of a given DataWithAxes within the list of data
- Return type:
- merge_as_dwa(dim, name=None)[source]
attempt to merge filtered dwa into one
Only possible if all filtered dwa and underlying data have same shape
- plot(plotter_backend='matplotlib', *args, **kwargs)[source]
Call a plotter factory and its plot method over the actual data
- pop(index)[source]
return and remove the DataWithAxes referred by its index
- Parameters:
index (
int) – index as returned by self.index_from_name_origin
See also
- Return type:
- remove(dwa)[source]
Use the DataWithAxes object comparison __eq__ to retrieve the elt to remove
- Parameters:
dwa (
DataWithAxes) – The da to remove from the list
- property data: List[DataWithAxes]
get the data contained in the object
- Type:
List[DataWithAxes]