sn, options['temporal_params'], options['spatial_params'], bl=bl, c1=c1, sn=neurons_sn, g=g, thr=0.8, mx=50, fast_merge=True) t_elMERGE = time() - t1 print t_elMERGE #%% plt.figure() crd = cse.plot_contours(A_m, Cn, thr=0.9) #%% refine spatial and temporal pl.close() t1 = time() A2, b2, C2 = cse.spatial.update_spatial_components(Yr, C_m, f, A_m, sn=sn, **options['spatial_params']) options['temporal_params'][ 'p'] = p # set it back to original value to perform full deconvolution C2, f2, S2, bl2, c12, neurons_sn2, g21, YrA = cse.temporal.update_temporal_components( Yr, A2, b2,
#%% update_temporal_components pl.close() t1 = time() options['temporal_params']['p'] = 0 # set this to zero for fast updating without deconvolution C,f,S,bl,c1,neurons_sn,g,YrA = cse.temporal.update_temporal_components(Yr,A,b,Cin,f_in,bl=None,c1=None,sn=None,g=None,**options['temporal_params']) t_elTEMPORAL = time() - t1 print(t_elTEMPORAL) #%% merge components corresponding to the same neuron t1 = time() A_m,C_m,nr_m,merged_ROIs,S_m,bl_m,c1_m,sn_m,g_m=cse.merging.merge_components(Yr,A,b,C,f,S,sn,options['temporal_params'], options['spatial_params'], bl=bl, c1=c1, sn=neurons_sn, g=g, thr=0.8, mx=50, fast_merge = True) t_elMERGE = time() - t1 print(t_elMERGE) #%% plt.figure() crd = cse.plot_contours(A_m,Cn,thr=0.9) #%% refine spatial and temporal pl.close() t1 = time() A2,b2,C2 = cse.spatial.update_spatial_components(Yr, C_m, f, A_m, sn=sn, **options['spatial_params']) options['temporal_params']['p'] = p # set it back to original value to perform full deconvolution C2,f2,S2,bl2,c12,neurons_sn2,g21,YrA = cse.temporal.update_temporal_components(Yr,A2,b2,C2,f,bl=None,c1=None,sn=None,g=None,**options['temporal_params']) print((time() - t1)) #%% A_or, C_or, srt = cse.utilities.order_components(A2,C2) #cse.utilities.view_patches(Yr,coo_matrix(A_or),C_or,b2,f2,d1,d2,YrA = YrA[srt,:], secs=1) cse.utilities.view_patches_bar(Yr,coo_matrix(A_or),C_or,b2,f2, d1,d2, YrA=YrA[srt,:]) #plt.show(block=True) plt.show() #%%
'n_processes':n_processes,'backend':'ipyparallel', 'memory_efficient':False, 'bas_nonneg':True, 'noise_range':[.25,.5], 'noise_method':'logmexp', 'lags':5, 'fudge_factor':1., 'verbosity':False } #%% PREPROCESS DATA t1 = time() Yr,sn,g=cse.preprocess_data(Yr,**preprocess_params) Ain, Cin, b_in, f_in, center=cse.initialize_components(Y, **init_params) print time() - t1 plt2 = plt.imshow(Cn,interpolation='None') plt.colorbar() plt.scatter(x=center[:,1], y=center[:,0], c='m', s=40) crd = cse.plot_contours(coo_matrix(Ain[:,::-1]),Cn,thr=0.9) plt.axis((-0.5,d2-0.5,-0.5,d1-0.5)) plt.gca().invert_yaxis() pl.show() #%% t1 = time() A,b,Cin = cse.update_spatial_components_parallel(Yr, Cin, f_in, Ain, sn=sn, **spatial_params) t_elSPATIAL = time() - t1 print t_elSPATIAL crd = cse.plot_contours(A,Cn,thr=0.9) #%% update_temporal_components t1 = time() C,f,Y_res,S,bl,c1,neurons_sn,g = cse.update_temporal_components_parallel(Yr,A,b,Cin,f_in,bl=None,c1=None,sn=None,g=None,**temporal_params) t_elTEMPORAL2 = time() - t1 print t_elTEMPORAL2 # took 98 sec
ds).mean(-1).mean(-2).reshape(len(data), -1), shapes.reshape(-1, 96 / ds, ds, 96 / ds, ds).mean(-1).mean(-2).reshape(len(shapes), -1), activity.copy(), 20) # reconstruction and residual based on low-res data denoised = activity_ds.T.dot(shapes.reshape(N + 1, -1)).reshape(data.shape) residual = data - denoised if plot_smooth_shapes: A2 = coo_matrix(np.transpose([gaussian(a, 1).ravel() for a in shapes[:N]])) else: A2 = coo_matrix(shapes[:N].reshape(N, -1).T) fig = plt.figure(figsize=(16.7, 10)) ax1 = fig.add_axes([.002, .512, .3, .46]) cse.plot_contours(A2, data[0].T, thr=0.9, display_numbers=False, colors='w') im1 = plt.imshow(data[0].T, cmap=gfp, vmin=mi, vmax=ma) plt.title('data') plt.axis('off') # create an axes on the right side of ax. The width of cax will be 5% # of ax and the padding between cax and ax will be fixed at 0.05 inch. divider = make_axes_locatable(ax1) cax = divider.append_axes("right", size="5%", pad=0.05) plt.colorbar(im1, cax=cax) ax2 = fig.add_axes([.332, .512, .3, .46]) cse.plot_contours(A2, denoised1[0].T, thr=0.9, display_numbers=False, colors='w') im2 = plt.imshow(denoised1[0].T, cmap=gfp, vmin=mi, vmax=ma)