#!/usr/bin/env python # coding: utf-8 database_path = '/media/andrey/My Passport/GIN_new/Anesthesia_CA1/meta_data/meta_recordings_sleep.xlsx' # ### Select the range of recordings for the analysis (see "Number" row in the meta data file) # In[4]: rec = [x for x in range(0,54)] # In[1]: import numpy as np import numpy.ma as ma import matplotlib.pyplot as plt import matplotlib.ticker as ticker import pandas as pd import seaborn as sns import pickle import os sns.set() sns.set_style("whitegrid") from scipy.signal import medfilt from scipy.stats import skew, kurtosis, zscore from scipy import signal from sklearn.linear_model import LinearRegression, TheilSenRegressor plt.rcParams['figure.figsize'] = [8, 8] # In[2]: from capipeline import * # ### Run the analysis # /media/andrey/My Passport/GIN/Anesthesia_CA1/validation/calcium_imaging # It creates a data frame *df_estimators* that contains basic information regarding stability of the recordings, such as # # - total number of identified neurons, # - traces and neuropils median inntensities for each ROI # - their standard deviation # - skewness of the signal # - estamation of their baseline (defined as a bottom quartile of signal intensities) # - their temporal stability (defined as the ratio between median signals of all ROIs in the first and the second parts of the recording) # In[5]: #df_estimators = pd.DataFrame() motion_index = np.zeros((len(rec),50000),dtype='float') recording_length = np.zeros((len(rec)),dtype='int') start_quiet_period = np.zeros((len(rec)),dtype='int') stop_quiet_period = np.zeros((len(rec)),dtype='int') for i, r in enumerate(rec): animal = get_animal_from_recording(r, database_path) #condition = get_condition(r, database_path) #print("#" + str(r) + " " + str(animal) + " " + str(condition) + " ") meta_data = pd.read_excel(database_path) path_excel_rec = str(meta_data['Folder'][r]) + str(meta_data['Subfolder'][r]) + '/suite2p/' stat = np.load(path_excel_rec+ '/plane0/ops.npy', allow_pickle=True) #plt.plot(stat.item(0)['yoff'],alpha=0.5) #plt.plot(stat.item(0)['xoff'],alpha=0.5) motion_index[i,:len(stat.item(0)['yoff'])] = np.sqrt(stat.item(0)['yoff']**2 + stat.item(0)['xoff']**2) recording_length[i] = len(stat.item(0)['yoff']) print(meta_data['Quiet periods'][r].split(',')) start_quiet_period[i] = int(meta_data['Quiet periods'][r].split(',')[0]) stop_quiet_period[i] = int(meta_data['Quiet periods'][r].split(',')[1]) #np.save("./xy-motion.npy",motion_index) mi = motion_index #mi = np.load("./xy-motion.npy") print(np.max(mi)) print(np.min(mi)) mi_av = np.mean(mi[:,:30000].reshape(mi.shape[0],100,300), axis=2) plt.rcParams["axes.grid"] = False plt.figure(figsize = (10,10)) pos = plt.imshow(mi_av,cmap='Purples',vmin = 0, vmax = 10,aspect='equal') plt.colorbar(pos) plt.scatter(start_quiet_period[0:max(rec)]/300,np.arange(max(rec)),marker='>',color='k',label='start of quiet period') plt.scatter(stop_quiet_period[0:max(rec)]/300,np.arange(max(rec)),marker='<',color='k',label='end of quiet period') plt.scatter(recording_length[0:max(rec)]/300, np.arange(max(rec)) ,marker='|',color='k',label='end of the recording') plt.legend() plt.xlabel('x 300 frames') plt.ylabel('recording') plt.title('Sleep dataset motion validation') #plt.gcf().set_facecolor("white") plt.savefig("Validation_motion.png") plt.savefig("Validation_motion.svg") #import plotly.express as px #import numpy as np #fig = px.imshow(mi, color_continuous_scale='RdBu_r',zmin = -10, zmax = 10) #fig.show() plt.show()