In [1]:
try:
    get_ipython().magic(u'load_ext autoreload')
    get_ipython().magic(u'autoreload 2')
except:
    print('NOT IPYTHON')

import numpy as np
import matplotlib as mpl
import matplotlib.pyplot as plt
from matplotlib.widgets import Slider
import caiman as cm
from caiman.source_extraction import cnmf
import bokeh
import bokeh.plotting as bpl
from bokeh.models import CustomJS, ColumnDataSource, Range1d
from bokeh.io import output_notebook, reset_output
import os


Using TensorFlow backend.
Debugging!
The autoreload extension is already loaded. To reload it, use:
  %reload_ext autoreload

In [2]:
def show_img(ax, img):
    from mpl_toolkits.axes_grid1 import make_axes_locatable
    im = ax.imshow(img)
    divider = make_axes_locatable(ax)
    cax = divider.append_axes("right", size="5%", pad=0.05)
    plt.colorbar(im, cax=cax)

step 1: load data


In [3]:
fname = './example_movies/data_endoscope.tif'
Y = cm.load(fname)
T, d1, d2 = Y.shape
print('The dimension of data is ', Y.shape)

ax = plt.axes()
ax.axis('off')
show_img(ax, Y[100])


('The dimension of data is ', (1000, 128, 128))

In [4]:
Cn = Y.local_correlations(swap_dim=False)
ax = plt.axes()
ax.axis('off')
show_img(ax, Cn)
print(Y.shape)


(1000, 128, 128)

From the example above, we can see that 1-photon data typically have large and blurring background that contaminates the detection of neural signal. This makes it very hard to detect neurons and extract their temporal activities. CNMF-E uses spatially filtering to remove the low spatial frequency term and visualize neurons via two summary images: local correlation image and peak-to-noise ratios (PNR) image. Local correlation image highlights the locally correlated spatial structures, and PNR image highlights neurons' calcium transients.

The spatial filtering that roughly removes the background is the key to the sucess of CNMF-E. The kernel is simply generated from a truncated Gaussian kernel. However, the important part is centering the kernel to make its mean equal to 0.


In [5]:
# parameters 
gSig = 3   # gaussian width of a 2D gaussian kernel, which approximates a neuron 
gSiz = 10  # average diameter of a neuron 
center_psf = True     # If True, the background can be roughly removed. This is useful when the background is strong. 

# show correlation image of the raw data; show correlation image and PNR image of the filtered data
cn_raw = cm.summary_images.local_correlations_fft(Y, swap_dim=False)
cn_filter, pnr = cm.summary_images.correlation_pnr(Y, gSig=gSig, center_psf=center_psf, swap_dim=False)
plt.figure(figsize=(10, 5))

for i, (data, title) in enumerate(((Y.mean(0), 'Mean image (raw)'),
                                   (Y.max(0), 'Max projection (raw)'),
                                   (cn_raw[1:-1,1:-1], 'Correlation (raw)'),
                                   (cn_filter, 'Correlation (filtered)'),
                                   (pnr, 'PNR (filtered)'),
                                   (cn_filter*pnr, 'Correlation*PNR (filtered)'))):
    plt.subplot(2,3,1+i)
    plt.imshow(data, cmap='jet', aspect='equal')
    plt.axis('off')
    plt.colorbar() 
    plt.title(title);


As we can see, the summary images resulted from the raw data poorly display isolated neurons. While spatial filtering significanly improves the visualization of single neurons. Our initialization procedure roots from this observation. We pick pixels with large local correlation coefficients and large PNR values, then we use them as seed pixels for initialization spatial & temporal components of all single neurons.

To do initialization, we have to specify two thresholds for detecting seed pixels: the mininum local correlation and the minimum PNR. All pxiels satisfying these two requirements are chosen as our seed pixels. The initialization procedure stops when there are no seed pixels.

When specifying the thresholds, we have to make sure most neurons have seed pixels above the thresholds. Otherwise, we may miss lots of neurons in this step. In the meanwhile, we want to make the thresholds to screen out most pixels that are out of neurons' ROIs. But don't be too picky about the parameter selection. CNMF-E can still pick neurons from the residual after we estimate the background and subtract it from the raw video in the later phase.

step 2: initialization


In [6]:
# pick thresholds 
%matplotlib notebook
fig = plt.figure(figsize=(10, 4))
plt.axes([0.05, 0.2, 0.4, 0.7])
im_cn = plt.imshow(cn_filter, cmap='jet')
plt.title('correlation image')
plt.colorbar()
plt.axes([0.5, 0.2, 0.4, 0.7])
im_pnr = plt.imshow(pnr, cmap='jet')
plt.title('PNR')
plt.colorbar();

s_cn_max = Slider(plt.axes([0.05, 0.01, 0.35, 0.03]), 'vmax', cn_filter.min(), cn_filter.max(), valinit=cn_filter.max())
s_cn_min = Slider(plt.axes([0.05, 0.07, 0.35, 0.03]), 'vmin', cn_filter.min(), cn_filter.max(), valinit=cn_filter.min())
s_pnr_max = Slider(plt.axes([0.5, 0.01, 0.35, 0.03]), 'vmax', pnr.min(), pnr.max(), valinit=pnr.max())
s_pnr_min = Slider(plt.axes([0.5, 0.07, 0.35, 0.03]), 'vmin', pnr.min(), pnr.max(), valinit=pnr.min())

def update(val):
    im_cn.set_clim([s_cn_min.val, s_cn_max.val])
    im_pnr.set_clim([s_pnr_min.val, s_pnr_max.val])
    fig.canvas.draw_idle()
s_cn_max.on_changed(update)
s_cn_min.on_changed(update)
s_pnr_max.on_changed(update)
s_pnr_min.on_changed(update)
# 'min_corr=0.85', 'min_pnr=20'


Out[6]:
0

In [7]:
%matplotlib inline
min_corr = 0.8
min_pnr = 10
min_pixel = 3    # minimum number of nonzero pixels
save_video = False 
if not os.path.exists('tmp'): 
    os.mkdir('tmp')
video_name = os.path.join('tmp', 'initialization.mp4')
from caiman.source_extraction.cnmf.initialization import init_neurons_corr_pnr
A, C, C_raw, S, center =  init_neurons_corr_pnr(Y, max_number=255,gSiz=gSiz, gSig=gSig,
                   center_psf=True, min_corr=min_corr, min_pnr=min_pnr, swap_dim = False, save_video = save_video,
                                                video_name = video_name, min_pixel=3)
plt.figure(figsize=(5,5))
plt.imshow(cn_filter*pnr, vmax=40, cmap='gray')
plt.plot(center[0], center[1], '.r')


0 neurons have been initialized
10 neurons have been initialized
20 neurons have been initialized
30 neurons have been initialized
40 neurons have been initialized
50 neurons have been initialized
caiman/summary_images.py:109: RuntimeWarning: invalid value encountered in true_divide
  Y /= np.std(Y,axis = 0)
caiman/source_extraction/cnmf/initialization.py:1213: RuntimeWarning: invalid value encountered in less
  cn_box[np.isnan(cn_box) | (cn_box < 0)] = 0
60 neurons have been initialized
70 neurons have been initialized
80 neurons have been initialized
90 neurons have been initialized
100 neurons have been initialized
110 neurons have been initialized
120 neurons have been initialized
130 neurons have been initialized
140 neurons have been initialized
150 neurons have been initialized
160 neurons have been initialized
170 neurons have been initialized
180 neurons have been initialized
190 neurons have been initialized
200 neurons have been initialized
210 neurons have been initialized
220 neurons have been initialized
230 neurons have been initialized
240 neurons have been initialized
250 neurons have been initialized
In total,  255 neurons were initialized.
Out[7]:
[<matplotlib.lines.Line2D at 0x7fc5c3fc58d0>]

If you set save_video as True, then you are supposed to find a video named 'initialization.mp4' in your current working folder. It desplays the whole procedure of the initialization.

Here we set the thresholds that are very high to only pick neurons with high qualities. We can still see some weak neurons that are not picked up. In the following steps, we are going to estimate the background first and then pick more neurons from the residual (Y-A*C-B) video.

Step 3: run CNMF


In [8]:
# memmap
fname_new = cm.save_memmap([fname], base_name='Yr')
Yr, dims, T = cm.load_memmap(fname_new)


./example_movies/data_endoscope.tif

In [9]:
# %% run
cnm = cnmf.CNMF(n_processes=2, method_init='corr_pnr', k=10, gSig=(3, 3), gSiz=(10, 10), merge_thresh=.8,
                p=1, dview=None, tsub=1, ssub=1, Ain=None, rf=(15, 15), stride=(10, 10),
                only_init_patch=True, gnb=10, nb_patch=3, method_deconvolution='oasis',
                low_rank_background=False, update_background_components=False, min_corr=.8,
                min_pnr=10, normalize_init=False, deconvolve_options_init=None,
                ring_size_factor=1.5, center_psf=True)

cnm.fit(Yr.T.reshape((T,) + dims, order='F'))


(1000, 128, 128)
using 2 processes
using 4000 pixels per process
using 20000 block_size
(30, 30)
(1000, 31, 31)
using 1 processes
using 225 pixels per process
using 20000 block_size
preprocessing ...
checking if missing data
Single Thread
225
225
225
225
61
initializing ...
Roi Extraction...
Init one photon
0 neurons have been initialized
In total,  10 neurons were initialized.
Compute Background
Compute Residuals
Update spatial
Generating residuals
entering the deconvolution 
3 out of total 10 temporal components updated
6 out of total 10 temporal components updated
7 out of total 10 temporal components updated
9 out of total 10 temporal components updated
10 out of total 10 temporal components updated
3 out of total 10 temporal components updated
6 out of total 10 temporal components updated
7 out of total 10 temporal components updated
9 out of total 10 temporal components updated
10 out of total 10 temporal components updated
stopping: overall temporal component not changing significantly
Update Temporal
Initializing update of Spatial Components
computing the distance indicators
found spatial support for each component
memmaping
Updating Spatial Components using lasso lars
clearing variables
clearing variables
clearing variables
clearing variables
clearing variables
thresholding components
Computing residuals
--- 0.589464902878 seconds ---
Removing tempfiles created
Compute Background Again
Estimate low rank Background
(1000, 31, 31)
using 1 processes
using 225 pixels per process
using 20000 block_size
preprocessing ...
checking if missing data
Single Thread
225
225
225
225
61
initializing ...
Roi Extraction...
Init one photon
/install/anaconda2/lib/python2.7/site-packages/skimage/transform/_warps.py:84: UserWarning: The default mode, 'constant', will be changed to 'reflect' in skimage 0.15.
  warn("The default mode, 'constant', will be changed to 'reflect' in "
0 neurons have been initialized
In total,  10 neurons were initialized.
Compute Background
Compute Residuals
Update spatial
Generating residuals
entering the deconvolution 
3 out of total 10 temporal components updated
5 out of total 10 temporal components updated
6 out of total 10 temporal components updated
7 out of total 10 temporal components updated
8 out of total 10 temporal components updated
9 out of total 10 temporal components updated
10 out of total 10 temporal components updated
3 out of total 10 temporal components updated
5 out of total 10 temporal components updated
6 out of total 10 temporal components updated
7 out of total 10 temporal components updated
8 out of total 10 temporal components updated
9 out of total 10 temporal components updated
10 out of total 10 temporal components updated
stopping: overall temporal component not changing significantly
Update Temporal
Initializing update of Spatial Components
computing the distance indicators
found spatial support for each component
memmaping
Updating Spatial Components using lasso lars
clearing variables
clearing variables
clearing variables
clearing variables
clearing variables
thresholding components
Computing residuals
--- 0.616480827332 seconds ---
Removing tempfiles created
Compute Background Again
Estimate low rank Background
(1000, 31, 31)
using 1 processes
using 225 pixels per process
using 20000 block_size
preprocessing ...
checking if missing data
Single Thread
225
225
225
225
61
initializing ...
Roi Extraction...
Init one photon
0 neurons have been initialized
In total,  10 neurons were initialized.
Compute Background
Compute Residuals
Update spatial
Generating residuals
entering the deconvolution 
3 out of total 10 temporal components updated
6 out of total 10 temporal components updated
8 out of total 10 temporal components updated
10 out of total 10 temporal components updated
3 out of total 10 temporal components updated
6 out of total 10 temporal components updated
8 out of total 10 temporal components updated
10 out of total 10 temporal components updated
stopping: overall temporal component not changing significantly
Update Temporal
Initializing update of Spatial Components
computing the distance indicators
found spatial support for each component
memmaping
Updating Spatial Components using lasso lars
clearing variables
clearing variables
clearing variables
clearing variables
clearing variables
thresholding components
Computing residuals
--- 0.652195930481 seconds ---
Removing tempfiles created
Compute Background Again
Estimate low rank Background
(1000, 31, 31)
using 1 processes
using 225 pixels per process
using 20000 block_size
preprocessing ...
checking if missing data
Single Thread
225
225
225
225
61
initializing ...
Roi Extraction...
Init one photon
0 neurons have been initialized
In total,  10 neurons were initialized.
Compute Background
Compute Residuals
Update spatial
Generating residuals
entering the deconvolution 
4 out of total 10 temporal components updated
7 out of total 10 temporal components updated
8 out of total 10 temporal components updated
10 out of total 10 temporal components updated
4 out of total 10 temporal components updated
7 out of total 10 temporal components updated
8 out of total 10 temporal components updated
10 out of total 10 temporal components updated
stopping: overall temporal component not changing significantly
Update Temporal
Initializing update of Spatial Components
computing the distance indicators
found spatial support for each component
memmaping
Updating Spatial Components using lasso lars
clearing variables
clearing variables
clearing variables
clearing variables
clearing variables
thresholding components
Computing residuals
--- 0.599547147751 seconds ---
Removing tempfiles created
Compute Background Again
Estimate low rank Background
(1000, 31, 31)
using 1 processes
using 225 pixels per process
using 20000 block_size
preprocessing ...
checking if missing data
Single Thread
225
225
225
225
61
initializing ...
Roi Extraction...
Init one photon
0 neurons have been initialized
In total,  10 neurons were initialized.
Compute Background
Compute Residuals
Update spatial
Generating residuals
entering the deconvolution 
4 out of total 10 temporal components updated
6 out of total 10 temporal components updated
8 out of total 10 temporal components updated
10 out of total 10 temporal components updated
4 out of total 10 temporal components updated
6 out of total 10 temporal components updated
8 out of total 10 temporal components updated
10 out of total 10 temporal components updated
stopping: overall temporal component not changing significantly
Update Temporal
Initializing update of Spatial Components
computing the distance indicators
found spatial support for each component
memmaping
Updating Spatial Components using lasso lars
clearing variables
clearing variables
clearing variables
clearing variables
clearing variables
thresholding components
Computing residuals
--- 0.507317066193 seconds ---
Removing tempfiles created
Compute Background Again
Estimate low rank Background
(1000, 31, 30)
using 1 processes
using 225 pixels per process
using 20000 block_size
preprocessing ...
checking if missing data
Single Thread
225
225
225
225
30
initializing ...
Roi Extraction...
Init one photon
0 neurons have been initialized
In total,  10 neurons were initialized.
Compute Background
Compute Residuals
Update spatial
Generating residuals
entering the deconvolution 
3 out of total 10 temporal components updated
5 out of total 10 temporal components updated
7 out of total 10 temporal components updated
9 out of total 10 temporal components updated
10 out of total 10 temporal components updated
3 out of total 10 temporal components updated
5 out of total 10 temporal components updated
7 out of total 10 temporal components updated
9 out of total 10 temporal components updated
10 out of total 10 temporal components updated
stopping: overall temporal component not changing significantly
Update Temporal
Initializing update of Spatial Components
computing the distance indicators
found spatial support for each component
memmaping
Updating Spatial Components using lasso lars
clearing variables
clearing variables
clearing variables
clearing variables
clearing variables
thresholding components
Computing residuals
--- 0.59604883194 seconds ---
Removing tempfiles created
Compute Background Again
Estimate low rank Background
(1000, 31, 31)
using 1 processes
using 225 pixels per process
using 20000 block_size
preprocessing ...
checking if missing data
Single Thread
225
225
225
225
61
initializing ...
Roi Extraction...
Init one photon
0 neurons have been initialized
In total,  10 neurons were initialized.
Compute Background
Compute Residuals
Update spatial
Generating residuals
entering the deconvolution 
3 out of total 10 temporal components updated
6 out of total 10 temporal components updated
7 out of total 10 temporal components updated
9 out of total 10 temporal components updated
10 out of total 10 temporal components updated
3 out of total 10 temporal components updated
6 out of total 10 temporal components updated
7 out of total 10 temporal components updated
9 out of total 10 temporal components updated
10 out of total 10 temporal components updated
stopping: overall temporal component not changing significantly
Update Temporal
Initializing update of Spatial Components
computing the distance indicators
found spatial support for each component
memmaping
Updating Spatial Components using lasso lars
clearing variables
clearing variables
clearing variables
clearing variables
clearing variables
thresholding components
Computing residuals
--- 0.640157938004 seconds ---
Removing tempfiles created
Compute Background Again
Estimate low rank Background
(1000, 31, 31)
using 1 processes
using 225 pixels per process
using 20000 block_size
preprocessing ...
checking if missing data
Single Thread
225
225
225
225
61
initializing ...
Roi Extraction...
Init one photon
0 neurons have been initialized
In total,  10 neurons were initialized.
Compute Background
Compute Residuals
Update spatial
Generating residuals
entering the deconvolution 
3 out of total 10 temporal components updated
5 out of total 10 temporal components updated
7 out of total 10 temporal components updated
9 out of total 10 temporal components updated
10 out of total 10 temporal components updated
3 out of total 10 temporal components updated
5 out of total 10 temporal components updated
7 out of total 10 temporal components updated
9 out of total 10 temporal components updated
10 out of total 10 temporal components updated
stopping: overall temporal component not changing significantly
Update Temporal
Initializing update of Spatial Components
computing the distance indicators
found spatial support for each component
memmaping
Updating Spatial Components using lasso lars
clearing variables
clearing variables
clearing variables
clearing variables
clearing variables
thresholding components
Computing residuals
--- 0.604423999786 seconds ---
Removing tempfiles created
Compute Background Again
Estimate low rank Background
(1000, 31, 31)
using 1 processes
using 225 pixels per process
using 20000 block_size
preprocessing ...
checking if missing data
Single Thread
225
225
225
225
61
initializing ...
Roi Extraction...
Init one photon
0 neurons have been initialized
In total,  10 neurons were initialized.
Compute Background
Compute Residuals
Update spatial
Generating residuals
entering the deconvolution 
3 out of total 10 temporal components updated
6 out of total 10 temporal components updated
8 out of total 10 temporal components updated
9 out of total 10 temporal components updated
10 out of total 10 temporal components updated
3 out of total 10 temporal components updated
6 out of total 10 temporal components updated
8 out of total 10 temporal components updated
9 out of total 10 temporal components updated
10 out of total 10 temporal components updated
stopping: overall temporal component not changing significantly
Update Temporal
Initializing update of Spatial Components
computing the distance indicators
found spatial support for each component
memmaping
Updating Spatial Components using lasso lars
clearing variables
clearing variables
clearing variables
clearing variables
clearing variables
thresholding components
Computing residuals
--- 0.561629056931 seconds ---
Removing tempfiles created
Compute Background Again
Estimate low rank Background
(1000, 31, 31)
using 1 processes
using 225 pixels per process
using 20000 block_size
preprocessing ...
checking if missing data
Single Thread
225
225
225
225
61
initializing ...
Roi Extraction...
Init one photon
0 neurons have been initialized
In total,  10 neurons were initialized.
Compute Background
Compute Residuals
Update spatial
Generating residuals
entering the deconvolution 
4 out of total 10 temporal components updated
6 out of total 10 temporal components updated
9 out of total 10 temporal components updated
10 out of total 10 temporal components updated
4 out of total 10 temporal components updated
6 out of total 10 temporal components updated
9 out of total 10 temporal components updated
10 out of total 10 temporal components updated
stopping: overall temporal component not changing significantly
Update Temporal
Initializing update of Spatial Components
computing the distance indicators
found spatial support for each component
memmaping
Updating Spatial Components using lasso lars
clearing variables
clearing variables
clearing variables
clearing variables
clearing variables
thresholding components
Computing residuals
--- 0.608149051666 seconds ---
Removing tempfiles created
Compute Background Again
Estimate low rank Background
(1000, 31, 31)
using 1 processes
using 225 pixels per process
using 20000 block_size
preprocessing ...
checking if missing data
Single Thread
225
225
225
225
61
initializing ...
Roi Extraction...
Init one photon
0 neurons have been initialized
In total,  10 neurons were initialized.
Compute Background
Compute Residuals
Update spatial
Generating residuals
entering the deconvolution 
3 out of total 10 temporal components updated
5 out of total 10 temporal components updated
7 out of total 10 temporal components updated
9 out of total 10 temporal components updated
10 out of total 10 temporal components updated
3 out of total 10 temporal components updated
5 out of total 10 temporal components updated
7 out of total 10 temporal components updated
9 out of total 10 temporal components updated
10 out of total 10 temporal components updated
stopping: overall temporal component not changing significantly
Update Temporal
Initializing update of Spatial Components
computing the distance indicators
found spatial support for each component
memmaping
Updating Spatial Components using lasso lars
clearing variables
clearing variables
clearing variables
clearing variables
clearing variables
thresholding components
Computing residuals
--- 0.506546974182 seconds ---
Removing tempfiles created
Compute Background Again
Estimate low rank Background
(1000, 31, 30)
using 1 processes
using 225 pixels per process
using 20000 block_size
preprocessing ...
checking if missing data
Single Thread
225
225
225
225
30
initializing ...
Roi Extraction...
Init one photon
0 neurons have been initialized
In total,  10 neurons were initialized.
Compute Background
Compute Residuals
Update spatial
Generating residuals
entering the deconvolution 
4 out of total 10 temporal components updated
6 out of total 10 temporal components updated
8 out of total 10 temporal components updated
10 out of total 10 temporal components updated
4 out of total 10 temporal components updated
6 out of total 10 temporal components updated
8 out of total 10 temporal components updated
10 out of total 10 temporal components updated
stopping: overall temporal component not changing significantly
Update Temporal
Initializing update of Spatial Components
computing the distance indicators
found spatial support for each component
memmaping
Updating Spatial Components using lasso lars
clearing variables
clearing variables
clearing variables
clearing variables
clearing variables
thresholding components
Computing residuals
--- 0.566662073135 seconds ---
Removing tempfiles created
Compute Background Again
Estimate low rank Background
(1000, 31, 31)
using 1 processes
using 225 pixels per process
using 20000 block_size
preprocessing ...
checking if missing data
Single Thread
225
225
225
225
61
initializing ...
Roi Extraction...
Init one photon
0 neurons have been initialized
In total,  10 neurons were initialized.
Compute Background
Compute Residuals
Update spatial
Generating residuals
entering the deconvolution 
4 out of total 10 temporal components updated
5 out of total 10 temporal components updated
8 out of total 10 temporal components updated
9 out of total 10 temporal components updated
10 out of total 10 temporal components updated
4 out of total 10 temporal components updated
5 out of total 10 temporal components updated
8 out of total 10 temporal components updated
9 out of total 10 temporal components updated
10 out of total 10 temporal components updated
stopping: overall temporal component not changing significantly
Update Temporal
Initializing update of Spatial Components
computing the distance indicators
found spatial support for each component
memmaping
Updating Spatial Components using lasso lars
clearing variables
clearing variables
clearing variables
clearing variables
clearing variables
thresholding components
Computing residuals
--- 0.563480854034 seconds ---
Removing tempfiles created
Compute Background Again
Estimate low rank Background
(1000, 31, 31)
using 1 processes
using 225 pixels per process
using 20000 block_size
preprocessing ...
checking if missing data
Single Thread
225
225
225
225
61
initializing ...
Roi Extraction...
Init one photon
0 neurons have been initialized
In total,  10 neurons were initialized.
Compute Background
Compute Residuals
Update spatial
Generating residuals
entering the deconvolution 
3 out of total 10 temporal components updated
6 out of total 10 temporal components updated
7 out of total 10 temporal components updated
8 out of total 10 temporal components updated
9 out of total 10 temporal components updated
10 out of total 10 temporal components updated
3 out of total 10 temporal components updated
6 out of total 10 temporal components updated
7 out of total 10 temporal components updated
8 out of total 10 temporal components updated
9 out of total 10 temporal components updated
10 out of total 10 temporal components updated
stopping: overall temporal component not changing significantly
Update Temporal
Initializing update of Spatial Components
computing the distance indicators
found spatial support for each component
memmaping
Updating Spatial Components using lasso lars
clearing variables
clearing variables
clearing variables
clearing variables
clearing variables
thresholding components
Computing residuals
--- 0.48602104187 seconds ---
Removing tempfiles created
Compute Background Again
Estimate low rank Background
(1000, 31, 31)
using 1 processes
using 225 pixels per process
using 20000 block_size
preprocessing ...
checking if missing data
Single Thread
225
225
225
225
61
initializing ...
Roi Extraction...
Init one photon
0 neurons have been initialized
In total,  10 neurons were initialized.
Compute Background
Compute Residuals
Update spatial
Generating residuals
entering the deconvolution 
4 out of total 10 temporal components updated
6 out of total 10 temporal components updated
9 out of total 10 temporal components updated
10 out of total 10 temporal components updated
4 out of total 10 temporal components updated
6 out of total 10 temporal components updated
9 out of total 10 temporal components updated
10 out of total 10 temporal components updated
stopping: overall temporal component not changing significantly
Update Temporal
Initializing update of Spatial Components
computing the distance indicators
found spatial support for each component
memmaping
Updating Spatial Components using lasso lars
clearing variables
clearing variables
clearing variables
clearing variables
clearing variables
thresholding components
Computing residuals
--- 0.49835395813 seconds ---
Removing tempfiles created
Compute Background Again
Estimate low rank Background
(1000, 31, 31)
using 1 processes
using 225 pixels per process
using 20000 block_size
preprocessing ...
checking if missing data
Single Thread
225
225
225
225
61
initializing ...
Roi Extraction...
Init one photon
0 neurons have been initialized
In total,  10 neurons were initialized.
Compute Background
Compute Residuals
Update spatial
Generating residuals
entering the deconvolution 
4 out of total 10 temporal components updated
7 out of total 10 temporal components updated
9 out of total 10 temporal components updated
10 out of total 10 temporal components updated
4 out of total 10 temporal components updated
7 out of total 10 temporal components updated
9 out of total 10 temporal components updated
10 out of total 10 temporal components updated
stopping: overall temporal component not changing significantly
Update Temporal
Initializing update of Spatial Components
computing the distance indicators
found spatial support for each component
memmaping
Updating Spatial Components using lasso lars
clearing variables
clearing variables
clearing variables
clearing variables
clearing variables
thresholding components
Computing residuals
--- 0.568211078644 seconds ---
Removing tempfiles created
Compute Background Again
Estimate low rank Background
(1000, 31, 31)
using 1 processes
using 225 pixels per process
using 20000 block_size
preprocessing ...
checking if missing data
Single Thread
225
225
225
225
61
initializing ...
Roi Extraction...
Init one photon
0 neurons have been initialized
In total,  10 neurons were initialized.
Compute Background
Compute Residuals
Update spatial
Generating residuals
entering the deconvolution 
3 out of total 10 temporal components updated
5 out of total 10 temporal components updated
7 out of total 10 temporal components updated
9 out of total 10 temporal components updated
10 out of total 10 temporal components updated
3 out of total 10 temporal components updated
5 out of total 10 temporal components updated
7 out of total 10 temporal components updated
9 out of total 10 temporal components updated
10 out of total 10 temporal components updated
stopping: overall temporal component not changing significantly
Update Temporal
Initializing update of Spatial Components
computing the distance indicators
found spatial support for each component
memmaping
Updating Spatial Components using lasso lars
clearing variables
clearing variables
clearing variables
clearing variables
clearing variables
thresholding components
Computing residuals
--- 0.536127090454 seconds ---
Removing tempfiles created
Compute Background Again
Estimate low rank Background
(1000, 31, 30)
using 1 processes
using 225 pixels per process
using 20000 block_size
preprocessing ...
checking if missing data
Single Thread
225
225
225
225
30
initializing ...
Roi Extraction...
Init one photon
0 neurons have been initialized
In total,  10 neurons were initialized.
Compute Background
Compute Residuals
Update spatial
Generating residuals
entering the deconvolution 
4 out of total 10 temporal components updated
7 out of total 10 temporal components updated
9 out of total 10 temporal components updated
10 out of total 10 temporal components updated
4 out of total 10 temporal components updated
7 out of total 10 temporal components updated
9 out of total 10 temporal components updated
10 out of total 10 temporal components updated
stopping: overall temporal component not changing significantly
Update Temporal
Initializing update of Spatial Components
computing the distance indicators
found spatial support for each component
memmaping
Updating Spatial Components using lasso lars
clearing variables
clearing variables
clearing variables
clearing variables
clearing variables
thresholding components
Computing residuals
--- 0.544420003891 seconds ---
Removing tempfiles created
Compute Background Again
Estimate low rank Background
(1000, 31, 31)
using 1 processes
using 225 pixels per process
using 20000 block_size
preprocessing ...
checking if missing data
Single Thread
225
225
225
225
61
initializing ...
Roi Extraction...
Init one photon
0 neurons have been initialized
In total,  10 neurons were initialized.
Compute Background
Compute Residuals
Update spatial
Generating residuals
entering the deconvolution 
4 out of total 10 temporal components updated
6 out of total 10 temporal components updated
8 out of total 10 temporal components updated
9 out of total 10 temporal components updated
10 out of total 10 temporal components updated
4 out of total 10 temporal components updated
6 out of total 10 temporal components updated
8 out of total 10 temporal components updated
9 out of total 10 temporal components updated
10 out of total 10 temporal components updated
stopping: overall temporal component not changing significantly
Update Temporal
Initializing update of Spatial Components
computing the distance indicators
found spatial support for each component
memmaping
Updating Spatial Components using lasso lars
clearing variables
clearing variables
clearing variables
clearing variables
clearing variables
thresholding components
Computing residuals
--- 0.528434038162 seconds ---
Removing tempfiles created
Compute Background Again
Estimate low rank Background
(1000, 31, 31)
using 1 processes
using 225 pixels per process
using 20000 block_size
preprocessing ...
checking if missing data
Single Thread
225
225
225
225
61
initializing ...
Roi Extraction...
Init one photon
0 neurons have been initialized
In total,  10 neurons were initialized.
Compute Background
Compute Residuals
Update spatial
Generating residuals
entering the deconvolution 
3 out of total 10 temporal components updated
6 out of total 10 temporal components updated
8 out of total 10 temporal components updated
9 out of total 10 temporal components updated
10 out of total 10 temporal components updated
3 out of total 10 temporal components updated
6 out of total 10 temporal components updated
8 out of total 10 temporal components updated
9 out of total 10 temporal components updated
10 out of total 10 temporal components updated
stopping: overall temporal component not changing significantly
Update Temporal
Initializing update of Spatial Components
computing the distance indicators
found spatial support for each component
memmaping
Updating Spatial Components using lasso lars
clearing variables
clearing variables
clearing variables
clearing variables
clearing variables
thresholding components
Computing residuals
--- 0.510095119476 seconds ---
Removing tempfiles created
Compute Background Again
Estimate low rank Background
(1000, 31, 31)
using 1 processes
using 225 pixels per process
using 20000 block_size
preprocessing ...
checking if missing data
Single Thread
225
225
225
225
61
initializing ...
Roi Extraction...
Init one photon
0 neurons have been initialized
In total,  10 neurons were initialized.
Compute Background
Compute Residuals
Update spatial
Generating residuals
entering the deconvolution 
3 out of total 10 temporal components updated
6 out of total 10 temporal components updated
8 out of total 10 temporal components updated
9 out of total 10 temporal components updated
10 out of total 10 temporal components updated
3 out of total 10 temporal components updated
6 out of total 10 temporal components updated
8 out of total 10 temporal components updated
9 out of total 10 temporal components updated
10 out of total 10 temporal components updated
stopping: overall temporal component not changing significantly
Update Temporal
Initializing update of Spatial Components
computing the distance indicators
found spatial support for each component
memmaping
Updating Spatial Components using lasso lars
clearing variables
clearing variables
clearing variables
clearing variables
clearing variables
thresholding components
Computing residuals
--- 0.593204975128 seconds ---
Removing tempfiles created
Compute Background Again
Estimate low rank Background
(1000, 31, 31)
using 1 processes
using 225 pixels per process
using 20000 block_size
preprocessing ...
checking if missing data
Single Thread
225
225
225
225
61
initializing ...
Roi Extraction...
Init one photon
0 neurons have been initialized
In total,  10 neurons were initialized.
Compute Background
Compute Residuals
Update spatial
Generating residuals
entering the deconvolution 
4 out of total 10 temporal components updated
6 out of total 10 temporal components updated
7 out of total 10 temporal components updated
9 out of total 10 temporal components updated
10 out of total 10 temporal components updated
4 out of total 10 temporal components updated
6 out of total 10 temporal components updated
7 out of total 10 temporal components updated
9 out of total 10 temporal components updated
10 out of total 10 temporal components updated
stopping: overall temporal component not changing significantly
Update Temporal
Initializing update of Spatial Components
computing the distance indicators
found spatial support for each component
memmaping
Updating Spatial Components using lasso lars
clearing variables
clearing variables
clearing variables
clearing variables
clearing variables
thresholding components
Computing residuals
--- 0.591088056564 seconds ---
Removing tempfiles created
Compute Background Again
Estimate low rank Background
(1000, 31, 31)
using 1 processes
using 225 pixels per process
using 20000 block_size
preprocessing ...
checking if missing data
Single Thread
225
225
225
225
61
initializing ...
Roi Extraction...
Init one photon
0 neurons have been initialized
In total,  10 neurons were initialized.
Compute Background
Compute Residuals
Update spatial
Generating residuals
entering the deconvolution 
3 out of total 10 temporal components updated
5 out of total 10 temporal components updated
6 out of total 10 temporal components updated
8 out of total 10 temporal components updated
9 out of total 10 temporal components updated
10 out of total 10 temporal components updated
3 out of total 10 temporal components updated
5 out of total 10 temporal components updated
6 out of total 10 temporal components updated
8 out of total 10 temporal components updated
9 out of total 10 temporal components updated
10 out of total 10 temporal components updated
stopping: overall temporal component not changing significantly
Update Temporal
Initializing update of Spatial Components
computing the distance indicators
found spatial support for each component
memmaping
Updating Spatial Components using lasso lars
clearing variables
clearing variables
clearing variables
clearing variables
clearing variables
thresholding components
Computing residuals
--- 0.511209011078 seconds ---
Removing tempfiles created
Compute Background Again
Estimate low rank Background
(1000, 31, 30)
using 1 processes
using 225 pixels per process
using 20000 block_size
preprocessing ...
checking if missing data
Single Thread
225
225
225
225
30
initializing ...
Roi Extraction...
Init one photon
0 neurons have been initialized
In total,  10 neurons were initialized.
Compute Background
Compute Residuals
Update spatial
Generating residuals
entering the deconvolution 
3 out of total 10 temporal components updated
6 out of total 10 temporal components updated
8 out of total 10 temporal components updated
9 out of total 10 temporal components updated
10 out of total 10 temporal components updated
3 out of total 10 temporal components updated
6 out of total 10 temporal components updated
8 out of total 10 temporal components updated
9 out of total 10 temporal components updated
10 out of total 10 temporal components updated
stopping: overall temporal component not changing significantly
Update Temporal
Initializing update of Spatial Components
computing the distance indicators
found spatial support for each component
memmaping
Updating Spatial Components using lasso lars
clearing variables
clearing variables
clearing variables
clearing variables
clearing variables
thresholding components
Computing residuals
--- 0.468898057938 seconds ---
Removing tempfiles created
Compute Background Again
Estimate low rank Background
(1000, 31, 31)
using 1 processes
using 225 pixels per process
using 20000 block_size
preprocessing ...
checking if missing data
Single Thread
225
225
225
225
61
initializing ...
Roi Extraction...
Init one photon
0 neurons have been initialized
In total,  10 neurons were initialized.
Compute Background
Compute Residuals
Update spatial
Generating residuals
entering the deconvolution 
3 out of total 10 temporal components updated
5 out of total 10 temporal components updated
7 out of total 10 temporal components updated
8 out of total 10 temporal components updated
10 out of total 10 temporal components updated
3 out of total 10 temporal components updated
5 out of total 10 temporal components updated
7 out of total 10 temporal components updated
8 out of total 10 temporal components updated
10 out of total 10 temporal components updated
stopping: overall temporal component not changing significantly
Update Temporal
Initializing update of Spatial Components
computing the distance indicators
found spatial support for each component
memmaping
Updating Spatial Components using lasso lars
clearing variables
clearing variables
clearing variables
clearing variables
clearing variables
thresholding components
Computing residuals
--- 0.595993995667 seconds ---
Removing tempfiles created
Compute Background Again
Estimate low rank Background
(1000, 31, 31)
using 1 processes
using 225 pixels per process
using 20000 block_size
preprocessing ...
checking if missing data
Single Thread
225
225
225
225
61
initializing ...
Roi Extraction...
Init one photon
0 neurons have been initialized
In total,  10 neurons were initialized.
Compute Background
Compute Residuals
Update spatial
Generating residuals
entering the deconvolution 
2 out of total 10 temporal components updated
5 out of total 10 temporal components updated
7 out of total 10 temporal components updated
9 out of total 10 temporal components updated
10 out of total 10 temporal components updated
2 out of total 10 temporal components updated
5 out of total 10 temporal components updated
7 out of total 10 temporal components updated
9 out of total 10 temporal components updated
10 out of total 10 temporal components updated
stopping: overall temporal component not changing significantly
Update Temporal
Initializing update of Spatial Components
computing the distance indicators
found spatial support for each component
memmaping
Updating Spatial Components using lasso lars
clearing variables
clearing variables
clearing variables
clearing variables
clearing variables
thresholding components
Computing residuals
--- 0.495157957077 seconds ---
Removing tempfiles created
Compute Background Again
Estimate low rank Background
(1000, 31, 31)
using 1 processes
using 225 pixels per process
using 20000 block_size
preprocessing ...
checking if missing data
Single Thread
225
225
225
225
61
initializing ...
Roi Extraction...
Init one photon
0 neurons have been initialized
In total,  10 neurons were initialized.
Compute Background
Compute Residuals
Update spatial
Generating residuals
entering the deconvolution 
3 out of total 10 temporal components updated
4 out of total 10 temporal components updated
7 out of total 10 temporal components updated
9 out of total 10 temporal components updated
10 out of total 10 temporal components updated
3 out of total 10 temporal components updated
4 out of total 10 temporal components updated
7 out of total 10 temporal components updated
9 out of total 10 temporal components updated
10 out of total 10 temporal components updated
stopping: overall temporal component not changing significantly
Update Temporal
Initializing update of Spatial Components
computing the distance indicators
found spatial support for each component
memmaping
Updating Spatial Components using lasso lars
clearing variables
clearing variables
clearing variables
clearing variables
clearing variables
thresholding components
Computing residuals
--- 0.625679016113 seconds ---
Removing tempfiles created
Compute Background Again
Estimate low rank Background
(1000, 31, 31)
using 1 processes
using 225 pixels per process
using 20000 block_size
preprocessing ...
checking if missing data
Single Thread
225
225
225
225
61
initializing ...
Roi Extraction...
Init one photon
0 neurons have been initialized
In total,  10 neurons were initialized.
Compute Background
Compute Residuals
Update spatial
Generating residuals
entering the deconvolution 
3 out of total 10 temporal components updated
5 out of total 10 temporal components updated
7 out of total 10 temporal components updated
9 out of total 10 temporal components updated
10 out of total 10 temporal components updated
3 out of total 10 temporal components updated
5 out of total 10 temporal components updated
7 out of total 10 temporal components updated
9 out of total 10 temporal components updated
10 out of total 10 temporal components updated
stopping: overall temporal component not changing significantly
Update Temporal
Initializing update of Spatial Components
computing the distance indicators
found spatial support for each component
memmaping
Updating Spatial Components using lasso lars
clearing variables
clearing variables
clearing variables
clearing variables
clearing variables
thresholding components
Computing residuals
--- 0.569766998291 seconds ---
Removing tempfiles created
Compute Background Again
Estimate low rank Background
(1000, 31, 31)
using 1 processes
using 225 pixels per process
using 20000 block_size
preprocessing ...
checking if missing data
Single Thread
225
225
225
225
61
initializing ...
Roi Extraction...
Init one photon
0 neurons have been initialized
In total,  10 neurons were initialized.
Compute Background
Compute Residuals
Update spatial
Generating residuals
entering the deconvolution 
2 out of total 10 temporal components updated
4 out of total 10 temporal components updated
6 out of total 10 temporal components updated
8 out of total 10 temporal components updated
10 out of total 10 temporal components updated
2 out of total 10 temporal components updated
4 out of total 10 temporal components updated
6 out of total 10 temporal components updated
8 out of total 10 temporal components updated
10 out of total 10 temporal components updated
stopping: overall temporal component not changing significantly
Update Temporal
Initializing update of Spatial Components
computing the distance indicators
found spatial support for each component
memmaping
Updating Spatial Components using lasso lars
clearing variables
clearing variables
clearing variables
clearing variables
clearing variables
thresholding components
Computing residuals
--- 0.606735944748 seconds ---
Removing tempfiles created
Compute Background Again
Estimate low rank Background
(1000, 31, 30)
using 1 processes
using 225 pixels per process
using 20000 block_size
preprocessing ...
checking if missing data
Single Thread
225
225
225
225
30
initializing ...
Roi Extraction...
Init one photon
0 neurons have been initialized
In total,  10 neurons were initialized.
Compute Background
Compute Residuals
Update spatial
Generating residuals
entering the deconvolution 
2 out of total 10 temporal components updated
5 out of total 10 temporal components updated
7 out of total 10 temporal components updated
9 out of total 10 temporal components updated
10 out of total 10 temporal components updated
2 out of total 10 temporal components updated
5 out of total 10 temporal components updated
7 out of total 10 temporal components updated
9 out of total 10 temporal components updated
10 out of total 10 temporal components updated
stopping: overall temporal component not changing significantly
Update Temporal
Initializing update of Spatial Components
computing the distance indicators
found spatial support for each component
memmaping
Updating Spatial Components using lasso lars
clearing variables
clearing variables
clearing variables
clearing variables
clearing variables
thresholding components
Computing residuals
--- 0.662768125534 seconds ---
Removing tempfiles created
Compute Background Again
Estimate low rank Background
(1000, 30, 31)
using 1 processes
using 225 pixels per process
using 20000 block_size
preprocessing ...
checking if missing data
Single Thread
225
225
225
225
30
initializing ...
Roi Extraction...
Init one photon
0 neurons have been initialized
In total,  10 neurons were initialized.
Compute Background
Compute Residuals
Update spatial
Generating residuals
entering the deconvolution 
4 out of total 10 temporal components updated
7 out of total 10 temporal components updated
9 out of total 10 temporal components updated
10 out of total 10 temporal components updated
4 out of total 10 temporal components updated
7 out of total 10 temporal components updated
9 out of total 10 temporal components updated
10 out of total 10 temporal components updated
stopping: overall temporal component not changing significantly
Update Temporal
Initializing update of Spatial Components
computing the distance indicators
found spatial support for each component
memmaping
Updating Spatial Components using lasso lars
clearing variables
clearing variables
clearing variables
clearing variables
clearing variables
thresholding components
Computing residuals
--- 0.633975982666 seconds ---
Removing tempfiles created
Compute Background Again
Estimate low rank Background
(1000, 30, 31)
using 1 processes
using 225 pixels per process
using 20000 block_size
preprocessing ...
checking if missing data
Single Thread
225
225
225
225
30
initializing ...
Roi Extraction...
Init one photon
0 neurons have been initialized
In total,  10 neurons were initialized.
Compute Background
Compute Residuals
Update spatial
Generating residuals
entering the deconvolution 
3 out of total 10 temporal components updated
6 out of total 10 temporal components updated
7 out of total 10 temporal components updated
8 out of total 10 temporal components updated
9 out of total 10 temporal components updated
10 out of total 10 temporal components updated
3 out of total 10 temporal components updated
6 out of total 10 temporal components updated
7 out of total 10 temporal components updated
8 out of total 10 temporal components updated
9 out of total 10 temporal components updated
10 out of total 10 temporal components updated
stopping: overall temporal component not changing significantly
Update Temporal
Initializing update of Spatial Components
computing the distance indicators
found spatial support for each component
memmaping
Updating Spatial Components using lasso lars
clearing variables
clearing variables
clearing variables
clearing variables
clearing variables
thresholding components
Computing residuals
--- 0.489789962769 seconds ---
Removing tempfiles created
Compute Background Again
Estimate low rank Background
(1000, 30, 31)
using 1 processes
using 225 pixels per process
using 20000 block_size
preprocessing ...
checking if missing data
Single Thread
225
225
225
225
30
initializing ...
Roi Extraction...
Init one photon
0 neurons have been initialized
In total,  10 neurons were initialized.
Compute Background
Compute Residuals
Update spatial
Generating residuals
entering the deconvolution 
3 out of total 10 temporal components updated
5 out of total 10 temporal components updated
7 out of total 10 temporal components updated
8 out of total 10 temporal components updated
9 out of total 10 temporal components updated
10 out of total 10 temporal components updated
3 out of total 10 temporal components updated
5 out of total 10 temporal components updated
7 out of total 10 temporal components updated
8 out of total 10 temporal components updated
9 out of total 10 temporal components updated
10 out of total 10 temporal components updated
stopping: overall temporal component not changing significantly
Update Temporal
Initializing update of Spatial Components
computing the distance indicators
found spatial support for each component
memmaping
Updating Spatial Components using lasso lars
clearing variables
clearing variables
clearing variables
clearing variables
clearing variables
thresholding components
Computing residuals
--- 0.532068014145 seconds ---
Removing tempfiles created
Compute Background Again
Estimate low rank Background
(1000, 30, 31)
using 1 processes
using 225 pixels per process
using 20000 block_size
preprocessing ...
checking if missing data
Single Thread
225
225
225
225
30
initializing ...
Roi Extraction...
Init one photon
0 neurons have been initialized
In total,  10 neurons were initialized.
Compute Background
Compute Residuals
Update spatial
Generating residuals
entering the deconvolution 
3 out of total 10 temporal components updated
6 out of total 10 temporal components updated
8 out of total 10 temporal components updated
10 out of total 10 temporal components updated
3 out of total 10 temporal components updated
6 out of total 10 temporal components updated
8 out of total 10 temporal components updated
10 out of total 10 temporal components updated
stopping: overall temporal component not changing significantly
Update Temporal
Initializing update of Spatial Components
computing the distance indicators
found spatial support for each component
memmaping
Updating Spatial Components using lasso lars
clearing variables
clearing variables
clearing variables
clearing variables
clearing variables
thresholding components
Computing residuals
--- 0.543202877045 seconds ---
Removing tempfiles created
Compute Background Again
Estimate low rank Background
(1000, 30, 31)
using 1 processes
using 225 pixels per process
using 20000 block_size
preprocessing ...
checking if missing data
Single Thread
225
225
225
225
30
initializing ...
Roi Extraction...
Init one photon
0 neurons have been initialized
In total,  10 neurons were initialized.
Compute Background
Compute Residuals
Update spatial
Generating residuals
entering the deconvolution 
3 out of total 10 temporal components updated
5 out of total 10 temporal components updated
7 out of total 10 temporal components updated
9 out of total 10 temporal components updated
10 out of total 10 temporal components updated
3 out of total 10 temporal components updated
5 out of total 10 temporal components updated
7 out of total 10 temporal components updated
9 out of total 10 temporal components updated
10 out of total 10 temporal components updated
stopping: overall temporal component not changing significantly
Update Temporal
Initializing update of Spatial Components
computing the distance indicators
found spatial support for each component
memmaping
Updating Spatial Components using lasso lars
clearing variables
clearing variables
clearing variables
clearing variables
clearing variables
thresholding components
Computing residuals
--- 0.59486413002 seconds ---
Removing tempfiles created
Compute Background Again
Estimate low rank Background
(1000, 30, 30)
using 1 processes
using 225 pixels per process
using 20000 block_size
preprocessing ...
checking if missing data
Single Thread
225
225
225
225
initializing ...
Roi Extraction...
Init one photon
0 neurons have been initialized
In total,  10 neurons were initialized.
Compute Background
Compute Residuals
Update spatial
Generating residuals
entering the deconvolution 
4 out of total 10 temporal components updated
7 out of total 10 temporal components updated
9 out of total 10 temporal components updated
10 out of total 10 temporal components updated
4 out of total 10 temporal components updated
7 out of total 10 temporal components updated
9 out of total 10 temporal components updated
10 out of total 10 temporal components updated
stopping: overall temporal component not changing significantly
Update Temporal
Initializing update of Spatial Components
computing the distance indicators
found spatial support for each component
memmaping
Updating Spatial Components using lasso lars
clearing variables
clearing variables
clearing variables
clearing variables
clearing variables
thresholding components
Computing residuals
--- 0.568876981735 seconds ---
Removing tempfiles created
Compute Background Again
Estimate low rank Background
58.1313650608
Transforming patches into full matrix
Skipped %d Empty Patch 0
Generating background

******** USING ONE BACKGROUND PER PATCH ******
Generating background DONE
merging
/install/anaconda2/lib/python2.7/site-packages/scipy/sparse/compressed.py:774: SparseEfficiencyWarning: Changing the sparsity structure of a csc_matrix is expensive. lil_matrix is more efficient.
  SparseEfficiencyWarning)
[200 211 260 270 320 330]
[ 60  70 121 130]
[ 35  45  92 102]
[124 131 183 191]
[273 282 332 341]
[143 158 205 216]
[280 290 340 350]
[275 284 334 343]
[203 215 265 276]
[156 162 218 220]
[ 91 100 150 160]
[21 32 80 90]
[241 250 301 314]
[202 212 263 272]
[ 94 103 153 165]
[169 176 227 232]
[ 83  99 142 157]
[226 228 235 237]
[170 224 230]
[266 277 335]
[196 208 268]
[140 155 204]
[ 84 144 159]
[236 289 295]
[222 278 283]
[40 50]
[ 51 110]
[201 262]
[342 351]
[ 97 106]
[210 271]
[120 180]
[316 327]
[312 323]
[101 163]
[10 25]
[281 344]
[154 214]
[31 42]
[ 52 111]
[ 0 61]
[22 81]
[ 93 151]
[ 67 128]
[240 300]
[115 174]
[185 249]
[219 225]
[ 53 112]
[287 347]
[184 193]
[321 331]
[248 255]
[ 57 114]
[ 64 122]
[311 322]
[213 221]
[182 190]
[346 355]
[33 43]
[292 353]
[ 63 123]
[34 44]
[349 357]
[264 274]
[259 267]
[ 5 62]
[246 305]
[172 231]
[108 118]
[47 55]
[147 209]
[20 38]
[167 178]
[30 41]
[145 206]
[37 95]
[152 164]
[328 338]
[279 286]
[146 207]
[134 198]
[186 247]
[14 28]
[245 308]
[345 354]
[ 2 65]
[244 252]
[16 74]
[129 135]
[181 242]
[105 166]
[ 46 104]
[179 216]
[185 206]
No neurons merged!
update temporal
Generating residuals
parallel dot product block size: 20000
Start product
Transposing
16383
entering the deconvolution 
40 out of total 220 temporal components updated
76 out of total 220 temporal components updated
104 out of total 220 temporal components updated
135 out of total 220 temporal components updated
160 out of total 220 temporal components updated
183 out of total 220 temporal components updated
198 out of total 220 temporal components updated
206 out of total 220 temporal components updated
212 out of total 220 temporal components updated
218 out of total 220 temporal components updated
220 out of total 220 temporal components updated
40 out of total 220 temporal components updated
76 out of total 220 temporal components updated
104 out of total 220 temporal components updated
135 out of total 220 temporal components updated
160 out of total 220 temporal components updated
183 out of total 220 temporal components updated
198 out of total 220 temporal components updated
206 out of total 220 temporal components updated
212 out of total 220 temporal components updated
218 out of total 220 temporal components updated
220 out of total 220 temporal components updated
stopping: overall temporal component not changing significantly
Out[9]:
<caiman.source_extraction.cnmf.cnmf.CNMF at 0x7fc5cde4e250>

