SQLiteEventWriter¶
class SQLiteEventWriter(settings: Optional[dict] = None)
Bases: MetaWriter
Save events into a single file with baseline between them discarded
Public Methods¶
- SQLiteEventWriter.close_resources(channel=None)¶
Do whatever needs doing to gracefully shut down on app exit
- Parameters:
channel (int) – channel ID
- SQLiteEventWriter.get_empty_settings(globally_available_plugins=None, standalone=False)¶
Get a dict populated with keys needed to initialize the filter if they are not set yet. This dict must have the following structure, but Min, Max, and Options can be skipped or explicitly set to None if they are not used. Value and Type are required. All values provided must be consistent with Type. EventFinder objects MUST include a MetaReader object in settings
settings = {'Parameter 1': {'Type': <int, float, str, bool>, 'Value': <value> or None, 'Options': [<option_1>, <option_2>, ... ] or None, 'Min': <min_value> or None, 'Max': <max_value> or None }, ... }
- Parameters:
- Returns:
the dict that must be filled in to initialize the filter
- Return type:
- SQLiteEventWriter.get_output_file_name()¶
get the name of the output file
Private Methods¶
- SQLiteEventWriter._finalize_initialization()¶
Apply the provided paramters and intialize any internal structures needed Should Raise if initialization fails.
This function is called at the end of the class constructor to perform additional initialization specific to the algorithm being implemented. kwargs provided to the base class constructor are available as class attributes.
- SQLiteEventWriter._init()¶
called at the start of base class initialization
- SQLiteEventWriter._initialize_database(channel: int)¶
Open a database or file handle for writing events - this function will be called from every channel in the reader
- Parameters:
channel (int) – the channel for which to initialize the database
- SQLiteEventWriter._rescale_data_to_adc(data, scale=None, offset=None, raw_data=False, dtype='u2', adc_min=-32768, adc_max=32767)¶
Not used by this writer
- Parameters:
data (numpy.ndarray) – 1D numpy array of data to write to the active file in the specified channel.
scale (float, optional) – Scaling between provided data type and encoded form for storage. If None, scale is calculated based on the data to maximally use the available adc range.
offset (float, optional) – Offset between provided data type and encoded form for storage. If None, offset is calculated based on the data to maximally use the available adc range.
raw_data (bool) – True means to simply write data as-is to file, False indicates to first rescale it. Default False.
dtype (type, optional) – Numpy dtype to use for storage. Defaults to 16-bit signed int.
adc_min (int) – Integer encoding the minimum adc code for the adc conversion.
adc_max (int) – Integer encoding the maximum adc code for the adc conversion.
- Returns:
Rescaled data as numpy array, scale factor, and offset.
- Return type:
- SQLiteEventWriter._set_output_dtype() str¶
set the output dtype - should be a numpy numeric type:
self.output_dtype = ‘<u2’
- SQLiteEventWriter._validate_settings(settings: dict) None¶
Validate that the settings dict contains the correct information for use by the subclass.
- Parameters:
settings (dict) – Parameters for event detection.
- Raises:
ValueError – If the settings dict does not contain the correct information.
- SQLiteEventWriter._write_channel_metadata(channel: int) None¶
Write any information you need to save about the channel.
- Parameters:
channel (int) – int indicating which output to flush
- SQLiteEventWriter._write_data(data, channel, index, scale=None, offset=None, start_sample=0, padding_before=0, padding_after=None, baseline_mean=None, baseline_std=None, raw_data=False, abort=False, last_call=False)¶
Append data and metadata to the active file handle.
- Parameters:
data (numpy.ndarray) – 1D numpy array of data to write to the active file in the specified channel.
channel (int) – Int indicating the channel from which it was acquired.
index (int) – event index
scale (Optional[float]) – Float indicating scaling between provided data type and encoded form for storage, default None.
offset (Optional[float]) – Float indicating offset between provided data type and encoded form for storage, default None.
start_sample (Optional[int]) – Integer index of the starting point of the provided array relative to the start of the experimental run, default 0.
padding_before (Optional[int]) – the length of the padding before the actual event start
padding_after (Optional[int]) – the length of the padding after the actual event end
baseline_mean (Optional[float]) – The local baseline, if available
baseline_std (Optional[float]) – the local standard deviation, if available
raw_data (bool) – True means to simply write data as-is to file, False indicates to first rescale it. Default False.
batch_size (int) – Number of events to batch before insert, default 100.
last_call (bool) – If True, flush the remaining batch, default False.
- Returns:
success of the write operation.
- Return type: