Utils#

baecon.utils.arg_parser()#

Argument parser for command line interface.

  • -c, --config_file: Full measurement configuration file.

  • -g, --gen_file: File listing invididual config files for use

    with generate_measurement_config_from_file().

  • -e, --engine: Measurement engine to use.

    currently not implemented but there could a standard engine, OptBayes engine, and others

  • -o, --output: Output file for saving data, or for saving a

    generated config file.

Returns

parsed arguements

Return type

dict

baecon.utils.dump_config(config: dict, file: str, options=None) None#
Saves configuration dictionary into file.

File type may be .toml, .yml, or .json.

Parameters
  • config (dict) – Configuration dictionary to load

  • file (str) – Configuration file to load.

  • options (optional) – Can be used in the future if functionality need extendsion, like encoding type.

baecon.utils.generate_measurement_config_from_file(config_list_file: str, out_file: str) None#
Generates measurement configuration from list of indiviual files, yielding

a single file for the measurement.

The config_list_file is a list of files of seperate configurations, e.g., configuration for individual scans, devices etc.This function loads each individual file into a Measurement_Settings object, then measurement configuration file. config_list_file will be a dict like file (e.g., json, yaml, toml) with structure:

{'acquisition_devices': {'device_name': configuration_file_name, ...}, 'scan_devices': {'device_name': configuration_file_name, ...}, 'scan_collections': {'scan_name': configuration_file_name, ...} 'averages': (int)}

Parameters
  • config_list_file (str) – Name of list file to load.

  • out_file (str) – Name of file for saving the configuration of the generated

  • Measurement_Settings.

baecon.utils.json_dump(config: dict, file: str, options=None) None#

Write configuration dictionary (config) to a json file.

Parameters
  • config (dict) – Configuration dictionary to save.

  • file (str) – path of toml file.

  • options (optional) – Can be used in the future if functionality need extendsion, like encoding type

baecon.utils.json_load(file: str, options=None) dict#

Reads json file and returns dict.

Parameters
  • file (str) – path of json file.

  • options (optional) – Can be used in the future if functionality need extendsion, like encoding type

Returns

Dictionary of json file contents.

Return type

dict

baecon.utils.load_config(file: str, options=None) dict#
Loads configuration file file and returns dictionary of configurations.

File type may be .toml, .yml, or .json.

Parameters
  • file (str) – Configuration file to load.

  • options (optional) – Can be used in the future if functionality

  • extendsion (need) –

  • type. (like encoding) –

Returns

Configuration dictionary

Return type

dict

baecon.utils.load_module_from_path(file_path: str)#
Loads module from specified path.

This is used to load specific Device analysis file for data.

Parameters

file_path (str) – String or path to file of module.

Returns

Module that was loaded

Return type

(python module)

baecon.utils.save_baecon_data(md: baecon.data.Measurement_Data, file_name: str, format: str = '.zarr', options=None) None#
Saves measurement data to choice of format.

The default format is a Zarr group file. Possible formats: zarr, netcdf, hdf5, and csv.

zarr and netcdf play well with xarray. For the other formats data is coverted pandas then saved.

Todo

Need to check settings saved as metadata correctly

Possible formats to implement in the future: parquet, feather.

Parameters
  • md (Measurement_Data) – Configuration of measurement.

  • file_name (str) – File name for saving data.

  • format (str, optional) – File format to use, defaults to ‘.zarr’

  • options (optional) – Options for extension in the future, likely

  • compression. (chunking and) –

baecon.utils.save_measurement_config(ms: baecon.base.Measurement_Settings, out_file: str) None#
Generatres configuration dictioary from Measurement_Settings object

and saves to specified file.

Parameters
  • ms (Measurement_Settings) – Measurement settings to save.

  • out_file (str) – Name of file to save.

baecon.utils.set_device_directory(Devices_directory: str)#
Sets default devices directory in Device to the input

directory.

Parameters

Devices_directory (str) – New directory for the devices.

baecon.utils.toml_dump(config: dict, file: str, options=None) None#

Write configuration dictionary (config) to a toml file.

Parameters
  • config (dict) – Configuration dictionary to save.

  • file (str) – path of toml file.

  • options (optional) – Can be used in the future if functionality need extendsion, like encoding type

baecon.utils.toml_load(file: str, options=None) dict#

Reads toml file and returns dict.

Parameters
  • file (str) – path of toml file.

  • options (optional) – Can be used in the future if functionality need extendsion, like encoding type.

Returns

Dictionary of toml file contents.

Return type

dict

baecon.utils.yaml_dump(config: dict, file: str, options=None) None#

Write configuration dictionary (config) to a yaml file.

Parameters
  • config (dict) – Configuration dictionary to save.

  • file (str or path) – name or path of yaml file.

  • options (optional) – Can be used in the future if functionality need extendsion, like encoding type

baecon.utils.yaml_load(file: str, options=None) dict#

Reads yaml file and returns dict.

Parameters
  • file (str) – path of yaml file.

  • options (optional) – Can be used in the future if functionality need extendsion, like encoding type

Returns

Dictionary of yaml file contents.

Return type

dict