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.

ipos.py 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. """Figure 1S2 and 5S1 eye position plots, use run -i ipos.py"""
  2. index = pd.Index([], name='mseu') # init as empty
  3. iposmi = pd.DataFrame(index=index, columns=['stimtype', 'iposfmi', 'relfmi', 'iposrmi',
  4. 'relrmi', 'areafmi', 'meanratefmi',
  5. 'meanburstratiofmi'])
  6. maxiposedge, iposbinw = 10, 0.5
  7. iposedges = np.arange(0, maxiposedge+iposbinw, iposbinw)
  8. """Figure 1S2"""
  9. ## plot cross trial stdev PDFs for control and opto trials:
  10. for stimtype, stimtypei in zip(STIMTYPESPLUSALL, STIMTYPESPLUSALLI):
  11. f, a = plt.subplots(figsize=DEFAULTFIGURESIZE)
  12. wintitle('ipos_opto %s stdev cross trial PDF' % stimtype)
  13. stdctrl = ipos_opto['std_xpos_cross'][:, stimtypei, False]
  14. stdopto = ipos_opto['std_xpos_cross'][:, stimtypei, True]
  15. a.hist(stdctrl, bins=iposedges, histtype='step', lw=1.5,
  16. color=opto2clr[False], alpha=1, label=opto2fb[False])
  17. a.hist(stdopto, bins=iposedges, histtype='step', lw=1.5,
  18. color=opto2clr[True], alpha=1, label=opto2fb[True])
  19. a.set_xlabel('Eye position $\sigma$ ($\mathregular{\degree}$)')
  20. a.set_ylabel('Experiment count')
  21. #a.legend(frameon=False)
  22. print('opto %s std_cross:' % stimtype, wilcoxon(stdctrl, stdopto))
  23. ## plot cross trial stdev CDFs for control and opto trials:
  24. for stimtype, stimtypei in zip(STIMTYPESPLUSALL, STIMTYPESPLUSALLI):
  25. f, a = plt.subplots(figsize=DEFAULTFIGURESIZE)
  26. wintitle('ipos_opto %s stdev cross trial CDF' % stimtype)
  27. stdctrl = ipos_opto['std_xpos_cross'][:, stimtypei, False]
  28. stdopto = ipos_opto['std_xpos_cross'][:, stimtypei, True]
  29. stdctrlbins = list(np.unique(stdctrl)) + [maxiposedge]
  30. stdoptobins = list(np.unique(stdopto)) + [maxiposedge]
  31. a.hist(stdctrl, bins=stdctrlbins, density=True, cumulative=True, histtype='step',
  32. lw=1.5, color=opto2clr[False], alpha=1, label=opto2fb[False])
  33. a.hist(stdopto, bins=stdoptobins, density=True, cumulative=True, histtype='step',
  34. lw=1.5, color=opto2clr[True], alpha=1, label=opto2fb[True])
  35. a.set_xlabel('Eye position $\sigma$ ($\mathregular{\degree}$)')
  36. a.set_ylabel('Cumulative probability')
  37. a.set_xlim(0, 9.5)
  38. a.set_xticks([0, 5])
  39. a.set_yticks([0, 0.5, 1])
  40. #a.legend(frameon=False)
  41. _, KS_p = ks_2samp(stdctrl, stdopto)
  42. txt = '$\mathregular{p_{KS}=%.2g}$' % KS_p # prob that distribs are the same
  43. a.add_artist(AnchoredText(txt, loc='upper left', frameon=False))
  44. ## scatter plot movie reliability FMI vs eye position stdev FMI:
  45. # run reliability FMI for each movie mseu:
  46. mseus, relfmis = zip(*mviFMI['rel'][:, 'run'].items()) # unpack indices and relfmi values
  47. mseus, relfmis = np.array(mseus), np.array(relfmis)
  48. # across-trial eye position stdev FMI for all movie experiments:
  49. mseiposfmis = ((ipos_opto['std_xpos_cross'][:, 'mvi', False]
  50. - ipos_opto['std_xpos_cross'][:, 'mvi', True]) /
  51. (ipos_opto['std_xpos_cross'][:, 'mvi', False]
  52. + ipos_opto['std_xpos_cross'][:, 'mvi', True]))
  53. # get mse string of every mseu in mviFMI:
  54. mses = np.array(['_'.join(mseu.split('_')[:-1]) for mseu in mseus])
  55. # assign appropriate iposfmi to each mseu:
  56. iposfmis = np.tile(np.nan, len(mseus)) # init to nans
  57. for msei, mse in enumerate(mses):
  58. if mse in mseiposfmis.index:
  59. iposfmis[msei] = mseiposfmis[mse]
  60. # boolean indicating entries with non-NaN rel FMI & ipos FMI:
  61. valid = ~np.isnan(iposfmis) & ~np.isnan(relfmis)
  62. # scatter plot:
  63. figsize = DEFAULTFIGURESIZE[0]*1.05, DEFAULTFIGURESIZE[1] # tweak to make space for labels
  64. f, a = plt.subplots(figsize=figsize)
  65. wintitle('rel FMI vs ipos stdev FMI')
  66. a.scatter(iposfmis[valid], relfmis[valid], clip_on=False,
  67. marker='.', c='None', edgecolor='black', s=DEFSZ)
  68. # plot regression:
  69. fname = os.path.join('stats', 'figure_1_S2i_coefs.csv')
  70. try:
  71. df = pd.read_csv(fname)
  72. foundregression = True
  73. except FileNotFoundError:
  74. print('Missing file: %s' % fname)
  75. foundregression = False
  76. if foundregression:
  77. mm = df['slope'][0]
  78. b = df['intercept'][0]
  79. x = np.array([iposfmis[valid].min(), iposfmis[valid].max()])
  80. y = mm * x + b
  81. a.plot(x, y, '-', color='red') # plot linregress fit
  82. a.set_ylabel("Reliability FMI")
  83. a.set_xlabel("Eye position $\sigma$ FMI")
  84. xmin, xmax = -0.15, 0.15
  85. ymin, ymax = -1, 1
  86. a.set_xlim(xmin, xmax)
  87. a.set_ylim(ymin, ymax)
  88. a.set_xticks([xmin, 0, xmax])
  89. a.set_yticks([ymin, 0, ymax])
  90. a.spines['left'].set_position(('outward', 4))
  91. a.spines['bottom'].set_position(('outward', 4))
  92. # save to iposmi dataframe:
  93. for mseu, iposfmi, relfmi in zip(mseus, iposfmis, relfmis):
  94. iposmi.loc[mseu, 'stimtype'] = 'mvi'
  95. iposmi.loc[mseu, 'iposfmi'] = iposfmi
  96. iposmi.loc[mseu, 'relfmi'] = relfmi
  97. """Figure 5S1"""
  98. ## plot eye position stdev distributions:
  99. ## plot cross trial stdev PDFs for run and sit trials:
  100. for stimtype, stimtypei in zip(STIMTYPESPLUSALL, STIMTYPESPLUSALLI):
  101. f, a = plt.subplots(figsize=DEFAULTFIGURESIZE)
  102. wintitle('ipos_st8 %s stdev cross trial PDF' % stimtype)
  103. stdrun = ipos_st8['std_xpos_cross'][:, stimtypei, 'run']
  104. stdsit = ipos_st8['std_xpos_cross'][:, stimtypei, 'sit']
  105. a.hist(stdrun, bins=iposedges, histtype='step', lw=1.5,
  106. color=st82clr['run'], alpha=1, label='Run')
  107. a.hist(stdsit, bins=iposedges, histtype='step', lw=1.5,
  108. color=st82clr['sit'], alpha=1, label='Sit')
  109. a.set_xlabel('Eye position $\sigma$ ($\mathregular{\degree}$)')
  110. a.set_ylabel('Experiment count')
  111. #a.legend(frameon=False)
  112. print('st8 %s std_cross:' % stimtype, wilcoxon(stdrun, stdsit))
  113. ## plot cross trial stdev CDFs for run and sit trials:
  114. for stimtype, stimtypei in zip(STIMTYPESPLUSALL, STIMTYPESPLUSALLI):
  115. f, a = plt.subplots(figsize=DEFAULTFIGURESIZE)
  116. wintitle('ipos_st8 %s stdev cross trial CDF' % stimtype)
  117. stdrun = ipos_st8['std_xpos_cross'][:, stimtypei, 'run']
  118. stdsit = ipos_st8['std_xpos_cross'][:, stimtypei, 'sit']
  119. stdrunbins = list(np.unique(stdrun)) + [maxiposedge]
  120. stdsitbins = list(np.unique(stdsit)) + [maxiposedge]
  121. a.hist(stdrun, bins=stdrunbins, density=True, cumulative=True, histtype='step',
  122. lw=1.5, color=st82clr['run'], alpha=1, label='Run')
  123. a.hist(stdsit, bins=stdsitbins, density=True, cumulative=True, histtype='step',
  124. lw=1.5, color=st82clr['sit'], alpha=1, label='Sit')
  125. a.set_xlabel('Eye position $\sigma$ ($\mathregular{\degree}$)')
  126. a.set_ylabel('Cumulative probability')
  127. a.set_xlim(0, 8)
  128. a.set_xticks([0, 5])
  129. a.set_yticks([0, 0.5, 1])
  130. #a.legend(frameon=False)
  131. _, KS_p = ks_2samp(stdrun, stdsit)
  132. #_, MW_p = scipy.stats.mannwhitneyu(stdrun, stdsit)
  133. txt = '$\mathregular{p_{KS}=%.2g}$' % KS_p # prob that distribs are the same
  134. a.add_artist(AnchoredText(txt, loc='upper left', frameon=False))
  135. ## scatter plot movie reliability RMI vs eye position stdev FMI:
  136. # feedback reliability RMI for each movie mseu:
  137. mseus, relrmis = zip(*mviRMI['rel'][:, False].items()) # unpack indices and relrmi values
  138. mseus, relrmis = np.array(mseus), np.array(relrmis)
  139. # across-trial eye position stdev RMI for each experiment, 27 vals, 1 per exp:
  140. mseiposrmis = ((ipos_st8['std_xpos_cross'][:, 'mvi', 'run']
  141. - ipos_st8['std_xpos_cross'][:, 'mvi', 'sit']) /
  142. (ipos_st8['std_xpos_cross'][:, 'mvi', 'run']
  143. + ipos_st8['std_xpos_cross'][:, 'mvi', 'sit']))
  144. # get mse string of every mseu in mviRMI:
  145. mses = np.array(['_'.join(mseu.split('_')[:-1]) for mseu in mseus])
  146. # assign appropriate iposrmi to each mseu:
  147. iposrmis = np.tile(np.nan, len(mseus)) # init to nans
  148. for msei, mse in enumerate(mses):
  149. if mse in mseiposrmis.index:
  150. iposrmis[msei] = mseiposrmis[mse]
  151. # boolean indicating entries with non-NaN rel RMI & ipos RMI:
  152. valid = ~np.isnan(iposrmis) & ~np.isnan(relrmis)
  153. # scatter plot:
  154. figsize = DEFAULTFIGURESIZE[0]*1.05, DEFAULTFIGURESIZE[1] # tweak to make space for labels
  155. f, a = plt.subplots(figsize=figsize)
  156. wintitle('rel RMI vs ipos stdev RMI')
  157. a.scatter(iposrmis[valid], relrmis[valid], clip_on=False,
  158. marker='.', c='None', edgecolor='black', s=DEFSZ)
  159. # plot regression:
  160. fname = os.path.join('stats', 'figure_5_S1i_coefs.csv')
  161. try:
  162. df = pd.read_csv(fname)
  163. foundregression = True
  164. except FileNotFoundError:
  165. print('Missing file: %s' % fname)
  166. foundregression = False
  167. if foundregression:
  168. mm = df['slope'][0]
  169. b = df['intercept'][0]
  170. x = np.array([iposrmis[valid].min(), iposrmis[valid].max()])
  171. y = mm * x + b
  172. a.plot(x, y, '-', color='red') # plot linregress fit
  173. a.set_ylabel("Reliability RMI")
  174. a.set_xlabel("Eye position $\sigma$ RMI")
  175. ymin, ymax = -1, 1
  176. #a.set_xlim(-0.1, 0.6)
  177. a.set_ylim(ymin, ymax)
  178. a.set_xticks([0, 0.5])
  179. a.set_yticks([ymin, 0, ymax])
  180. a.spines['left'].set_position(('outward', 4))
  181. a.spines['bottom'].set_position(('outward', 4))
  182. # save to iposmi dataframe:
  183. for mseu, iposrmi, relrmi in zip(mseus, iposrmis, relrmis):
  184. iposmi.loc[mseu, 'stimtype'] = 'mvi' # automatically adds a new mseu row if needed
  185. iposmi.loc[mseu, 'iposrmi'] = iposrmi
  186. iposmi.loc[mseu, 'relrmi'] = relrmi