Dataset class
hardware_control.base.Dataset module
- class hardware_control.base.Dataset.Dataset(name: str, app=None)
Bases:
QObjectCollect values from different instrument parameters over time.
A Dataset object collects the values of each instrument parameter in a given list of parameters once per a given time interval in the Dataset’s self.data dictionary. For each parameter, self.data has a key (of the format ‘instrument:parameter’) which accesses a list with all returned values for the given parameter. self.data also has a key (‘time:time’) with the times at which the values were returned.
The values are taken from app._data, meaning that they are not taken directly from the instrument; a Dataset therefore does not communicate with any actual hardware. It is assumed that the user has set up a timer that pulls new values from the hardware into the app._data dictionary periodically. This setup can create small discrepancies between the actual data in the instrument and what is recorded in the Dataset, but in practice this has not been an issue for our experiments.
A single Dataset can be used to group together certain instrument-parameter combinations that are useful to log into a file or display in a single plot.
The Dataset object can automate saving self.data to disc in different formats and enables other widgets to easily display the whole dataset or certain columns versus time.
Since parameters in instruments sometimes have complicated names, the class provides an easy way to overwrite names when the data is output to, for example, disc, using self.define_alias.
- autosave() None
Autosave data.
- clear() None
Clear the Dataset’s contents.
- define_alias(original_name: str, alias: str) None
Define an alias for an original parameter name of format <instrument>:<parameter>.
The alias will be used when saving and plotting.
- get_columns(columns: list) dict
Return a subset of columns.
- Parameters:
columns – Keys in self.data that should be returned
- Returns:
dictionary of requested columns
- Return type:
dict
- header_get_instruments() str
Create a string of all values used in the dataset.
Use the channel alias if available.
- save(filename: Path, file_format: str) None
Saves the Dataset to a file. Format specifies the file format.
Note: the file_format specifier is not case sensitive.
- File Formats:
- jsonpicklenpytxt
- save_json(filename: Path) None
Save data as a json file.
- save_npy(filename: Path) None
Save data as a .npy file.
- save_pickle(filename: Path) None
Save data as a pickle file.
- save_txt(filename: Path, header: str | None = None) None
Save data as a txt file.
- Parameters:
filename – filename to be used. If the file already exists, the data will be appended to it.
header – None or string to be used as a header. If given, the header should include the datetime. Each line of the header must end with \n.
- set_save_interval(interval: float) None
Set the autosave interval in seconds.
- set_update_interval(interval: float) None
Set the update interval (when a new row is added) in seconds.
- start_autosave(interval: float = 120, file_format: str = 'JSON', filename: str = 'autosave') None
Activates the dataset’s autosave feature.
- start_updates(interval: float = 10) None
Start automaticaly logging data every interval seconds.
- to_pandas(columns: list | None = None, cleanup: bool = True) DataFrame
Return a subset of columns as a pandas dataframe and optionally clean it up.
- Parameters:
columns – Keys in self.data that should be returned
cleanup – Remove all None values
- track_instrument(instrument: str, parameter: str | None = None, alias: str | None = None, plot_ax: int | None = 1, auto_update=True) None
Add a parameter from an instrument to the dataset.
- Parameters:
instrument – The instrument name
parameter – The parameter that should be tracked. If None, all read parameters in the instrument are tracked.
alias – Use given string as an alias when plotting or saving the dataset (only used if a parameter was given)
plot_ax – Axis – either 1 or 2 – the parameter(s) should be plotted on. Default is 1.
auto_update – Add the variable to the list the list of variables in the app_settings that gets automatically updated. A reason to set this to False would be to have this on a different update schedule than the default app one.
- update_data() None
Log values from the specified instruments in the Dataset.
This is normally called by the internal timer.