Parameter#
- class Parameter(name, label='', unit='', data_type=DataType.FLOAT, collection_type=CollectionType.SCALAR, element_indices=None)#
Bases:
BaseModel
A basic data structure that represents a single variable.
The variable can be a high-level or low-level control knob of an instrument such as the amplitude of a pulse or a control voltage; a physical quantity such as resonance frequency; or an abstract concept like the number of averages in a measurement.
Setting
combines Parameter with a numerical, boolean, or string value to represent a quantity.Create a new model by parsing and validating input data from keyword arguments.
Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.
self is explicitly positional-only to allow self as a field name.
Module:
exa.common.data.parameter
Attributes
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
Returns the parent label.
Returns the parent name.
Parameter name used as identifier
name
SI unit of the quantity, if applicable.
Data type or a tuple of datatypes that this parameter accepts and validates.
Data format that this parameter accepts and validates.
For parameters representing a single value in a collection-valued parent parameter, this field gives the indices of that value.
Methods
Attach Parameter information to a numerical array.
Build an xarray Dataset, where the only DataArray is given by results and coordinates are given by variables.
Utility for creating an element-wise parameter for a single value in a collection valued parameter.
This function is meant to behave like a BaseModel method to initialise private attributes.
Create a Setting object with given value.
Validate that given value matches the
data_type
andcollection_type
.- Parameters:
- data_type: DataType | tuple[DataType, ...]#
Data type or a tuple of datatypes that this parameter accepts and validates. One of
DataType
. Default: FLOAT.
- collection_type: CollectionType#
Data format that this parameter accepts and validates. One of
CollectionType
. Default: SCALAR.
- element_indices: int | list[int] | None#
For parameters representing a single value in a collection-valued parent parameter, this field gives the indices of that value. If populated, the
self.name
andself.label
will be updated in post init to include the indices (becoming"<parent name>__<index0>__<index1>__...__<indexN>"
and"<parent label> <indices>"
, respectively). The parent name can then be retrieved withself.parent_name
and the parent label withself.parent_label
.
- property parent_name: str | None#
Returns the parent name.
This None except in element-wise parameters where gives the name of the parent parameter.
- property parent_label: str | None#
Returns the parent label.
This None except in element-wise parameters where gives the label of the parent parameter.
- set(value)#
Create a Setting object with given value.
- static build_data_set(variables, data, attributes=None, extra_variables=None)#
Build an xarray Dataset, where the only DataArray is given by results and coordinates are given by variables. The data is reshaped to correspond to the sizes of the variables. For example,
variables = [(par_x, [1,2,3]), (par_y: [-1, -2])]
will shape the data to 3-by-2 array. If there are not enough variables to reshape the data, remaining dimensions can be given by extra_variables. For example,variables = [(par_x: [1,2,3])], extra_variables=[('y', 2)]
yields the same 3-by-2 data.'y'
will then be a “dimension without coordinate” in xarray terms.- Parameters:
variables (list[tuple[Parameter, list[Any]]]) – Coordinates of the set.
data (tuple[Parameter, list[Any] | ndarray[Any]]) – Data Parameter and associated data as a possible nested list.
attributes (dict[str, Any]) – metadata to attach to the whole Dataset.
extra_variables (list[tuple[str, int]] | None) – Valueless dimensions and their sizes.
- validate(value)#
Validate that given value matches the
data_type
andcollection_type
.
- build_data_array(data, dimensions=None, coords=None, metadata=None)#
Attach Parameter information to a numerical array.
Given an array of numerical values, returns a corresponding
xr.DataArray
instance that gets its name, units, and dimension names (unless explicitly given) from theParameter
instance.
- create_element_parameter_for(indices)#
Utility for creating an element-wise parameter for a single value in a collection valued parameter.
- model_config: ClassVar[ConfigDict] = {'extra': 'ignore', 'frozen': True, 'ser_json_inf_nan': 'constants', 'validate_assignment': True, 'validate_default': True}#
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- model_post_init(context, /)#
This function is meant to behave like a BaseModel method to initialise private attributes.
It takes context as an argument since that’s what pydantic-core passes when calling it.
- Parameters:
self (BaseModel) – The BaseModel instance.
context (Any) – The context.
- Return type:
None