Fig_S2.py 3.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. import matplotlib.pyplot as plt
  2. import numpy as np
  3. import pandas as pd
  4. from c_inv.inference_paper_submission.layout import Frame, Figure
  5. from c_inv.inference_paper_submission.panels import oricon_matrix, marginal_tuning, contrast_amp_distr
  6. from c_inv.inference_paper_submission.util import (cm2inch, c_inv_paper_series, JNEUROSCIPARS, set_mpl_pars,
  7. align_y_axis_labels, inhibcol, excitcol)
  8. from pathlib import Path
  9. set_mpl_pars()
  10. plt.rcParams['font.sans-serif'] = ['Arial']
  11. layoutstring = 'ABC'
  12. layout = Frame(layoutstring, left=0.01, top=0.07, right=0.017, bot=0.15, h_space=0.03,
  13. w_space=0.015, panelpars={'A': {'left': 0.12, 'right': 0.09, 'width_ratio': 1.3,
  14. 'h_space': 0.05, 'w_space': 0.05},
  15. 'B': {'left': 0.26, 'h_space': 0.05, 'w_space': 0.02,
  16. 'width_ratio': 0.95},
  17. 'C': {'left': 0.2, 'width_ratio': 0.95}})
  18. layout.panels['A'].new_panels('12\n34')
  19. layout.panels['B'].new_panels('14\n23', panelpars={'4': {'invis': True},
  20. '1': {'width_ratio': 2},
  21. '2': {'width_ratio': 2,
  22. 'height_ratio': 3},
  23. '3': {'height_ratio': 3}})
  24. figure = Figure(layout, cm2inch(JNEUROSCIPARS['doublecolumn']), 2.2)
  25. figure.annotate(fontweight='bold')
  26. keys = [{'m': 'Ntsr1Cre_2020_0001', 's': 4, 'e': 9, 'u': 17},
  27. {'m': 'Ntsr1Cre_2020_0001', 's': 4, 'e': 9, 'u': 34},
  28. {'m': 'Ntsr1Cre_2020_0001', 's': 3, 'e': 9, 'u': 14},
  29. {'m': 'PVCre_2019_0009', 's': 4, 'e': 5, 'u': 60},
  30. {'m': 'PVCre_2019_0009', 's': 3, 'e': 6, 'u': 22},
  31. {'m': 'PVCre_2019_0009', 's': 3, 'e': 6, 'u': 34}]
  32. ###########
  33. # load data
  34. ###########
  35. pkg_dir = Path(__file__).parent
  36. data_dir = pkg_dir.joinpath('Data')
  37. oricon1 = pd.read_pickle(data_dir.joinpath('S2_oricon0.pkl'))
  38. oricon2 = pd.read_pickle(data_dir.joinpath('S2_oricon1.pkl'))
  39. oricon3 = pd.read_pickle(data_dir.joinpath('S2_oricon2.pkl'))
  40. oricon4 = pd.read_pickle(data_dir.joinpath('S2_oricon3.pkl'))
  41. marg_data = pd.read_pickle(data_dir.joinpath('S2_marginals_data.pkl'))
  42. marg_pars = np.load(str(data_dir.joinpath('S2_marginals_pars.npy')), allow_pickle=True)
  43. exc_amps = pd.read_pickle(data_dir.joinpath('S2_con_amps_exc.pkl'))
  44. inh_amps = pd.read_pickle(data_dir.joinpath('S2_con_amps_inh.pkl'))
  45. ax1 = figure.axes['A1']
  46. _, cbar1 = oricon_matrix(ax1, oricon1, cbar=True)
  47. cbar1.set_label('Firing (Hz)', labelpad=5)
  48. ax2 = figure.axes['A2']
  49. _, cbar2 = oricon_matrix(ax2, oricon2, cbar=True)
  50. cbar2.set_label('Firing (Hz)', labelpad=4)
  51. ax3 = figure.axes['A3']
  52. _, cbar3 = oricon_matrix(ax3, oricon3, cbar=True)
  53. cbar3.set_label('Firing (Hz)', labelpad=5)
  54. cbar3.set_ticks([5, 10])
  55. ax4 = figure.axes['A4']
  56. _, cbar4 = oricon_matrix(ax4, oricon4, cbar=True)
  57. cbar4.set_label('Firing (Hz)', labelpad=7.5)
  58. for ax in [ax1, ax2, ax3, ax4]:
  59. ax.set_yticks([0, 6, 12])
  60. ax.set_yticklabels([0, 90, 180])
  61. ax.set_xticks([0, 4, 7])
  62. ax.set_xticklabels([0, 0.3, 1])
  63. ax1.set_xlabel('')
  64. ax1.set_xticklabels([])
  65. ax2.set_xlabel('')
  66. ax2.set_ylabel('')
  67. ax2.set_xticklabels([])
  68. ax2.set_yticklabels([])
  69. ax4.set_ylabel('')
  70. ax4.set_yticklabels([])
  71. ax1 = figure.axes['B1']
  72. ax2 = figure.axes['B2']
  73. ax3 = figure.axes['B3']
  74. plt.rcParams['lines.markersize'] = 3
  75. marginal_tuning(marg_data, marg_pars, [ax1, ax2, ax3], tuning_model='wrap_gauss')
  76. ax3.set_xlabel('Firing (Hz)')
  77. ax3.set_xlim([12, 22])
  78. ax1.set_ylabel('Firing (Hz)')
  79. ax2.set_yticks([0, 3, 6, 9, 12])
  80. ax2.set_yticklabels([0, 45, 90, 135, 180])
  81. ax2.set_xticks([0, 4, 7])
  82. ax2.set_xticklabels([0, 0.3, 1])
  83. align_y_axis_labels(ax2, ax1)
  84. ax4 = figure.axes['C']
  85. contrast_amp_distr(exc_amps, inh_amps, ax4, excit_col=excitcol, inhib_col=inhibcol)