SQLiteEventLoader¶
class SQLiteEventLoader(settings: Optional[dict] = None)
Bases: MetaEventLoader
Subclass of MetaEventLoader for loading event data from SQLite databases.
This class provides methods to extract, filter, and stream event data stored in SQLite databases generated by Poriscope. It supports efficient querying and generator-based iteration over large event datasets.
Public Methods¶
- SQLiteEventLoader.close_resources(channel=None)¶
Perform any actions necessary to gracefully close resources before app exit
- SQLiteEventLoader.get_channels()¶
Return the keys of valid channels in the reader
- Returns:
keys of valid channels in the reader
- Return type:
List[int]
- SQLiteEventLoader.get_empty_settings(globally_available_plugins=None, standalone=False)¶
- Parameters:
globally_available_plugins (Optional[ Dict[str, List[str]]]) – a dict containing all data plugins that exist to date, keyed by metaclass. Must include “MetaReader” as a key, with explicitly set Type MetaReader.
standalone (bool) – False if this is called as part of a GUI, True otherwise. Default False
- Returns:
the dict that must be filled in to initialize the filter
- Return type:
Purpose: Provide a list of settings details to users to assist in instantiating an instance of your MetaWriter subclass.
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.
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 }, ... }
Several parameter keywords are reserved: these are
‘Input File’ ‘Output File’ ‘Folder’
These must have Type str and will cause the GUI to generate widgets to allow selection of these elements when used
This function must implement returning of a dictionary of settings required to initialize the filter, in the specified format. Values in this dictionary can be accessed downstream through the
self.settingsclass variable. This structure is a nested dictionary that supplies both values and a variety of information about those values, used by poriscope to perform sanity and consistency checking at instantiation.While this function is technically not abstract in MetaEventLoader, which already has an implementation of this function that ensures that settings will have the required
Input Filekey available to users, in most cases you will need to override it to add any other settings required by your subclass or to specify which files types are allowed. If you need additional settings, which you almost certainly do, you MUST callsuper().get_empty_settings(globally_available_plugins, standalone)before any additional code that you add. For example, your implementation could look like this, to limit it to sqlite files:settings = super().get_empty_settings(globally_available_plugins, standalone) settings["Input File"]["Options"] = [ "SQLite3 Files (*.sqlite3)", "Database Files (*.db)", "SQLite Files (*.sqlite)", ] return settings
which will ensure that your have the
Input Filekey and limit visible options to sqlite3 files. By default, it will accept any file type as output, hence the specification of theOptionskey for the relevant plugin in the example above.
- SQLiteEventLoader.get_num_events(channel)¶
get the number of events available in the given channel
- SQLiteEventLoader.get_samplerate(channel)¶
Return the sampling rate for the channel.
- SQLiteEventLoader.get_valid_indices(channel: int) List[int]¶
- Parameters:
channel (int) – channel number from which to load data.
- Returns:
A list of event ids
- Return type:
List[int]
- Raises:
ValueError if no event_ids exist
Purpose Return a list of indices correspond to the id of events within the given channel, or a list of all valid indices in the database if channel is not specified
- SQLiteEventLoader.load_event(channel, index, data_filter=None)¶
- Parameters:
- Returns:
data and context corresponding to the event, with baseline padding before and after
- Return type:
Purpose: Load the data and metadata associated with a single specified event
Return the data and context for the event identified by index, optionally first applying a filter or preprofessing function to the data returned. You are responsible for raising an appropriate error if the index provided is invalid. The data must be returned as a dict with at least the following keys:
event = { 'data': npt.NDArray[np.float64], # the data in pA 'absolute_start': int, # the start index of the event relative to the start of the experiment 'padding_before': int, # number of data points in event['data'] before the event start estimate 'padding_after': int, # number of data points in event['data'] after the event end estimate 'baseline_mean': float, # local baseline mean value in pA - can be estimated from the padding if need be 'baseline_std': float # local baseline standard deviation in pA - can be estimated from the padding if need be }
- SQLiteEventLoader.reset_channel(channel=None)¶
Perform any actions necessary to gracefully close resources before app exit
Private Methods¶
- SQLiteEventLoader._finalize_initialization() None¶
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.
- SQLiteEventLoader._init() None¶
Purpose: Perform generic class construction operations.
All data plugins have this function and must provide an implementation. This is called immediately at the start of class creation and is used to do whatever is required to set up your reader. Note that no app settings are available when this is called, so this function should be used only for generic class construction operations. Most readers simply
passthis function.
- SQLiteEventLoader._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.