Code functions¶
The MainWindow object is located in the main.py file. This object is the main window that opens when you run pyhon main.py. Here is every function that constitutes that window and how the data is processed by each function.
- class main.MainWindow(*args, **kwargs)¶
Bases:
QMainWindow
- bin_matrix(mat, bin_size, bin_method)¶
Bins the input matrix along the timepoints dimension using the specified binning method.
- Parameters:
mat (numpy.ndarray of shape (n, t)) – The input matrix to be binned, where each row represents an element and each column represents a timepoint.
bin_size (int) – The number of timepoints to include in each bin. Must be smaller than the number of timepoints in mat.
bin_method (str) – The method used to bin the data. Options are “mean” to compute the mean of each bin, or “sum” to compute the sum.
- Raises:
ValueError – If bin_method is not one of the accepted values (“mean” or “sum”).
- Returns:
A matrix with the same number of rows as mat but with columns reduced by the binning operation.
- Return type:
numpy.ndarray of shape (n, b)
- Example:
>>> mat = np.array([[1, 2, 3, 4], [5, 6, 7, 8]]) >>> bin_size = 2 >>> bin_method = "mean" >>> binned_mat = self.bin_matrix(mat, bin_size, bin_method) >>> print(binned_mat) array([[1.5, 3.5], [5.5, 7.5]])
- browse_files()¶
Opens a file browing dialog to open a new file.
This function also loads the file tree model and shows it in the variable browser widget.
- clear_behavior()¶
Deletes the value of the
MainWindow.data_behavior
variable.This function also updates the buttons related to load and clear the variable At the end the function clears visualization in the
MainWindow.data_preview
widget.
- clear_cells()¶
Deletes the value of the
MainWindow.data_cells
variable.This function also updates the buttons related to load and clear the variable At the end the function clears visualization in the
MainWindow.data_preview
widget.
- clear_coordinates()¶
Deletes the value of the
MainWindow.data_coordinates
variable.This function also updates the buttons related to load and clear the variable At the end the function clears visualization in the
MainWindow.data_preview
widget.
- clear_dFFo()¶
Deletes the value of the
MainWindow.data_dFFo
variable.This function also updates the buttons related to load and clear the variable At the end the function clears visualization in the
MainWindow.data_preview
widget.
- clear_neuronal_activity()¶
Deletes the value of the
MainWindow.data_neuronal_activity
variable.This function also updates the buttons related to load and clear the variable At the end the function clears visualization in the
MainWindow.data_preview
widget.
- clear_stims()¶
Deletes the value of the
MainWindow.data_stims
variable.This function also updates the buttons related to load and clear the variable At the end the function clears visualization in the
MainWindow.data_preview
widget.
- dict_to_matlab_struct(pars_dict)¶
Converts a Python dictionary to a MATLAB struct.
- Parameters:
pars_dict (dict) – A dictionary where keys represent the names of fields in the MATLAB struct and the values represent the corresponding field values.
- Returns:
A MATLAB struct where the keys are the field names and the values are converted to the appropriate MATLAB data type.
- Return type:
dict
This function recursively converts a Python dictionary to a MATLAB struct. It handles nested dictionaries by recursively calling the conversion function. Numeric values (integers or floats) are converted into MATLAB double type, while other data types are kept unchanged.
- edit_bin()¶
Reads the binning parameters and performs the binning in the selected dataset.
Loads the bin size and bin method from the UI, and shows feedback to the user about the performed operation. If the input is invalid nothing is changed.
- edit_transpose()¶
Transpose the currently visualized variable.
Simple transpose of the data currently viewed in the MainWindow.data_preview widget. This method changes both the stored data and the visualization. Also, a message is shown to the user about the interpretation of the transpose.
- edit_trimmatrix()¶
Edits the currently visualized matrix by trimming its rows and/or columns based on user-specified indices.
- Returns:
None
This method uses the start and end indices entered by the user to trim the matrix currently selected for editing. Depending on the selection, it will trim one of the following datasets: dFFo, neuronal_activity, coordinates, stims, cells, or behavior. For each dataset, if valid start and end indices are provided for the x-axis or y-axis, it slices the data accordingly and updates the view for that dataset.
After trimming, the console log is updated to notify the user, and the appropriate preview function is called to display the updated dataset.
- enscomp_get_color()¶
Opens the QColorDialog to select a color for the selected analysis.
The selected color will be applied to the elements of the algorithm selected in the combo box for the Ensemble Compare tab. :return: None :rtype: None
- enscomp_get_color_behavior()¶
Opens the QColorDialog to select a color for the behavior.
The selected color will be applied to the elements of the behavior. :return: None :rtype: None
- enscomp_get_color_stims()¶
Opens the QColorDialog to select a color for the stimulation.
The selected color will be applied to the elements of the stimulation. :return: None :rtype: None
- ensembles_compare_get_elements_labels(criteria)¶
Retrieves elements and their labels for ensembles comparison based on a given criterion.
This method extracts elements from the results dictionary according to the specified criterion (e.g., neurons in ensemble or timecourse). It also generates labels for these elements, indicating the algorithm and the ensemble index.
- Parameters:
criteria (string) – The key used to extract elements from each algorithm’s results.
- Returns:
A tuple containing the array of elements and their corresponding labels.
- Return type:
tuple (numpy.ndarray, list of string)
- ensembles_compare_get_simmatrix(method, all_elements)¶
Calculates the similarity matrix for a set of elements using the specified method.
This method computes pairwise similarity or distance metrics (e.g., cosine, Euclidean, correlation, Jaccard) and formats the result as a similarity matrix.
- Parameters:
method (string) – The similarity or distance metric to use. Valid options are: ‘Cosine’, ‘Euclidean’, ‘Correlation’, ‘Jaccard’.
all_elements (numpy.ndarray) – A numpy array containing the elements to compare. Each row represents a single element, and columns represent features.
- Raises:
ValueError – If an unsupported method is provided.
- Returns:
A similarity matrix where each entry represents the pairwise similarity between elements.
- Return type:
numpy.ndarray
- ensembles_compare_similarity(component=None, first_show=False)¶
Computes and visualizes the similarity matrix for ensembles based on a selected component.
This method calculates the similarity matrix for ensembles using either the “Neurons” or “Timecourses” component. It updates the visualization options and plots the results.
- Parameters:
component (str, optional) – Specifies the component to compute the similarity for (“Neurons” or “Timecourses”). If not provided, the currently selected component in the GUI is used.
first_show (bool, optional) – Indicates whether this is the initial visualization, which determines default visualization settings.
- Returns:
None
- Return type:
None
- ensembles_compare_similarity_update_combbox(text)¶
Updates the combo boxes for similarity method and colormap based on the selected component.
This method adjusts the currently displayed options in the similarity method and colormap combo boxes to match the visualization settings for the selected component (“Neurons” or “Timecourses”).
- Parameters:
text (string) – The selected component, either “Neurons” or “Timecourses”.
- Returns:
None
- Return type:
None
- ensembles_compare_tabchange(index)¶
Handles tab changes in the GUI, updating the interface and displaying similarity maps as needed.
This method is triggered when the user switches tabs in the GUI. It updates the state of dropdown menus and enables/disables specific components depending on the selected tab. If the user navigates to the tabs for “Neurons” or “Timecourses”, it ensures that the similarity maps are displayed for the first time.
- Parameters:
index (int) – The index of the currently selected tab. - 2: Neurons tab - 3: Timecourses tab
- Returns:
None
- Return type:
None
- ensembles_compare_update_combo_results(text)¶
Updates the visualization options for the selected algorithm.
This function is executed when the combo box value is changed. Loads the visualization options for the current algorithm.
- Parameters:
text (string) – Name of the selected analysis as shown in the combo box.
- Returns:
None
- Return type:
None
- ensembles_compare_update_ensembles()¶
Updates the ensembles comparison settings and visualizations.
This method collects the selected ensembles from various methods (SVD, PCA, ICA, X2P), updates their corresponding properties (index, neurons in ensemble, and timecourse), and applies the visualization options to the GUI. The method also updates the comparison map and timecourse visualizations.
- Returns:
None
- Return type:
None
- ensembles_compare_update_map(ensembles_to_compare)¶
Updates the spatial map in ensembles compare.
This function calculates the shared neurons between every ensemble according to the current visualization options, and asigns colors for each neuron in the map.
- Parameters:
ensembles_to_compare (dict) – Dictionary with where each key is the name of an algorithm, the value is another dictionary. The key used here is neus_in_ens with a binary numpy matrix with shape with the members of each ensemble.
- Returns:
None
- Return type:
None
- ensembles_compare_update_opts(algorithm)¶
Updates the option buttons with the data from the given analysis.
This function receives the name of some algorithm and then updates the options in the Ensemble Compare tab. In this function the slider and labels of each analysis is assigned and then the general buttons are loaded.
- Parameters:
algorithm (string) – String with the name of the algorithm, in lower case and three chars syntax.
- Returns:
None
- Return type:
None
- ensembles_compare_update_timecourses(ensembles_to_compare)¶
Updates the timecourse plot in the ensembles compare tab.
This function extracts the timecourse of the selected ensembles accordingly with the current visualization options and then plots those in the corresponding figure.
- Parameters:
ensembles_to_compare (dict) – Dictionary with where each key is the name of an algorithm, the value is another dictionary. The keys used here are “neus_in_ens” with a binary numpy matrix with shape with the members of each ensemble and “timecourse” with a binary matrix describing the moment of activation of the selected ensembles.
- Returns:
None
- Return type:
None
- ensvis_tabchange(index)¶
Identifies the tab change in the ensamble visualizer for asynchronous loading of plots.
The loading of all the comparations and plots could be slow when loaded all at the same time. For this, the plots are loaded only when the user reaches the relevant tab.
- Parameters:
index (int) – Index of the tab opened by the user.
- get_data_to_save()¶
Prepares data for saving based on the selected checkboxes in the GUI.
This method compiles data from various sources, including input data, results, analysis parameters, algorithms results, ensembles comparison, and performance metrics. It gathers and organizes the data to be saved into a dictionary format, which can later be written to a file. The specific data included depends on the user’s selections in the GUI checkboxes.
It collects the following data: - Input data (e.g., dFFo, neuronal activity, stimuli, coordinates, behavior, etc.) - Results from the ensembles comparison - Parameters used in the analysis - Full algorithm results - Performance metrics for ensembles, including correlation with stimuli, behavior, and cross-correlation
The method also generates a timestamp and stores it in the data under the key “EnsemblesGUI”.
- Returns:
A dictionary containing the data to be saved.
- Return type:
dict
- initialize_ensemble_view()¶
Loads the slider for ensemble selection for the chosen analysis and sets its limits.
- Returns:
None
- Return type:
None
This function makes available the ensemble selector. This function also loads the visualization of the first ensemble.
- item_clicked(index)¶
Handles the click event on a variable in the
MainWindow.tree_view
, displaying relevant information about the selected variable and enabling or disabling assign and clear buttons in the UI.- Parameters:
index (QModelIndex) – The index of the clicked item in the file model.
- Returns:
None
This method retrieves information about the selected variable, including its path in the file, type, and size. The item’s name is extracted from the path and displayed along with its description in the UI. Depending on the type and size of the item, it enables or disables specific buttons related to the assigning to a dataset. The relevant information is also stored for further processing.
- load_defaults_ica()¶
Loads default ICA parameter values into the UI fields.
This method retrieves the default parameter values for ICA analysis from MainWindow.ica_defaults and sets the corresponding values in the UI fields. It also updates the console log to indicate that the default values have been successfully loaded.
- Returns:
None
- load_defaults_pca()¶
Loads default PCA parameter values into the UI fields.
This method retrieves the default parameter values for PCA analysis from MainWindow.pca_defaults and sets the corresponding values in the UI fields. It also updates the console log to indicate that the default values have been successfully loaded.
- Returns:
None
- load_defaults_sgc()¶
Loads default SGC parameter values into the UI fields.
This method retrieves the default parameter values for SGC analysis from MainWindow.sgc_defaults and sets the corresponding values in the UI fields. It also updates the console log to indicate that the default values have been successfully loaded.
- Returns:
None
- load_defaults_svd()¶
Loads default SVD parameter values into the UI fields.
This method retrieves the default parameter values for SVD analysis from MainWindow.svd_defaults and sets the corresponding values in the UI fields. It also updates the console log to indicate that the default values have been successfully loaded.
- Returns:
None
- load_defaults_x2p()¶
Loads default Xsembles2P parameter values into the UI fields.
This method retrieves the default parameter values for Xsembles2P analysis from MainWindow.x2p_defaults and sets the corresponding values in the UI fields. It also updates the console log to indicate that the default values have been successfully loaded.
- Returns:
None
- main_tabs_change(index)¶
Identifies the change in tabs to load some data.
This function allows the asynchronous verification and loading of some tabs identified by index. For the analysis tabs, the necessary data is evaluated and then change the text accordingly. For the ensembles compare tab the visualizations are only loaded when the user reaches this tab.
- Parameters:
index (int) – Index of the currently open tab, 0 indexing.
- performance_check_change()¶
Updates the list of selected methods for performance comparison based on user input.
This method checks the state of multiple checkboxes corresponding to different analysis methods (SVD, PCA, ICA, X2P, SGC) and updates the list of methods to compare. It also enables or disables the compare button based on whether any methods are selected.
- Returns:
None
- Return type:
None
- performance_compare()¶
Performs performance comparison and initializes relevant performance tabs.
This method sets up temporary variables to track which performance tabs have been displayed, sets the default tab to the first tab, and updates the correlations with stimulus data if such data is available.
- Returns:
None
- Return type:
None
- performance_tabchange(index)¶
Handles tab changes in the performance analysis section of the GUI, triggering updates for the selected tab.
This method ensures that specific updates are performed when the user switches tabs in the performance analysis section. Each tab corresponds to a different type of performance metric or visualization.
- Parameters:
index (int) – The index of the currently selected tab. - 0: Correlation with ensemble presentation - 1: Correlations between cells - 2: Cross correlations between ensembles and stimuli - 3: Correlation with behavior - 4: Cross correlations with behavior
- Returns:
None
- Return type:
None
- plot_ICA_results(answer)¶
Plots the results of the ICA algorithm, including assembly templates, time projections, binary assembly templates, core cells and binary assemblies.
- Parameters:
answer (dict) – Dictionary containing the ICA output data from MATLAB, including assembly templates, time projections, binary assembly templates, and binary assemblies.
- Returns:
None
- Return type:
None
- plot_PCA_results(pars, answer)¶
Plots the results of the PCA algorithm, including eigen values, principal components, rho and delta values, correlation of cells, core cells and ensembles time course.
- Parameters:
answer (dict) – Dictionary containing the PCA output data from MATLAB, including eigen values, principal components, rho and delta values, correlation of cells, core cells and ensembles time course.
- Returns:
None
- Return type:
None
- plot_SVD_results(answer)¶
Plots and saves the results of the SVD algorithm, including similarity maps, singular values, components, and ensemble timecourses.
- Parameters:
answer (dict) – Dictionary containing the SVD output data from MATLAB, including matrices for similarity maps, singular values, component vectors, ensemble timecourses, and neuron groupings.
- Returns:
None
- Return type:
None
- plot_X2P_results(answer)¶
Plots the results of the X2P algorithm, including similarity map, EPI, onsemble activity, offsemble activity, activity, onsembles neurons and offsemble neurons.
- Parameters:
answer (dict) – Dictionary containing the X2P output data from MATLAB, including similaty map, EPI, onsemble activity, offsemble activity, activity, onnsembles neurons and offsemble neurons.
- Returns:
None
- Return type:
None
- plot_sgc_results(answer)¶
- reset_gui()¶
Reset the GUI, delete all the variables and analysis results. Also clears all the figures and restores the analysis and display options. The result is the GUI just like the first time you opened it.
- run_ICA()¶
Retrieves user-defined parameters for ICA from the GUI, applies default values if fields are empty, and initiates the ICA analysis in parallel. The function also updates the console log with messages about the current status and resets any previously displayed ICA figures.
- Returns:
None
- Return type:
None
- run_PCA()¶
Retrieves user-defined parameters for PCA from the GUI, applies default values if fields are empty, and initiates the PCA analysis in parallel. The function also updates the console log with messages about the current status and resets any previously displayed PCA figures.
- Returns:
None
- Return type:
None
- run_ica_parallel(spikes, pars_matlab)¶
Initializes and runs the MATLAB engine to execute the ICA algorithm on neural activity data in parallel. This function also handles MATLAB path setup, updates parameter values in the GUI, and plots the results.
- Parameters:
spikes (matlab.double) – Matrix of neural activity data to be processed.
pars_matlab (dict) – MATLAB structure of parameters for the ICA algorithm.
- Returns:
List of times taken for MATLAB engine setup, ICA execution, and plotting.
- Return type:
list[float]
- run_ica_parallel_end(times)¶
Runs when the ICA execution process finishes, logging timing information for each stage of the computation, and re-enables the ICA run button.
- Parameters:
times (list[float]) – List containing the time taken for MATLAB engine loading, algorithm execution, and plotting in seconds.
- Returns:
None
- Return type:
None
- run_pca_parallel(raster, pars_matlab, pars)¶
Initializes and runs the MATLAB engine to execute the PCA algorithm on neural activity data in parallel. This function also handles MATLAB path setup, updates parameter values in the GUI, and plots the results.
- Parameters:
raster (matlab.double) – Matrix of neural activity data to be processed.
pars_matlab (dict) – MATLAB structure of parameters for the PCA algorithm.
pars (dict) – Python dictionary of parameters for the PCA algorithm, used for plotting.
- Returns:
List of times taken for MATLAB engine setup, PCA execution, and plotting.
- Return type:
list[float]
- run_pca_parallel_end(times)¶
Runs when the PCA execution process finishes, logging timing information for each stage of the computation, and re-enables the PCA run button.
- Parameters:
times (list[float]) – List containing the time taken for MATLAB engine loading, algorithm execution, and plotting in seconds.
- Returns:
None
- Return type:
None
- run_sgc()¶
Retrieves user-defined parameters for SGC from the GUI, applies default values if fields are empty, and initiates the SGC analysis in parallel. The function also updates the console log with messages about the current status and resets any previously displayed SGC figures.
- Returns:
None
- Return type:
None
- run_sgc_parallel(dFFo, pars_matlab)¶
Initializes and runs the MATLAB engine to execute the SGC algorithm on neural activity data in parallel. This function also handles MATLAB path setup, updates parameter values in the GUI, and plots the results.
- Parameters:
spikes (matlab.double) – Matrix of neural activity data to be processed.
dFFo (matlab.double) – Matrix of neural flourescence data to be processed
pars_matlab (dict) – MATLAB structure of parameters for the SGC algorithm.
- Returns:
List of times taken for MATLAB engine setup, SGC execution, and plotting.
- Return type:
list[float]
- run_sgc_parallel_end(times)¶
Runs when the SGC execution process finishes, logging timing information for each stage of the computation, and re-enables the SGC run button.
- Parameters:
times (list[float]) – List containing the time taken for MATLAB engine loading, algorithm execution, and plotting in seconds.
- Returns:
None
- Return type:
None
- run_svd()¶
Retrieves user-defined parameters for Singular Value Decomposition (SVD) from the GUI, applies default values if fields are empty, and initiates the SVD analysis in parallel. The function also updates the console log with messages about the current status and resets any previously displayed SVD figures.
- Returns:
None
- Return type:
None
- run_svd_parallel(spikes, coords_foo, pars_matlab)¶
Initializes and runs the MATLAB engine to execute the SVD algorithm on neural activity data in parallel. This function also handles MATLAB path setup, updates parameter values in the GUI, and plots the results.
- Parameters:
spikes (matlab.double) – Matrix of neural activity data to be processed.
coords_foo (matlab.double) – Matrix of dummy coordinates used as input for the SVD function.
pars_matlab (dict) – MATLAB structure of parameters for the SVD algorithm.
- Returns:
List of times taken for MATLAB engine setup, SVD execution, and plotting.
- Return type:
list[float]
- run_svd_parallel_end(times)¶
Finalizes the SVD execution process, logging timing information for each stage of the computation, and re-enables the SVD run button.
- Parameters:
times (list[float]) – List containing the time taken for MATLAB engine loading, algorithm execution, and plotting in seconds.
- Returns:
None
- Return type:
None
- run_x2p()¶
Retrieves user-defined parameters for Xsembles2P from the GUI, applies default values if fields are empty, and initiates the X2P analysis in parallel. The function also updates the console log with messages about the current status and resets any previously displayed X2P figures.
- Returns:
None
- Return type:
None
- run_x2p_parallel(raster, pars_matlab)¶
Initializes and runs the MATLAB engine to execute the X2P algorithm on neural activity data in parallel. This function also handles MATLAB path setup, updates parameter values in the GUI, and plots the results.
- Parameters:
raster (matlab.double) – Matrix of neural activity data to be processed.
pars_matlab (dict) – MATLAB structure of parameters for the X2P algorithm.
- Returns:
List of times taken for MATLAB engine setup, X2P execution, and plotting.
- Return type:
list[float]
- run_x2p_parallel_end(times)¶
Runs when the X2P execution process finishes, logging timing information for each stage of the computation, and re-enables the X2P run button.
- Parameters:
times (list[float]) – List containing the time taken for MATLAB engine loading, algorithm execution, and plotting in seconds.
- Returns:
None
- Return type:
None
- save_data_to_hdf5(group, data)¶
Recursively saves data to an HDF5 file group.
This method iterates through a dictionary and saves its contents to the provided HDF5 group. If a value in the dictionary is another dictionary, it creates a subgroup and recursively saves its contents. If the value is a list, it attempts to create a dataset in the group, catching exceptions if the data cannot be saved. For other data types, the method directly stores the value in the group.
- Parameters:
group (h5py.Group) – The HDF5 group to which the data will be saved.
data (dict) – The data to be saved, which can be a dictionary, list, or other types.
- save_results_hdf5()¶
Saves the current results to an HDF5 file.
This method retrieves the data to be saved using
MainWindow.get_data_to_save()
, prompts the user to choose a location and name for the file, and then saves the data in HDF5 format. The file is saved using theMainWindow.save_data_to_hdf5()
method to recursively write the data into the file.The file is named based on the current date and a prefix “EnsGUI”, and the user is prompted to choose a location and file name via a file dialog.
- Raises:
IOError – If the file could not be saved.
- save_results_mat()¶
Saves the current results to a MATLAB (.mat) file.
This method retrieves the data to be saved using the
MainWindow.get_data_to_save()
method, prompts the user to choose a location and file name using a file dialog, and then saves the retrieved data into a MATLAB .mat file using the scipy.io.savemat() function.The default file name is based on the current date and a prefix “EnsGUI”. If the user cancels or does not provide a file name, the function will not proceed.
If an error occurs while saving the file, an IOError is raised to notify the user that the file could not be saved.
- Raises:
IOError – If there is an error saving the file, for example, if the file path is invalid or the file cannot be written to.
- save_results_pkl()¶
Saves the current results to a Pickle (.pkl) file.
This method retrieves the data to be saved using the
MainWindow.get_data_to_save()
method, prompts the user to choose a location and file name using a file dialog, and then saves the retrieved data into a Pickle (.pkl) file. The Pickle format is a binary format used for serializing Python objects.The default file name is based on the current date and a prefix “EnsGUI”. If the user cancels or does not provide a file name, the function will not proceed.
If an error occurs while saving the file, an IOError is raised to notify the user that the file could not be saved.
- Raises:
IOError – If there is an error saving the file, for example, if the file path is invalid or the file cannot be written to.
- set_able_edit_options(boolval)¶
Changes the enabled status of the editing options.
- Parameters:
boolval (bool) – When true, all the buttons for editing are enabled, dissabled otherwise.
- set_behavior()¶
Sets the value of the
MainWindow.data_behavior
variable.The assigned value is the one of the selected variable in the variable broswer. This function also updates the buttons related to load and clear the variable and triggers the visualization function. At the end the function shows the loaded data in the
MainWindow.data_preview
widget.
- set_cells()¶
Sets the value of the
MainWindow.data_cells
variable.The assigned value is the one of the selected variable in the variable broswer. This function also updates the buttons related to load and clear the variable and triggers the visualization function. At the end the function shows the loaded data in the
MainWindow.data_preview
widget.
- set_coordinates()¶
Sets the value of the
MainWindow.data_coordinates
variable.The assigned value is the one of the selected variable in the variable broswer. Only the first two elements of the second dimention are assigned. This function also updates the buttons related to load and clear the variable and triggers the visualization function. At the end the function shows the loaded data in the
MainWindow.data_preview
widget.
- set_dFFo()¶
Sets the
MainWindow.dFFo
dataset by assigning data from a file and updating the relevant UI components.This method loads the dFFo dataset from the selected file. It then updates the UI to reflect that the dataset has been assigned, enables buttons for further edition, and logs the update message.
- Returns:
None
- set_neuronal_activity()¶
Sets the
MainWindow.data_neuronal_activity
dataset by assigning data from a file and updating the relevant UI components.This method loads the data_neuronal_activity dataset from the selected file and extracts the number of cells (cant_neurons) and time points (cant_timepoints). It then updates the UI to reflect that the dataset has been assigned, enables buttons for further edition, and logs the update message.
- Returns:
None
- set_stims()¶
Sets the value of the
MainWindow.data_stims
variable.The assigned value is the one of the selected variable in the variable broswer. This function also updates the buttons related to load and clear the variable and triggers the visualization function. At the end the function shows the loaded data in the
MainWindow.data_preview
widget.
- update_analysis_results()¶
Pre-loads the General tab in the ensembles visualizer.
- Returns:
None
- Return type:
None
This function also saves the state of shown/not-shown of the other tabs for asynchronous loading and caching.
- update_console_log(message, msg_type='log')¶
Updates the console log with a new message, formatted with a specific color based on the message type.
- Parameters:
message (str) – The message to be displayed in the console log.
msg_type (str, optional) – The type of the message, which determines its color. It can be one of “log”, “error”, “warning”, or “complete”. Defaults to “log”.
- Returns:
None
This method formats the log entry by including the current timestamp and the provided message. The message is displayed in a monospace font with different colors based on the message type. The new message is appended to the console log, and the view is updated to scroll to the bottom to ensure the message is visible.
- update_corr_behavior()¶
Updates the plot of correlation with behavior data by initiating a parallel worker thread.
This method retrieves the plot widget for displaying correlation with behavior, and starts a worker thread to perform the correlation update in parallel, which is then rendered in the plot widget.
- Returns:
None
- Return type:
None
- update_corr_behavior_parallel(plot_widget)¶
Calculates and updates the correlation between the ensemble timecourses and behavior data.
This method computes the correlation for each selected method (e.g., SVD, PCA, ICA, etc.) between the ensemble timecourses and the behavior data, and then updates the plot widget with the results. It handles the display by organizing the plots into a specified layout based on the number of methods being compared.
- Parameters:
plot_widget (MatplotlibWidget) – The widget used to display the correlation plots.
- Returns:
None
- Return type:
None
- update_corr_stim()¶
Updates the plot of correlation with stimulus data by initiating a parallel worker thread.
This method retrieves the plot widget for displaying correlation with stimuli, and starts a worker thread to perform the correlation update in parallel, which is then rendered in the plot widget.
- Returns:
None
- Return type:
None
- update_corr_stim_parallel(plot_widget)¶
Calculates and updates the correlation between the ensemble timecourses and stimulus data.
This method computes the correlation for each selected method (e.g., SVD, PCA, ICA, etc.) between the ensemble timecourses and the stimulus data, and then updates the plot widget with the results. It handles the display by organizing the plots into a specified layout based on the number of methods being compared.
- Parameters:
plot_widget (MatplotlibWidget) – The widget used to display the correlation plots.
- Returns:
None
- Return type:
None
- update_correlation_cells()¶
Updates the plot of correlation between the activations of the neurons in the same ensemble by initiating a parallel worker thread.
This method retrieves the plot widget for displaying correlation between the neurons in the ensembles, and starts a worker thread to perform the correlation update in parallel, which is then rendered in the plot widget.
- Returns:
None
- Return type:
None
- update_correlation_cells_parallel(plot_widget)¶
Calculates and updates the correlation between the activation of the cells in the ensemble.
This method computes the correlation for each selected method (e.g., SVD, PCA, ICA, etc.) between the neurons in the ensemble, and then updates the plot widget with the results. It handles the display by organizing the plots into a specified layout based on the number of methods being compared.
- Parameters:
plot_widget (MatplotlibWidget) – The widget used to display the correlation plots.
- Returns:
None
- Return type:
None
- update_cross_behavior()¶
Updates the plot of cross-correlation with behavior data by initiating a parallel worker thread.
This method retrieves the plot widget for displaying cross-correlation with behavior, and starts a worker thread to perform the cross-correlation update in parallel, which is then rendered in the plot widget.
- Returns:
None
- Return type:
None
- update_cross_behavior_parallel(plot_widget)¶
Calculates and updates the cross-correlation between the ensemble timecourses and behavior data.
This method computes the cross-correlation for each selected method (e.g., SVD, PCA, ICA, etc.) between the ensemble timecourses and the behavior data, and then updates the plot widget with the results. It handles the display by organizing the plots into a specified layout based on the number of methods being compared.
- Parameters:
plot_widget (MatplotlibWidget) – The widget used to display the cross-correlation plots.
- Returns:
None
- Return type:
None
- update_cross_ens_stim()¶
Updates the plot of cross-correlation with stimulus data by initiating a parallel worker thread.
This method retrieves the plot widget for displaying cross-correlation with stimuli, and starts a worker thread to perform the cross-correlation update in parallel, which is then rendered in the plot widget.
- Returns:
None
- Return type:
None
- update_cross_ens_stim_parallel(plot_widget)¶
Calculates and updates the cross-correlation between the ensemble timecourses and stimulus data.
This method computes the cross-correlation for each selected method (e.g., SVD, PCA, ICA, etc.) between the ensemble timecourses and the stimulus data, and then updates the plot widget with the results. It handles the display by organizing the plots into a specified layout based on the number of methods being compared.
- Parameters:
plot_widget (MatplotlibWidget) – The widget used to display the cross-correlation plots.
- Returns:
None
- Return type:
None
- update_edit_validators(lim_sup_x=10000000, lim_sup_y=10000000)¶
Update the validators for bining and slicing.
- Parameters:
lim_sup_x (int, optional) – Maximum value possible for the x dimention, defaults to 10000000
lim_sup_y (int, optional) – Mavimum value possible for the y dimention, defaults to 10000000
- update_ens_vis_coords()¶
Shows the neurons maps in the ensembles visualizer and enables the visualizer buttons.
This is a separated function to be executed also when the visualization options are updated and show the visualization with the new options in real time.
- Returns:
None
- Return type:
None
- update_enscomp_options(exp_data)¶
Loads the behavior or stimulation data into the Ensemble Compare tab.
This function is executed when a dataset of behavior or stimulation is assigned. The data of this dataset is loaded in the corresponding field in the ensembles compare tab.
- Parameters:
exp_data (string.) – Kind of dataset, options are “behavior” and “stims”.
- update_ensemble_visualization(value)¶
Loads the visualization of the selected ensemble.
This function shows the members of the ensemble, exclusive members and timepoints of activation of the selected ensemble in text boxes. If coordinates are provided, it also loads the visualization of the coordinates and enables customization buttons If dFFo is provided it also plots the dFFo traces.
- Parameters:
value (int) – Index of th eensamble to be shown, indexed at 1.
- Returns:
None
- Return type:
None
- update_ensvis_allbinary()¶
Plot the binary activations of every neurons in every ensemble.
This function creates a subplot for every ensemble and shows the activations of every neuron in every ensemble.
- Returns:
None
- Return type:
None
- update_ensvis_allcoords()¶
Plot the coordiantes of the neurons in every ensemble.
This function creates a subplot for every ensemble and shows the neuron maps for every ensemble.
- Returns:
None
- Return type:
None
- update_ensvis_alldFFo()¶
Plot the dFFo of the neurons in every ensemble.
This function creates a subplot for every ensemble and shows the dFFo traces for every neuron in every ensemble.
- Returns:
None
- Return type:
None
- update_ensvis_allens()¶
Plot the activations of every ensemble.
This function creates figure with the timecourse of every ensemble identified.
- Returns:
None
- Return type:
None
- validate_needed_data(needed_data)¶
Validates that all required data for a given analysis are present in the current session.
- Parameters:
needed_data (list of str) – A list of strings representing the names of the required attributes.
- Returns:
True if all required attributes are present, False otherwise.
- Return type:
bool
This method checks whether the object has the necessary attributes as specified in the needed_data list. If any required attribute is missing, it returns False, indicating that the data is not valid. Otherwise, it returns True.
- varlabels_clear()¶
Clears the saved labels for the currently visualized dataset.
- Returns:
None
Determines the label family based on the currently visualized dataset (
MainWindow.currently_visualizing
) and removes the corresponding entries from theMainWindow.varlabels
dictionary if they exist. This action clears all custom labels previously assigned to the dataset.After clearing the labels, the function updates the view of the current dataset to reflect the removal of labels and reinitializes the
MainWindow.table_setlabels
widget to show empty label entries.
- varlabels_save()¶
Saves the labels entered by the user for the currently visualized dataset.
- Returns:
None
Based on the current dataset selected (
MainWindow.currently_visualizing
), this function assigns a label family, retrieves the label values entered by the user in the second column ofMainWindow.table_setlabels
, and stores them in theMainWindow.varlabels
dictionary under the corresponding label family. If a label is missing for any row, the row index is used as the default label.After saving, the function updates the view of the current dataset to reflect any changes and logs a message to notify the user.
- varlabels_setup_tab(rows_cant)¶
Sets up the table for labeling variables according to the currently visualized dataset.
- Parameters:
rows_cant (int) – The number of rows to display in the table.
- Returns:
None
Based on the dataset currently selected for viewing (
MainWindow.currently_visualizing
), this function configures the label for the index column and initializes the label family. It sets the row count ofMainWindow.table_setlabels
to rows_cant, populates the table with index values in the first column, and sets up editable label fields in the second column. If labels have already been registered for the selected dataset type, these are pre-filled in the table; otherwise, previous entries are cleared.The first column items are set as non-editable to prevent user modification of index values.
- view_behavior()¶
Displays the data saved in the
MainWindow.behavior
variable.This function also runs update the status for editing the variable using
MainWindow.set_able_edit_options()
and updates validators usingMainWindow.update_edit_validators()
. This function also triggers the setup of the variable labels tab usingMainWindow.varlabels_setup_tab()
.
- view_cells()¶
Displays the data saved in the
MainWindow.cells
variable.This function also runs update the status for editing the variable using
MainWindow.set_able_edit_options()
and updates validators usingMainWindow.update_edit_validators()
. This function also triggers the setup of the variable labels tab usingMainWindow.varlabels_setup_tab()
.
- view_coordinates()¶
Displays the data saved in the
MainWindow.coordinates
variable.This function also runs update the status for editing the variable using
MainWindow.set_able_edit_options()
and updates validators usingMainWindow.update_edit_validators()
. This function also triggers the setup of the variable labels tab usingMainWindow.varlabels_setup_tab()
.
- view_dFFo()¶
Displays the data saved in the
MainWindow.dFFo
variable.This function also runs update the status for editing the variable using
MainWindow.set_able_edit_options()
and updates validators usingMainWindow.update_edit_validators()
. This function also triggers the setup of the variable labels tab usingMainWindow.varlabels_setup_tab()
.
- view_neuronal_activity()¶
Displays the data saved in the
MainWindow.neuronal_activity
variable.This function also runs update the status for editing the variable using
MainWindow.set_able_edit_options()
and updates validators usingMainWindow.update_edit_validators()
. This function also triggers the setup of the variable labels tab usingMainWindow.varlabels_setup_tab()
.
- view_stims()¶
Displays the data saved in the
MainWindow.stims
variable.This function also runs update the status for editing the variable using
MainWindow.set_able_edit_options()
and updates validators usingMainWindow.update_edit_validators()
. This function also triggers the setup of the variable labels tab usingMainWindow.varlabels_setup_tab()
.
- vis_ensembles_ica()¶
Loads the results of the ICA into the ensembles visualizer.
This is done this way to use only one function to update the ensembles visualizer. The variable
MainWindow.ensemble_currently_shown
is used to set the algorithm to show. Then the global funtionMainWindow.update_analysis_results()
is executed.
- vis_ensembles_pca()¶
Loads the results of the PCA into the ensembles visualizer.
This is done this way to use only one function to update the ensembles visualizer. The variable
MainWindow.ensemble_currently_shown
is used to set the algorithm to show. Then the global funtionMainWindow.update_analysis_results()
is executed.
- vis_ensembles_sgc()¶
Loads the results of the SGC into the ensembles visualizer.
This is done this way to use only one function to update the ensembles visualizer. The variable
MainWindow.ensemble_currently_shown
is used to set the algorithm to show. Then the global funtionMainWindow.update_analysis_results()
is executed.
- vis_ensembles_svd()¶
Loads the results of the SVD into the ensembles visualizer.
This is done this way to use only one function to update the ensembles visualizer. The variable
MainWindow.ensemble_currently_shown
is used to set the algorithm to show. Then the global funtionMainWindow.update_analysis_results()
is executed.
- vis_ensembles_x2p()¶
Loads the results of the X2P into the ensembles visualizer.
This is done this way to use only one function to update the ensembles visualizer. The variable
MainWindow.ensemble_currently_shown
is used to set the algorithm to show. Then the global funtionMainWindow.update_analysis_results()
is executed.
- we_have_results()¶
Updates the UI for the ensembles compare and performance analysis given the available analysis results.
- Returns:
None
- Return type:
None
- class main.WorkerRunnable(long_running_function, *args, **kwargs)¶
Bases:
QRunnable
Runnable task to execute a long-running function in a separate thread.
- Parameters:
long_running_function (callable) – The function to be executed in the thread.
args (tuple) – Positional arguments to pass to the function.
kwargs (dict) – Keyword arguments to pass to the function.
- Variables:
long_running_function (callable) – The function to execute in the thread.
args (tuple) – Positional arguments for the function.
kwargs (dict) – Keyword arguments for the function.
signals (WorkerSignals) – Signals for communicating the result of the function execution.
- run()¶
Execute the long-running function with the provided arguments.
- Raises:
Exception – Propagates any exception raised by the long-running function.
- Returns:
Emits the result of the function execution via the result_ready signal.
- Return type:
None
- class main.WorkerSignals¶
Bases:
QObject
Signals used by the worker thread.
- Variables:
result_ready (pyqtSignal(object)) – Signal emitted when the long-running function finishes execution and returns a result.
- result_ready¶
pyqtSignal(*types, name: str = …, revision: int = …, arguments: Sequence = …) -> PYQT_SIGNAL
types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.