Parameter#

class Parameter(name, label=None, unit=None, data_type=None, collection_type=None, element_indices=None, _parent_name=None, _parent_label=None)#

Bases: object

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.

Module: exa.common.data.parameter

Attributes

collection_type

Data format that this parameter accepts and validates.

data_type

Data type or a tuple of datatypes 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.

label

name

parent_label

Returns the parent label.

parent_name

Returns the parent name.

unit

SI unit of the quantity, if applicable.

name

Parameter name used as identifier

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.

copy

Return a copy of the parameter, where attributes defined in attributes are replaced.

create_element_parameter_for

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

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 = None#

name

Type:

Parameter label used as pretty identifier for display purposes. Default

unit: str = None#

SI unit of the quantity, if applicable.

data_type: DataType | Tuple[DataType, ...] = None#

Data type or a tuple of datatypes that this parameter accepts and validates. One of DataType. Default: NUMBER.

collection_type: CollectionType = None#

Data format that this parameter accepts and validates. One of CollectionType. Default: SCALAR.

element_indices: int | list[int] | None = 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.

Args:

variables: Coordinates of the set. data: Data Parameter and associated data as a possible nested list. attributes: metadata to attach to the whole Dataset. extra_variables: Valueless dimensions and their sizes.

Parameters:
validate(value)#

Validate that given value matches the data_type and collection_type.

Parameters:

value (Any) –

Return type:

bool

copy(**attributes)#

Return a copy of the parameter, where attributes defined in attributes are replaced.

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:

InvalidParameterValueError – If self is not collection-valued.

Return type:

Parameter