Skip to content

Interpreting Results

eftychios pnevmatikakis edited this page Jun 15, 2018 · 3 revisions

Result variables for 2p batch analysis

The results of CaImAn are saved in the cnmf object. The variables of interest are:

  • cnm.A: Set of spatial components. Saved as a sparse column format matrix with dimensions (# of pixels X # of components). Each column corresponds to a spatial component.
  • cnm.C: Set of temporal components. Saved as a numpy array with dimensions (# of components X # of timesteps). Each row corresponds to a background component denoised and deconvolved.
  • cnm.b: Set of background spatial components (for 2p analysis): Saved as a numpy array with dimensions (# of pixels X # of components). Each column corresponds to a spatial background component.
  • cnm.f: Set of temporal background components (for 2p analysis). Saved as a numpy array with dimensions (# of background components X # of timesteps). Each row corresponds to a temporal background component.
  • cnm.S: Deconvolved neural activity (spikes) for each component. Saved as a numpy array with dimensions (# of background components X # of timesteps). Each row corresponds to the deconvolved neural activity for the corresponding component.
  • cnm.YrA: Set or residual components. Saved as a numpy array with dimensions (# of components X # of timesteps). Each row corresponds to the residual signal after denoising the corresponding component in cnm.C.
  • cnm.F_dff: Set of DF/F normalized temporal components. Saved as a numpy array with dimensions (# of components X # of timesteps). Each row corresponds to the DF/F fluorescence for the corresponding component.

To view the spatial components, their corresponding vectors need first to be reshaped into 2d images. For example if you want to view the i-th component you can type

import matplotlib.pyplot as plt
plt.figure(); plt.imshow(np.reshape(cnm.A[:,i-1].toarray(), dims, order='F'))

where dims is a list or tuple that has the dimensions of the FOV. Similarly if you want to plot the trace for the i-th component you can simply type

plt.figure(); plt.plot(C[i-1])

The commands caiman.utils.visualization.plot_contours and caiman.utils.visualization.view_patches_bar can be used to visualize all the components.

Variables for component evaluation

If you use post-screening to evaluate the quality of the components and remove bad components the results are stored in the lists:

  • idx_components: List containing the indexes of accepted components.
  • idx_components_bad: List containing the indexes of rejected components.

These lists can be used to index the results. For example cnm.A[:,idx_components] or cnm.C[idx_components] will return the accepted spatial or temporal components, respectively. If you want to view the first accepted component you can type

plt.figure(); plt.imshow(np.reshape(cnm.A[:,idx_components[0]].toarray(), dims, order='F'))
plt.figure(); plt.plot(C[idx_components[0]])

Variables for 1p processing (CNMF-E)

The variables for one photon processing are the same, with an additional variable cnm.W for the matrix that is used to compute the background using the ring model.

Variables for online processing

For online processing the spatial and temporal components are stored together with the background components.

  • cnm.Ab: Set of spatial components and spatial background components.
  • cnm.C_on: Set of temporal components and temporal background components. The first components correspond to background. To separate the components you can type
C, f = cnm.C_on[cnm.gnb:cnm.M], cnm.C_on[:cnm.gnb]
A, b = cnm.Ab[:, cnm.gnb:cnm.M], cnm.Ab[:, :cnm.gnb]

Note that if you run the online algorithm for multiple epochs, cnm.C_on will save the traces for all the epochs. To extract the last epoch you can type

T_total = cnm.C_on.shape[-1]  # total number of frames 
C_on_last = cnm.C_on[:,-T_total//epochs:]