sashimi.config#
Classes
PurePath subclass that can make system calls. |
Functions
- sashimi.config.cli_edit_config(name=None, val=None, file_path=PosixPath('/home/runner/.sashimi/hardware_config.toml'))[source]#
- sashimi.config.get_nested(d, path)[source]#
Get value from a nested dictionary, addressing it via a list of keys indicating the value to the path.
Example:
>>> d = dict(a=dict(a0=0, a1=1)) >>> get_nested(d, ['a', 'a1']) 1
If the path points to an undefined branch in the hierarchy, all required nested keys are added to the dictionary and an empty dictionary is added as value at that location.
Example
>>> d = dict(a=dict(a0=0, a1=1)) >>> get_nested(d, ['a', 'a2', 'new_dict']) >>> print(d) {'a': {'a0': 0, 'a1': 1, 'a2': {'new_dict': {}}}}
- Parameters:
d – nested dictionary to address;
path – list of keys forming the path to the required entry;
- Returns:
entry from addressed path.
- sashimi.config.read_config(file_path=PosixPath('/home/runner/.sashimi/hardware_config.toml'))[source]#
Read Sashimi config.
- Parameters:
file_path (Path object) – Path of the config file (optional).
- Returns:
sashimi configuration
- Return type:
ConfigParser object
- sashimi.config.set_nested(d, path, value)[source]#
Set value in a nested dictionary in an arbitrary existing or new position of the hierarchy.
Example:
>>> d = dict(a=dict(a0=0, a1=1)) >>> set_nested(d, ['a', 'a1'], 0) >>> print(d) {'a': {'a1': 0, 'a0': 0}} >>> set_nested(d, ['a', 'a2', 'new_entry'], 2) >>> print(d) {'a': {'a1': 0, 'a2': {'new_entry': 2}, 'a0': 0}}
- Parameters:
d – nested dictionary to address;
path – list of keys forming the path to the required entry;
value – value to be set;
- sashimi.config.write_config_value(dict_path, val, file_path=PosixPath('/home/runner/.sashimi/hardware_config.toml'))[source]#
Write a new value in the config file. To make things simple, ignore sections and look directly for matching parameters names.
- Parameters:
dict_path (str or list of strings) – Full path of the section to configure (e.g., [“piezo”, “position_read”, “min_val”])
val – New value.
file_path (Path object) – Path of the config file (optional).
- sashimi.config.write_default_config(file_path=PosixPath('/home/runner/.sashimi/hardware_config.toml'), template={'array_ram_MB': 450, 'camera': {'default_binning': 1, 'default_exposure': 60, 'id': 0, 'max_sensor_resolution': [2048, 2048], 'name': 'mock'}, 'default_paths': {'data': '/home/runner', 'log': '/home/runner/logs', 'presets': '/home/runner/presets', 'scope_instructions': '.'}, 'email': {'password': 'foo', 'user': 'foo'}, 'external_communication': {'address': 'tcp://O1-589:5555', 'name': 'stytra'}, 'light_source': {'intensity_units': 'mock', 'name': 'mock', 'port': 'COM4'}, 'notifier': 'none', 'notifier_options': {}, 'piezo': {'scale': 0.025}, 'sample_rate': 40000, 'scanning': 'mock', 'scopeless': False, 'voxel_size': {'x': 0.3, 'y': 0.3}, 'xy_board': {'write': {'channel': 'Dev2/ao0:1', 'max_val': 10, 'min_val': - 5}}, 'z_board': {'read': {'channel': 'Dev1/ai0:0', 'max_val': 10, 'min_val': 0}, 'sync': {'channel': '/Dev1/ao/StartTrigger'}, 'write': {'channel': 'Dev1/ao0:3', 'max_val': 10, 'min_val': - 5}}})[source]#
Write configuration file at first repo usage. In this way, we don’t need to keep a confusing template config file in the repo.
- Parameters:
file_path (Path object) – Path of the config file (optional).
template (dict) – Template of the config file to be written (optional).