123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139 |
- #!/usr/bin/env python
- # coding: utf-8
- database_path = '/media/andrey/My Passport/GIN/backup_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,74)] #74
- # 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'])] = stat.item(0)['yoff']
- 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[:,:27000].reshape(mi.shape[0],90,300), axis=2)
- plt.rcParams["axes.grid"] = False
- plt.figure(figsize = (10,10))
- plt.imshow(mi_av,cmap='RdBu',vmin = -10, vmax = 10,aspect='equal')
- plt.scatter(start_quiet_period[0:max(rec)]/300,np.arange(max(rec)),marker='>',color='k',label='start of quite period')
- plt.scatter(stop_quiet_period[0:max(rec)]/300,np.arange(max(rec)),marker='<',color='k',label='end of quite 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()
|