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: int | None = None) None¶
Perform any actions necessary to gracefully close resources before app exit
- SQLiteEventLoader.get_channels() List[int]¶
Return the keys of valid channels in the reader
- Returns:
keys of valid channels in the reader
- Return type:
List[int]
- Raises:
ValueError – if no channels are found
sqlite3.Error – if a database operation fails
Exception – if an unexpected error occurs while fetching channels
- SQLiteEventLoader.get_empty_settings(globally_available_plugins: Dict[str, List[str]] | None = None, standalone: bool = False) Dict[str, Dict[str, Any]]¶
Declare the settings this event loader exposes, on top of the base contract.
Called by poriscope when the plugin is instantiated or reconfigured, to build the settings dialog and to sanity-check whatever the user enters; the accepted values are then readable through
self.settings. Seeget_empty_settings()for the structure of the dict and whatType,Value,Min,Max,OptionsandUnitsmean in it, and for the reserved keys the GUI builds file pickers from.The keys this plugin adds:
Input File- the SQLite database to read raw event samples from, as written bySQLiteEventWriter.
- Parameters:
- Returns:
the dict that must be filled in to initialize the filter
- Return type:
- SQLiteEventLoader.get_num_events(channel: int) int¶
get the number of events available in the given channel
- Parameters:
channel (int) – the channel to consider
- Returns:
The number of events in the channel for the given experiment
- Return type:
- Raises:
sqlite3.Error – if a database operation fails
Exception – if an unexpected error occurs while counting events
- SQLiteEventLoader.get_samplerate(channel: int) float¶
Return the sampling rate for the channel.
- Parameters:
channel (int) – the channel to consider
- Returns:
Sampling rate for the dataset.
- Return type:
- Raises:
ValueError – if no samplerate is found for the given channel
sqlite3.Error – if a database operation fails
Exception – if an unexpected error occurs while fetching the samplerate
- 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
sqlite3.Error – if a database operation fails
Exception – if an unexpected error occurs while fetching event ids
Purpose Return a list of indices corresponding to the id of events within the given channel. channel is required; there is no “all channels” mode.
- SQLiteEventLoader.load_event(channel: int, index: int, data_filter: Callable | None = None) Dict[str, ndarray[tuple[int, ...], dtype[float64]] | int | float]¶
- Parameters:
- Returns:
data and context corresponding to the event, with baseline padding before and after
- Return type:
- Raises:
IndexError – if no event with the given index exists for the given channel
ValueError – if a value error occurs while loading the event
sqlite3.Error – if a database operation fails
Exception – if an unexpected error occurs while loading the event
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 }
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.