Scheduled service maintenance on November 22


On Friday, November 22, 2024, between 06:00 CET and 18:00 CET, GIN services will undergo planned maintenance. Extended service interruptions should be expected. We will try to keep downtimes to a minimum, but recommend that users avoid critical tasks, large data uploads, or DOI requests during this time.

We apologize for any inconvenience.

Validation_motion.py 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. #!/usr/bin/env python
  2. # coding: utf-8
  3. database_path = '/media/andrey/My Passport/GIN/backup_Anesthesia_CA1/meta_data/meta_recordings - anesthesia.xlsx'
  4. # ### Select the range of recordings for the analysis (see "Number" row in the meta data file)
  5. # In[4]:
  6. rec = [x for x in range(0,188)]
  7. # In[1]:
  8. import numpy as np
  9. import numpy.ma as ma
  10. import matplotlib.pyplot as plt
  11. import matplotlib.ticker as ticker
  12. import pandas as pd
  13. import seaborn as sns
  14. import pickle
  15. import os
  16. sns.set()
  17. sns.set_style("whitegrid")
  18. from scipy.signal import medfilt
  19. from scipy.stats import skew, kurtosis, zscore
  20. from scipy import signal
  21. from sklearn.linear_model import LinearRegression, TheilSenRegressor
  22. plt.rcParams['figure.figsize'] = [8, 8]
  23. # In[2]:
  24. from capipeline import *
  25. motion_index = np.zeros((len(rec),100000),dtype='float')
  26. recording_length = np.zeros((len(rec)),dtype='int')
  27. number_of_quiet_periods = 6
  28. start_quiet_period = np.zeros((len(rec),number_of_quiet_periods),dtype='int')
  29. stop_quiet_period = np.zeros((len(rec),number_of_quiet_periods),dtype='int')
  30. for i, r in enumerate(rec):
  31. print("Reconrding # ", r)
  32. animal = get_animal_from_recording(r, database_path)
  33. #condition = get_condition(r, database_path)
  34. #print("#" + str(r) + " " + str(animal) + " " + str(condition) + " ")
  35. meta_data = pd.read_excel(database_path)
  36. path_excel_rec = str(meta_data['Folder'][r]) + str(meta_data['Subfolder'][r]) + str(meta_data['Recording idx'][r]) + '/suite2p/'
  37. stat = np.load(path_excel_rec+ '/plane0/ops.npy', allow_pickle=True)
  38. #plt.plot(stat.item(0)['yoff'],alpha=0.5)
  39. #plt.plot(stat.item(0)['xoff'],alpha=0.5)
  40. motion_index[i,:len(stat.item(0)['yoff'])] = stat.item(0)['yoff']
  41. print("Min motion index:", min(motion_index[i,:]))
  42. print("Max motion index:", max(motion_index[i,:]))
  43. recording_length[i] = len(stat.item(0)['yoff'])
  44. print("Recording length:", recording_length[i])
  45. print("Quiet periods: ", type(meta_data['Quiet periods'][r]),type('str'))
  46. if (type(meta_data['Quiet periods'][r]) == type('str')):
  47. print("Quiet periods: ", meta_data['Quiet periods'][r].split(','))
  48. for k in range(int(len(meta_data['Quiet periods'][r].split(','))/2)):
  49. start_quiet_period[i,k] = int(meta_data['Quiet periods'][r].split(',')[k*2])
  50. stop_quiet_period[i,k] = int(meta_data['Quiet periods'][r].split(',')[k*2+1])
  51. print(start_quiet_period[i,k])
  52. print(stop_quiet_period[i,k] )
  53. else:
  54. print("Nan for recording:", r)
  55. start_quiet_period[i,0] = 0
  56. stop_quiet_period[i,0] = recording_length[i]
  57. # np.save("./xy-motion.npy",motion_index)
  58. mi = motion_index
  59. #mi = np.load("./xy-motion.npy")
  60. print(np.max(mi))
  61. print(np.min(mi))
  62. mi_av = np.mean(mi[:,:9000].reshape(mi.shape[0],100,90), axis=2)
  63. plt.rcParams["axes.grid"] = False
  64. plt.figure(figsize = (15,10))
  65. plt.imshow(mi_av,cmap='RdBu',vmin = -10, vmax = 10,aspect='equal')
  66. for k in range(int(number_of_quiet_periods/2)):
  67. plt.scatter(start_quiet_period[0:len(rec),k]/90,np.arange(len(rec)),marker=9,color='k',label='start of quite period')
  68. plt.scatter(stop_quiet_period[0:len(rec),k]/90,np.arange(len(rec)),marker=8,color='k',label='end of quite period')
  69. plt.scatter(recording_length[0:len(rec)]/90, np.arange(len(rec)) ,marker='|',color='k',label='end of the recording')
  70. plt.legend(loc='upper right')
  71. plt.xlabel('x 90 frames')
  72. plt.ylabel('recording')
  73. plt.title('Transition state dataset motion validation')
  74. #plt.gcf().set_facecolor("white")
  75. plt.xlim([0,100])
  76. plt.savefig("Validation_motion.png")
  77. plt.savefig("Validation_motion.svg")
  78. #import plotly.express as px
  79. #import numpy as np
  80. #fig = px.imshow(mi, color_continuous_scale='RdBu_r',zmin = -10, zmax = 10)
  81. #fig.show()
  82. plt.show()