#!/usr/bin/env python # coding: utf-8 database_path = '/media/andrey/My Passport/GIN/Anesthesia_CA1/meta_data/meta_recordings_transition_state.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,198)] #198 # 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 * motion_index = np.zeros((len(rec),100000),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): print("Reconrding # ", r) 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]) + str(meta_data['Recording idx'][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'] print(min(motion_index[i,:])) print(max(motion_index[i,:])) 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 = (15,10)) plt.imshow(mi_av,cmap='RdBu',vmin = -10, vmax = 10,aspect='equal') plt.scatter(start_quiet_period[0:len(rec)]/300,np.arange(len(rec)),marker='>',color='k',label='start of quite period') plt.scatter(stop_quiet_period[0:len(rec)]/300,np.arange(len(rec)),marker='<',color='k',label='end of quite period') plt.scatter(recording_length[0:len(rec)]/300, np.arange(len(rec)) ,marker='|',color='k',label='end of the recording') plt.legend() plt.xlabel('x 300 frames') plt.ylabel('recording') plt.title('Transition state dataset motion validation') #plt.gcf().set_facecolor("white") plt.xlim([0,100]) 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()