mjolnir.measurements.measures#

This module provides classes for measuring things.

Functions

Id(x)

Classes

Measure(param[, delegates, live_plot])

Defines a gettable during a measurement.

MeasureSet([params])

A set of Measure s.

mjolnir.measurements.measures.Id(x)[source]#
Parameters:

x (_T)

Return type:

_T

class mjolnir.measurements.measures.Measure(param, delegates=<factory>, live_plot=True)[source]#

Bases: Generic[_T]

Defines a gettable during a measurement.

This class represents a parameter to measure during a measurement executed by handler.MeasurementHandler.measure(). Additional parameters that derive from the main parameter (through DelegateParameter) may be measured by passing them as a sequence as delegates to the constructor. delegates are always gotten after the parameter, and only their parameter’s cache is queried to avoid unnecessary instrument communication. Hence, the delegates work on the same raw data that is returned from the get call to the main parameter.

This can, for example, be used for storing processed data (i.e., like a procfn) together with the raw data.

In addition to the measurement, this class implements live plotting such that, when plot_callback is called, a plot is updated with the latest cached value.

Parameters:
delegates: Sequence[DelegateParameter]#
get(cache=False)[source]#

The parameter value.

Parameters:

cache (bool)

Return type:

_T

get_delegates(cache=True)[source]#

The delegate values, defaults to the cache.

Parameters:

cache (bool)

Return type:

list[_T]

initialize_plotting(sweeps, axs, dynamic_x_axis=False)[source]#

Set up live plotting for a measurement defined by sweeps.

Does nothing if live_plot is False.

Parameters:
  • sweeps (SweepList) – The SweepList defining the measurement sweep.

  • axs (npt.NDArray[Axes]) – The axes to plot in.

  • dynamic_x_axis (bool) – Whether the x-axis is dynamically updated to the current data range or has a static range of the setpoints. This is automatically set to True if any of the sweeps’ transforms are unequal to the identity.

Return type:

Sequence[Artist]

Notes

Todo

  • Handle direct product setpoints (sweep & sweep).

    • Could add extra x-axis

  • Plot 2d if requested and sweeps is at least 2d.

    • Could add a 1d subplot.

    • Would need to check if not too slow.

  • Plot 2d for 2d ParameterWithSetpoints?

  • Plot all parameters of a single axis (only the first one is currently selected).

    • Could add additional axis spines.

    • Would be in conflict with current multiple line plots for ‘small’ ParameterWithSetpoints.

live_plot: bool = True#
param: ParameterBase#
property plot_callback: FunctionChain#
reset_plotting()[source]#

Reset plotting so that calling plot_callback raises a RuntimeError.

property shape: tuple[int, ...]#

The shape of the result that get() returns.

property shape_delegates: list[tuple[int, ...]]#

The shape of the result that get_delegates() returns.

class mjolnir.measurements.measures.MeasureSet(params=())[source]#

Bases: set[Measure[_T]]

A set of Measure s.

Parameters:

params (Iterable[Measure | ParameterBase])

add(_MeasureSet__element)[source]#

Add an element to a set.

This has no effect if the element is already present.

property axes: list[npt.NDArray[Axes]]#
property delegates: list[DelegateParameter]#
property fig: Figure#
property full_names: list[str]#
property full_names_delegates: list[str]#
get(cache=False)[source]#

The parameter values.

Parameters:

cache (bool)

Return type:

list[_T]

get_delegates(cache=True)[source]#
Parameters:

cache (bool)

Return type:

list[_T]

initialize_plotting(sweeps, dynamic_x_axis=False, plot_style=None)[source]#

Initialize plotting for all member Measure s for which live_plot is true.

Parameters:
  • sweeps (SweepList) – The SweepList defining the measurement sweep.

  • dynamic_x_axis (bool) – Whether the x-axis is dynamically updated to the current data range or has a static range of the setpoints.

  • plot_style – A matplotlib plot style to use for the plotting.

property params: list[ParameterBase]#

All parameters of member Measure s.

property plot_callback: Callable[[int, int], None]#
reset_plotting()[source]#

Reset plotting so that calling :prop:`plot_callback` raises a RuntimeError.

property shapes: list[tuple[int, ...]]#

The shapes of the result that get() returns.

property shapes_delegates: list[tuple[int, ...]]#

The shapes of the result that get_delegates() returns.

update(*s)[source]#

Update a set with the union of itself and others.