fig1S33S1.py 71 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656
  1. """Figure 1S3 and 3S1 unit classification plots, use run -i fig1S33S1.py"""
  2. index = pd.Index(mvigrtmsustrs, name='msu')
  3. columns = ['mvi_meanrate', 'mvi_meanburstratio', 'grt_meanrate', 'grt_meanburstratio',
  4. 'sbc', 'depth', 'normdepth', 'dsi', 'rfdist',
  5. 'mvi_meanrate_raw', 'mvi_meanburstratio_raw',
  6. 'grt_meanrate_raw', 'grt_meanburstratio_raw']
  7. fig1S33S1 = pd.DataFrame(index=index, columns=columns)
  8. from scipy.stats import gmean
  9. import matplotlib as mpl
  10. from matplotlib.patches import Rectangle
  11. TRANSTHRESH = 0.2
  12. ONOFFTHRESH = 0.2
  13. # stripplot FMI by SbC/non-SbC, mvi and grt, meanrate and meanburstratio:
  14. np.random.seed(0) # to get identical horizontal jitter in strip plots on every run
  15. figsize = DEFAULTFIGURESIZE
  16. for stimtype in STIMTYPES:
  17. stimtypelabel = stimtype2axislabel[stimtype]
  18. for measure in ['meanrate', 'meanburstratio']:
  19. axislabel = measure2axislabel[measure]
  20. axislabel = short2longaxislabel.get(axislabel, axislabel)
  21. if axislabel.islower():
  22. axislabel = axislabel.capitalize()
  23. fmis, sbcs = [], []
  24. colname = '_'.join([stimtype, measure]) # e.g. 'mvi_meanrate'
  25. for msustr in mvigrtmsustrs:
  26. # save sbc to fig1S33S1 df, regardless of FMI val, will be overwritten multiple
  27. # times with the same value, but that's OK:
  28. sbc = celltype.loc[msustr]['sbc'] # bool
  29. fig1S33S1.loc[msustr]['sbc'] = sbc
  30. fmi = maxFMI.loc[msustr, 'none', stimtype][measure] # ignore run condition for FMI
  31. if np.isnan(fmi):
  32. continue
  33. fmis.append(fmi)
  34. sbcs.append(sbc)
  35. fig1S33S1.loc[msustr][colname] = fmi
  36. fmis = np.asarray(fmis)
  37. sbcs = np.asarray(sbcs)
  38. sbcfmis = fmis[sbcs == True]
  39. nonsbcfmis = fmis[sbcs == False]
  40. f, a = plt.subplots(figsize=figsize)
  41. wintitle('FMI SbC %s %s strip' % (stimtypelabel, measure))
  42. # plot y=0 line:
  43. a.axhline(y=0, ls='--', marker='', color='lightgray', zorder=-np.inf)
  44. data = pd.DataFrame.from_dict({'SbC':sbcfmis, 'Non-SbC':nonsbcfmis},
  45. orient='index').transpose()
  46. sns.stripplot(ax=a, data=data, clip_on=False, marker='.',
  47. color='None', edgecolor='black', size=np.sqrt(50))
  48. # get fname of appropriate LMM .cvs file:
  49. fname = None # sanity check: clear from previous loop
  50. if stimtype == 'mvi':
  51. if measure == 'meanrate':
  52. fname = os.path.join('stats', 'figure_1S3a_pred_means.csv')
  53. elif measure == 'meanburstratio':
  54. fname = os.path.join('stats', 'figure_1S3f_pred_means.csv')
  55. elif stimtype == 'grt':
  56. if measure == 'meanrate':
  57. fname = os.path.join('stats', 'figure_3S1a_pred_means.csv')
  58. elif measure == 'meanburstratio':
  59. fname = os.path.join('stats', 'figure_3S1f_pred_means.csv')
  60. # fetch LMM means from .csv:
  61. df = pd.read_csv(fname)
  62. meannonsbcfmi = df['non_sbc'][0]
  63. meansbcfmi = df['sbc'][0]
  64. # plot mean with short horizontal lines:
  65. a.plot([-0.25, 0.25], [meansbcfmi, meansbcfmi], '-', lw=2, c='red', zorder=np.inf)
  66. a.plot([0.75, 1.25], [meannonsbcfmi, meannonsbcfmi], '-', lw=2, c='red', zorder=np.inf)
  67. a.set_ylabel('%s FMI' % axislabel)
  68. a.set_ylim(-1, 1)
  69. a.set_yticks([-1, 0, 1])
  70. a.tick_params(bottom=False)
  71. a.spines['bottom'].set_position(('outward', 5))
  72. a.spines['bottom'].set_visible(False)
  73. '''
  74. # stripplot FMI by shell/core, mvi and grt, meanrate and meanburstratio:
  75. np.random.seed(0) # to get identical horizontal jitter in strip plots on every run
  76. figsize = DEFAULTFIGURESIZE
  77. for stimtype in STIMTYPES:
  78. stimtypelabel = stimtype2axislabel[stimtype]
  79. for measure in ['meanrate', 'meanburstratio']:
  80. axislabel = measure2axislabel[measure]
  81. axislabel = short2longaxislabel.get(axislabel, axislabel)
  82. if axislabel.islower():
  83. axislabel = axislabel.capitalize()
  84. fmis, layers = [], []
  85. colname = '_'.join([stimtype, measure]) # e.g. 'mvi_meanrate'
  86. for msustr in mvigrtmsustrs:
  87. # save layer to fig1S33S1 df, regardless of FMI val, will be overwritten multiple
  88. # times with the same value, but that's OK:
  89. layer = celltype.loc[msustr]['layer'] # str
  90. fig1S33S1.loc[msustr]['layer'] = layer
  91. fmi = maxFMI.loc[msustr, 'none', stimtype][measure] # ignore run condition for FMI
  92. if np.isnan(fmi):
  93. continue
  94. fmis.append(fmi)
  95. layers.append(layer)
  96. fig1S33S1.loc[msustr][colname] = fmi # might overwrite w/ identical values
  97. fmis = np.asarray(fmis)
  98. layers = np.asarray(layers)
  99. shellfmis = fmis[layers == 'shell']
  100. corefmis = fmis[layers == 'core']
  101. f, a = plt.subplots(figsize=figsize)
  102. wintitle('FMI layer %s %s strip' % (stimtypelabel, measure))
  103. # plot y=0 line:
  104. a.axhline(y=0, ls='--', marker='', color='lightgray', zorder=-np.inf)
  105. data = pd.DataFrame.from_dict({'Shell':shellfmis, 'Core':corefmis},
  106. orient='index').transpose()
  107. sns.stripplot(ax=a, data=data, clip_on=False, marker='.',
  108. color='None', edgecolor='black', size=np.sqrt(50))
  109. # get fname of appropriate LMM .cvs file:
  110. fname = None # sanity check: clear from previous loop
  111. if stimtype == 'mvi':
  112. if measure == 'meanrate':
  113. fname = os.path.join('stats', 'figure_1S3b_pred_means.csv')
  114. elif measure == 'meanburstratio':
  115. fname = os.path.join('stats', 'figure_1S3g_pred_means.csv')
  116. elif stimtype == 'grt':
  117. if measure == 'meanrate':
  118. fname = os.path.join('stats', 'figure_3S1b_pred_means.csv')
  119. elif measure == 'meanburstratio':
  120. fname = os.path.join('stats', 'figure_3S1g_pred_means.csv')
  121. # fetch LMM means from .csv:
  122. df = pd.read_csv(fname)
  123. meancorefmi = df['core'][0]
  124. meanshellfmi = df['shell'][0]
  125. # plot mean with short horizontal lines:
  126. a.plot([-0.25, 0.25], [meanshellfmi, meanshellfmi], '-', lw=2, c='red', zorder=np.inf)
  127. a.plot([0.75, 1.25], [meancorefmi, meancorefmi], '-', lw=2, c='red', zorder=np.inf)
  128. a.set_ylabel('%s FMI' % axislabel)
  129. a.set_ylim(-1, 1)
  130. a.set_yticks([-1, 0, 1])
  131. a.tick_params(bottom=False)
  132. a.spines['bottom'].set_position(('outward', 5))
  133. a.spines['bottom'].set_visible(False)
  134. '''
  135. # scatter plot FMI vs. depth by mvi and grt, meanrate and meanburstratio:
  136. figsize = DEFAULTFIGURESIZE
  137. for stimtype in STIMTYPES:
  138. stimtypelabel = stimtype2axislabel[stimtype]
  139. for measure in ['meanrate', 'meanburstratio']:
  140. axislabel = measure2axislabel[measure]
  141. axislabel = short2longaxislabel.get(axislabel, axislabel)
  142. if axislabel.islower():
  143. axislabel = axislabel.capitalize()
  144. fmis, depths = [], []
  145. colname = '_'.join([stimtype, measure]) # e.g. 'mvi_meanrate'
  146. for msustr in mvigrtmsustrs:
  147. # save depth to fig1S33S1 df, regardless of FMI val, will be overwritten multiple
  148. # times with the same value, but that's OK:
  149. depth = celltype.loc[msustr]['depth'] # float
  150. fig1S33S1.loc[msustr]['depth'] = depth
  151. fmi = maxFMI.loc[msustr, 'none', stimtype][measure] # ignore run condition for FMI
  152. if np.isnan(fmi):
  153. continue
  154. fmis.append(fmi)
  155. depths.append(depth)
  156. fig1S33S1.loc[msustr][colname] = fmi # might overwrite w/ identical values
  157. fmis = np.asarray(fmis)
  158. depths = np.asarray(depths)
  159. f, a = plt.subplots(figsize=figsize)
  160. wintitle('FMI depth %s %s' % (stimtypelabel, measure))
  161. # plot y=0 line:
  162. a.axhline(y=0, ls='--', marker='', color='lightgray', zorder=-np.inf)
  163. a.scatter(depths, fmis, clip_on=False, marker='.', c='None', edgecolor='k', s=DEFSZ)
  164. # get fname of appropriate LMM .cvs file:
  165. fname = None # sanity check: clear from previous loop
  166. if stimtype == 'mvi':
  167. if measure == 'meanrate':
  168. fname = os.path.join('stats', 'figure_1S3b_coefs.csv')
  169. elif measure == 'meanburstratio':
  170. fname = os.path.join('stats', 'figure_1S3g_coefs.csv')
  171. elif stimtype == 'grt':
  172. if measure == 'meanrate':
  173. fname = os.path.join('stats', 'figure_3S1b_coefs.csv')
  174. elif measure == 'meanburstratio':
  175. fname = os.path.join('stats', 'figure_3S1g_coefs.csv')
  176. # fetch LMM linregress fit params from .csv:
  177. df = pd.read_csv(fname)
  178. mm = df['slope'][0]
  179. b = df['intercept'][0]
  180. x = np.array([np.nanmin(depths), np.nanmax(depths)])
  181. y = mm * x + b
  182. a.plot(x, y, '-', color='red') # plot linregress fit
  183. a.set_xlabel('Depth ($\mathregular{\mu}$m)')
  184. a.set_ylabel('%s FMI' % axislabel)
  185. a.set_xlim(0, 500)
  186. a.set_ylim(-1, 1)
  187. a.set_yticks([-1, 0, 1])
  188. a.spines['left'].set_position(('outward', 4))
  189. a.spines['bottom'].set_position(('outward', 4))
  190. # scatter plot FMI vs. normalized depth by mvi and grt, meanrate and meanburstratio:
  191. figsize = DEFAULTFIGURESIZE
  192. for stimtype in STIMTYPES:
  193. stimtypelabel = stimtype2axislabel[stimtype]
  194. for measure in ['meanrate', 'meanburstratio']:
  195. axislabel = measure2axislabel[measure]
  196. axislabel = short2longaxislabel.get(axislabel, axislabel)
  197. if axislabel.islower():
  198. axislabel = axislabel.capitalize()
  199. fmis, normdepths = [], []
  200. colname = '_'.join([stimtype, measure]) # e.g. 'mvi_meanrate'
  201. for msustr in mvigrtmsustrs:
  202. # save normdepth to fig1S33S1 df, regardless of FMI val, will be overwritten
  203. # multiple times with the same value, but that's OK:
  204. normdepth = celltype.loc[msustr]['normdepth'] # float
  205. fig1S33S1.loc[msustr]['normdepth'] = normdepth
  206. fmi = maxFMI.loc[msustr, 'none', stimtype][measure] # ignore run condition for FMI
  207. if np.isnan(fmi):
  208. continue
  209. fmis.append(fmi)
  210. normdepths.append(normdepth)
  211. fig1S33S1.loc[msustr][colname] = fmi # might overwrite w/ identical values
  212. fmis = np.asarray(fmis)
  213. normdepths = np.asarray(normdepths)
  214. f, a = plt.subplots(figsize=figsize)
  215. wintitle('FMI normdepth %s %s' % (stimtypelabel, measure))
  216. # plot y=0 line:
  217. a.axhline(y=0, ls='--', marker='', color='lightgray', zorder=-np.inf)
  218. a.scatter(normdepths, fmis, clip_on=False, marker='.', c='None', edgecolor='k', s=DEFSZ)
  219. '''
  220. # get fname of appropriate LMM .cvs file:
  221. fname = None # sanity check: clear from previous loop
  222. if stimtype == 'mvi':
  223. if measure == 'meanrate':
  224. fname = os.path.join('stats', 'figure_1S3b_coefs.csv')
  225. elif measure == 'meanburstratio':
  226. fname = os.path.join('stats', 'figure_1S3g_coefs.csv')
  227. elif stimtype == 'grt':
  228. if measure == 'meanrate':
  229. fname = os.path.join('stats', 'figure_3S1b_coefs.csv')
  230. elif measure == 'meanburstratio':
  231. fname = os.path.join('stats', 'figure_3S1g_coefs.csv')
  232. # fetch LMM linregress fit params from .csv:
  233. df = pd.read_csv(fname)
  234. mm = df['slope'][0]
  235. b = df['intercept'][0]
  236. x = np.array([np.nanmin(normdepths), np.nanmax(normdepths)])
  237. y = mm * x + b
  238. a.plot(x, y, '-', color='red') # plot linregress fit
  239. '''
  240. a.set_xlabel('Normalized depth')
  241. a.set_ylabel('%s FMI' % axislabel)
  242. #a.set_xlim(0, 2)
  243. a.set_ylim(-1, 1)
  244. a.set_yticks([-1, 0, 1])
  245. a.spines['left'].set_position(('outward', 4))
  246. a.spines['bottom'].set_position(('outward', 4))
  247. # scatter plot FMI vs. DSI by mvi and grt, meanrate and meanburstratio:
  248. figsize = DEFAULTFIGURESIZE
  249. for stimtype in STIMTYPES:
  250. stimtypelabel = stimtype2axislabel[stimtype]
  251. for measure in ['meanrate', 'meanburstratio']:
  252. axislabel = measure2axislabel[measure]
  253. axislabel = short2longaxislabel.get(axislabel, axislabel)
  254. if axislabel.islower():
  255. axislabel = axislabel.capitalize()
  256. fmis, dsis = [], []
  257. colname = '_'.join([stimtype, measure]) # e.g. 'mvi_meanrate'
  258. for msustr in mvigrtmsustrs:
  259. # save DSI to fig1S33S1 df, regardless of FMI val, will be overwritten multiple
  260. # times with the same value, but that's OK:
  261. dsi = celltype.loc[msustr]['dsi'] # float
  262. fig1S33S1.loc[msustr]['dsi'] = dsi
  263. fmi = maxFMI.loc[msustr, 'none', stimtype][measure] # ignore run condition for FMI
  264. if np.isnan(fmi):
  265. continue
  266. fmis.append(fmi)
  267. dsis.append(dsi)
  268. fig1S33S1.loc[msustr][colname] = fmi # might overwrite w/ identical values
  269. fmis = np.asarray(fmis)
  270. dsis = np.asarray(dsis)
  271. f, a = plt.subplots(figsize=figsize)
  272. wintitle('FMI DSI %s %s' % (stimtypelabel, measure))
  273. # plot y=0 line:
  274. a.axhline(y=0, ls='--', marker='', color='lightgray', zorder=-np.inf)
  275. a.scatter(dsis, fmis, clip_on=False, marker='.', c='None', edgecolor='k', s=DEFSZ)
  276. # get fname of appropriate LMM .cvs file:
  277. fname = None # sanity check: clear from previous loop
  278. if stimtype == 'mvi':
  279. if measure == 'meanrate':
  280. fname = os.path.join('stats', 'figure_1S3c_coefs.csv')
  281. elif measure == 'meanburstratio':
  282. fname = os.path.join('stats', 'figure_1S3h_coefs.csv')
  283. elif stimtype == 'grt':
  284. if measure == 'meanrate':
  285. fname = os.path.join('stats', 'figure_3S1c_coefs.csv')
  286. elif measure == 'meanburstratio':
  287. fname = os.path.join('stats', 'figure_3S1h_coefs.csv')
  288. # fetch LMM linregress fit params from .csv:
  289. df = pd.read_csv(fname)
  290. mm = df['slope'][0]
  291. b = df['intercept'][0]
  292. x = np.array([np.nanmin(dsis), np.nanmax(dsis)])
  293. y = mm * x + b
  294. a.plot(x, y, '-', color='red') # plot linregress fit
  295. a.set_xlabel('DSI')
  296. a.set_ylabel('%s FMI' % axislabel)
  297. a.set_xlim(0, 1)
  298. a.set_ylim(-1, 1)
  299. a.set_yticks([-1, 0, 1])
  300. a.spines['left'].set_position(('outward', 4))
  301. a.spines['bottom'].set_position(('outward', 4))
  302. # scatter plot FMI vs. distance of MUA envl RF from screen center, by mvi and grt,
  303. # meanrate and meanburstratio:
  304. figsize = DEFAULTFIGURESIZE
  305. for stimtype in STIMTYPES:
  306. stimtypelabel = stimtype2axislabel[stimtype]
  307. for measure in ['meanrate', 'meanburstratio']:
  308. axislabel = measure2axislabel[measure]
  309. axislabel = short2longaxislabel.get(axislabel, axislabel)
  310. if axislabel.islower():
  311. axislabel = axislabel.capitalize()
  312. fmis, ds = [], []
  313. colname = '_'.join([stimtype, measure]) # e.g. 'mvi_meanrate'
  314. for msustr in mvigrtmsustrs:
  315. # save rfdist to fig1S33S1 df, regardless of FMI val, will be overwritten multiple
  316. # times with the same value, but that's OK:
  317. x0, y0 = cellscreenpos.loc[msustr]
  318. d = np.sqrt(x0**2 + y0**2) # distance from screen center, deg
  319. fig1S33S1.loc[msustr]['rfdist'] = d
  320. fmi = maxFMI.loc[msustr, 'none', stimtype][measure] # ignore run condition for FMI
  321. if np.isnan(fmi):
  322. continue
  323. fmis.append(fmi)
  324. ds.append(d)
  325. fig1S33S1.loc[msustr][colname] = fmi # might overwrite w/ identical values
  326. fmis = np.asarray(fmis)
  327. ds = np.asarray(ds)
  328. f, a = plt.subplots(figsize=figsize)
  329. wintitle('FMI rfdist %s %s' % (stimtypelabel, measure))
  330. # plot y=0 line:
  331. a.axhline(y=0, ls='--', marker='', color='lightgray', zorder=-np.inf)
  332. a.scatter(ds, fmis, clip_on=False, marker='.', c='None', edgecolor='k', s=DEFSZ)
  333. # get fname of appropriate LMM .cvs file:
  334. fname = None # sanity check: clear from previous loop
  335. if stimtype == 'mvi':
  336. if measure == 'meanrate':
  337. fname = os.path.join('stats', 'figure_1S3d_coefs.csv')
  338. elif measure == 'meanburstratio':
  339. fname = os.path.join('stats', 'figure_1S3i_coefs.csv')
  340. elif stimtype == 'grt':
  341. if measure == 'meanrate':
  342. fname = os.path.join('stats', 'figure_3S1d_coefs.csv')
  343. elif measure == 'meanburstratio':
  344. fname = os.path.join('stats', 'figure_3S1i_coefs.csv')
  345. # fetch LMM linregress fit params from .csv:
  346. df = pd.read_csv(fname)
  347. mm = df['slope'][0]
  348. b = df['intercept'][0]
  349. x = np.array([np.nanmin(ds), np.nanmax(ds)])
  350. y = mm * x + b
  351. a.plot(x, y, '-', color='red') # plot linregress fit
  352. a.set_xlabel('RF dist. from center ($\degree$)')
  353. a.set_ylabel('%s FMI' % axislabel)
  354. a.set_xlim(0, 40)
  355. a.set_ylim(-1, 1)
  356. a.set_yticks([-1, 0, 1])
  357. a.spines['left'].set_position(('outward', 4))
  358. a.spines['bottom'].set_position(('outward', 4))
  359. # scatter plot FMI vs raw measure, for rate and burst ratio during control condition,
  360. # by mvi and grt:
  361. stimtype2resp = {'mvi':mviresp, 'grt':grtresp}
  362. figsize = DEFAULTFIGURESIZE
  363. for stimtype in STIMTYPES:
  364. stimtypelabel = stimtype2axislabel[stimtype]
  365. resp = stimtype2resp[stimtype]
  366. if stimtype == 'mvi':
  367. resp = resp.xs('nat', level='kind') # dereference movie 'kind' index level
  368. for measure in ['meanrate', 'meanburstratio']:
  369. axislabel = measure2axislabel[measure]
  370. axislabel = short2longaxislabel.get(axislabel, axislabel)
  371. axisunits = measure2axisunits.get(measure, '')
  372. if axislabel.islower():
  373. axislabel = axislabel.capitalize()
  374. fmis, msrs = [], []
  375. fmicolname = '_'.join([stimtype, measure]) # e.g. 'mvi_meanrate'
  376. msrcolname = '_'.join([stimtype, measure, 'raw']) # e.g. 'mvi_meanrate_raw'
  377. for msustr in mvigrtmsustrs:
  378. mseustr, fmi = maxFMI.loc[msustr, 'none', stimtype][['mseu', measure]]
  379. if pd.isna(mseustr) or pd.isna(fmi):
  380. continue
  381. msr = resp.loc[mseustr, 'none', False][measure]
  382. fmis.append(fmi)
  383. msrs.append(msr)
  384. fig1S33S1.loc[msustr][fmicolname] = fmi # might overwrite w/ identical values
  385. fig1S33S1.loc[msustr][msrcolname] = msr
  386. fmis, msrs = np.asarray(fmis), np.asarray(msrs)
  387. ## scatter plot FMI vs raw measure:
  388. f, a = plt.subplots(figsize=figsize)
  389. wintitle('FMI raw %s %s' % (stimtypelabel, measure))
  390. # plot y=0 line:
  391. a.axhline(y=0, ls='--', marker='', color='lightgray', zorder=-np.inf)
  392. a.scatter(msrs, fmis, clip_on=False, marker='.', c='None', edgecolor='k', s=DEFSZ)
  393. # get fname of appropriate LMM .cvs file:
  394. fname = None # sanity check: clear from previous loop
  395. if stimtype == 'mvi':
  396. if measure == 'meanrate':
  397. fname = os.path.join('stats', 'figure_1S3e_coefs.csv')
  398. elif measure == 'meanburstratio':
  399. fname = os.path.join('stats', 'figure_1S3j_coefs.csv')
  400. elif stimtype == 'grt':
  401. if measure == 'meanrate':
  402. fname = os.path.join('stats', 'figure_3S1e_coefs.csv')
  403. elif measure == 'meanburstratio':
  404. fname = os.path.join('stats', 'figure_3S1j_coefs.csv')
  405. # fetch LMM linregress fit params from .csv:
  406. df = pd.read_csv(fname)
  407. mm = df['slope'][0]
  408. b = df['intercept'][0]
  409. x = np.array([np.nanmin(msrs), np.nanmax(msrs)])
  410. y = mm * x + b
  411. a.plot(x, y, '-', color='red') # plot linregress fit
  412. a.set_xlabel('%s' % axislabel+axisunits)
  413. a.set_ylabel('%s FMI' % axislabel)
  414. a.set_xlim(xmin=0)
  415. a.set_ylim(-1, 1)
  416. #a.set_xticks(ticks)
  417. a.set_yticks([-1, 0, 1])
  418. a.spines['left'].set_position(('outward', 4))
  419. a.spines['bottom'].set_position(('outward', 4))
  420. #### old opto scatter plots:
  421. '''
  422. # scatter plot grating meanrates, coloured by sbc:
  423. figsize = DEFAULTFIGURESIZE
  424. logmin, logmax = -1.2, 2
  425. logticks = np.array([-1, 0, 1, 2])
  426. #log0min = logmin + 0.05
  427. for st8 in ['none']:#ALLST8S:
  428. f, a = plt.subplots(figsize=figsize)
  429. wintitle('opto meanrate grating %s sbc' % st8)
  430. rons, roffs, sbcs = [], [], []
  431. for mseustr in grtmseustrs:
  432. meanrate = grtresp.loc[mseustr, st8]['meanrate']
  433. msustr = mseustr2msustr(mseustr)
  434. sbc = celltype.loc[msustr]['sbc']
  435. if np.isnan(sbc):
  436. sbc = None # works properly as sbcclrs dict key
  437. if meanrate.isna().any(): # missing one or both meanrates
  438. #print('%s: missing one or both opto conditions, skipping' % mseustr)
  439. continue
  440. rons.append(meanrate[True])
  441. roffs.append(meanrate[False])
  442. sbcs.append(sbc)
  443. #fig3.loc[mseustr, 'meanrate'] = meanrate[False], meanrate[True] # save
  444. rons = np.asarray(rons)
  445. roffs = np.asarray(roffs)
  446. sbcs = np.asarray(sbcs)
  447. sbcclrs = [ {True:'r', False:green, None:'black'}[sbc] for sbc in sbcs ]
  448. # plot y=x line:
  449. xyline = [10**logmin, 10**logmax], [10**logmin, 10**logmax]
  450. a.plot(xyline[0], xyline[1], '--', color='gray', zorder=-1)
  451. # plot all points:
  452. a.scatter(rons, roffs, marker='.', c='None', edgecolor=sbcclrs, s=DEFSZ)
  453. # plot mean of points grouped by sbc:
  454. sbclogmean = gmean(rons[sbcs == True]), gmean(roffs[sbcs == True])
  455. notsbclogmean = gmean(rons[sbcs == False]), gmean(roffs[sbcs == False])
  456. a.scatter(sbclogmean[0], sbclogmean[1], marker='+', c='r', s=100)
  457. a.scatter(notsbclogmean[0], notsbclogmean[1], marker='+', c=green, s=100)
  458. a.set_ylabel('Feedback FR (spk/s)')
  459. a.set_xlabel('Suppression FR (spk/s)')
  460. a.set_xscale('log')
  461. a.set_yscale('log')
  462. a.set_xlim(10**logmin, 10**logmax)
  463. a.set_ylim(10**logmin, 10**logmax)
  464. a.set_xticks(10.0**logticks)
  465. a.set_yticks(a.get_xticks()) # make log scale y ticks the same as x ticks
  466. axes_disable_scientific(a)
  467. a.minorticks_off()
  468. a.set_aspect('equal')
  469. #t, p = ttest_rel(rons, roffs) # paired t-test
  470. #a.add_artist(AnchoredText('p$=$%.2g' % p, loc='lower right', frameon=False))
  471. patch = Rectangle((0, 0), 0, 0)
  472. l = a.legend([patch, patch], ['SbC', 'Non-SbC'], loc='upper left',
  473. handlelength=0, handletextpad=0, frameon=False)
  474. for t, c in zip(l.get_texts(), ['r', green]):
  475. t.set_color(c)
  476. # scatter plot movie meanrates, coloured by sbc:
  477. figsize = DEFAULTFIGURESIZE
  478. logmin, logmax = -1.2, 2
  479. logticks = np.array([-1, 0, 1, 2])
  480. #log0min = logmin + 0.05
  481. for st8 in ['none']:#ALLST8S:
  482. f, a = plt.subplots(figsize=figsize)
  483. wintitle('opto meanrate movie nat %s sbc' % st8)
  484. rons, roffs, sbcs = [], [], []
  485. for mseustr in mvimseustrs:
  486. meanrate = mviresp.loc[mseustr, 'nat', st8]['meanrate']
  487. msustr = mseustr2msustr(mseustr)
  488. sbc = celltype.loc[msustr]['sbc']
  489. if np.isnan(sbc):
  490. sbc = None # works properly as sbcclrs dict key
  491. if meanrate.isna().any(): # missing one or both meanrates
  492. #print('%s: missing one or both opto conditions, skipping' % mseustr)
  493. continue
  494. rons.append(meanrate[True])
  495. roffs.append(meanrate[False])
  496. sbcs.append(sbc)
  497. #fig3.loc[mseustr, 'meanrate'] = meanrate[False], meanrate[True] # save
  498. rons = np.asarray(rons)
  499. roffs = np.asarray(roffs)
  500. sbcs = np.asarray(sbcs)
  501. sbcclrs = [ {True:'r', False:green, None:'black'}[sbc] for sbc in sbcs ]
  502. # plot y=x line:
  503. xyline = [10**logmin, 10**logmax], [10**logmin, 10**logmax]
  504. a.plot(xyline[0], xyline[1], '--', color='gray', zorder=-1)
  505. # plot all points:
  506. a.scatter(rons, roffs, marker='.', c='None', edgecolor=sbcclrs, s=DEFSZ)
  507. # plot mean of points grouped by sbc:
  508. sbclogmean = gmean(rons[sbcs == True]), gmean(roffs[sbcs == True])
  509. notsbclogmean = gmean(rons[sbcs == False]), gmean(roffs[sbcs == False])
  510. a.scatter(sbclogmean[0], sbclogmean[1], marker='+', c='r', s=100)
  511. a.scatter(notsbclogmean[0], notsbclogmean[1], marker='+', c=green, s=100)
  512. a.set_ylabel('Feedback FR (spk/s)')
  513. a.set_xlabel('Suppression FR (spk/s)')
  514. a.set_xscale('log')
  515. a.set_yscale('log')
  516. a.set_xlim(10**logmin, 10**logmax)
  517. a.set_ylim(10**logmin, 10**logmax)
  518. a.set_xticks(10.0**logticks)
  519. a.set_yticks(a.get_xticks()) # make log scale y ticks the same as x ticks
  520. axes_disable_scientific(a)
  521. a.minorticks_off()
  522. a.set_aspect('equal')
  523. #t, p = ttest_rel(rons, roffs) # paired t-test
  524. #a.add_artist(AnchoredText('p$=$%.2g' % p, loc='lower right', frameon=False))
  525. patch = Rectangle((0, 0), 0, 0)
  526. l = a.legend([patch, patch], ['SbC', 'Non-SbC'], loc='upper left',
  527. handlelength=0, handletextpad=0, frameon=False)
  528. for t, c in zip(l.get_texts(), ['r', green]):
  529. t.set_color(c)
  530. # scatter plot grating burst ratio, coloured by sbc:
  531. figsize = DEFAULTFIGURESIZE
  532. logmin, logmax = -3.55, 0
  533. logticks = np.array([-3, -2, -1, 0])
  534. for st8 in ['none']:#ALLST8S:
  535. f, a = plt.subplots(figsize=figsize)
  536. wintitle('opto burst ratio grating %s sbc' % st8)
  537. brons, broffs, sbcs = [], [], []
  538. for mseustr in grtmseustrs:
  539. br = grtresp.loc[mseustr, st8]['meanburstratio']
  540. msustr = mseustr2msustr(mseustr)
  541. sbc = celltype.loc[msustr]['sbc']
  542. if np.isnan(sbc):
  543. sbc = None # works properly as sbcclrs dict key
  544. if br.isna().any(): # missing for at least one opto condition
  545. continue
  546. brons.append(br[True])
  547. broffs.append(br[False])
  548. sbcs.append(sbc)
  549. #fig3.loc[mseustr, 'meanburstratio'] = br[False], br[True] # save
  550. brons, broffs, sbcs = np.asarray(brons), np.asarray(broffs), np.asarray(sbcs)
  551. sbcclrs = [ {True:'r', False:green, None:'black'}[sbc] for sbc in sbcs ]
  552. # plot y=x line:
  553. xyline = [10**logmin, 10**logmax], [10**logmin, 10**logmax]
  554. a.plot(xyline[0], xyline[1], '--', color='gray', zorder=-1)
  555. # plot all points:
  556. a.scatter(brons, broffs, marker='.', c='None', edgecolor=sbcclrs, s=DEFSZ)
  557. # plot mean of points grouped by sbc:
  558. # filter out 0 value burst ratios before calculating geometric mean:
  559. sbcbrons = brons[sbcs == True][brons[sbcs == True] > 0]
  560. sbcbroffs = broffs[sbcs == True][broffs[sbcs == True] > 0]
  561. notsbcbrons = brons[sbcs == False][brons[sbcs == False] > 0]
  562. notsbcbroffs = broffs[sbcs == False][broffs[sbcs == False] > 0]
  563. sbclogmean = gmean(sbcbrons), gmean(sbcbroffs)
  564. notsbclogmean = gmean(notsbcbrons), gmean(notsbcbroffs)
  565. a.scatter(sbclogmean[0], sbclogmean[1], marker='+', c='r', s=100)
  566. a.scatter(notsbclogmean[0], notsbclogmean[1], marker='+', c=green, s=100)
  567. a.set_xlabel('Suppression BR') # keep it short to maximize space for axes
  568. a.set_ylabel('Feedback BR')
  569. a.set_xscale('log')
  570. a.set_yscale('log')
  571. a.set_xlim(10**logmin, 10**logmax)
  572. a.set_ylim(10**logmin, 10**logmax)
  573. a.set_xticks(10.0**logticks)
  574. a.set_yticks(a.get_xticks()) # make log scale y ticks the same as x ticks
  575. a.minorticks_off()
  576. axes_disable_scientific(a)
  577. a.set_aspect('equal')
  578. #t, p = ttest_rel(brons, broffs) # paired t-test
  579. #a.add_artist(AnchoredText('p$=$%.2g' % p, loc='upper left', frameon=False))
  580. patch = Rectangle((0, 0), 0, 0)
  581. l = a.legend([patch, patch], ['SbC', 'Non-SbC'], loc='upper left',
  582. handlelength=0, handletextpad=0, frameon=False)
  583. for t, c in zip(l.get_texts(), ['r', green]):
  584. t.set_color(c)
  585. # scatter plot movie burst ratio, coloured by sbc:
  586. figsize = DEFAULTFIGURESIZE
  587. logmin, logmax = -3.55, 0
  588. logticks = np.array([-3, -2, -1, 0])
  589. for st8 in ['none']:#ALLST8S:
  590. f, a = plt.subplots(figsize=figsize)
  591. wintitle('opto burst ratio movie nat %s sbc' % st8)
  592. brons, broffs, sbcs = [], [], []
  593. for mseustr in mvimseustrs:
  594. br = mviresp.loc[mseustr, 'nat', st8]['meanburstratio']
  595. msustr = mseustr2msustr(mseustr)
  596. sbc = celltype.loc[msustr]['sbc']
  597. if np.isnan(sbc):
  598. sbc = None
  599. if br.isna().any(): # missing for at least one opto condition
  600. continue
  601. brons.append(br[True])
  602. broffs.append(br[False])
  603. sbcs.append(sbc)
  604. #fig3.loc[mseustr, 'meanburstratio'] = br[False], br[True] # save
  605. brons, broffs, sbcs = np.asarray(brons), np.asarray(broffs), np.asarray(sbcs)
  606. sbcclrs = [ {True:'r', False:green, None:'black'}[sbc] for sbc in sbcs ]
  607. # plot y=x line:
  608. xyline = [10**logmin, 10**logmax], [10**logmin, 10**logmax]
  609. a.plot(xyline[0], xyline[1], '--', color='gray', zorder=-1)
  610. # plot all points:
  611. a.scatter(brons, broffs, marker='.', c='None', edgecolor=sbcclrs, s=DEFSZ)
  612. # plot mean of points grouped by sbc:
  613. # filter out 0 value burst ratios before calculating geometric mean:
  614. sbcbrons = brons[sbcs == True][brons[sbcs == True] > 0]
  615. sbcbroffs = broffs[sbcs == True][broffs[sbcs == True] > 0]
  616. notsbcbrons = brons[sbcs == False][brons[sbcs == False] > 0]
  617. notsbcbroffs = broffs[sbcs == False][broffs[sbcs == False] > 0]
  618. sbclogmean = gmean(sbcbrons), gmean(sbcbroffs)
  619. notsbclogmean = gmean(notsbcbrons), gmean(notsbcbroffs)
  620. a.scatter(sbclogmean[0], sbclogmean[1], marker='+', c='r', s=100)
  621. a.scatter(notsbclogmean[0], notsbclogmean[1], marker='+', c=green, s=100)
  622. a.set_xlabel('Suppression BR') # keep it short to maximize space for axes
  623. a.set_ylabel('Feedback BR')
  624. a.set_xscale('log')
  625. a.set_yscale('log')
  626. a.set_xlim(10**logmin, 10**logmax)
  627. a.set_ylim(10**logmin, 10**logmax)
  628. a.set_xticks(10.0**logticks)
  629. a.set_yticks(a.get_xticks()) # make log scale y ticks the same as x ticks
  630. a.minorticks_off()
  631. axes_disable_scientific(a)
  632. a.set_aspect('equal')
  633. #t, p = ttest_rel(brons, broffs) # paired t-test
  634. #a.add_artist(AnchoredText('p$=$%.2g' % p, loc='upper left', frameon=False))
  635. patch = Rectangle((0, 0), 0, 0)
  636. l = a.legend([patch, patch], ['SbC', 'Non-SbC'], loc='upper left',
  637. handlelength=0, handletextpad=0, frameon=False)
  638. for t, c in zip(l.get_texts(), ['r', green]):
  639. t.set_color(c)
  640. # scatter plot grating meanrates, coloured by DSI:
  641. figsize = DEFAULTFIGURESIZE
  642. logmin, logmax = -1.2, 2
  643. logticks = np.array([-1, 0, 1, 2])
  644. #log0min = logmin + 0.05
  645. for st8 in ['none']:#ALLST8S:
  646. f, a = plt.subplots(figsize=figsize)
  647. wintitle('opto meanrate grating %s dsi' % st8)
  648. rons, roffs, dsis = [], [], []
  649. for mseustr in grtmseustrs:
  650. meanrate = grtresp.loc[mseustr, st8]['meanrate']
  651. msustr = mseustr2msustr(mseustr)
  652. dsi = celltype.loc[msustr]['dsi']
  653. if meanrate.isna().any(): # missing one or both meanrates
  654. #print('%s: missing one or both opto conditions, skipping' % mseustr)
  655. continue
  656. rons.append(meanrate[True])
  657. roffs.append(meanrate[False])
  658. dsis.append(dsi)
  659. #fig3.loc[mseustr, 'meanrate'] = meanrate[False], meanrate[True] # save
  660. rons = np.asarray(rons)
  661. roffs = np.asarray(roffs)
  662. dsis = np.asarray(dsis)
  663. cmap = plt.get_cmap() # use default, normalized from 0 to 1
  664. dsiclrs = []
  665. for dsi in dsis:
  666. if np.isnan(dsi):
  667. dsiclrs.append('gray')
  668. else:
  669. dsiclrs.append(cmap(dsi))
  670. # plot y=x line:
  671. xyline = [10**logmin, 10**logmax], [10**logmin, 10**logmax]
  672. a.plot(xyline[0], xyline[1], '--', color='gray', zorder=-1)
  673. # plot all points:
  674. a.scatter(rons, roffs, marker='.', c='None', edgecolor=dsiclrs, s=DEFSZ)
  675. a.set_ylabel('Feedback FR (spk/s)')
  676. a.set_xlabel('Suppression FR (spk/s)')
  677. a.set_xscale('log')
  678. a.set_yscale('log')
  679. a.set_xlim(10**logmin, 10**logmax)
  680. a.set_ylim(10**logmin, 10**logmax)
  681. a.set_xticks(10.0**logticks)
  682. a.set_yticks(a.get_xticks()) # make log scale y ticks the same as x ticks
  683. axes_disable_scientific(a)
  684. a.minorticks_off()
  685. a.set_aspect('equal')
  686. #t, p = ttest_rel(rons, roffs) # paired t-test
  687. #a.add_artist(AnchoredText('p$=$%.2g' % p, loc='lower right', frameon=False))
  688. #scalarmappable = mpl.cm.ScalarMappable(norm=None, cmap=cmap)
  689. #f.colorbar(scalarmappable, label='DSI')
  690. # scatter plot movie meanrates, coloured by dsi:
  691. figsize = DEFAULTFIGURESIZE
  692. logmin, logmax = -1.2, 2
  693. logticks = np.array([-1, 0, 1, 2])
  694. #log0min = logmin + 0.05
  695. for st8 in ['none']:#ALLST8S:
  696. f, a = plt.subplots(figsize=figsize)
  697. wintitle('opto meanrate movie nat %s dsi' % st8)
  698. rons, roffs, dsis = [], [], []
  699. for mseustr in mvimseustrs:
  700. meanrate = mviresp.loc[mseustr, 'nat', st8]['meanrate']
  701. msustr = mseustr2msustr(mseustr)
  702. dsi = celltype.loc[msustr]['dsi']
  703. if meanrate.isna().any(): # missing one or both meanrates
  704. #print('%s: missing one or both opto conditions, skipping' % mseustr)
  705. continue
  706. rons.append(meanrate[True])
  707. roffs.append(meanrate[False])
  708. dsis.append(dsi)
  709. #fig3.loc[mseustr, 'meanrate'] = meanrate[False], meanrate[True] # save
  710. rons = np.asarray(rons)
  711. roffs = np.asarray(roffs)
  712. dsis = np.asarray(dsis)
  713. cmap = plt.get_cmap() # use default, normalized from 0 to 1
  714. dsiclrs = []
  715. for dsi in dsis:
  716. if np.isnan(dsi):
  717. dsiclrs.append('gray')
  718. else:
  719. dsiclrs.append(cmap(dsi))
  720. # plot y=x line:
  721. xyline = [10**logmin, 10**logmax], [10**logmin, 10**logmax]
  722. a.plot(xyline[0], xyline[1], '--', color='gray', zorder=-1)
  723. # plot all points:
  724. a.scatter(rons, roffs, marker='.', c='None', edgecolor=dsiclrs, s=DEFSZ)
  725. a.set_ylabel('Feedback FR (spk/s)')
  726. a.set_xlabel('Suppression FR (spk/s)')
  727. a.set_xscale('log')
  728. a.set_yscale('log')
  729. a.set_xlim(10**logmin, 10**logmax)
  730. a.set_ylim(10**logmin, 10**logmax)
  731. a.set_xticks(10.0**logticks)
  732. a.set_yticks(a.get_xticks()) # make log scale y ticks the same as x ticks
  733. axes_disable_scientific(a)
  734. a.minorticks_off()
  735. a.set_aspect('equal')
  736. #t, p = ttest_rel(rons, roffs) # paired t-test
  737. #a.add_artist(AnchoredText('p$=$%.2g' % p, loc='lower right', frameon=False))
  738. #scalarmappable = mpl.cm.ScalarMappable(norm=None, cmap=cmap)
  739. #f.colorbar(scalarmappable, label='DSI')
  740. # scatter plot grating burst ratio, coloured by dsi:
  741. figsize = DEFAULTFIGURESIZE
  742. logmin, logmax = -3.55, 0
  743. logticks = np.array([-3, -2, -1, 0])
  744. for st8 in ['none']:#ALLST8S:
  745. f, a = plt.subplots(figsize=figsize)
  746. wintitle('opto burst ratio grating %s dsi' % st8)
  747. brons, broffs, dsis = [], [], []
  748. for mseustr in grtmseustrs:
  749. br = grtresp.loc[mseustr, st8]['meanburstratio']
  750. msustr = mseustr2msustr(mseustr)
  751. dsi = celltype.loc[msustr]['dsi']
  752. if br.isna().any(): # missing for at least one opto condition
  753. continue
  754. brons.append(br[True])
  755. broffs.append(br[False])
  756. dsis.append(dsi)
  757. #fig3.loc[mseustr, 'meanburstratio'] = br[False], br[True] # save
  758. brons, broffs, dsis = np.asarray(brons), np.asarray(broffs), np.asarray(dsis)
  759. cmap = plt.get_cmap() # use default, normalized from 0 to 1
  760. dsiclrs = []
  761. for dsi in dsis:
  762. if np.isnan(dsi):
  763. dsiclrs.append('gray')
  764. else:
  765. dsiclrs.append(cmap(dsi))
  766. # plot y=x line:
  767. xyline = [10**logmin, 10**logmax], [10**logmin, 10**logmax]
  768. a.plot(xyline[0], xyline[1], '--', color='gray', zorder=-1)
  769. # plot all points:
  770. a.scatter(brons, broffs, marker='.', c='None', edgecolor=dsiclrs, s=DEFSZ)
  771. a.set_xlabel('Suppression BR') # keep it short to maximize space for axes
  772. a.set_ylabel('Feedback BR')
  773. a.set_xscale('log')
  774. a.set_yscale('log')
  775. a.set_xlim(10**logmin, 10**logmax)
  776. a.set_ylim(10**logmin, 10**logmax)
  777. a.set_xticks(10.0**logticks)
  778. a.set_yticks(a.get_xticks()) # make log scale y ticks the same as x ticks
  779. a.minorticks_off()
  780. axes_disable_scientific(a)
  781. a.set_aspect('equal')
  782. #t, p = ttest_rel(brons, broffs) # paired t-test
  783. #a.add_artist(AnchoredText('p$=$%.2g' % p, loc='upper left', frameon=False))
  784. #scalarmappable = mpl.cm.ScalarMappable(norm=None, cmap=cmap)
  785. #f.colorbar(scalarmappable, label='DSI')
  786. # scatter plot movie burst ratio, coloured by dsi:
  787. figsize = DEFAULTFIGURESIZE
  788. logmin, logmax = -3.55, 0
  789. logticks = np.array([-3, -2, -1, 0])
  790. for st8 in ['none']:#ALLST8S:
  791. f, a = plt.subplots(figsize=figsize)
  792. wintitle('opto burst ratio movie nat %s dsi' % st8)
  793. brons, broffs, dsis = [], [], []
  794. for mseustr in mvimseustrs:
  795. br = mviresp.loc[mseustr, 'nat', st8]['meanburstratio']
  796. msustr = mseustr2msustr(mseustr)
  797. dsi = celltype.loc[msustr]['dsi']
  798. if br.isna().any(): # missing for at least one opto condition
  799. continue
  800. brons.append(br[True])
  801. broffs.append(br[False])
  802. dsis.append(dsi)
  803. #fig3.loc[mseustr, 'meanburstratio'] = br[False], br[True] # save
  804. brons, broffs, dsis = np.asarray(brons), np.asarray(broffs), np.asarray(dsis)
  805. cmap = plt.get_cmap() # use default, normalized from 0 to 1
  806. dsiclrs = []
  807. for dsi in dsis:
  808. if np.isnan(dsi):
  809. dsiclrs.append('gray')
  810. else:
  811. dsiclrs.append(cmap(dsi))
  812. # plot y=x line:
  813. xyline = [10**logmin, 10**logmax], [10**logmin, 10**logmax]
  814. a.plot(xyline[0], xyline[1], '--', color='gray', zorder=-1)
  815. # plot all points:
  816. a.scatter(brons, broffs, marker='.', c='None', edgecolor=dsiclrs, s=DEFSZ)
  817. a.set_xlabel('Suppression BR') # keep it short to maximize space for axes
  818. a.set_ylabel('Feedback BR')
  819. a.set_xscale('log')
  820. a.set_yscale('log')
  821. a.set_xlim(10**logmin, 10**logmax)
  822. a.set_ylim(10**logmin, 10**logmax)
  823. a.set_xticks(10.0**logticks)
  824. a.set_yticks(a.get_xticks()) # make log scale y ticks the same as x ticks
  825. a.minorticks_off()
  826. axes_disable_scientific(a)
  827. a.set_aspect('equal')
  828. #t, p = ttest_rel(brons, broffs) # paired t-test
  829. #a.add_artist(AnchoredText('p$=$%.2g' % p, loc='upper left', frameon=False))
  830. #scalarmappable = mpl.cm.ScalarMappable(norm=None, cmap=cmap)
  831. #f.colorbar(scalarmappable, label='DSI')
  832. # scatter plot grating meanrates, coloured by dLGN layer (shell/core):
  833. figsize = DEFAULTFIGURESIZE
  834. logmin, logmax = -1.2, 2
  835. logticks = np.array([-1, 0, 1, 2])
  836. #log0min = logmin + 0.05
  837. for st8 in ['none']:#ALLST8S:
  838. f, a = plt.subplots(figsize=figsize)
  839. wintitle('opto meanrate grating %s layer' % st8)
  840. rons, roffs, layers = [], [], []
  841. for mseustr in grtmseustrs:
  842. meanrate = grtresp.loc[mseustr, st8]['meanrate']
  843. msustr = mseustr2msustr(mseustr)
  844. layer = celltype.loc[msustr]['layer']
  845. if meanrate.isna().any(): # missing one or both meanrates
  846. #print('%s: missing one or both opto conditions, skipping' % mseustr)
  847. continue
  848. rons.append(meanrate[True])
  849. roffs.append(meanrate[False])
  850. layers.append(layer)
  851. #fig3.loc[mseustr, 'meanrate'] = meanrate[False], meanrate[True] # save
  852. rons = np.asarray(rons)
  853. roffs = np.asarray(roffs)
  854. layers = np.asarray(layers)
  855. layerclrs = [ {'shell':violet, 'core':green, 'nan':'black'}[layer] for layer in layers ]
  856. # plot y=x line:
  857. xyline = [10**logmin, 10**logmax], [10**logmin, 10**logmax]
  858. a.plot(xyline[0], xyline[1], '--', color='gray', zorder=-1)
  859. # plot all points:
  860. a.scatter(rons, roffs, marker='.', c='None', edgecolor=layerclrs, s=DEFSZ)
  861. # plot mean of points grouped by layer:
  862. shelllogmean = gmean(rons[layers == 'shell']), gmean(roffs[layers == 'shell'])
  863. corelogmean = gmean(rons[layers == 'core']), gmean(roffs[layers == 'core'])
  864. a.scatter(shelllogmean[0], shelllogmean[1], marker='+', c=violet, s=100)
  865. a.scatter(corelogmean[0], corelogmean[1], marker='+', c=green, s=100)
  866. a.set_ylabel('Feedback FR (spk/s)')
  867. a.set_xlabel('Suppression FR (spk/s)')
  868. a.set_xscale('log')
  869. a.set_yscale('log')
  870. a.set_xlim(10**logmin, 10**logmax)
  871. a.set_ylim(10**logmin, 10**logmax)
  872. a.set_xticks(10.0**logticks)
  873. a.set_yticks(a.get_xticks()) # make log scale y ticks the same as x ticks
  874. axes_disable_scientific(a)
  875. a.minorticks_off()
  876. a.set_aspect('equal')
  877. #t, p = ttest_rel(rons, roffs) # paired t-test
  878. #a.add_artist(AnchoredText('p$=$%.2g' % p, loc='lower right', frameon=False))
  879. patch = Rectangle((0, 0), 0, 0)
  880. l = a.legend([patch, patch], ['Shell', 'Core'], loc='upper left',
  881. handlelength=0, handletextpad=0, frameon=False)
  882. for t, c in zip(l.get_texts(), [violet, green]):
  883. t.set_color(c)
  884. # scatter plot movie meanrates, coloured by dLGN layer (shell/core):
  885. figsize = DEFAULTFIGURESIZE
  886. logmin, logmax = -1.2, 2
  887. logticks = np.array([-1, 0, 1, 2])
  888. #log0min = logmin + 0.05
  889. for st8 in ['none']:#ALLST8S:
  890. f, a = plt.subplots(figsize=figsize)
  891. wintitle('opto meanrate movie nat %s layer' % st8)
  892. rons, roffs, layers = [], [], []
  893. for mseustr in mvimseustrs:
  894. meanrate = mviresp.loc[mseustr, 'nat', st8]['meanrate']
  895. msustr = mseustr2msustr(mseustr)
  896. layer = celltype.loc[msustr]['layer']
  897. if meanrate.isna().any(): # missing one or both meanrates
  898. #print('%s: missing one or both opto conditions, skipping' % mseustr)
  899. continue
  900. rons.append(meanrate[True])
  901. roffs.append(meanrate[False])
  902. layers.append(layer)
  903. #fig3.loc[mseustr, 'meanrate'] = meanrate[False], meanrate[True] # save
  904. rons = np.asarray(rons)
  905. roffs = np.asarray(roffs)
  906. layers = np.asarray(layers)
  907. layerclrs = [ {'shell':violet, 'core':green, 'nan':'black'}[layer] for layer in layers ]
  908. # plot y=x line:
  909. xyline = [10**logmin, 10**logmax], [10**logmin, 10**logmax]
  910. a.plot(xyline[0], xyline[1], '--', color='gray', zorder=-1)
  911. # plot all points:
  912. a.scatter(rons, roffs, marker='.', c='None', edgecolor=layerclrs, s=DEFSZ)
  913. # plot mean of points grouped by layer:
  914. shelllogmean = gmean(rons[layers == 'shell']), gmean(roffs[layers == 'shell'])
  915. corelogmean = gmean(rons[layers == 'core']), gmean(roffs[layers == 'core'])
  916. a.scatter(shelllogmean[0], shelllogmean[1], marker='+', c=violet, s=100)
  917. a.scatter(corelogmean[0], corelogmean[1], marker='+', c=green, s=100)
  918. a.set_ylabel('Feedback FR (spk/s)')
  919. a.set_xlabel('Suppression FR (spk/s)')
  920. a.set_xscale('log')
  921. a.set_yscale('log')
  922. a.set_xlim(10**logmin, 10**logmax)
  923. a.set_ylim(10**logmin, 10**logmax)
  924. a.set_xticks(10.0**logticks)
  925. a.set_yticks(a.get_xticks()) # make log scale y ticks the same as x ticks
  926. axes_disable_scientific(a)
  927. a.minorticks_off()
  928. a.set_aspect('equal')
  929. #t, p = ttest_rel(rons, roffs) # paired t-test
  930. #a.add_artist(AnchoredText('p$=$%.2g' % p, loc='lower right', frameon=False))
  931. patch = Rectangle((0, 0), 0, 0)
  932. l = a.legend([patch, patch], ['Shell', 'Core'], loc='upper left',
  933. handlelength=0, handletextpad=0, frameon=False)
  934. for t, c in zip(l.get_texts(), [violet, green]):
  935. t.set_color(c)
  936. # scatter plot grating burst ratio, coloured by dLGN layer (shell/core):
  937. figsize = DEFAULTFIGURESIZE
  938. logmin, logmax = -3.55, 0
  939. logticks = np.array([-3, -2, -1, 0])
  940. for st8 in ['none']:#ALLST8S:
  941. f, a = plt.subplots(figsize=figsize)
  942. wintitle('opto burst ratio grating %s layer' % st8)
  943. brons, broffs, layers = [], [], []
  944. for mseustr in grtmseustrs:
  945. br = grtresp.loc[mseustr, st8]['meanburstratio']
  946. msustr = mseustr2msustr(mseustr)
  947. layer = celltype.loc[msustr]['layer']
  948. if br.isna().any(): # missing for at least one opto condition
  949. continue
  950. brons.append(br[True])
  951. broffs.append(br[False])
  952. layers.append(layer)
  953. #fig3.loc[mseustr, 'meanburstratio'] = br[False], br[True] # save
  954. brons, broffs, layers = np.asarray(brons), np.asarray(broffs), np.asarray(layers)
  955. layerclrs = [ {'shell':violet, 'core':green, 'nan':'black'}[layer] for layer in layers ]
  956. # plot y=x line:
  957. xyline = [10**logmin, 10**logmax], [10**logmin, 10**logmax]
  958. a.plot(xyline[0], xyline[1], '--', color='gray', zorder=-1)
  959. # plot all points:
  960. a.scatter(brons, broffs, marker='.', c='None', edgecolor=layerclrs, s=DEFSZ)
  961. # plot mean of points grouped by layer:
  962. # filter out 0 vals before calculating geometric mean:
  963. shellis = layers == 'shell'
  964. coreis = layers == 'core'
  965. shellbrons = brons[shellis][brons[shellis] > 0]
  966. shellbroffs = broffs[shellis][broffs[shellis] > 0]
  967. corebrons = brons[coreis][brons[coreis] > 0]
  968. corebroffs = broffs[coreis][broffs[coreis] > 0]
  969. shelllogmean = gmean(shellbrons), gmean(shellbroffs)
  970. corelogmean = gmean(corebrons), gmean(corebroffs)
  971. a.scatter(shelllogmean[0], shelllogmean[1], marker='+', c=violet, s=100)
  972. a.scatter(corelogmean[0], corelogmean[1], marker='+', c=green, s=100)
  973. a.set_xlabel('Suppression BR') # keep it short to maximize space for axes
  974. a.set_ylabel('Feedback BR')
  975. a.set_xscale('log')
  976. a.set_yscale('log')
  977. a.set_xlim(10**logmin, 10**logmax)
  978. a.set_ylim(10**logmin, 10**logmax)
  979. a.set_xticks(10.0**logticks)
  980. a.set_yticks(a.get_xticks()) # make log scale y ticks the same as x ticks
  981. a.minorticks_off()
  982. axes_disable_scientific(a)
  983. a.set_aspect('equal')
  984. #t, p = ttest_rel(brons, broffs) # paired t-test
  985. #a.add_artist(AnchoredText('p$=$%.2g' % p, loc='upper left', frameon=False))
  986. patch = Rectangle((0, 0), 0, 0)
  987. l = a.legend([patch, patch], ['Shell', 'Core'], loc='upper left',
  988. handlelength=0, handletextpad=0, frameon=False)
  989. for t, c in zip(l.get_texts(), [violet, green]):
  990. t.set_color(c)
  991. # scatter plot movie burst ratio, coloured by dLGN layer (shell/core):
  992. figsize = DEFAULTFIGURESIZE
  993. logmin, logmax = -3.55, 0
  994. logticks = np.array([-3, -2, -1, 0])
  995. for st8 in ['none']:#ALLST8S:
  996. f, a = plt.subplots(figsize=figsize)
  997. wintitle('opto burst ratio movie nat %s layer' % st8)
  998. brons, broffs, layers = [], [], []
  999. for mseustr in mvimseustrs:
  1000. br = mviresp.loc[mseustr, 'nat', st8]['meanburstratio']
  1001. msustr = mseustr2msustr(mseustr)
  1002. layer = celltype.loc[msustr]['layer']
  1003. if br.isna().any(): # missing for at least one opto condition
  1004. continue
  1005. brons.append(br[True])
  1006. broffs.append(br[False])
  1007. layers.append(layer)
  1008. #fig3.loc[mseustr, 'meanburstratio'] = br[False], br[True] # save
  1009. brons, broffs, layers = np.asarray(brons), np.asarray(broffs), np.asarray(layers)
  1010. layerclrs = [ {'shell':violet, 'core':green, 'nan':'black'}[layer] for layer in layers ]
  1011. # plot y=x line:
  1012. xyline = [10**logmin, 10**logmax], [10**logmin, 10**logmax]
  1013. a.plot(xyline[0], xyline[1], '--', color='gray', zorder=-1)
  1014. # plot all points:
  1015. a.scatter(brons, broffs, marker='.', c='None', edgecolor=layerclrs, s=DEFSZ)
  1016. # plot mean of points grouped by layer:
  1017. # filter out 0 vals before calculating geometric mean:
  1018. shellis = layers == 'shell'
  1019. coreis = layers == 'core'
  1020. shellbrons = brons[shellis][brons[shellis] > 0]
  1021. shellbroffs = broffs[shellis][broffs[shellis] > 0]
  1022. corebrons = brons[coreis][brons[coreis] > 0]
  1023. corebroffs = broffs[coreis][broffs[coreis] > 0]
  1024. shelllogmean = gmean(shellbrons), gmean(shellbroffs)
  1025. corelogmean = gmean(corebrons), gmean(corebroffs)
  1026. a.scatter(shelllogmean[0], shelllogmean[1], marker='+', c=violet, s=100)
  1027. a.scatter(corelogmean[0], corelogmean[1], marker='+', c=green, s=100)
  1028. a.set_xlabel('Suppression BR') # keep it short to maximize space for axes
  1029. a.set_ylabel('Feedback BR')
  1030. a.set_xscale('log')
  1031. a.set_yscale('log')
  1032. a.set_xlim(10**logmin, 10**logmax)
  1033. a.set_ylim(10**logmin, 10**logmax)
  1034. a.set_xticks(10.0**logticks)
  1035. a.set_yticks(a.get_xticks()) # make log scale y ticks the same as x ticks
  1036. a.minorticks_off()
  1037. axes_disable_scientific(a)
  1038. a.set_aspect('equal')
  1039. #t, p = ttest_rel(brons, broffs) # paired t-test
  1040. #a.add_artist(AnchoredText('p$=$%.2g' % p, loc='upper left', frameon=False))
  1041. patch = Rectangle((0, 0), 0, 0)
  1042. l = a.legend([patch, patch], ['Shell', 'Core'], loc='upper left',
  1043. handlelength=0, handletextpad=0, frameon=False)
  1044. for t, c in zip(l.get_texts(), [violet, green]):
  1045. t.set_color(c)
  1046. '''
  1047. '''
  1048. # scatter plot spontaneous meanrates:
  1049. figsize = DEFAULTFIGURESIZE
  1050. logmin, logmax = -1.2, 2
  1051. logticks = np.array([-1, 0, 1, 2])
  1052. #log0min = logmin + 0.05
  1053. for st8 in ['none']:#ALLST8S:
  1054. f, a = plt.subplots(figsize=figsize)
  1055. wintitle('opto meanrate spontaneous %s' % st8)
  1056. rons, roffs = [], []
  1057. for mseustr in sponmseustrs:
  1058. meanrate = sponresp.loc[mseustr]['meanrate']
  1059. if meanrate.isna().any(): # missing one or both meanrates
  1060. #print('%s: missing one or both opto conditions, skipping' % mseustr)
  1061. continue
  1062. rons.append(meanrate[True])
  1063. roffs.append(meanrate[False])
  1064. #fig3.loc[mseustr, 'meanrate'] = meanrate[False], meanrate[True] # save
  1065. rons = np.asarray(rons)
  1066. roffs = np.asarray(roffs)
  1067. # replace off-scale low values with log0min, so the points remain visible:
  1068. #pltrons, pltroffs = rons.copy(), roffs.copy()
  1069. #pltrons[pltrons <= 10**logmin] = 10**log0min
  1070. #pltroffs[pltroffs <= 10**logmin] = 10**log0min
  1071. # plot y=x line:
  1072. xyline = [10**logmin, 10**logmax], [10**logmin, 10**logmax]
  1073. a.plot(xyline[0], xyline[1], '--', color='gray', zorder=-1)
  1074. a.scatter(rons, roffs, marker='.', c='None', edgecolor=st82clr[st8], s=DEFSZ)
  1075. a.set_xlabel('Suppression FR (spk/s)')
  1076. a.set_ylabel('Feedback FR (spk/s)')
  1077. a.set_xscale('log')
  1078. a.set_yscale('log')
  1079. a.set_xlim(10**logmin, 10**logmax)
  1080. a.set_ylim(10**logmin, 10**logmax)
  1081. a.set_xticks(10.0**logticks)
  1082. a.set_yticks(a.get_xticks()) # make log scale y ticks the same as x ticks
  1083. a.minorticks_off()
  1084. axes_disable_scientific(a)
  1085. a.set_aspect('equal')
  1086. t, p = ttest_rel(rons, roffs) # paired t-test
  1087. a.add_artist(AnchoredText('p$=$%.2g' % p, loc='lower right', frameon=False))
  1088. mu = rons.mean(), roffs.mean()
  1089. txt = '$\mathregular{\mu=%.1f, %.1f}$' % mu
  1090. a.add_artist(AnchoredText(txt, loc='upper left', frameon=False))
  1091. # scatter plot spontaneous burst ratio:
  1092. figsize = DEFAULTFIGURESIZE
  1093. logmin, logmax = -3.55, 0
  1094. logticks = np.array([-3, -2, -1, 0])
  1095. for st8 in ['none']:#ALLST8S:
  1096. f, a = plt.subplots(figsize=figsize)
  1097. wintitle('opto burst ratio spontaneous %s' % st8)
  1098. brons, broffs = [], []
  1099. for mseustr in sponmseustrs:
  1100. br = sponresp.loc[mseustr]['meanburstratio']
  1101. if br.isna().any(): # missing for at least one opto condition
  1102. continue
  1103. brons.append(br[True])
  1104. broffs.append(br[False])
  1105. #fig3.loc[mseustr, 'meanburstratio'] = br[False], br[True] # save
  1106. brons, broffs = np.asarray(brons), np.asarray(broffs)
  1107. # plot y=x line:
  1108. xyline = [10**logmin, 10**logmax], [10**logmin, 10**logmax]
  1109. a.plot(xyline[0], xyline[1], '--', color='gray', zorder=-1)
  1110. a.scatter(brons, broffs, marker='.', c='None', edgecolor=st82clr[st8], s=DEFSZ)
  1111. a.set_xlabel('Suppression BR') # keep it short to maximize space for axes
  1112. a.set_ylabel('Feedback BR')
  1113. a.set_xscale('log')
  1114. a.set_yscale('log')
  1115. a.set_xlim(10**logmin, 10**logmax)
  1116. a.set_ylim(10**logmin, 10**logmax)
  1117. a.set_xticks(10.0**logticks)
  1118. a.set_yticks(a.get_xticks()) # make log scale y ticks the same as x ticks
  1119. a.minorticks_off()
  1120. axes_disable_scientific(a)
  1121. a.set_aspect('equal')
  1122. t, p = ttest_rel(brons, broffs) # paired t-test
  1123. a.add_artist(AnchoredText('p$=$%.2g' % p, loc='upper left', frameon=False))
  1124. '''
  1125. ## movie onset ON/OFF/transient classification, also doesn't cluster, but doesn't seem
  1126. ## to match classical sense of ON/OFF/transient from luminance step function in chirp
  1127. ## stimulus (at least in Ntsr mice which had both movie and chirp stim, see fig1S33S1_ntsr.py),
  1128. ## so leaving this out for now:
  1129. '''
  1130. # plot normalized PSTHs wrt movie onset coloured by ON/OFF/transient classification
  1131. figsize = 10, 5
  1132. #logmin, logmax = -1.2, 2
  1133. #logticks = np.array([-1, 0, 1, 2])
  1134. #log0min = logmin + 0.05
  1135. f, a = plt.subplots(figsize=figsize)
  1136. wintitle('mvionsetpsth nat ONOFFTHRESH=%.2f TRANSTHRESH=%.2f' % (ONOFFTHRESH, TRANSTHRESH))
  1137. clr2zorder = {'gray': -3, 'black':-2, green:-1, 'red':0}
  1138. for msustr, row in celltype.iterrows():
  1139. onoff = row['onoff']
  1140. trans = row['trans']
  1141. mvionsetpsth = row['mvionsetpsth']
  1142. t = row['t']
  1143. clr = 'gray'
  1144. if trans >= TRANSTHRESH: # first try and classify by trans
  1145. clr = 'black'
  1146. elif onoff >= ONOFFTHRESH: # try and classify by on/off
  1147. clr = green
  1148. elif onoff < -ONOFFTHRESH:
  1149. clr = 'red'
  1150. zorder = clr2zorder[clr]
  1151. a.plot(t, mvionsetpsth, '-', color=clr, alpha=1, zorder=zorder)
  1152. a.axvline(x=0, ls='--', marker='', color='lightgray', zorder=-np.inf)
  1153. a.axvline(x=0.1, ls='--', marker='', color='lightgray', zorder=-np.inf)
  1154. a.set_ylabel('Normalized firing rate')
  1155. a.set_xlabel('Time from movie onset (s)')
  1156. dt = np.diff(t).mean()
  1157. a.set_xlim(t[0], t[-1]+dt)
  1158. #a.set_ylim(-0.1, 2)
  1159. patch = Rectangle((0, 0), 0, 0)
  1160. l = a.legend([patch, patch, patch], ['On', 'Off', 'Transient'], loc='upper left',
  1161. handlelength=0, handletextpad=0, frameon=False)
  1162. for t, c in zip(l.get_texts(), [green, 'red', 'black']):
  1163. t.set_color(c)
  1164. # scatter plot grating meanrates, coloured by ON/OFF/transient:
  1165. figsize = DEFAULTFIGURESIZE
  1166. logmin, logmax = -1.2, 2
  1167. logticks = np.array([-1, 0, 1, 2])
  1168. #log0min = logmin + 0.05
  1169. for st8 in ['none']:#ALLST8S:
  1170. f, a = plt.subplots(figsize=figsize)
  1171. wintitle('opto meanrate grating %s ONOFFTHRESH=%.2f TRANSTHRESH=%.2f'
  1172. % (st8, ONOFFTHRESH, TRANSTHRESH))
  1173. rons, roffs, onoffs, transs = [], [], [], []
  1174. for mseustr in grtmseustrs:
  1175. meanrate = grtresp.loc[mseustr, st8]['meanrate']
  1176. msustr = mseustr2msustr(mseustr)
  1177. onoff = celltype.loc[msustr]['onoff']
  1178. trans = celltype.loc[msustr]['trans']
  1179. if meanrate.isna().any(): # missing one or both meanrates
  1180. #print('%s: missing one or both opto conditions, skipping' % mseustr)
  1181. continue
  1182. rons.append(meanrate[True])
  1183. roffs.append(meanrate[False])
  1184. onoffs.append(onoff)
  1185. transs.append(trans)
  1186. #fig3.loc[mseustr, 'meanrate'] = meanrate[False], meanrate[True] # save
  1187. rons = np.asarray(rons)
  1188. roffs = np.asarray(roffs)
  1189. clrs = []
  1190. for onoff, trans in zip(onoffs, transs):
  1191. clr = 'gray'
  1192. if trans >= TRANSTHRESH: # first try and classify by trans
  1193. clr = 'black'
  1194. elif onoff >= ONOFFTHRESH: # try and classify by on/off
  1195. clr = green
  1196. elif onoff < -ONOFFTHRESH:
  1197. clr = 'red'
  1198. clrs.append(clr)
  1199. # plot y=x line:
  1200. xyline = [10**logmin, 10**logmax], [10**logmin, 10**logmax]
  1201. a.plot(xyline[0], xyline[1], '--', color='gray', zorder=-1)
  1202. # plot all points:
  1203. a.scatter(rons, roffs, marker='.', c='None', edgecolor=clrs, s=DEFSZ)
  1204. a.set_ylabel('Feedback FR (spk/s)')
  1205. a.set_xlabel('Suppression FR (spk/s)')
  1206. a.set_xscale('log')
  1207. a.set_yscale('log')
  1208. a.set_xlim(10**logmin, 10**logmax)
  1209. a.set_ylim(10**logmin, 10**logmax)
  1210. a.set_xticks(10.0**logticks)
  1211. a.set_yticks(a.get_xticks()) # make log scale y ticks the same as x ticks
  1212. axes_disable_scientific(a)
  1213. a.minorticks_off()
  1214. a.set_aspect('equal')
  1215. #t, p = ttest_rel(rons, roffs) # paired t-test
  1216. #a.add_artist(AnchoredText('p$=$%.2g' % p, loc='lower right', frameon=False))
  1217. patch = Rectangle((0, 0), 0, 0)
  1218. l = a.legend([patch, patch, patch], ['On', 'Off', 'Transient'], loc='upper left',
  1219. handlelength=0, handletextpad=0, frameon=False)
  1220. for t, c in zip(l.get_texts(), [green, 'red', 'black']):
  1221. t.set_color(c)
  1222. # scatter plot movie meanrates, coloured by ON/OFF/transient:
  1223. figsize = DEFAULTFIGURESIZE
  1224. logmin, logmax = -1.2, 2
  1225. logticks = np.array([-1, 0, 1, 2])
  1226. #log0min = logmin + 0.05
  1227. for st8 in ['none']:#ALLST8S:
  1228. f, a = plt.subplots(figsize=figsize)
  1229. wintitle('opto meanrate movie nat %s ONOFFTHRESH=%.2f TRANSTHRESH=%.2f'
  1230. % (st8, ONOFFTHRESH, TRANSTHRESH))
  1231. rons, roffs, onoffs, trans = [], [], [], []
  1232. for mseustr in mvimseustrs:
  1233. meanrate = mviresp.loc[mseustr, 'nat', st8]['meanrate']
  1234. msustr = mseustr2msustr(mseustr)
  1235. onoff = celltype.loc[msustr]['onoff']
  1236. trans = celltype.loc[msustr]['trans']
  1237. if meanrate.isna().any(): # missing one or both meanrates
  1238. #print('%s: missing one or both opto conditions, skipping' % mseustr)
  1239. continue
  1240. rons.append(meanrate[True])
  1241. roffs.append(meanrate[False])
  1242. onoffs.append(onoff)
  1243. transs.append(trans)
  1244. #fig3.loc[mseustr, 'meanrate'] = meanrate[False], meanrate[True] # save
  1245. rons = np.asarray(rons)
  1246. roffs = np.asarray(roffs)
  1247. clrs = []
  1248. for onoff, trans in zip(onoffs, transs):
  1249. clr = 'gray'
  1250. if trans >= TRANSTHRESH: # first try and classify by trans
  1251. clr = 'black'
  1252. elif onoff >= ONOFFTHRESH: # try and classify by on/off
  1253. clr = green
  1254. elif onoff < -ONOFFTHRESH:
  1255. clr = 'red'
  1256. clrs.append(clr)
  1257. # plot y=x line:
  1258. xyline = [10**logmin, 10**logmax], [10**logmin, 10**logmax]
  1259. a.plot(xyline[0], xyline[1], '--', color='gray', zorder=-1)
  1260. # plot all points:
  1261. a.scatter(rons, roffs, marker='.', c='None', edgecolor=clrs, s=DEFSZ)
  1262. a.set_ylabel('Feedback FR (spk/s)')
  1263. a.set_xlabel('Suppression FR (spk/s)')
  1264. a.set_xscale('log')
  1265. a.set_yscale('log')
  1266. a.set_xlim(10**logmin, 10**logmax)
  1267. a.set_ylim(10**logmin, 10**logmax)
  1268. a.set_xticks(10.0**logticks)
  1269. a.set_yticks(a.get_xticks()) # make log scale y ticks the same as x ticks
  1270. axes_disable_scientific(a)
  1271. a.minorticks_off()
  1272. a.set_aspect('equal')
  1273. #t, p = ttest_rel(rons, roffs) # paired t-test
  1274. #a.add_artist(AnchoredText('p$=$%.2g' % p, loc='lower right', frameon=False))
  1275. patch = Rectangle((0, 0), 0, 0)
  1276. l = a.legend([patch, patch, patch], ['On', 'Off', 'Transient'], loc='upper left',
  1277. handlelength=0, handletextpad=0, frameon=False)
  1278. for t, c in zip(l.get_texts(), [green, 'red', 'black']):
  1279. t.set_color(c)
  1280. # scatter plot grating burst ratio, coloured by ON/OFF/transient:
  1281. figsize = DEFAULTFIGURESIZE
  1282. logmin, logmax = -3.55, 0
  1283. logticks = np.array([-3, -2, -1, 0])
  1284. for st8 in ['none']:#ALLST8S:
  1285. f, a = plt.subplots(figsize=figsize)
  1286. wintitle('opto burst ratio grating %s ONOFFTHRESH=%.2f TRANSTHRESH=%.2f'
  1287. % (st8, ONOFFTHRESH, TRANSTHRESH))
  1288. brons, broffs, onoffs, trans = [], [], [], []
  1289. for mseustr in grtmseustrs:
  1290. br = grtresp.loc[mseustr, st8]['meanburstratio']
  1291. msustr = mseustr2msustr(mseustr)
  1292. onoff = celltype.loc[msustr]['onoff']
  1293. trans = celltype.loc[msustr]['trans']
  1294. if br.isna().any(): # missing for at least one opto condition
  1295. continue
  1296. brons.append(br[True])
  1297. broffs.append(br[False])
  1298. onoffs.append(onoff)
  1299. transs.append(trans)
  1300. brons, broffs = np.asarray(brons), np.asarray(broffs)
  1301. clrs = []
  1302. for onoff, trans in zip(onoffs, transs):
  1303. clr = 'gray'
  1304. if trans >= TRANSTHRESH: # first try and classify by trans
  1305. clr = 'black'
  1306. elif onoff >= ONOFFTHRESH: # try and classify by on/off
  1307. clr = green
  1308. elif onoff < -ONOFFTHRESH:
  1309. clr = 'red'
  1310. clrs.append(clr)
  1311. # plot y=x line:
  1312. xyline = [10**logmin, 10**logmax], [10**logmin, 10**logmax]
  1313. a.plot(xyline[0], xyline[1], '--', color='gray', zorder=-1)
  1314. # plot all points:
  1315. a.scatter(brons, broffs, marker='.', c='None', edgecolor=clrs, s=DEFSZ)
  1316. a.set_xlabel('Suppression BR') # keep it short to maximize space for axes
  1317. a.set_ylabel('Feedback BR')
  1318. a.set_xscale('log')
  1319. a.set_yscale('log')
  1320. a.set_xlim(10**logmin, 10**logmax)
  1321. a.set_ylim(10**logmin, 10**logmax)
  1322. a.set_xticks(10.0**logticks)
  1323. a.set_yticks(a.get_xticks()) # make log scale y ticks the same as x ticks
  1324. a.minorticks_off()
  1325. axes_disable_scientific(a)
  1326. a.set_aspect('equal')
  1327. #t, p = ttest_rel(brons, broffs) # paired t-test
  1328. #a.add_artist(AnchoredText('p$=$%.2g' % p, loc='upper left', frameon=False))
  1329. patch = Rectangle((0, 0), 0, 0)
  1330. l = a.legend([patch, patch, patch], ['On', 'Off', 'Transient'], loc='upper left',
  1331. handlelength=0, handletextpad=0, frameon=False)
  1332. for t, c in zip(l.get_texts(), [green, 'red', 'black']):
  1333. t.set_color(c)
  1334. # scatter plot movie burst ratio, coloured by ON/OFF/transient:
  1335. figsize = DEFAULTFIGURESIZE
  1336. logmin, logmax = -3.55, 0
  1337. logticks = np.array([-3, -2, -1, 0])
  1338. for st8 in ['none']:#ALLST8S:
  1339. f, a = plt.subplots(figsize=figsize)
  1340. wintitle('opto burst ratio movie nat %s ONOFFTHRESH=%.2f TRANSTHRESH=%.2f'
  1341. % (st8, ONOFFTHRESH, TRANSTHRESH))
  1342. brons, broffs, onoffs, trans = [], [], [], []
  1343. for mseustr in mvimseustrs:
  1344. br = mviresp.loc[mseustr, 'nat', st8]['meanburstratio']
  1345. msustr = mseustr2msustr(mseustr)
  1346. onoff = celltype.loc[msustr]['onoff']
  1347. trans = celltype.loc[msustr]['trans']
  1348. if br.isna().any(): # missing for at least one opto condition
  1349. continue
  1350. brons.append(br[True])
  1351. broffs.append(br[False])
  1352. onoffs.append(onoff)
  1353. transs.append(trans)
  1354. #fig3.loc[mseustr, 'meanburstratio'] = br[False], br[True] # save
  1355. brons, broffs = np.asarray(brons), np.asarray(broffs)
  1356. for onoff, trans in zip(onoffs, transs):
  1357. clr = 'gray'
  1358. if trans >= TRANSTHRESH: # first try and classify by trans
  1359. clr = 'black'
  1360. elif onoff >= ONOFFTHRESH: # try and classify by on/off
  1361. clr = green
  1362. elif onoff < -ONOFFTHRESH:
  1363. clr = 'red'
  1364. clrs.append(clr)
  1365. # plot y=x line:
  1366. xyline = [10**logmin, 10**logmax], [10**logmin, 10**logmax]
  1367. a.plot(xyline[0], xyline[1], '--', color='gray', zorder=-1)
  1368. # plot all points:
  1369. a.scatter(brons, broffs, marker='.', c='None', edgecolor=clrs, s=DEFSZ)
  1370. a.set_xlabel('Suppression BR') # keep it short to maximize space for axes
  1371. a.set_ylabel('Feedback BR')
  1372. a.set_xscale('log')
  1373. a.set_yscale('log')
  1374. a.set_xlim(10**logmin, 10**logmax)
  1375. a.set_ylim(10**logmin, 10**logmax)
  1376. a.set_xticks(10.0**logticks)
  1377. a.set_yticks(a.get_xticks()) # make log scale y ticks the same as x ticks
  1378. a.minorticks_off()
  1379. axes_disable_scientific(a)
  1380. a.set_aspect('equal')
  1381. #t, p = ttest_rel(brons, broffs) # paired t-test
  1382. #a.add_artist(AnchoredText('p$=$%.2g' % p, loc='upper left', frameon=False))
  1383. patch = Rectangle((0, 0), 0, 0)
  1384. l = a.legend([patch, patch, patch], ['On', 'Off', 'Transient'], loc='upper left',
  1385. handlelength=0, handletextpad=0, frameon=False)
  1386. for t, c in zip(l.get_texts(), [green, 'red', 'black']):
  1387. t.set_color(c)
  1388. # scatter plot grating meanrates, coloured by distance of MUA envl RF from center of screen:
  1389. figsize = 3.5, DEFAULTFIGURESIZE[1] #DEFAULTFIGURESIZE
  1390. logmin, logmax = -1.2, 2
  1391. logticks = np.array([-1, 0, 1, 2])
  1392. #log0min = logmin + 0.05
  1393. for st8 in ['none']:#ALLST8S:
  1394. f, a = plt.subplots(figsize=figsize)
  1395. wintitle('opto meanrate grating %s rfdist' % st8)
  1396. rons, roffs, ds = [], [], []
  1397. for mseustr in grtmseustrs:
  1398. meanrate = grtresp.loc[mseustr, st8]['meanrate']
  1399. msustr = mseustr2msustr(mseustr)
  1400. x0, y0 = cellscreenpos.loc[msustr]
  1401. d = np.sqrt(x0**2 + y0**2) # distance from screen center, deg
  1402. if meanrate.isna().any(): # missing one or both meanrates
  1403. #print('%s: missing one or both opto conditions, skipping' % mseustr)
  1404. continue
  1405. rons.append(meanrate[True])
  1406. roffs.append(meanrate[False])
  1407. ds.append(d)
  1408. #fig3.loc[mseustr, 'meanrate'] = meanrate[False], meanrate[True] # save
  1409. rons = np.asarray(rons)
  1410. roffs = np.asarray(roffs)
  1411. ds = np.asarray(ds)
  1412. maxds = intround(np.nanmax(ds))
  1413. normds = ds / maxds
  1414. cmap = plt.get_cmap() # use default, normalized from 0 to 1
  1415. dclrs = []
  1416. for normd in normds:
  1417. if np.isnan(normd):
  1418. dclrs.append('gray')
  1419. else:
  1420. dclrs.append(cmap(normd))
  1421. # plot y=x line:
  1422. xyline = [10**logmin, 10**logmax], [10**logmin, 10**logmax]
  1423. a.plot(xyline[0], xyline[1], '--', color='gray', zorder=-1)
  1424. # plot all points:
  1425. a.scatter(rons, roffs, marker='.', c='none', edgecolor=dclrs, s=DEFSZ, cmap='viridis')
  1426. a.set_ylabel('Feedback FR (spk/s)')
  1427. a.set_xlabel('Suppression FR (spk/s)')
  1428. a.set_xscale('log')
  1429. a.set_yscale('log')
  1430. a.set_xlim(10**logmin, 10**logmax)
  1431. a.set_ylim(10**logmin, 10**logmax)
  1432. a.set_xticks(10.0**logticks)
  1433. a.set_yticks(a.get_xticks()) # make log scale y ticks the same as x ticks
  1434. axes_disable_scientific(a)
  1435. a.minorticks_off()
  1436. a.set_aspect('equal')
  1437. #t, p = ttest_rel(rons, roffs) # paired t-test
  1438. #a.add_artist(AnchoredText('p$=$%.2g' % p, loc='lower right', frameon=False))
  1439. scalarmappable = mpl.cm.ScalarMappable(norm=None, cmap=cmap)
  1440. scalarmappable.set_clim(0, maxds)
  1441. f.colorbar(scalarmappable, ticks=[0, maxds], label='Dist. from center ($\degree$)')
  1442. # scatter plot movie meanrates, coloured by distance of MUA envl RF from center of screen:
  1443. figsize = 3.5, DEFAULTFIGURESIZE[1] #DEFAULTFIGURESIZE
  1444. logmin, logmax = -1.2, 2
  1445. logticks = np.array([-1, 0, 1, 2])
  1446. #log0min = logmin + 0.05
  1447. for st8 in ['none']:#ALLST8S:
  1448. f, a = plt.subplots(figsize=figsize)
  1449. wintitle('opto meanrate movie nat %s rfdist' % st8)
  1450. rons, roffs, ds = [], [], []
  1451. for mseustr in mvimseustrs:
  1452. meanrate = mviresp.loc[mseustr, 'nat', st8]['meanrate']
  1453. msustr = mseustr2msustr(mseustr)
  1454. x0, y0 = cellscreenpos.loc[msustr]
  1455. d = np.sqrt(x0**2 + y0**2) # distance from screen center, deg
  1456. if meanrate.isna().any(): # missing one or both meanrates
  1457. #print('%s: missing one or both opto conditions, skipping' % mseustr)
  1458. continue
  1459. rons.append(meanrate[True])
  1460. roffs.append(meanrate[False])
  1461. ds.append(d)
  1462. #fig3.loc[mseustr, 'meanrate'] = meanrate[False], meanrate[True] # save
  1463. rons = np.asarray(rons)
  1464. roffs = np.asarray(roffs)
  1465. ds = np.asarray(ds)
  1466. maxds = intround(np.nanmax(ds))
  1467. normds = ds / maxds
  1468. cmap = plt.get_cmap() # use default, normalized from 0 to 1
  1469. dclrs = []
  1470. for normd in normds:
  1471. if np.isnan(normd):
  1472. dclrs.append('gray')
  1473. else:
  1474. dclrs.append(cmap(normd))
  1475. # plot y=x line:
  1476. xyline = [10**logmin, 10**logmax], [10**logmin, 10**logmax]
  1477. a.plot(xyline[0], xyline[1], '--', color='gray', zorder=-1)
  1478. # plot all points:
  1479. a.scatter(rons, roffs, marker='.', c='None', edgecolor=dclrs, s=DEFSZ)
  1480. a.set_ylabel('Feedback FR (spk/s)')
  1481. a.set_xlabel('Suppression FR (spk/s)')
  1482. a.set_xscale('log')
  1483. a.set_yscale('log')
  1484. a.set_xlim(10**logmin, 10**logmax)
  1485. a.set_ylim(10**logmin, 10**logmax)
  1486. a.set_xticks(10.0**logticks)
  1487. a.set_yticks(a.get_xticks()) # make log scale y ticks the same as x ticks
  1488. axes_disable_scientific(a)
  1489. a.minorticks_off()
  1490. a.set_aspect('equal')
  1491. #t, p = ttest_rel(rons, roffs) # paired t-test
  1492. #a.add_artist(AnchoredText('p$=$%.2g' % p, loc='lower right', frameon=False))
  1493. scalarmappable = mpl.cm.ScalarMappable(norm=None, cmap=cmap)
  1494. scalarmappable.set_clim(0, maxds)
  1495. f.colorbar(scalarmappable, ticks=[0, maxds], label='Dist. from center ($\degree$)')
  1496. # scatter plot grating burst ratio, coloured by distance of MUA envl RF from center of screen:
  1497. figsize = 3.6, DEFAULTFIGURESIZE[1] #DEFAULTFIGURESIZE
  1498. logmin, logmax = -3.55, 0
  1499. logticks = np.array([-3, -2, -1, 0])
  1500. for st8 in ['none']:#ALLST8S:
  1501. f, a = plt.subplots(figsize=figsize)
  1502. wintitle('opto burst ratio grating %s rfdist' % st8)
  1503. brons, broffs, ds = [], [], []
  1504. for mseustr in grtmseustrs:
  1505. br = grtresp.loc[mseustr, st8]['meanburstratio']
  1506. msustr = mseustr2msustr(mseustr)
  1507. x0, y0 = cellscreenpos.loc[msustr]
  1508. d = np.sqrt(x0**2 + y0**2) # distance from screen center, deg
  1509. if br.isna().any(): # missing for at least one opto condition
  1510. continue
  1511. brons.append(br[True])
  1512. broffs.append(br[False])
  1513. ds.append(d)
  1514. #fig3.loc[mseustr, 'meanburstratio'] = br[False], br[True] # save
  1515. brons, broffs, ds = np.asarray(brons), np.asarray(broffs), np.asarray(ds)
  1516. maxds = intround(np.nanmax(ds))
  1517. normds = ds / maxds
  1518. cmap = plt.get_cmap() # use default, normalized from 0 to 1
  1519. dclrs = []
  1520. for normd in normds:
  1521. if np.isnan(normd):
  1522. dclrs.append('gray')
  1523. else:
  1524. dclrs.append(cmap(normd))
  1525. # plot y=x line:
  1526. xyline = [10**logmin, 10**logmax], [10**logmin, 10**logmax]
  1527. a.plot(xyline[0], xyline[1], '--', color='gray', zorder=-1)
  1528. # plot all points:
  1529. a.scatter(brons, broffs, marker='.', c='None', edgecolor=dclrs, s=DEFSZ)
  1530. a.set_xlabel('Suppression BR') # keep it short to maximize space for axes
  1531. a.set_ylabel('Feedback BR')
  1532. a.set_xscale('log')
  1533. a.set_yscale('log')
  1534. a.set_xlim(10**logmin, 10**logmax)
  1535. a.set_ylim(10**logmin, 10**logmax)
  1536. a.set_xticks(10.0**logticks)
  1537. a.set_yticks(a.get_xticks()) # make log scale y ticks the same as x ticks
  1538. a.minorticks_off()
  1539. axes_disable_scientific(a)
  1540. a.set_aspect('equal')
  1541. #t, p = ttest_rel(brons, broffs) # paired t-test
  1542. #a.add_artist(AnchoredText('p$=$%.2g' % p, loc='upper left', frameon=False))
  1543. scalarmappable = mpl.cm.ScalarMappable(norm=None, cmap=cmap)
  1544. scalarmappable.set_clim(0, maxds)
  1545. f.colorbar(scalarmappable, ticks=[0, maxds], label='Dist. from center ($\degree$)')
  1546. # scatter plot movie burst ratio, coloured by distance of MUA envl RF from center of screen:
  1547. figsize = 3.6, DEFAULTFIGURESIZE[1] #DEFAULTFIGURESIZE
  1548. logmin, logmax = -3.55, 0
  1549. logticks = np.array([-3, -2, -1, 0])
  1550. for st8 in ['none']:#ALLST8S:
  1551. f, a = plt.subplots(figsize=figsize)
  1552. wintitle('opto burst ratio movie nat %s rfdist' % st8)
  1553. brons, broffs, ds = [], [], []
  1554. for mseustr in mvimseustrs:
  1555. br = mviresp.loc[mseustr, 'nat', st8]['meanburstratio']
  1556. msustr = mseustr2msustr(mseustr)
  1557. x0, y0 = cellscreenpos.loc[msustr]
  1558. d = np.sqrt(x0**2 + y0**2) # distance from screen center, deg
  1559. if br.isna().any(): # missing for at least one opto condition
  1560. continue
  1561. brons.append(br[True])
  1562. broffs.append(br[False])
  1563. ds.append(d)
  1564. #fig3.loc[mseustr, 'meanburstratio'] = br[False], br[True] # save
  1565. brons, broffs, ds = np.asarray(brons), np.asarray(broffs), np.asarray(ds)
  1566. maxds = intround(np.nanmax(ds))
  1567. normds = ds / maxds
  1568. cmap = plt.get_cmap() # use default, normalized from 0 to 1
  1569. dclrs = []
  1570. for normd in normds:
  1571. if np.isnan(normd):
  1572. dclrs.append('gray')
  1573. else:
  1574. dclrs.append(cmap(normd))
  1575. # plot y=x line:
  1576. xyline = [10**logmin, 10**logmax], [10**logmin, 10**logmax]
  1577. a.plot(xyline[0], xyline[1], '--', color='gray', zorder=-1)
  1578. # plot all points:
  1579. a.scatter(brons, broffs, marker='.', c='None', edgecolor=dclrs, s=DEFSZ)
  1580. a.set_xlabel('Suppression BR') # keep it short to maximize space for axes
  1581. a.set_ylabel('Feedback BR')
  1582. a.set_xscale('log')
  1583. a.set_yscale('log')
  1584. a.set_xlim(10**logmin, 10**logmax)
  1585. a.set_ylim(10**logmin, 10**logmax)
  1586. a.set_xticks(10.0**logticks)
  1587. a.set_yticks(a.get_xticks()) # make log scale y ticks the same as x ticks
  1588. a.minorticks_off()
  1589. axes_disable_scientific(a)
  1590. a.set_aspect('equal')
  1591. #t, p = ttest_rel(brons, broffs) # paired t-test
  1592. #a.add_artist(AnchoredText('p$=$%.2g' % p, loc='upper left', frameon=False))
  1593. scalarmappable = mpl.cm.ScalarMappable(norm=None, cmap=cmap)
  1594. scalarmappable.set_clim(0, maxds)
  1595. f.colorbar(scalarmappable, ticks=[0, maxds], label='Dist. from center ($\degree$)')
  1596. '''