In [10]:
# %% DISCARD LOW QUALITY COMPONENT
final_frate = 10
r_values_min = 0.1  # threshold on space consistency
fitness_min = - 10  # threshold on time variability
# threshold on time variability (if nonsparse activity)
fitness_delta_min = - 10
Npeaks = 10
traces = cnm.C + cnm.YrA
# TODO: todocument
idx_components, idx_components_bad = cm.components_evaluation.estimate_components_quality(
    traces, Yr, cnm.A, cnm.C, cnm.b, cnm.f, final_frate=final_frate, Npeaks=Npeaks,
    r_values_min=r_values_min, fitness_min=fitness_min, fitness_delta_min=fitness_delta_min)

print(('Keeping ' + str(len(idx_components)) + ' and discarding  ' + str(len(idx_components_bad))))


tB:-2.0,tA:9.0
Computing event exceptionality delta
Removing Baseline
binning data ...
interpolating data ...
(5, 220)
Computing event exceptionality
caiman/components_evaluation.py:141: RuntimeWarning: divide by zero encountered in log
  erf = np.log(erf)
Evaluating spatial footprint
components evaluated:0
Neuron:97 includes overlaping spiking neurons
Neuron:116 includes overlaping spiking neurons
Neuron:154 includes overlaping spiking neurons
Neuron:199 includes overlaping spiking neurons
components evaluated:200
Neuron:217 includes overlaping spiking neurons
Keeping 200 and discarding  20

