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.

Figure2_compact.py 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. #!/usr/bin/env python
  2. # coding: utf-8
  3. # ### Link to the file with meta information on recordings
  4. # In[14]:
  5. #import matplotlib.pyplot as plt
  6. #plt.rcParams["figure.figsize"] = (20,3)
  7. database_path = '/media/andrey/My Passport/GIN/backup_Anesthesia_CA1/meta_data/meta_recordings - anesthesia.xlsx'
  8. # ### Select the range of recordings for the analysis (see "Number" row in the meta data file)
  9. # In[4]:
  10. rec = [x for x in range(0,189)]
  11. #rec = [1,2]
  12. # In[1]:
  13. import numpy as np
  14. import numpy.ma as ma
  15. import matplotlib.pyplot as plt
  16. import matplotlib.ticker as ticker
  17. import pandas as pd
  18. import seaborn as sns
  19. import pickle
  20. import os
  21. sns.set()
  22. sns.set_style("whitegrid")
  23. from scipy.signal import medfilt
  24. from scipy.stats import skew, kurtosis, zscore
  25. from scipy import signal
  26. from sklearn.linear_model import LinearRegression, TheilSenRegressor
  27. plt.rcParams['figure.figsize'] = [16, 8]
  28. color_awake = (0,191/255,255/255)
  29. color_mmf = (245/255,143/255,32/255)
  30. color_keta = (181./255,34./255,48./255)
  31. color_iso = (143./255,39./255,143./255)
  32. custom_palette ={'keta':color_keta, 'iso':color_iso,'fenta':color_mmf,'awa':color_awake}
  33. # In[2]:
  34. from capipeline import *
  35. # ### Load the result of the analysis
  36. # In[8]:
  37. df_estimators = pd.read_pickle("./calcium_imaging_stability_validation.pkl")
  38. df_estimators['neuronID'] = df_estimators.index
  39. df_estimators["animal_cat"] = df_estimators["animal"].astype("category")
  40. #df_estimators["multihue"] = df_estimators["animal"].astype("string") + df_estimators["condition"]
  41. df_estimators["batch"] = (df_estimators["recording"] > 133).astype("int") + 1
  42. df_estimators["batch"] = "batch" + df_estimators["batch"].astype("string")
  43. df_estimators["multihue"] = df_estimators["batch"] + df_estimators["condition"]
  44. print(df_estimators["multihue"])
  45. # ### Plot
  46. # In[9]:
  47. parameters = ['number.neurons','traces.median','traces.skewness','decay','median.stability']
  48. labels = ['Extracted \n ROIs','Median, \n A.U.','Skewness','Decay time, \n s','1st/2nd \n ratio, %']
  49. number_subplots = len(parameters)
  50. #recordings_ranges = [[0,31],[32,55],[56,95],[96,133],[134,160],[161,188]]
  51. #recordings_ranges = [[0,55],[56,133],[134,188]]
  52. #recordings_ranges = [[0,133],[134,188]] #test
  53. recordings_ranges = [[0,188]]
  54. for rmin,rmax in recordings_ranges:
  55. f, axes = plt.subplots(number_subplots, 1, figsize=(2, 4.5)) # sharex=Truerex=True
  56. sns.despine(left=True)
  57. for i, param in enumerate(parameters):
  58. lw = 0.8
  59. df_nneurons = df_estimators.groupby(['recording','multihue','condition'], as_index=False)['number.neurons'].median()
  60. if (i == 0):
  61. sns.scatterplot(x='multihue', y='number.neurons', data=df_nneurons[(df_nneurons.recording>=rmin)&(df_nneurons.recording<=rmax)], hue = "condition", palette = custom_palette, ax=axes[i], marker = '.',edgecolor="black", linewidth = lw*0.5) #
  62. else:
  63. sns.boxplot(x='multihue', y=param, data=df_estimators[(df_estimators.recording>=rmin)&(df_estimators.recording<=rmax)], dodge=False, hue = "condition", palette=custom_palette, showfliers = False, ax=axes[i],linewidth=lw)
  64. #sns.swarmplot(x='multihue', y=param, data=df_estimators[(df_estimators.recording>=rmin)&(df_estimators.recording<=rmax)], dodge=False, hue = "condition", palette=custom_palette, showfliers = False, ax=axes[i], color=".25")
  65. #if (i == 0):
  66. # param = "animal_cat"
  67. # print(np.unique(df_estimators[param]))
  68. # axes[i].set_yticks(np.unique(df_estimators[param]))
  69. #
  70. # sns.swarmplot(x='multihue', y=param, data=df_estimators[(df_estimators.recording>=rmin)&(df_estimators.recording<=rmax)&(df_estimators['neuronID'] == 0)],dodge=False, hue = "condition", palette=custom_palette, s=1, edgecolor='black', linewidth=1, ax=axes[i])
  71. # #ax.set(ylabel="")
  72. if i == 0:
  73. axes[i].set_ylim([0.0,1200.0])
  74. if i > 0:
  75. axes[i].set_ylim([0.0,1000.0])
  76. if i > 1:
  77. axes[i].set_ylim([0.0,10.0])
  78. if i > 2:
  79. axes[i].set_ylim([0.0,1.0])
  80. if i > 3:
  81. axes[i].set_ylim([80,120])
  82. axes[i].get_xaxis().set_visible(True)
  83. else:
  84. axes[i].get_xaxis().set_visible(False)
  85. if i < number_subplots-1:
  86. axes[i].xaxis.label.set_visible(False)
  87. #if i==0:
  88. # axes[i].set_title("Validation: stability check (recordings #%d-#%d)" % (rmin,rmax), fontsize=6, pad=20)
  89. axes[i].set_ylabel(labels[i], fontsize=8,labelpad=5)
  90. #axes[i].set_xlabel("Recording", fontsize=8,labelpad=5)
  91. #axes[i].axis('off')
  92. axes[i].xaxis.set_tick_params(labelsize=6)
  93. axes[i].yaxis.set_tick_params(labelsize=6)
  94. axes[i].get_legend().remove()
  95. #axes[i].xaxis.set_major_locator(ticker.MultipleLocator(20))
  96. #axes[i].xaxis.set_major_formatter(ticker.ScalarFormatter())
  97. #plt.legend(loc='upper right',fontsize=8)
  98. #plt.legend(bbox_to_anchor=(1.01, 1), loc=2, borderaxespad=0.,fontsize=9)
  99. plt.xticks(rotation=45)
  100. plt.savefig("Validation_stability_check_figure2).png",dpi=300)
  101. plt.savefig("Validation_stability_check_figure2).svg")
  102. #plt.show()
  103. # In[13]:
  104. '''
  105. sns.displot(data=df_estimators, x="median.stability", hue = 'multihue',palette=custom_palette, kind="kde")
  106. plt.xlim([80,120])
  107. plt.xlabel("Stability, %", fontsize = 25)
  108. plt.title("Validation: summary on stability (recordings #%d-#%d)" % (min(rec),max(rec)), fontsize = 20, pad=20)
  109. plt.grid(False)
  110. plt.savefig("Validation_summary_stability_recordings_#%d-#%d)" % (min(rec),max(rec)))
  111. #plt.show()
  112. # In[62]:
  113. df_estimators["median.stability"].describe()
  114. '''