Qudi
Public Member Functions | Public Attributes | Static Public Attributes | List of all members
save_logic.SaveLogic Class Reference

A general class which saves all kinds of data in a general sense. More...

Inheritance diagram for save_logic.SaveLogic:
Inheritance graph
[legend]
Collaboration diagram for save_logic.SaveLogic:
Collaboration graph
[legend]

Public Member Functions

def __init__ (self, config, kwargs)
 
def on_activate (self)
 Definition, configuration and initialisation of the SaveLogic.
 
def on_deactivate (self)
 
def dailylog (self)
 Returns the daily log handler.
 
def dailylog_set_level (self, level)
 Sets the log level of the daily log handler. More...
 
def save_data (self, data, filepath=None, parameters=None, filename=None, filelabel=None, timestamp=None, filetype='text', fmt='%.15e', delimiter='\t', plotfig=None)
 General save routine for data. More...
 
def save_array_as_text (self, data, filename, filepath='', fmt='%.15e', header='', delimiter='\t', comments='#', append=False)
 
def get_daily_directory (self)
 Creates the daily directory. More...
 
def get_path_for_module (self, module_name)
 Method that creates a path for 'module_name' where data are stored. More...
 

Public Attributes

 lock
 
 active_poi_name
 
 os_system
 
 data_dir
 

Static Public Attributes

 log_into_daily_directory = ConfigOption('log_into_daily_directory', False, missing='warn')
 
dictionary mpl_qd_style
 

Detailed Description

A general class which saves all kinds of data in a general sense.

Member Function Documentation

◆ dailylog_set_level()

def save_logic.SaveLogic.dailylog_set_level (   self,
  level 
)

Sets the log level of the daily log handler.

Parameters
levelint: log level, see logging

◆ get_daily_directory()

def save_logic.SaveLogic.get_daily_directory (   self)

Creates the daily directory.

Returns
string: path to the daily directory.

If the daily directory does not exits in the specified <root_dir> path in the config file, then it is created according to the following scheme:

<root_dir>\<year>\<month>\<yearmonthday>

and the filepath is returned. There should be always a filepath returned.

◆ get_path_for_module()

def save_logic.SaveLogic.get_path_for_module (   self,
  module_name 
)

Method that creates a path for 'module_name' where data are stored.

Parameters
stringmodule_name: Specify the folder, which should be created in the daily directory. The module_name can be e.g. 'Confocal'.
Returns
string: absolute path to the module name

◆ save_data()

def save_logic.SaveLogic.save_data (   self,
  data,
  filepath = None,
  parameters = None,
  filename = None,
  filelabel = None,
  timestamp = None,
  filetype = 'text',
  fmt = '%.15e',
  delimiter = '\t',
  plotfig = None 
)

General save routine for data.

Parameters
dictionarydata: Dictionary containing the data to be saved. The keys should be strings containing the data header/description. The corresponding items are one or more 1D arrays or one 2D array containing the data (list or numpy.ndarray). Example:
data = {'Frequency (MHz)': [1,2,4,5,6]}
data = {'Frequency': [1, 2, 4], 'Counts': [234, 894, 743, 423]}
data = {'Frequency (MHz),Counts':[[1,234], [2,894],...[30,504]]}
stringfilepath: optional, the path to the directory, where the data will be saved. If the specified path does not exist yet, the saving routine will try to create it. If no path is passed (default filepath=None) the saving routine will create a directory by the name of the calling module inside the daily data directory. If no calling module can be inferred and/or the requested path can not be created the data will be saved in a subfolder of the daily data directory called UNSPECIFIED
dictionaryparameters: optional, a dictionary with all parameters you want to save in the header of the created file. string filename: optional, if you really want to fix your own filename. If passed, the whole file will have the name
<filename>

If nothing is specified the save logic will generate a filename either based on the module name from which this method was called, or it will use the passed filelabel if that is speficied. You also need to specify the ending of the filename! string filelabel: optional, if filelabel is set and no filename was specified, the savelogic will create a name which looks like

YYYY-MM-DD_HHh-MMm-SSs_<filelabel>.dat

The timestamp will be created at runtime if no user defined timestamp was passed.

Parameters
datetimetimestamp: optional, a datetime.datetime object. You can create this object with datetime.datetime.now() in the calling module if you want to fix the timestamp for the filename. Be careful when passing a filename and a timestamp, because then the timestamp will be ignored.
stringfiletype: optional, the file format the data should be saved in. Valid inputs are 'text', 'xml' and 'npz'. Default is 'text'.
stringor list of strings fmt: optional, format specifier for saved data. See python documentation for "Format Specification Mini-Language". If you want for example save a float in scientific notation with 6 decimals this would look like '%.6e'. For saving integers you could use 'd', 's' for strings. The default is '%.15e' for numbers and 's' for str. If len(data) > 1 you should pass a list of format specifiers; one for each item in the data dict. If only one specifier is passed but the data arrays have different data types this can lead to strange behaviour or failure to save right away.
stringdelimiter: optional, insert here the delimiter, like '
' for new line, '' for tab, ',' for a comma ect.

1D data

1D data should be passed in a dictionary where the data trace should be assigned to one identifier like

{'<identifier>':[list of values]}
{'Numbers of counts':[1.4, 4.2, 5, 2.0, 5.9 , ... , 9.5, 6.4]}

You can also pass as much 1D arrays as you want:

{'Frequency (MHz)':list1, 'signal':list2, 'correlations': list3, ...}

2D data

2D data should be passed in a dictionary where the matrix like data should be assigned to one identifier like

{'<identifier>':[[1,2,3],[4,5,6],[7,8,9]]}

which will result in: <identifier> 1 2 3 4 5 6 7 8 9

    YOU ARE RESPONSIBLE FOR THE IDENTIFIER! DO NOT FORGET THE UNITS FOR THE SAVED TIME
    TRACE/MATRIX.

Member Data Documentation

◆ mpl_qd_style

dictionary save_logic.SaveLogic.mpl_qd_style
static
Initial value:
= {
'axes.prop_cycle': cycler(
'color',
['#1f17f4',
'#ffa40e',
'#ff3487',
'#008b00',
'#17becf',
'#850085'
]
) + cycler('marker', ['o', 's', '^', 'v', 'D', 'd']),
'axes.edgecolor': '0.3',
'xtick.color': '0.3',
'ytick.color': '0.3',
'axes.labelcolor': 'black',
'font.size': '14',
'lines.linewidth': '2',
'figure.figsize': '12, 6',
'lines.markeredgewidth': '0',
'lines.markersize': '5',
'axes.spines.right': True,
'axes.spines.top': True,
'xtick.minor.visible': True,
'ytick.minor.visible': True,
'savefig.dpi': '180'
}

The documentation for this class was generated from the following file: