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

model_config

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

parent_label

Returns the parent label.

parent_name

Returns the parent name.

name

Parameter name used as identifier

label

name

unit

SI unit of the quantity, if applicable.

data_type

Data type or a tuple of datatypes that this parameter accepts and validates.

collection_type

Data format that this parameter accepts and validates.

element_indices

For parameters representing a single value in a collection-valued parent parameter, this field gives the indices of that value.

Methods

build_data_array

Attach Parameter information to a numerical array.

build_data_set

Build an xarray Dataset, where the only DataArray is given by results and coordinates are given by variables.

create_element_parameter_for

Utility for creating an element-wise parameter for a single value in a collection valued parameter.

model_post_init

This function is meant to behave like a BaseModel method to initialise private attributes.

set

Create a Setting object with given value.

validate

Validate that given value matches the data_type and collection_type.

Parameters:
name: str#

Parameter name used as identifier

label: str#

name

Type:

Parameter label used as pretty identifier for display purposes. Default

unit: str#

SI unit of the quantity, if applicable.

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 and self.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 with self.parent_name and the parent label with self.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.

Parameters:

value (Any) –

Return type:

Setting

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:
validate(value)#

Validate that given value matches the data_type and collection_type.

Parameters:

value (Any) –

Return type:

bool

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 the Parameter instance.

Parameters:
  • data (ndarray) – numerical values

  • dimensions (list[Hashable]) – names of the dimensions of data

  • coords (dict[Hashable, Any]) – coordinates labeling the dimensions of data

  • metadata (dict[str, Any]) – additional xr.DataArray.attrs

Returns:

corresponding DataArray

Return type:

DataArray

create_element_parameter_for(indices)#

Utility for creating an element-wise parameter for a single value in a collection valued parameter.

Parameters:

indices (int | list[int]) – The indices in the collection for which to create the element-wise parameter.

Returns:

The element-wise parameter.

Raises:

UnprocessableEntityError – If self is not collection-valued.

Return type:

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