Package reference#
- class automea.__main__.Analysis[source]#
Bases:
objectClass for performing analysis of MEA datasets.
This class provides methods for loading datasets, performing various analyses, and visualizing the results.
- util#
Utility functions module.
- Type:
module
- signal#
The recorded signal. Default is None.
- Type:
array_like or None
- time#
The time array. Default is None.
- Type:
array_like or None
- spikes#
The detected spikes. List with timestamp of every spike. Default is None.
- Type:
array_like or None
- spikes_binary#
The binary representation of detected spikes. Default is None.
- Type:
array_like or None
- active_channels#
Indices of channels that are active (mean firing rate > 0.1 spikes/s). Is set when detect_spikes() is called. Default is None.
- Type:
array_like or None
- reverbs#
The detected reverberations. List of lists with start and end timestamp of reverb. Default is None.
- Type:
array_like or None
- reverbs_binary#
The binary representation of detected reverberations. Default is None.
- Type:
array_like or None
- bursts#
The detected bursts. List of lists with start and end timestamp of burst. Default is None.
- Type:
array_like or None
- bursts_binary#
The binary representation of detected bursts. Default is None.
- Type:
array_like or None
- net_reverbs#
The detected network reverberations. List of lists with start and end timestamp of network reverb. Default is None.
- Type:
array_like or None
- reverbs_binary#
The binary representation of detected network reverberations. Default is None.
- Type:
array_like or None
- net_bursts#
The detected network bursts. List of lists with start and end timestamp of network burst. Default is None.
- Type:
array_like or None
- net_bursts_binary#
The binary representation of detected network bursts. Default is None.
- Type:
array_like or None
- adZero#
Variable to convert integer signal (default in h5 dataset) to mV. Is subracted from integer signal. Default is 0
- Type:
- conversionFactor#
Variable to convert integer signal (default in h5 dataset) to mV. Is multiplied to integer signal. Default is 59604
- Type:
- exponent#
Variable to convert integer signal (default in h5 dataset) to mV. Is multiplied to integer signal. Default is -12
- Type:
- total_timesteps_signal#
Number of timesteps present in measured signal. Default is 6 million.
- Type:
- time#
Array containing time for measured signal in seconds. Uses samplingFreq and total_timesteps_signal.
- Type:
array_like
- threshold_params#
- Dictionary of parameters used to detect threshold. Includes:
- ‘rising’(keystr, valueint)
How many standard deviations are used to set threshold. Default is 5.
- ‘startTime’(keystr, valuefloat)
Start time (s) to consider signal. Default is 0.
- ‘baseTime’(keystr, valuefloat)
Time lenght in ms to consider signal for std calculation. Default is 0.250.
- ‘segments’(keystr, valueint)
Number of segment to perform for calculation. Default is 10.
- Type:
- spike_params#
- Dictionary of parameters used to detect spikes. Includes:
- ‘deadtime’: (keystr, valuefloat)
Amount of time after detecting a spike for which no spike is detect. Default is 3_000*1e-6.
- Type:
- reverbs_params#
- Dictionary of parameters used to detect reverberations. Includes:
- ‘max_interval_start’(keystr, valueint)
Maximum interval between spikes to start reverberation detection in ms. Default is 15.
- ‘max_interval_end’(keystr, valueint)
Maximum interval between spikes to end reverberation detection in ms. Default is 20.
- ‘min_interval_between’(keystr, valueint)
Minimum interval between spikes to consider for reverberation detection in ms. Default is 25.
- ‘min_duration’(keystr, valueint)
Minimum reverberation duration in ms. Default is 20.
- ‘min_spikes’(keystr, valueint)
Minimum number of spikes to consider in a reverberation. Default is 5.
- Type:
- bursts_params#
- Dictionary of parameters used to detect bursts (from reverberations). Includes:
- ‘min_interval_between’(keystr, valueint)
Minimum interval between spikes to consider for reverberation detection in ms. Default is 300.
- Type:
- _pretrained_models#
List containing name of pretrained ML models used for reverberation detection.
- model_params#
- Dictionary of parameters used in model-based reverberation detection. Includes:
- ‘name’(keystr, valuestr)
Name of the model. Default is None.
- ‘input_type’(keystr, valuestr)
String defining type of input used by the model (‘signal’ or ‘spikes’). Deault is None and changed when model is loaded.
- ‘input_average’(keystr, valueint)
How many points are used to calculate average of input. Default is 30.
- ‘window_size’(keystr, valueint)
Size of window (in timestamps) used as input for the model (before averaging). Default is 50_000.
- ‘window_overlap’(keystr, valueint)
Overlap between windows when sweeping a channel. Default is 25_000.
- Type:
- analysis_params#
- Parameters for analysis - which quantities user wants to save - each one creates an output file. Includes:
- ‘save_spikes’(keystr, valuebool)
Whether or not to save spikes in a dedicated file. Default is False.
- ‘save_reverbs’(keystr, valuebool)
Whether or not to save reverberations in a dedicated file. Default is False.
- ‘save_bursts’(keystr, valuebool)
Whether or not to save bursts in a dedicated file. Default is False.
- ‘save_net_reverbs(keystr, valuebool)
Whether or not to save network reverberations in a dedicated file. Default is False.
- ‘save_net_bursts’(keystr, valuebool)
Whether or not to save network bursts in a dedicated file. Default is False.
- ‘save_stats’(keystr, valuebool)
Whether or not to save statistics in a dedicated file. Default is False.
- Type:
- loadmodel(setting='default')[source]#
Load a machine learning model to perform reverberations/bursts detection.
- convert_signal(signal, adzero, conversionfactor, exponent)[source]#
Convert raw signal values to physical units using the provided parameters: adzero, conversionfactor, and exponent
- convert_threshold(threshold, adzero, conversionfactor, exponent)[source]#
Convert threshold value to physical units using the provided parameters: adzero, conversionfactor, and exponent.
- loadwell(file:str, well, method = 'default', spikes = False, reverbs = False,
bursts = False, net_reverbs = False, net_bursts = False)
Load data for a specific well.
- convert_timestamps_to_binary(input_timestamp, input_type, size=None)[source]#
Convert timestamps to binary representation.
- convert_binary_to_timestamps(input_binary, input_type)[source]#
Convert binary representation data to timestamps.
- _convert_binary_reverb_to_timestamp(input_binary)[source]#
Convert binary representation of reverbs to timestamps.
- _detect_spikes(signal, threshold)[source]#
Detect spikes in a signal based on a given threshold value.
- _predict_reverbs(model_input, spikes_binary)[source]#
Predict reverberations using a pre-trained machine learning model.
- normalize_threshold(signal, threshold)[source]#
Normalize the threshold relative to the input signal.
- reduce_dimension(X, input_type=None, reduction_factor=None)[source]#
Reduce the dimensionality of the input data.
- reduce_norm_abs_signal(signal)[source]#
Reduce the dimensionality of the normalized absolute signal.
- detect_net(inp, minChannelsParticipating=None, minSimultaneousChannels=None)[source]#
Detect net bursts or net reverbs.
- analyze_dataset(file=None, mode='csv', save_default=False)[source]#
Analyze the datasets from a CSV file, and save the results to CSV files.
- plot_window(signal, start_time=None, duration=None, threshold=None, spikes=None, reverberations=None,
bursts=None, net_bursts=None, save=False, output_name=None, figsize=(6, 6), yunits=’a.u.’, xunits=’s’)
Plot a window of the signal with detected spikes, reverberations, bursts, and network bursts.
- plot_raster(spikes, reverbs=None, bursts=None, net_reverbs=None, net_bursts=None)[source]#
Plot a raster plot of spikes with optional overlay of reverberations, bursts, and network bursts.
- plot_raster_well(file:str, well, method = 'default', reverbs = False, bursts = False,
net_reverbs = False, net_bursts = False)
Plot a raster plot for a specific well with optional overlay of events.
Initializes class with default attributes.
- analyze_dataset(file=None, mode='csv', save_default=False)[source]#
Analyze the datasets from a CSV file, and save the results to CSV files.
This method conducts a thorough analysis of the dataset, encompassing the detection of reverberations (reverbs), bursts, network bursts, and various statistics. It then saves the results to CSV files based on the specified mode and whether to save default analysis results.
- Parameters:
file (str or None, optional) – The file name or path of the CSV with datasets to analyze. If None, the dataset associated with the dataset attribute will be analyzed.
mode (str, optional) – The mode of analysis. Default is ‘csv’, meaning it will receiva a CSV file with the dataset information.
save_default (bool, optional) – Determines whether to also save the results of default analysis alongside model-based analysis. Default is False.
Notes
The method first creates dataframes to store information about reverbs, bursts, network bursts, and statistics.
It loads the CSV file, iterates over each dataset, and analyzes each well speficified within the dataset.
For each well, it performs spike detection, threshold detection, and then applies the specified methods (default or model-based) for reverbs, bursts, and network bursts detection.
It calculates various statistics based on the detected bursts and network bursts.
Finally, it saves the results to separate CSV files according to the specified mode and whether to save default analysis results.
- convert_binary_to_timestamps(input_binary, input_type)[source]#
Convert binary representation data to timestamps.
This method converts a binary representation to timestamps for the specified input type, such as ‘spikes’, ‘reverbs’, or ‘bursts’.
- Parameters:
input_binary (array_like) – The binary representation data to be converted to timestamps.
input_type (str, optional) – The type of input binary. Options are ‘spikes’, ‘reverbs’, or ‘bursts’.
- Returns:
The timestamps corresponding to the binary representation.
- Return type:
Examples
>>> obj = Analysis() >>> spikes_timestamps = obj.convert_binary_to_timestamps(spikes_binary, input_type='spikes')
Notes
For ‘spikes’, each 1 in the binary array represents a spike timestamp.
For ‘reverbs’ and ‘bursts’, consecutive 1s in the binary array represent timestamp ranges.
- convert_signal(signal, adzero, conversionfactor, exponent)[source]#
Convert raw signal values to physical units using the provided parameters: adzero, conversionfactor, and exponent
- Parameters:
- Returns:
The converted signal values in physical units.
- Return type:
array_like
Examples
>>> obj = Analysis() >>> converted_signal = obj.convert_signal(raw_signal, ad_zero_value, conversion_factor, exponent_value)
- convert_threshold(threshold, adzero, conversionfactor, exponent)[source]#
Convert threshold value to physical units using the provided parameters: adzero, conversionfactor, and exponent.
- Parameters:
- Returns:
The converted threshold value in physical units.
- Return type:
Examples
>>> obj = Analysis() >>> converted_threshold = obj.convert_threshold(threshold_value, ad_zero_value, conversion_factor, exponent_value)
- convert_timestamps_to_binary(input_timestamp, input_type, size=None)[source]#
Convert timestamps to binary representation.
This method converts timestamps to a binary representation suitable for the specified input type, such as ‘spikes’, ‘reverbs’, or ‘bursts’.
- Parameters:
- Returns:
The binary representation of the timestamps data.
- Return type:
array_like
Examples
>>> obj = Analysis() >>> spikes_binary = obj.convert_timestamps_to_binary(spikes_timestamps, input_type='spikes')
Notes
If ‘size’ is not provided, it defaults to the total number of timesteps in the signal.
For ‘spikes’, each spike timestamp is represented as 1 in the binary array.
For ‘reverbs’ and ‘bursts’, each timestamp range is represented as 1 in the binary array.
- detect_bursts()[source]#
Detect bursts in the signal based on the detected reverberations.
- Return type:
None
Notes
If no reverberations are detected or if the ‘reverbs’ attribute is empty, no bursts will be detected.
Detected bursts are stored in the ‘bursts’ attribute.
- detect_net(inp, minChannelsParticipating=None, minSimultaneousChannels=None)[source]#
Detect net bursts or net reverbs.
- Parameters:
Notes
A net burst or net reverb is defined by bursts or reverbs occurring simultaneously on multiple channels.
The function detects net bursts or net reverbs based on the input type.
It starts a net burst when the number of channels bursting together exceeds ‘minChannelsParticipating’.
It ends a net burst when the number of simultaneous channels drops below ‘minSimultaneousChannels’.
The resulting net bursts or net reverbs are stored in the corresponding attributes (‘net_reverbs’ or ‘net_bursts’) and their binary representations are stored in ‘net_reverbs_binary’ or ‘net_bursts_binary’, respectively.
- detect_reverbs(method='default')[source]#
Detects reverberations based on the specified method.
- Parameters:
method (str, optional) – The method used for reverberations detection. Options are ‘default’, ‘manual’, or ‘model’. Default is ‘default’.
- Return type:
None
Notes
If method is ‘default’, the default parameters for reverberations detection are used.
If method is ‘manual’, the user can specify manual parameters for reverberations detection.
If method is ‘model’, reverberations are detected using a pre-trained machine learning model.
Detect reverberations are stored in the reverb attribute.
- detect_spikes()[source]#
Detect spikes in the signal.
This method detects spikes from the signal attribute of the analysis object based on the threshold attribute.
- Return type:
None
Notes
It checks if the signal attribute is a numpy array, and if not, prints an error message and returns.
If the signal attribute is a 1D numpy array, it detects spikes and updates the spikes and spikes_binary attributes.
If the signal attribute is a 2D numpy array (multiple channels), it detects spikes for each channel and updates the spikes and spikes_binary attributes accordingly.
Calculates the number of active channels (mean-firing-rate > 0.1 spikes/s)
- detect_threshold()[source]#
Detect threshold value for spike detection.
This method calculates the threshold(s) value(s) based on the signal data and threshold parameters provided in the analysis object.
- Return type:
None
Examples
>>> obj = Analysis() >>> obj.detect_threshold()
Notes
If the ‘signal’ attribute is not a numpy array, an error message is printed, and the method returns.
The threshold value is calculated segment-wise based on the mean and standard deviation of the signal.
The calculated threshold value is stored in the ‘threshold’ attribute of the analysis object.
- files_and_well_csv(file)[source]#
Load filenames and associated wells from a CSV file.
This method reads a CSV file containing filenames and associated wells, and populates the dataset and wellsLabels attributes accordingly.
- Parameters:
file (str) – The name of the CSV file to load, relative to the path_to_csv attribute.
- Return type:
None
Examples
>>> obj = Analysis() >>> obj.files_and_well_csv('data.csv')
CSV file format example: filename;wells file1.h5;A1,B2,C3 file2.h5f;all file3.h5;D4,E5,F6
In the above example, we want to analyze wells A1, B2, and C3 fromfile1.h5, all wells from file2.h5, and D4, E5 and F6 from and file3.h5.
- loadh5(filename=None)[source]#
Load data from an HDF5 file into the analysis object.
- Parameters:
filename (str, optional) – The name of the HDF5 file to load. If None, it loads the dataset specified in the dataset attribute.
- Return type:
None
Notes
If None, sets the dataset attribute equals to the filename input
The ‘infoChannel’, ‘adZero’, ‘conversionFactor’, ‘exponent’, and ‘wellsFromData’ attributes are updated based on the data loaded from the HDF5 file.
Examples
>>> obj = Analysis() >>> obj.loadh5() # Load the dataset from dataset attribute
>>> obj.loadh5('example.h5') # Load data from a specific HDF5 file
- loadmodel(setting='default')[source]#
Load a machine learning model to perform reverberations/bursts detection. Automatically loads bundled pretrained models if available.
- loadsignal(signal)[source]#
Load a signal into the analysis object.
- Parameters:
signal (array_like) – The signal data to be loaded for analysis. It can be a 1D or 2D array, depending if the signal has one or multiple channels.
- Return type:
None
Notes
If the signal is 1D, it is assumed to be a one-channel time series signal.
If the signal is 2D, it is assumed to be a collection of channels, with signals over time.
The total_timesteps_signal attribute is updated to reflect the length of the signal.
The
timeattribute is generated based on the sampling frequency and the length of the signal.
Examples
>>> obj = Analysis() >>> obj.loadsignal(signal_data)
- loadspikes(spikes)[source]#
Load spike data into the analysis object.
This method allows loading spike data into the analysis object for further processing.
- Parameters:
spikes (array_like) – The spike data to be loaded for analysis.
- Return type:
None
- loadwell(file, well, method='default', spikes=False, reverbs=False, bursts=False, net_reverbs=False, net_bursts=False)[source]#
Load data for a specific well.
This method loads data for a specific well from an HDF5 file into the analysis object for further processing. Optionally, it can also detect spikes and analyze them for reverberations and bursts, calling the deticated methods.
- Parameters:
file (str) – The name of the HDF5 file containing the data.
method (str, optional) – The method to use for detecting reverbs and bursts if spikes are detected. Default is ‘default’.
spikes (bool, optional) – Whether to detect spikes. Default is False.
reverbs (bool, optional) – Whether to analyze reverberations. Default is False.
bursts (bool, optional) – Whether to analyze bursts. Default is False.
net_reverbs (bool, optional) – Whether to analyze net reverberations. Default is False.
net_bursts (bool, optional) – Whether to analyze net bursts. Default is False.
- Return type:
None
Examples
>>> obj = Analysis() >>> obj.loadwell('data.h5', 'well_label', method='model', spikes=True, reverbs=True)
Notes
The file parameter specifies the name of the HDF5 file containing the data.
The well parameter can be either a well label (str) or index (int).
The method parameter determines the method to use for detecting reverberations and bursts. It is only used if spikes are detected and defaults to ‘default’.
The spikes, reverbs, bursts, net_reverbs, and net_bursts parameters control which analyses to perform after loading the data. They default to False.
- normalize_signal(signal)[source]#
Normalize the input signal.
- Parameters:
signal (array_like) – Input signal to be normalized.
- Returns:
Normalized signal.
- Return type:
array_like
Notes
The normalization is performed by dividing the signal by its maximum absolute value.
- normalize_threshold(signal, threshold)[source]#
Normalize the threshold relative to the input signal.
- Parameters:
signal (array_like) – Input signal used for normalization.
threshold (float) – Threshold value to be normalized.
- Returns:
Normalized threshold.
- Return type:
Notes
The threshold is normalized by dividing it by the maximum absolute value of the input signal.
- plot_raster(spikes, reverbs=None, bursts=None, net_reverbs=None, net_bursts=None, start_time=None, end_time=None, save=None, show=True)[source]#
Plot a raster plot of spikes with optional overlay of reverberations, bursts, and network bursts.
- Parameters:
spikes (array_like) – The timestamps of spikes. Can be a list of timestamps for multiple channels.
reverbs (array_like, optional) – The timestamps data of detected reverberations.
bursts (array_like, optional) – The timestamps data of detected bursts.
net_reverbs (array_like, optional) – The timestamps data of detected network reverberations.
net_bursts (array_like, optional) – The timestamps data of detected network bursts.
start_time (float, optional) – Starting time of the plot, in seconds.
end_time (float, optional) – Ending time of the plot, in seconds.
save (str, optional) – Name of the generated plot figure.
show (bool, optional) – Whether to show or not the plot. Default is True.
- Return type:
None
Notes
Each spike is represented by a vertical line at its timestamp.
Detected events are filled between their start and end timestamps.
- plot_raster_well(file, well, method='default', reverbs=False, bursts=False, net_reverbs=False, net_bursts=False, start_time=None, end_time=None, save=None)[source]#
Plot a raster plot for a specific well with optional overlay of events.
- Parameters:
file (str) – The filename or path of the data file.
well (str) – The label or ID of the well to plot.
method (str, optional) – The method used for detecting events. Default is ‘default’.
reverbs (bool, optional) – Whether to overlay detected reverberations on the raster plot. Default is False.
bursts (bool, optional) – Whether to overlay detected bursts on the raster plot. Default is False.
net_reverbs (bool, optional) – Whether to overlay detected network reverberations on the raster plot. Default is False.
net_bursts (bool, optional) – Whether to overlay detected network bursts on the raster plot. Default is False.
start_time (float, optional) – Starting time of the plot, in seconds.
end_time (float, optional) – Ending time of the plot, in seconds.
save (str, optional) – Name of the generated plot figure.
- Return type:
None
- plot_window(signal, start_time=None, duration=None, threshold=None, spikes=None, reverberations=None, net_reverberations=None, bursts=None, net_bursts=None, save=None, show=True, figsize=(6, 6), yunits='a.u.', xunits='s')[source]#
Plot a window of the signal with detected spikes, reverberations, bursts, and network bursts.
- Parameters:
signal (array_like) – The input signal data.
start_time (float, optional) – The start time of the window in seconds. Default is None (start from the beginning).
duration (float, optional) – The duration of the window in seconds. Default is None (plot until the end of the signal).
threshold (float, optional) – The threshold value for plotting. Default is None (no threshold line).
spikes (array_like, optional) – The timestamps of detected spikes. Default is None (no spikes in the plot)
reverberations (array_like, optional) – The timestamps data of detected reverberations. Default is None
bursts (array_like, optional) – The timestamps data detected bursts. Default is None
net_bursts (array_like, optional) – The timestamps data of detected network bursts. Default is None
save (str, optional) – Name of the generated plot figure.
show (bool, optional) – Whether to show or not the plot. Default is True.
figsize (tuple, optional) – The size of the figure (width, height) in inches. Default is (6, 6).
yunits (str, optional) – The units of the y-axis. Default is ‘a.u.’ (arbitrary units).
xunits (str, optional) – The units of the x-axis. Default is ‘s’ (seconds).
Notes
It normalizes the signal if yunits is ‘a.u.’ and converts it to millivolts (mV) if yunits is ‘mV’.
Detected spikes, reverberations, bursts, and network bursts are overlaid on the plot with different colors.
- reduce_dimension(X, input_type=None, reduction_factor=None)[source]#
Reduce the dimensionality of the input data.
- Parameters:
- Returns:
Dimensionally reduced input data.
- Return type:
array_like
Notes
If ‘input_type’ is ‘spikes’, the dimensionality is reduced by selecting every ‘reduction_factor’ element.
If ‘input_type’ is ‘signal’, the dimensionality is reduced by averaging every ‘reduction_factor’ elements.
- reduce_norm_abs_signal(signal)[source]#
Reduce the dimensionality of the normalized absolute signal.
- Parameters:
signal (array_like) – Input signal to be normalized and dimensionally reduced.
- Returns:
Dimensionally reduced normalized absolute signal.
- Return type:
array_like
- reverbs_params_default()[source]#
Set default parameters for reverberations/bursts detection.
- Return type:
None
Notes
This method sets default parameters for detecting reverberations, including: - max_interval_start: Maximum interval start time for a reverberation. - max_interval_end: Maximum interval end time for a reverberation. - min_interval_between: Minimum interval between reverberations. - min_duration: Minimum duration of a reverberation. - min_spikes: Minimum number of spikes required to consider a reverberation.
- reverbs_params_manual(params)[source]#
Set manual parameters for reverberations detection.
- Parameters:
params (list) – List containing manual parameters for reverberations detection in the following order: - max_interval_start: Maximum interval start time for a reverberation. - max_interval_end: Maximum interval end time for a reverberation. - min_interval_between: Minimum interval between reverberations. - min_duration: Minimum duration of a reverberation. - min_spikes: Minimum number of spikes required to consider a reverberation.
- Return type:
None
- save_spikes()[source]#
Save spikes data to a CSV file.
Notes
The method saves spikes data to a CSV file containing columns for channel ID, channel label, well ID, well label, compound ID, compound name, experiment, dose in pM, dose label, and timestamp.
The CSV file is saved in the output folder with a filename based on the output name attribute and the type of data being saved (e.g., ‘_REVERBS_PREDICTED.csv’).