stanza.utils

Module Contents

Functions

NameDescription
substitute_parametersSubstitute parameters in a template string.
get_config_resourceGet config file content
load_device_configLoad a device configuration YAML file.
generate_channel_configsGenerate ChannelConfigs for the device.
device_from_configCreate a device from a DeviceConfig object.
device_from_yamlLoad a device from a YAML configuration file.

API

1stanza.utils.substitute_parameters(
2 template: str, substitutions: dict[str, typing.Any]
3) -> str

Substitute parameters in a template string.

Parameters:

template
str

The template string to substitute parameters in.

substitutions
dict[str, typing.Any]

A dictionary of substitutions to make.

Returns:

The substituted string.

1stanza.utils.get_config_resource(
2 config_path: str | pathlib.Path, encoding: str = 'utf-8'
3) -> str

Get config file content

Parameters:

config_path
str | pathlib.Path

The path to the config file.

encoding
strDefaults to 'utf-8'

The encoding of the config file.

Returns:

The config file content.

1stanza.utils.load_device_config(
2 config_path: str | pathlib.Path, is_stanza_config: bool = False
3) -> stanza.models.DeviceConfig

Load a device configuration YAML file.

Parameters:

is_stanza_config
boolDefaults to False

Whether the config is a stanza config.

Returns:

The device configuration.

Raises:

ValueError: If the file cannot be loaded.

1stanza.utils.generate_channel_configs(device_config: stanza.models.DeviceConfig) -> dict[str, stanza.base.channels.ChannelConfig]

Generate ChannelConfigs for the device.

Parameters:

device_config
stanza.models.DeviceConfig

The device configuration.

Returns:

A dictionary mapping of gate/contact name to ChannelConfigs.

1stanza.utils.device_from_config(
2 device_config: stanza.models.DeviceConfig, **driver_kwargs: typing.Any
3) -> stanza.device.Device

Create a device from a DeviceConfig object.

Parameters:

device_config
stanza.models.DeviceConfig

The device configuration object.

Returns:

A configured Device instance with instantiated instruments.

Raises:

ValueError: If required driver field is missing or instruments cannot be instantiated.

1stanza.utils.device_from_yaml(
2 config_path: str | pathlib.Path,
3 is_stanza_config: bool = False,
4 **driver_kwargs: typing.Any
5) -> stanza.device.Device

Load a device from a YAML configuration file.

Parameters:

config_path
str | pathlib.Path

Path to the device configuration YAML file.

is_stanza_config
boolDefaults to False

Whether the config is a stanza config.

Returns:

A configured Device instance with instantiated instruments.

Raises:

ValueError: If required driver field is missing or instruments cannot be instantiated.