Perform CNMFE using the implementation provided by the CaImAn library.
I highly recommend going through the following before using this module
- CNMFE builds upon CNMF
Pnevmatikakis, E. A., Gao, Y., Soudry, D., Pfau, D., Lacefield, C., Poskanzer, K., … Paninski, L. (2014). A structured matrix factorization framework for large scale calcium imaging data analysis, 1–16.
- CaImAn CNMF-E demo notebook, the implementation in Mesmerize is basically from the demo
Ain: Seed spatial components from another CNMFE item by entering its UUID here.
Please see the CaImAn demo notebook mentioned above to understand the rest of the parameters. The Caiman docs also provide descriptions of the parameters: https://caiman.readthedocs.io/
You can also enter parameters for CNMF and component evaluation as keyword arguments (kwargs) in the the respective text boxes if you select “Use CNMF kwrags” or “Use evaluation params”. This is useful if you want to enter parameters that cannot be entered in the GUI for example. Use single quotes if you want to enter string kwargs, do not use double quotes.
This module creates two types of batch items, one where you can inspect the Correlation & PNR images and another that performs CNMFE and extracts components. Here is an outline of typical usage:
Enter a gSig parameter value and a name for “Inspect Correlation and PNR”, the text entry for “Stop here”. Click “Add to batch”. Run the batch item.
Double-click the batch item, you will be presented with a GUI to help optimize min_corr and min_pnr. For the correlation image use the vmin slider to optimize the seperation of cells and set the min_corr parameter to this value. Likewise, optimize the value for the PNR until the PNR image mostly contains regions that show real signal and no or few regions that are likely to be just noise and set this vmin value as the min_pnr parameter. You may need to try slightly different variations to optimize the parameters.
Enter the rest of the parameters and give a name under “Perform CNMF-E”, click “Add to batch” and run the item.
Double-click the batch item and you will be presented with 3 options. The first option will display the correlation-pnr images and the second option is currently non-functional (matplotlib Qt issue). The last option will import the components extracted by CNMFE into an open Viewer. The components are managed by the ROI Manager.
This modules uses the Batch Manager.
The parameters used for CNMFE are stored in the work environment of the viewer and this log is carried over and saved in Project Samples as well. To see the parameters that were used for CNMFE in the viewer, execute
get_workEnv().history_trace in the viewer console and look for the ‘cnmfe’ entry.
If you’re using Windows, large memmap files will linger in your batch dir or work dir, you can clean them out periodically.
A script can be used to add CNMFE batch items. This is much faster than using the GUI.
Add Corr PNR items¶
Add Corr PNR batch items from a batch that contains motion corrected items. This example add 2 variants of parameters (just gSig) for each motion corrected item.
Caiman Motion Correction script usage examples for how to load images if you want to add Corr PNR items from images that are not in a batch.
1# Get the batch manager 2bm = get_batch_manager() 3 4# Get the CNMFE module 5cnmfe_mod = get_module('cnmfe', hide=True) 6 7# Start index to start processing the new items after they have been added 8start_ix = bm.df.index.size + 1 9 10for ix, r in bm.df.iterrows(): 11 if ix == start_ix: 12 break 13 14 # Load the output of the motion corrected batch item 15 # The output will load into the viewer that this script 16 # is running in. 17 bm.load_item_output(module='caiman_motion_correction', viewers=viewer, UUID=r['uuid']) 18 19 # Get the currently set params 20 # You just need the dict with all the correct keys 21 # You will just modify the "gSig" and "item_name" keys 22 params = cnmfe_mod.get_params(item_type='corr_pnr', group_params=True) 23 24 # Get the name of the mot cor item 25 name = r['name'] 26 params['item_name'] = name 27 28 params['border_pix'] = border_pix 29 30 # Set the gSig and name params 31 params['corr_pnr_kwargs']['gSig'] = 8 32 33 # Add to batch 34 cnmfe_mod.add_to_batch_corr_pnr(params) 35 36 # Another variant of params 37 params['corr_pnr_kwargs']['gSig'] = 10 38 39 # Add to batch with this variant of params 40 cnmfe_mod.add_to_batch_corr_pnr(params) 41 42# Cleanup the work environment 43vi._clear_workEnv() 44 45# Start the batch from the start_ix 46bm.process_batch(start_ix, clear_viewers=True)