In [11]:
# %% rerun updating the components to refine
cnm = cnmf.CNMF(n_processes=1, k=cnm.A.shape, gSig=[gSig, gSig], merge_thresh=0.8, p=1,
                dview=None, Ain=cnm.A, Cin=cnm.C, b_in=cnm.b,
                f_in=cnm.f, rf=None, stride=None, method_deconvolution='oasis', gnb=None,
                low_rank_background=False, update_background_components=False)

cnm.fit(Yr.T.reshape((T,) + dims, order='F'))


(1000, 128, 128)
using 1 processes
using 4000 pixels per process
using 20000 block_size
preprocessing ...
checking if missing data
Single Thread
4000
4000
4000
4000
384
update spatial ...
Initializing update of Spatial Components
computing the distance indicators
found spatial support for each component
memmaping
Updating Spatial Components using lasso lars
clearing variables
clearing variables
clearing variables
clearing variables
clearing variables
thresholding components
eliminating 18 empty spatial components
Computing residuals
parallel dot product block size: 1000
Start product
999
1999
2999
3999
4999
5999
6999
7999
8999
9999
10999
11999
12999
13999
14999
15999
16383
--- 21.2636239529 seconds ---
Removing tempfiles created
update temporal ...
deconvolution ...
Generating residuals
parallel dot product block size: 20000
Start product
Transposing
16383
entering the deconvolution 
37 out of total 220 temporal components updated
75 out of total 220 temporal components updated
107 out of total 220 temporal components updated
134 out of total 220 temporal components updated
163 out of total 220 temporal components updated
182 out of total 220 temporal components updated
199 out of total 220 temporal components updated
210 out of total 220 temporal components updated
216 out of total 220 temporal components updated
219 out of total 220 temporal components updated
220 out of total 220 temporal components updated
37 out of total 220 temporal components updated
75 out of total 220 temporal components updated
107 out of total 220 temporal components updated
134 out of total 220 temporal components updated
163 out of total 220 temporal components updated
182 out of total 220 temporal components updated
199 out of total 220 temporal components updated
210 out of total 220 temporal components updated
216 out of total 220 temporal components updated
219 out of total 220 temporal components updated
220 out of total 220 temporal components updated
stopping: overall temporal component not changing significantly
refinement...
merge components ...
[110 111 119]
[ 27 172 193]
[ 47 143]
(16384, 215)
update spatial ...
Initializing update of Spatial Components
computing the distance indicators
found spatial support for each component
memmaping
Updating Spatial Components using lasso lars
clearing variables
clearing variables
clearing variables
clearing variables
clearing variables
thresholding components
eliminating 3 empty spatial components
Computing residuals
parallel dot product block size: 1000
Start product
999
1999
2999
3999
4999
5999
6999
7999
8999
9999
10999
11999
12999
13999
14999
15999
16383
--- 21.8653271198 seconds ---
Removing tempfiles created
update temporal ...
Generating residuals
parallel dot product block size: 20000
Start product
Transposing
16383
entering the deconvolution 
30 out of total 215 temporal components updated
63 out of total 215 temporal components updated
94 out of total 215 temporal components updated
122 out of total 215 temporal components updated
149 out of total 215 temporal components updated
171 out of total 215 temporal components updated
188 out of total 215 temporal components updated
202 out of total 215 temporal components updated
210 out of total 215 temporal components updated
214 out of total 215 temporal components updated
215 out of total 215 temporal components updated
30 out of total 215 temporal components updated
63 out of total 215 temporal components updated
94 out of total 215 temporal components updated
122 out of total 215 temporal components updated
149 out of total 215 temporal components updated
171 out of total 215 temporal components updated
188 out of total 215 temporal components updated
202 out of total 215 temporal components updated
210 out of total 215 temporal components updated
214 out of total 215 temporal components updated
215 out of total 215 temporal components updated
stopping: overall temporal component not changing significantly
Out[11]:
<caiman.source_extraction.cnmf.cnmf.CNMF at 0x7fc5cde4ef90>

