qudi.util.datastorage.CsvDataStorage

class qudi.util.datastorage.CsvDataStorage(*, file_extension='.csv', **kwargs)[source]

Bases: qudi.util.datastorage.TextDataStorage

Helper class to store (measurement)data on disk as CSV file. This is a specialized sub-class of TextDataStorage that uses hard-coded commas as delimiter and includes column headers uncommented in the first row of data. This is the standard format for importing a table into e.g. MS Excel.

__init__(*, file_extension='.csv', **kwargs)[source]

See: qudi.util.datastorage.TextDataStorage

Methods

__init__(*[, file_extension])

See: qudi.util.datastorage.TextDataStorage

add_global_metadata(name[, value, overwrite])

Set a single global metadata key-value pair or alternatively multiple ones as dict.

append_file(data, file_path)

Append single or multiple rows to an existing data file.

create_header([timestamp, metadata, notes, ...])

Include column_headers without line comment specifier.

get_global_metadata()

Return a copy of the global metadata dict.

get_unified_metadata([local_metadata])

Helper method to return a dictionary containing provided local metadata as well as global metadata depending on the include_global_metadata flag.

load_data(file_path)

See load_data() for more information.

new_file(*[, timestamp, metadata, notes, ...])

Create a new data file on disk and write header string to it.

remove_global_metadata(names)

Remove a global metadata key-value pair by key.

save_data(data, *[, timestamp, metadata, ...])

See save_data() for more information.

save_thumbnail(mpl_figure, file_path)

Save a matplotlib figure visualizing the saved data in the configured image format.

Attributes

delimiter

file_extension

__init__(*, file_extension='.csv', **kwargs)[source]

See: qudi.util.datastorage.TextDataStorage

classmethod add_global_metadata(name, value=None, *, overwrite=False)

Set a single global metadata key-value pair or alternatively multiple ones as dict. Metadata added this way will persist for all data storage instances in this process until being selectively removed by calls to “remove_global_metadata”.

append_file(data, file_path)

Append single or multiple rows to an existing data file.

Parameters:
datanumpy.ndarray

Data array to be appended. For 1D arrays, it represents a single row. For 2D arrays, it represents multiple rows.

file_pathstr

File path to append to.

Returns:
tuple

Number of rows written (int). Number of columns written (int).

create_header(timestamp=None, metadata=None, notes=None, column_headers=None, column_dtypes=None)[source]

Include column_headers without line comment specifier. for more information see: qudi.util.datastorage.TextDataStorage.create_header()

property delimiter

!! processed by numpydoc !!

property file_extension

!! processed by numpydoc !!

classmethod get_global_metadata()

Return a copy of the global metadata dict.

get_unified_metadata(local_metadata=None)

Helper method to return a dictionary containing provided local metadata as well as global metadata depending on the include_global_metadata flag.

Parameters:
local_metadatadict

Metadata to include in addition to global metadata.

include_global_metadatabool, optional

Flag indicating whether to include global metadata.

Returns:
dict

New dictionary containing local metadata and global metadata.

static load_data(file_path)[source]

See load_data() for more information.

Parameters:
file_pathstr, optional

Path to the file to load data from.

new_file(*, timestamp=None, metadata=None, notes=None, nametag=None, column_headers=None, column_dtypes=None, filename=None)

Create a new data file on disk and write header string to it. Will overwrite old files silently if they have the same path.

Parameters:
metadatadict, optional

Named metadata values to be saved in the data header.

notesstr, optional

String that is included in the file header “as-is”.

nametagstr, optional

Nametag to include in the generic filename.

timestampdatetime.datetime, optional

Timestamp to use. Will create one if missing.

filenamestr, optional

Custom filename to use (nametag, timestamp, and configured file_extension will not be included for file naming).

Returns:
tuple

Full file path (str), timestamp used (datetime.datetime).

classmethod remove_global_metadata(names)

Remove a global metadata key-value pair by key. Does not raise an error if the key is not found.

save_data(data, *, timestamp=None, metadata=None, notes=None, nametag=None, column_headers=None, column_dtypes=None, filename=None)

See save_data() for more information.

Parameters:
column_headersstr or list, optional

Data column header strings or a single string.

save_thumbnail(mpl_figure, file_path)

Save a matplotlib figure visualizing the saved data in the configured image format. It is recommended to use the same file path as the corresponding data file (if applicable) and exclude the file extension (which will be added according to the image format).

Parameters:
mpl_figurematplotlib.figure.Figure

The matplotlib figure object to save as an image.

file_pathstr

Full file path to use without the file extension.

Returns:
str

Full absolute path of the saved image.