Example #1
0
    all_masks=mdend.mov;
else:
    all_masks=masks_tmp              

all_masksForPlot=[kk*(ii+1)*1.0 for ii,kk in enumerate(all_masks)]
plt.imshow(np.max(np.asarray(all_masksForPlot,dtype=np.float16),axis=0))


#%% extract DF/F from orginal movie, needs to reload the motion corrected movie
m=XMovie(mat=np.load(filename_mc)['mov'], frameRate=frameRate);    
m.crop(max_shift,max_shift,max_shift,max_shift)    
minPercentileRemove=1;
# remove an estimation of what a Dark patch is, you should provide a better estimate
F0=np.percentile(m.mov,minPercentileRemove)
m.mov=m.mov-F0; 
traces, tracesDFF = m.extract_traces_from_masks(all_masks,type='DFF',window_sec=15,minQuantile=8)
plt.plot(tracesDFF)
#%%
plt.imshow(tracesDFF.T)


#%% save the results of the analysis in python format
np.savez(filename_analysis,all_masks=all_masks,spcomps=spcomps,fx=fx,fy=fy,fz=fz,traces=traces,tracesDFF=tracesDFF)

#%% save the results of the analysis and motion corrected movie in matlab format
import scipy.io as sio
sio.savemat(filename_analysis[:-4]+'.mat', {'all_masks':np.transpose(all_masks,(1,2,0)),'spcomps':np.transpose(spcomps,(1,2,0)),'traces':traces,'tracesDFF':tracesDFF})
m=XMovie(mat=np.load(filename_mc)['mov'], frameRate=frameRate);    
sio.savemat(filename_mc[:-4]+'.mat', {'mov':np.transpose(np.load(filename_mc)['mov'],(1,2,0)),'frameRate':frameRate,'shifts':shifts,'templates':np.transpose(templates,(1,2,0))})