spinqick.helper_functions.file_manager

Helper functions for managing configs and file saving.

Attributes

logger

DATA_DIRECTORY

Classes

SaveData

Save data in netcdf4 format.

Functions

get_data_dir([datadir])

Get the data directory for today's date. If it doesn't exist, make the directory.

check_configs_exist()

Check if readout and hardware configs exist.

get_new_timestamp([datadir])

Set up a data folder for today's date and get a current timestamp.

get_new_filename(suffix, data_path, timestamp)

Create a new filename from data path and timestamp.

load_config_yaml(filename)

Load a config from yaml file format.

load_config_json(filename, config_model)

Load config from json.

save_config_yaml(config, filename)

Save a config to a yaml file.

save_config_json(config, filename)

Save pydantic model object to json file.

load_hardware_config()

Load hardware config file.

save_prog(prog, filename)

Save a qickprogram to json.

load_qickprogram(fname, soccfg)

Loads a qickprogram from json.

Module Contents

spinqick.helper_functions.file_manager.logger
spinqick.helper_functions.file_manager.DATA_DIRECTORY = ''
spinqick.helper_functions.file_manager.get_data_dir(datadir=DATA_DIRECTORY)

Get the data directory for today’s date. If it doesn’t exist, make the directory.

Parameters:

datadir (str) – general data directory where you want to store data from your experiments. Also where you store the config files for spinqick.

Returns:

path to the directory

Return type:

str

spinqick.helper_functions.file_manager.check_configs_exist()

Check if readout and hardware configs exist.

spinqick.helper_functions.file_manager.get_new_timestamp(datadir=DATA_DIRECTORY)

Set up a data folder for today’s date and get a current timestamp.

Parameters:

datadir (str) – general data directory where you want to store data from your experiments. Also where you store the config files for spinqick.

Returns:

-path to the directory created -timestamp to uniquely identify a file in the directory

Return type:

tuple[str, int]

spinqick.helper_functions.file_manager.get_new_filename(suffix, data_path, timestamp)

Create a new filename from data path and timestamp.

Parameters:
  • datapath – file directory

  • timestamp (int) – time in seconds

  • suffix (str)

  • data_path (str)

Returns:

full file path

Return type:

str

spinqick.helper_functions.file_manager.load_config_yaml(filename)

Load a config from yaml file format.

Parameters:

filename (str) – config file name

Returns:

config dictionary

Return type:

dict

spinqick.helper_functions.file_manager.load_config_json(filename, config_model)

Load config from json.

Parameters:

filename (str)

spinqick.helper_functions.file_manager.save_config_yaml(config, filename)

Save a config to a yaml file.

Parameters:
  • config (dict) – dictionary

  • filename (str) – config file name

spinqick.helper_functions.file_manager.save_config_json(config, filename)

Save pydantic model object to json file.

Parameters:
  • config (pydantic.BaseModel)

  • filename (str)

spinqick.helper_functions.file_manager.load_hardware_config()

Load hardware config file.

Parameters:

datadir – general data directory where you want to store data from your experiments. Also where you store the config files for spinqick.

Returns:

hardware config dictionary

Return type:

spinqick.models.hardware_config_models.HardwareConfig

spinqick.helper_functions.file_manager.save_prog(prog, filename)

Save a qickprogram to json.

Parameters:
  • prog (qick.qick_asm.AbsQickProgram)

  • filename (str)

spinqick.helper_functions.file_manager.load_qickprogram(fname, soccfg)

Loads a qickprogram from json.

This requires the soccfg used to run the program.

Parameters:
  • fname (str)

  • soccfg (qick.QickConfig)

class spinqick.helper_functions.file_manager.SaveData(*args, **kwargs)

Bases: netCDF4.Dataset

Save data in netcdf4 format.

Check out their documentation for information at https://unidata.github.io/netcdf4-python/. Don’t forget to run .close() on the Dataset object after you’ve finished adding data.

filename_prefix
get_filename_prefix()

Returns the filename prefix for the given netcdf object.

add_axis(label, data=None, units=None, dtype=np.float32)

Provide axes for the data you want to store. If the axis doesn’t have data associated with it (ie I and Q axis) then leave data=None. This sets the axis dimension to unlimited.

Parameters:
  • label (str) – A label for the axis you’re providing

  • data (numpy.ndarray | None) – If the axis has data associated with it (i.e. time in seconds) you can provide it here

  • units (str | None) – Provide a string that describes the units of this axis

  • dtype – datatype of the data provided. This is in a numpy dtype form.

add_multivariable_axis(dim_label, sweep_dict, group_path=None, dtype=np.float32)

Adds a dimension to netCDF object which corresponds to multiple swept variables.

Parameters:
  • dim_label (str) – name of the dimension associate with this axis

  • sweep_dict (dict) – provide the axis dictionary. This needs to be in the format that is used for spinqickdata axis dictionaries.

  • group_path (str | None) – if the dataset is in a specific folder within the netcdf file, specify the name of this folder.

  • dtype – datatype of the data provided. This is in a numpy dtype form.

add_dataset(label, axes, data, units=None, group_path=None, dtype=np.float32)

Adds a data array to the netcdf object. Axes needs the be a list of axis values.

Parameters:
  • label (str) – A label for the data you’re providing

  • axes (list[str]) – Provide a list of the axes you made which reflects the shape of the data array

  • data (numpy.ndarray) – Data in array form

  • units (str | None) – Provide a string that describes the units of this axis

  • group_path (str | None) – if the dataset is in a specific folder within the netcdf file, specify the name of this folder.

  • dtype – datatype of the data provided. This is in a numpy dtype form.

save_last_plot(fignum=None)

Saves a figure as a .png with the same filename as the data.

save_config_json(full_config)

Saves a pydantic model as a json file.

Parameters:

full_config (pydantic.BaseModel)

save_prog_json(prog)

Saves a qick program to a json file.

Parameters:

prog (qick.qick_asm.AbsQickProgram)