Skip to content

Measure

This module contains the base classes for making measurements with a device.

ATTRIBUTE DESCRIPTION
MAX_LEN

maximum length of data buffer

TYPE: int

CLASS DESCRIPTION
Measurer

Base class for maker tools

Program

Base Program template

ProgramDetails

ProgramDetails dataclass represents the set of inputs, default values, truncated docstring and tooltip of a program class

Documentation last updated: 2025-02-22

Measurer

Measurer(*, verbose: bool = False, **kwargs)

Base class for maker tools.

ATTRIBUTE DESCRIPTION
buffer

data buffer for the device

TYPE: deque

buffer_df

data buffer as a DataFrame

TYPE: DataFrame

records

records for the device

TYPE: deque

records_df

records as a DataFrame

TYPE: DataFrame

record_event

event for recording data

TYPE: Event

program

program to run

TYPE: Program

runs

dictionary of runs

TYPE: dict

n_runs

number of runs

TYPE: int

connection_details

connection details for the device

TYPE: dict

device

device object that communicates with physical tool

TYPE: Device

flags

flags for the class

TYPE: SimpleNamespace[str, bool]

is_busy

whether the device is busy

TYPE: bool

is_connected

whether the device is connected

TYPE: bool

verbose

verbosity of class

TYPE: bool

METHOD DESCRIPTION
connect

connect to the device

disconnect

disconnect from the device

resetFlags

reset all flags to class attribute _default_flags

shutdown

shutdown procedure for tool

Initialize Measurer class

PARAMETER DESCRIPTION
verbose

verbosity of class. Defaults to False.

TYPE: bool DEFAULT: False

buffer_df property

buffer_df: DataFrame

Data buffer as a DataFrame

connection_details property

connection_details: dict

Connection details for the device

is_busy property

is_busy: bool

Whether the device is busy

is_connected property

is_connected: bool

Whether the device is connected

records_df property

records_df: DataFrame

Records as a DataFrame

verbose property writable

verbose: bool

Verbosity of class

__enter__

__enter__()

Context manager enter method

__exit__

__exit__(exc_type, exc_value, traceback)

Context manager exit method

clearCache

clearCache()

Clear the cache

connect

connect()

Connect to the device

disconnect

disconnect()

Disconnect from the device

getData

getData(
    query: Any | None = None, *args, **kwargs
) -> Any | None

Get data from the device

PARAMETER DESCRIPTION
query

query to device. Defaults to None.

TYPE: Any DEFAULT: None

RETURNS DESCRIPTION
Any | None

Any|None: data from device

getDataframe

getDataframe(
    data_store: Iterable[tuple[NamedTuple, datetime]],
) -> DataFrame

Get dataframe of data collected

PARAMETER DESCRIPTION
data_store

data store

TYPE: Iterable[tuple[NamedTuple, datetime]]

RETURNS DESCRIPTION
DataFrame

pd.DataFrame: dataframe of data collected

loadProgram

loadProgram(
    program: Program,
    docstring_parser: Callable[[Any, bool], ProgramDetails]
    | None = None,
)

Load a program to the Measurer

PARAMETER DESCRIPTION
program

program to load

TYPE: Program

measure

measure(
    *args,
    parameters: dict | None = None,
    blocking: bool = True,
    **kwargs,
) -> DataFrame | None

Run the measurement program

args: positional arguments parameters (dict, optional): dictionary of kwargs. Defaults to None. blocking (bool, optional): whether to block until completion. Defaults to True. *kwargs: keyword arguments

RETURNS DESCRIPTION
DataFrame | None

pd.DataFrame|None: dataframe of data collected

record

record(
    on: bool,
    show: bool = False,
    clear_cache: bool = False,
    *,
    callback: Callable | None = None,
    **kwargs,
)

Record data from the device

PARAMETER DESCRIPTION
on

whether to record data

TYPE: bool

show

whether to show data. Defaults to False.

TYPE: bool DEFAULT: False

clear_cache

whether to clear the cache. Defaults to False.

TYPE: bool DEFAULT: False

callback

callback function to process data. Defaults to None.

TYPE: Callable DEFAULT: None

reset

reset()

Reset the device and clear cache

resetFlags

resetFlags()

Reset all flags to class attribute _default_flags

saveData

saveData(filepath: str | Path)

Save data to file

PARAMETER DESCRIPTION
filepath

path to save file

TYPE: str | Path

shutdown

shutdown()

Shutdown procedure for tool

stream

stream(
    on: bool,
    show: bool = False,
    *,
    callback: Callable | None = None,
    **kwargs,
)

Stream data from the device

PARAMETER DESCRIPTION
on

whether to stream data

TYPE: bool

show

whether to show data. Defaults to False.

TYPE: bool DEFAULT: False

callback

callback function to process data. Defaults to None.

TYPE: Callable DEFAULT: None

Program

Program(
    instrument: Measurer | None = None,
    parameters: dict | None = None,
    verbose: bool = False,
    **kwargs,
)

Base Program template

ATTRIBUTE DESCRIPTION
data

data collected from device when running the program

TYPE: deque

instrument

Measurer object

TYPE: Measurer

parameters

dictionary of kwargs

TYPE: dict

verbose

verbosity of class

TYPE: bool

data_df

dataframe of data collected

TYPE: DataFrame

METHOD DESCRIPTION
getDataframe

get dataframe of data collected

run

measurement program to run

saveData

save data to file

==========

Initialize Program class

PARAMETER DESCRIPTION
instrument

Measurer object. Defaults to None.

TYPE: Measurer DEFAULT: None

parameters

dictionary of kwargs. Defaults to None.

TYPE: dict DEFAULT: None

verbose

verbosity of class. Defaults to False.

TYPE: bool DEFAULT: False

data_df property

data_df: DataFrame

Data collected from device when running the program

getDataframe

getDataframe(
    data_store: Iterable[NamedTuple, datetime],
) -> DataFrame

Get dataframe of data collected

PARAMETER DESCRIPTION
data_store

data store

TYPE: Iterable[NamedTuple, datetime]

RETURNS DESCRIPTION
DataFrame

pd.DataFrame: dataframe of data collected

parseDocstring staticmethod

parseDocstring(
    program_class: Program, verbose: bool = False
) -> ProgramDetails

Get the input fields and defaults

PARAMETER DESCRIPTION
program_class

program class of interest

TYPE: Callable

verbose

whether to print out truncated docstring. Defaults to False.

TYPE: bool DEFAULT: False

RETURNS DESCRIPTION
ProgramDetails

details of program class

TYPE: ProgramDetails

run

run(*args, **kwargs) -> DataFrame

Measurement program to run

RETURNS DESCRIPTION
DataFrame

pd.DataFrame: Dataframe of data collected

saveData

saveData(filepath: str | Path)

Save data to file

PARAMETER DESCRIPTION
filepath

path to save file

TYPE: str | Path

ProgramDetails dataclass

ProgramDetails(
    signature: Signature,
    description: str = "",
    parameter_descriptions: dict[str, str] = dict(),
    return_descriptions: dict[tuple[str], str] = dict(),
)

ProgramDetails dataclass represents the set of inputs, default values, truncated docstring and tooltip of a program class

Constructor:
inputs (list[str]): list of input field names
defaults (dict[str, Any]): dictionary of kwargs and default values
short_doc (str): truncated docstring of the program
tooltip (str): descriptions of input fields