Step 4: Visualize results


In [12]:
%matplotlib notebook
output_notebook()  # create output within this notebook
# reset_output()  # default creates output in seperate html file
traces_fluo = cm.utils.visualization.nb_view_patches(Yr, cnm.A, cnm.C, cnm.b, cnm.f, 
                                                     dims[0],dims[1], denoised_color='red',
                                                     image_neurons=cn_filter)


Loading BokehJS ...

In [13]:
def nb_view_background(b, f, dims):
    bokeh.io.curdoc().clear()
    d1, d2 = dims
    nb = np.linalg.norm(b, 2, 0)
    b = b / nb
    f = f * nb[:, None]
    nr, T = f.shape
    # split sources up, such that Bokeh does not warn
    # "ColumnDataSource's columns must be of the same length"
    source = ColumnDataSource(data=dict(x=np.arange(T), y=f[0] / 100))
    source_ = ColumnDataSource(data=dict(z=f / 100))
    nb = np.linalg.norm(b, 2, 0)
    source3 = ColumnDataSource(
        data=dict(image=[b[:, 0].reshape(dims, order='F')[::-1]],
                  im=[b.T.reshape((-1,) + dims, order='F')[:, ::-1]],
                  x=[0], y=[d2], dw=[d1], dh=[d2]))

    callback = CustomJS(args=dict(source=source, source_=source_, source3=source3), code="""
            var data = source.get('data')
            var data_ = source_.get('data')
            var f = cb_obj.get('value')-1
            x = data['x']
            y = data['y']
            for (i = 0; i < x.length; i++) {
                y[i] = data_['z'][i+f*x.length]
            }

            var dh = source3.data['dh'][0];
            var dw = source3.data['dw'][0];
            var image = source3.data['image'][0];
            var images = source3.data['im'][0];
            for (var i = 0; i < x.length; i++) {
                for (var j = 0; j < dw; j++){
                    image[i*dh+j] = images[f*dh*dw + i*dh + j];
                }
            }

            source3.trigger('change')
            source.trigger('change')
        """)

    plot = bpl.figure(plot_width=600, plot_height=300)
    plot.line('x', 'y', source=source, line_width=1, line_alpha=0.6)

    slider = bokeh.models.Slider(start=1, end=f.shape[0], value=1, step=1,
                                 title="Background Number", callback=callback)

    xr = Range1d(start=0, end=d1)
    yr = Range1d(start=d2, end=0)
    plot1 = bpl.figure(x_range=xr, y_range=yr, plot_width=300, plot_height=300)
    colormap = mpl.cm.get_cmap('jet')
    cmap = bokeh.models.mappers.LinearColorMapper([mpl.colors.rgb2hex(m)
                                                   for m in colormap(np.arange(colormap.N))])
    cmap.high = b.max()
    plot1.image(image='image', x='x', y='y', dw='dw', dh='dh',
                color_mapper=cmap, source=source3)

    bpl.show(bokeh.layouts.layout([[slider], [bokeh.layouts.row(plot1, plot)]]))

In [14]:
nb_view_background(cnm.b, cnm.f, dims)



In [15]:
%matplotlib inline
fig = plt.figure(figsize=(10,10))
crd = cm.utils.visualization.plot_contours(cnm.A, cn_filter, thr=0.9)


caiman/utils/visualization.py:906: UserWarning: The way to call utilities.plot_contours has changed. Look at the definition for more details.
  warn("The way to call utilities.plot_contours has changed. Look at the definition for more details.")