123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656 |
- """Figure 1S3 and 3S1 unit classification plots, use run -i fig1S33S1.py"""
- index = pd.Index(mvigrtmsustrs, name='msu')
- columns = ['mvi_meanrate', 'mvi_meanburstratio', 'grt_meanrate', 'grt_meanburstratio',
- 'sbc', 'depth', 'normdepth', 'dsi', 'rfdist',
- 'mvi_meanrate_raw', 'mvi_meanburstratio_raw',
- 'grt_meanrate_raw', 'grt_meanburstratio_raw']
- fig1S33S1 = pd.DataFrame(index=index, columns=columns)
- from scipy.stats import gmean
- import matplotlib as mpl
- from matplotlib.patches import Rectangle
- TRANSTHRESH = 0.2
- ONOFFTHRESH = 0.2
- # stripplot FMI by SbC/non-SbC, mvi and grt, meanrate and meanburstratio:
- np.random.seed(0) # to get identical horizontal jitter in strip plots on every run
- figsize = DEFAULTFIGURESIZE
- for stimtype in STIMTYPES:
- stimtypelabel = stimtype2axislabel[stimtype]
- for measure in ['meanrate', 'meanburstratio']:
- axislabel = measure2axislabel[measure]
- axislabel = short2longaxislabel.get(axislabel, axislabel)
- if axislabel.islower():
- axislabel = axislabel.capitalize()
- fmis, sbcs = [], []
- colname = '_'.join([stimtype, measure]) # e.g. 'mvi_meanrate'
- for msustr in mvigrtmsustrs:
- # save sbc to fig1S33S1 df, regardless of FMI val, will be overwritten multiple
- # times with the same value, but that's OK:
- sbc = celltype.loc[msustr]['sbc'] # bool
- fig1S33S1.loc[msustr]['sbc'] = sbc
- fmi = maxFMI.loc[msustr, 'none', stimtype][measure] # ignore run condition for FMI
- if np.isnan(fmi):
- continue
- fmis.append(fmi)
- sbcs.append(sbc)
- fig1S33S1.loc[msustr][colname] = fmi
- fmis = np.asarray(fmis)
- sbcs = np.asarray(sbcs)
- sbcfmis = fmis[sbcs == True]
- nonsbcfmis = fmis[sbcs == False]
- f, a = plt.subplots(figsize=figsize)
- wintitle('FMI SbC %s %s strip' % (stimtypelabel, measure))
- # plot y=0 line:
- a.axhline(y=0, ls='--', marker='', color='lightgray', zorder=-np.inf)
- data = pd.DataFrame.from_dict({'SbC':sbcfmis, 'Non-SbC':nonsbcfmis},
- orient='index').transpose()
- sns.stripplot(ax=a, data=data, clip_on=False, marker='.',
- color='None', edgecolor='black', size=np.sqrt(50))
- # get fname of appropriate LMM .cvs file:
- fname = None # sanity check: clear from previous loop
- if stimtype == 'mvi':
- if measure == 'meanrate':
- fname = os.path.join('stats', 'figure_1S3a_pred_means.csv')
- elif measure == 'meanburstratio':
- fname = os.path.join('stats', 'figure_1S3f_pred_means.csv')
- elif stimtype == 'grt':
- if measure == 'meanrate':
- fname = os.path.join('stats', 'figure_3S1a_pred_means.csv')
- elif measure == 'meanburstratio':
- fname = os.path.join('stats', 'figure_3S1f_pred_means.csv')
- # fetch LMM means from .csv:
- df = pd.read_csv(fname)
- meannonsbcfmi = df['non_sbc'][0]
- meansbcfmi = df['sbc'][0]
- # plot mean with short horizontal lines:
- a.plot([-0.25, 0.25], [meansbcfmi, meansbcfmi], '-', lw=2, c='red', zorder=np.inf)
- a.plot([0.75, 1.25], [meannonsbcfmi, meannonsbcfmi], '-', lw=2, c='red', zorder=np.inf)
- a.set_ylabel('%s FMI' % axislabel)
- a.set_ylim(-1, 1)
- a.set_yticks([-1, 0, 1])
- a.tick_params(bottom=False)
- a.spines['bottom'].set_position(('outward', 5))
- a.spines['bottom'].set_visible(False)
- '''
- # stripplot FMI by shell/core, mvi and grt, meanrate and meanburstratio:
- np.random.seed(0) # to get identical horizontal jitter in strip plots on every run
- figsize = DEFAULTFIGURESIZE
- for stimtype in STIMTYPES:
- stimtypelabel = stimtype2axislabel[stimtype]
- for measure in ['meanrate', 'meanburstratio']:
- axislabel = measure2axislabel[measure]
- axislabel = short2longaxislabel.get(axislabel, axislabel)
- if axislabel.islower():
- axislabel = axislabel.capitalize()
- fmis, layers = [], []
- colname = '_'.join([stimtype, measure]) # e.g. 'mvi_meanrate'
- for msustr in mvigrtmsustrs:
- # save layer to fig1S33S1 df, regardless of FMI val, will be overwritten multiple
- # times with the same value, but that's OK:
- layer = celltype.loc[msustr]['layer'] # str
- fig1S33S1.loc[msustr]['layer'] = layer
- fmi = maxFMI.loc[msustr, 'none', stimtype][measure] # ignore run condition for FMI
- if np.isnan(fmi):
- continue
- fmis.append(fmi)
- layers.append(layer)
- fig1S33S1.loc[msustr][colname] = fmi # might overwrite w/ identical values
- fmis = np.asarray(fmis)
- layers = np.asarray(layers)
- shellfmis = fmis[layers == 'shell']
- corefmis = fmis[layers == 'core']
- f, a = plt.subplots(figsize=figsize)
- wintitle('FMI layer %s %s strip' % (stimtypelabel, measure))
- # plot y=0 line:
- a.axhline(y=0, ls='--', marker='', color='lightgray', zorder=-np.inf)
- data = pd.DataFrame.from_dict({'Shell':shellfmis, 'Core':corefmis},
- orient='index').transpose()
- sns.stripplot(ax=a, data=data, clip_on=False, marker='.',
- color='None', edgecolor='black', size=np.sqrt(50))
- # get fname of appropriate LMM .cvs file:
- fname = None # sanity check: clear from previous loop
- if stimtype == 'mvi':
- if measure == 'meanrate':
- fname = os.path.join('stats', 'figure_1S3b_pred_means.csv')
- elif measure == 'meanburstratio':
- fname = os.path.join('stats', 'figure_1S3g_pred_means.csv')
- elif stimtype == 'grt':
- if measure == 'meanrate':
- fname = os.path.join('stats', 'figure_3S1b_pred_means.csv')
- elif measure == 'meanburstratio':
- fname = os.path.join('stats', 'figure_3S1g_pred_means.csv')
- # fetch LMM means from .csv:
- df = pd.read_csv(fname)
- meancorefmi = df['core'][0]
- meanshellfmi = df['shell'][0]
- # plot mean with short horizontal lines:
- a.plot([-0.25, 0.25], [meanshellfmi, meanshellfmi], '-', lw=2, c='red', zorder=np.inf)
- a.plot([0.75, 1.25], [meancorefmi, meancorefmi], '-', lw=2, c='red', zorder=np.inf)
- a.set_ylabel('%s FMI' % axislabel)
- a.set_ylim(-1, 1)
- a.set_yticks([-1, 0, 1])
- a.tick_params(bottom=False)
- a.spines['bottom'].set_position(('outward', 5))
- a.spines['bottom'].set_visible(False)
- '''
- # scatter plot FMI vs. depth by mvi and grt, meanrate and meanburstratio:
- figsize = DEFAULTFIGURESIZE
- for stimtype in STIMTYPES:
- stimtypelabel = stimtype2axislabel[stimtype]
- for measure in ['meanrate', 'meanburstratio']:
- axislabel = measure2axislabel[measure]
- axislabel = short2longaxislabel.get(axislabel, axislabel)
- if axislabel.islower():
- axislabel = axislabel.capitalize()
- fmis, depths = [], []
- colname = '_'.join([stimtype, measure]) # e.g. 'mvi_meanrate'
- for msustr in mvigrtmsustrs:
- # save depth to fig1S33S1 df, regardless of FMI val, will be overwritten multiple
- # times with the same value, but that's OK:
- depth = celltype.loc[msustr]['depth'] # float
- fig1S33S1.loc[msustr]['depth'] = depth
- fmi = maxFMI.loc[msustr, 'none', stimtype][measure] # ignore run condition for FMI
- if np.isnan(fmi):
- continue
- fmis.append(fmi)
- depths.append(depth)
- fig1S33S1.loc[msustr][colname] = fmi # might overwrite w/ identical values
- fmis = np.asarray(fmis)
- depths = np.asarray(depths)
- f, a = plt.subplots(figsize=figsize)
- wintitle('FMI depth %s %s' % (stimtypelabel, measure))
- # plot y=0 line:
- a.axhline(y=0, ls='--', marker='', color='lightgray', zorder=-np.inf)
- a.scatter(depths, fmis, clip_on=False, marker='.', c='None', edgecolor='k', s=DEFSZ)
- # get fname of appropriate LMM .cvs file:
- fname = None # sanity check: clear from previous loop
- if stimtype == 'mvi':
- if measure == 'meanrate':
- fname = os.path.join('stats', 'figure_1S3b_coefs.csv')
- elif measure == 'meanburstratio':
- fname = os.path.join('stats', 'figure_1S3g_coefs.csv')
- elif stimtype == 'grt':
- if measure == 'meanrate':
- fname = os.path.join('stats', 'figure_3S1b_coefs.csv')
- elif measure == 'meanburstratio':
- fname = os.path.join('stats', 'figure_3S1g_coefs.csv')
- # fetch LMM linregress fit params from .csv:
- df = pd.read_csv(fname)
- mm = df['slope'][0]
- b = df['intercept'][0]
- x = np.array([np.nanmin(depths), np.nanmax(depths)])
- y = mm * x + b
- a.plot(x, y, '-', color='red') # plot linregress fit
- a.set_xlabel('Depth ($\mathregular{\mu}$m)')
- a.set_ylabel('%s FMI' % axislabel)
- a.set_xlim(0, 500)
- a.set_ylim(-1, 1)
- a.set_yticks([-1, 0, 1])
- a.spines['left'].set_position(('outward', 4))
- a.spines['bottom'].set_position(('outward', 4))
- # scatter plot FMI vs. normalized depth by mvi and grt, meanrate and meanburstratio:
- figsize = DEFAULTFIGURESIZE
- for stimtype in STIMTYPES:
- stimtypelabel = stimtype2axislabel[stimtype]
- for measure in ['meanrate', 'meanburstratio']:
- axislabel = measure2axislabel[measure]
- axislabel = short2longaxislabel.get(axislabel, axislabel)
- if axislabel.islower():
- axislabel = axislabel.capitalize()
- fmis, normdepths = [], []
- colname = '_'.join([stimtype, measure]) # e.g. 'mvi_meanrate'
- for msustr in mvigrtmsustrs:
- # save normdepth to fig1S33S1 df, regardless of FMI val, will be overwritten
- # multiple times with the same value, but that's OK:
- normdepth = celltype.loc[msustr]['normdepth'] # float
- fig1S33S1.loc[msustr]['normdepth'] = normdepth
- fmi = maxFMI.loc[msustr, 'none', stimtype][measure] # ignore run condition for FMI
- if np.isnan(fmi):
- continue
- fmis.append(fmi)
- normdepths.append(normdepth)
- fig1S33S1.loc[msustr][colname] = fmi # might overwrite w/ identical values
- fmis = np.asarray(fmis)
- normdepths = np.asarray(normdepths)
- f, a = plt.subplots(figsize=figsize)
- wintitle('FMI normdepth %s %s' % (stimtypelabel, measure))
- # plot y=0 line:
- a.axhline(y=0, ls='--', marker='', color='lightgray', zorder=-np.inf)
- a.scatter(normdepths, fmis, clip_on=False, marker='.', c='None', edgecolor='k', s=DEFSZ)
- '''
- # get fname of appropriate LMM .cvs file:
- fname = None # sanity check: clear from previous loop
- if stimtype == 'mvi':
- if measure == 'meanrate':
- fname = os.path.join('stats', 'figure_1S3b_coefs.csv')
- elif measure == 'meanburstratio':
- fname = os.path.join('stats', 'figure_1S3g_coefs.csv')
- elif stimtype == 'grt':
- if measure == 'meanrate':
- fname = os.path.join('stats', 'figure_3S1b_coefs.csv')
- elif measure == 'meanburstratio':
- fname = os.path.join('stats', 'figure_3S1g_coefs.csv')
- # fetch LMM linregress fit params from .csv:
- df = pd.read_csv(fname)
- mm = df['slope'][0]
- b = df['intercept'][0]
- x = np.array([np.nanmin(normdepths), np.nanmax(normdepths)])
- y = mm * x + b
- a.plot(x, y, '-', color='red') # plot linregress fit
- '''
- a.set_xlabel('Normalized depth')
- a.set_ylabel('%s FMI' % axislabel)
- #a.set_xlim(0, 2)
- a.set_ylim(-1, 1)
- a.set_yticks([-1, 0, 1])
- a.spines['left'].set_position(('outward', 4))
- a.spines['bottom'].set_position(('outward', 4))
- # scatter plot FMI vs. DSI by mvi and grt, meanrate and meanburstratio:
- figsize = DEFAULTFIGURESIZE
- for stimtype in STIMTYPES:
- stimtypelabel = stimtype2axislabel[stimtype]
- for measure in ['meanrate', 'meanburstratio']:
- axislabel = measure2axislabel[measure]
- axislabel = short2longaxislabel.get(axislabel, axislabel)
- if axislabel.islower():
- axislabel = axislabel.capitalize()
- fmis, dsis = [], []
- colname = '_'.join([stimtype, measure]) # e.g. 'mvi_meanrate'
- for msustr in mvigrtmsustrs:
- # save DSI to fig1S33S1 df, regardless of FMI val, will be overwritten multiple
- # times with the same value, but that's OK:
- dsi = celltype.loc[msustr]['dsi'] # float
- fig1S33S1.loc[msustr]['dsi'] = dsi
- fmi = maxFMI.loc[msustr, 'none', stimtype][measure] # ignore run condition for FMI
- if np.isnan(fmi):
- continue
- fmis.append(fmi)
- dsis.append(dsi)
- fig1S33S1.loc[msustr][colname] = fmi # might overwrite w/ identical values
- fmis = np.asarray(fmis)
- dsis = np.asarray(dsis)
- f, a = plt.subplots(figsize=figsize)
- wintitle('FMI DSI %s %s' % (stimtypelabel, measure))
- # plot y=0 line:
- a.axhline(y=0, ls='--', marker='', color='lightgray', zorder=-np.inf)
- a.scatter(dsis, fmis, clip_on=False, marker='.', c='None', edgecolor='k', s=DEFSZ)
- # get fname of appropriate LMM .cvs file:
- fname = None # sanity check: clear from previous loop
- if stimtype == 'mvi':
- if measure == 'meanrate':
- fname = os.path.join('stats', 'figure_1S3c_coefs.csv')
- elif measure == 'meanburstratio':
- fname = os.path.join('stats', 'figure_1S3h_coefs.csv')
- elif stimtype == 'grt':
- if measure == 'meanrate':
- fname = os.path.join('stats', 'figure_3S1c_coefs.csv')
- elif measure == 'meanburstratio':
- fname = os.path.join('stats', 'figure_3S1h_coefs.csv')
- # fetch LMM linregress fit params from .csv:
- df = pd.read_csv(fname)
- mm = df['slope'][0]
- b = df['intercept'][0]
- x = np.array([np.nanmin(dsis), np.nanmax(dsis)])
- y = mm * x + b
- a.plot(x, y, '-', color='red') # plot linregress fit
- a.set_xlabel('DSI')
- a.set_ylabel('%s FMI' % axislabel)
- a.set_xlim(0, 1)
- a.set_ylim(-1, 1)
- a.set_yticks([-1, 0, 1])
- a.spines['left'].set_position(('outward', 4))
- a.spines['bottom'].set_position(('outward', 4))
- # scatter plot FMI vs. distance of MUA envl RF from screen center, by mvi and grt,
- # meanrate and meanburstratio:
- figsize = DEFAULTFIGURESIZE
- for stimtype in STIMTYPES:
- stimtypelabel = stimtype2axislabel[stimtype]
- for measure in ['meanrate', 'meanburstratio']:
- axislabel = measure2axislabel[measure]
- axislabel = short2longaxislabel.get(axislabel, axislabel)
- if axislabel.islower():
- axislabel = axislabel.capitalize()
- fmis, ds = [], []
- colname = '_'.join([stimtype, measure]) # e.g. 'mvi_meanrate'
- for msustr in mvigrtmsustrs:
- # save rfdist to fig1S33S1 df, regardless of FMI val, will be overwritten multiple
- # times with the same value, but that's OK:
- x0, y0 = cellscreenpos.loc[msustr]
- d = np.sqrt(x0**2 + y0**2) # distance from screen center, deg
- fig1S33S1.loc[msustr]['rfdist'] = d
- fmi = maxFMI.loc[msustr, 'none', stimtype][measure] # ignore run condition for FMI
- if np.isnan(fmi):
- continue
- fmis.append(fmi)
- ds.append(d)
- fig1S33S1.loc[msustr][colname] = fmi # might overwrite w/ identical values
- fmis = np.asarray(fmis)
- ds = np.asarray(ds)
- f, a = plt.subplots(figsize=figsize)
- wintitle('FMI rfdist %s %s' % (stimtypelabel, measure))
- # plot y=0 line:
- a.axhline(y=0, ls='--', marker='', color='lightgray', zorder=-np.inf)
- a.scatter(ds, fmis, clip_on=False, marker='.', c='None', edgecolor='k', s=DEFSZ)
- # get fname of appropriate LMM .cvs file:
- fname = None # sanity check: clear from previous loop
- if stimtype == 'mvi':
- if measure == 'meanrate':
- fname = os.path.join('stats', 'figure_1S3d_coefs.csv')
- elif measure == 'meanburstratio':
- fname = os.path.join('stats', 'figure_1S3i_coefs.csv')
- elif stimtype == 'grt':
- if measure == 'meanrate':
- fname = os.path.join('stats', 'figure_3S1d_coefs.csv')
- elif measure == 'meanburstratio':
- fname = os.path.join('stats', 'figure_3S1i_coefs.csv')
- # fetch LMM linregress fit params from .csv:
- df = pd.read_csv(fname)
- mm = df['slope'][0]
- b = df['intercept'][0]
- x = np.array([np.nanmin(ds), np.nanmax(ds)])
- y = mm * x + b
- a.plot(x, y, '-', color='red') # plot linregress fit
- a.set_xlabel('RF dist. from center ($\degree$)')
- a.set_ylabel('%s FMI' % axislabel)
- a.set_xlim(0, 40)
- a.set_ylim(-1, 1)
- a.set_yticks([-1, 0, 1])
- a.spines['left'].set_position(('outward', 4))
- a.spines['bottom'].set_position(('outward', 4))
- # scatter plot FMI vs raw measure, for rate and burst ratio during control condition,
- # by mvi and grt:
- stimtype2resp = {'mvi':mviresp, 'grt':grtresp}
- figsize = DEFAULTFIGURESIZE
- for stimtype in STIMTYPES:
- stimtypelabel = stimtype2axislabel[stimtype]
- resp = stimtype2resp[stimtype]
- if stimtype == 'mvi':
- resp = resp.xs('nat', level='kind') # dereference movie 'kind' index level
- for measure in ['meanrate', 'meanburstratio']:
- axislabel = measure2axislabel[measure]
- axislabel = short2longaxislabel.get(axislabel, axislabel)
- axisunits = measure2axisunits.get(measure, '')
- if axislabel.islower():
- axislabel = axislabel.capitalize()
- fmis, msrs = [], []
- fmicolname = '_'.join([stimtype, measure]) # e.g. 'mvi_meanrate'
- msrcolname = '_'.join([stimtype, measure, 'raw']) # e.g. 'mvi_meanrate_raw'
- for msustr in mvigrtmsustrs:
- mseustr, fmi = maxFMI.loc[msustr, 'none', stimtype][['mseu', measure]]
- if pd.isna(mseustr) or pd.isna(fmi):
- continue
- msr = resp.loc[mseustr, 'none', False][measure]
- fmis.append(fmi)
- msrs.append(msr)
- fig1S33S1.loc[msustr][fmicolname] = fmi # might overwrite w/ identical values
- fig1S33S1.loc[msustr][msrcolname] = msr
- fmis, msrs = np.asarray(fmis), np.asarray(msrs)
- ## scatter plot FMI vs raw measure:
- f, a = plt.subplots(figsize=figsize)
- wintitle('FMI raw %s %s' % (stimtypelabel, measure))
- # plot y=0 line:
- a.axhline(y=0, ls='--', marker='', color='lightgray', zorder=-np.inf)
- a.scatter(msrs, fmis, clip_on=False, marker='.', c='None', edgecolor='k', s=DEFSZ)
- # get fname of appropriate LMM .cvs file:
- fname = None # sanity check: clear from previous loop
- if stimtype == 'mvi':
- if measure == 'meanrate':
- fname = os.path.join('stats', 'figure_1S3e_coefs.csv')
- elif measure == 'meanburstratio':
- fname = os.path.join('stats', 'figure_1S3j_coefs.csv')
- elif stimtype == 'grt':
- if measure == 'meanrate':
- fname = os.path.join('stats', 'figure_3S1e_coefs.csv')
- elif measure == 'meanburstratio':
- fname = os.path.join('stats', 'figure_3S1j_coefs.csv')
- # fetch LMM linregress fit params from .csv:
- df = pd.read_csv(fname)
- mm = df['slope'][0]
- b = df['intercept'][0]
- x = np.array([np.nanmin(msrs), np.nanmax(msrs)])
- y = mm * x + b
- a.plot(x, y, '-', color='red') # plot linregress fit
- a.set_xlabel('%s' % axislabel+axisunits)
- a.set_ylabel('%s FMI' % axislabel)
- a.set_xlim(xmin=0)
- a.set_ylim(-1, 1)
- #a.set_xticks(ticks)
- a.set_yticks([-1, 0, 1])
- a.spines['left'].set_position(('outward', 4))
- a.spines['bottom'].set_position(('outward', 4))
- #### old opto scatter plots:
- '''
- # scatter plot grating meanrates, coloured by sbc:
- figsize = DEFAULTFIGURESIZE
- logmin, logmax = -1.2, 2
- logticks = np.array([-1, 0, 1, 2])
- #log0min = logmin + 0.05
- for st8 in ['none']:#ALLST8S:
- f, a = plt.subplots(figsize=figsize)
- wintitle('opto meanrate grating %s sbc' % st8)
- rons, roffs, sbcs = [], [], []
- for mseustr in grtmseustrs:
- meanrate = grtresp.loc[mseustr, st8]['meanrate']
- msustr = mseustr2msustr(mseustr)
- sbc = celltype.loc[msustr]['sbc']
- if np.isnan(sbc):
- sbc = None # works properly as sbcclrs dict key
- if meanrate.isna().any(): # missing one or both meanrates
- #print('%s: missing one or both opto conditions, skipping' % mseustr)
- continue
- rons.append(meanrate[True])
- roffs.append(meanrate[False])
- sbcs.append(sbc)
- #fig3.loc[mseustr, 'meanrate'] = meanrate[False], meanrate[True] # save
- rons = np.asarray(rons)
- roffs = np.asarray(roffs)
- sbcs = np.asarray(sbcs)
- sbcclrs = [ {True:'r', False:green, None:'black'}[sbc] for sbc in sbcs ]
- # plot y=x line:
- xyline = [10**logmin, 10**logmax], [10**logmin, 10**logmax]
- a.plot(xyline[0], xyline[1], '--', color='gray', zorder=-1)
- # plot all points:
- a.scatter(rons, roffs, marker='.', c='None', edgecolor=sbcclrs, s=DEFSZ)
- # plot mean of points grouped by sbc:
- sbclogmean = gmean(rons[sbcs == True]), gmean(roffs[sbcs == True])
- notsbclogmean = gmean(rons[sbcs == False]), gmean(roffs[sbcs == False])
- a.scatter(sbclogmean[0], sbclogmean[1], marker='+', c='r', s=100)
- a.scatter(notsbclogmean[0], notsbclogmean[1], marker='+', c=green, s=100)
- a.set_ylabel('Feedback FR (spk/s)')
- a.set_xlabel('Suppression FR (spk/s)')
- a.set_xscale('log')
- a.set_yscale('log')
- a.set_xlim(10**logmin, 10**logmax)
- a.set_ylim(10**logmin, 10**logmax)
- a.set_xticks(10.0**logticks)
- a.set_yticks(a.get_xticks()) # make log scale y ticks the same as x ticks
- axes_disable_scientific(a)
- a.minorticks_off()
- a.set_aspect('equal')
- #t, p = ttest_rel(rons, roffs) # paired t-test
- #a.add_artist(AnchoredText('p$=$%.2g' % p, loc='lower right', frameon=False))
- patch = Rectangle((0, 0), 0, 0)
- l = a.legend([patch, patch], ['SbC', 'Non-SbC'], loc='upper left',
- handlelength=0, handletextpad=0, frameon=False)
- for t, c in zip(l.get_texts(), ['r', green]):
- t.set_color(c)
- # scatter plot movie meanrates, coloured by sbc:
- figsize = DEFAULTFIGURESIZE
- logmin, logmax = -1.2, 2
- logticks = np.array([-1, 0, 1, 2])
- #log0min = logmin + 0.05
- for st8 in ['none']:#ALLST8S:
- f, a = plt.subplots(figsize=figsize)
- wintitle('opto meanrate movie nat %s sbc' % st8)
- rons, roffs, sbcs = [], [], []
- for mseustr in mvimseustrs:
- meanrate = mviresp.loc[mseustr, 'nat', st8]['meanrate']
- msustr = mseustr2msustr(mseustr)
- sbc = celltype.loc[msustr]['sbc']
- if np.isnan(sbc):
- sbc = None # works properly as sbcclrs dict key
- if meanrate.isna().any(): # missing one or both meanrates
- #print('%s: missing one or both opto conditions, skipping' % mseustr)
- continue
- rons.append(meanrate[True])
- roffs.append(meanrate[False])
- sbcs.append(sbc)
- #fig3.loc[mseustr, 'meanrate'] = meanrate[False], meanrate[True] # save
- rons = np.asarray(rons)
- roffs = np.asarray(roffs)
- sbcs = np.asarray(sbcs)
- sbcclrs = [ {True:'r', False:green, None:'black'}[sbc] for sbc in sbcs ]
- # plot y=x line:
- xyline = [10**logmin, 10**logmax], [10**logmin, 10**logmax]
- a.plot(xyline[0], xyline[1], '--', color='gray', zorder=-1)
- # plot all points:
- a.scatter(rons, roffs, marker='.', c='None', edgecolor=sbcclrs, s=DEFSZ)
- # plot mean of points grouped by sbc:
- sbclogmean = gmean(rons[sbcs == True]), gmean(roffs[sbcs == True])
- notsbclogmean = gmean(rons[sbcs == False]), gmean(roffs[sbcs == False])
- a.scatter(sbclogmean[0], sbclogmean[1], marker='+', c='r', s=100)
- a.scatter(notsbclogmean[0], notsbclogmean[1], marker='+', c=green, s=100)
- a.set_ylabel('Feedback FR (spk/s)')
- a.set_xlabel('Suppression FR (spk/s)')
- a.set_xscale('log')
- a.set_yscale('log')
- a.set_xlim(10**logmin, 10**logmax)
- a.set_ylim(10**logmin, 10**logmax)
- a.set_xticks(10.0**logticks)
- a.set_yticks(a.get_xticks()) # make log scale y ticks the same as x ticks
- axes_disable_scientific(a)
- a.minorticks_off()
- a.set_aspect('equal')
- #t, p = ttest_rel(rons, roffs) # paired t-test
- #a.add_artist(AnchoredText('p$=$%.2g' % p, loc='lower right', frameon=False))
- patch = Rectangle((0, 0), 0, 0)
- l = a.legend([patch, patch], ['SbC', 'Non-SbC'], loc='upper left',
- handlelength=0, handletextpad=0, frameon=False)
- for t, c in zip(l.get_texts(), ['r', green]):
- t.set_color(c)
- # scatter plot grating burst ratio, coloured by sbc:
- figsize = DEFAULTFIGURESIZE
- logmin, logmax = -3.55, 0
- logticks = np.array([-3, -2, -1, 0])
- for st8 in ['none']:#ALLST8S:
- f, a = plt.subplots(figsize=figsize)
- wintitle('opto burst ratio grating %s sbc' % st8)
- brons, broffs, sbcs = [], [], []
- for mseustr in grtmseustrs:
- br = grtresp.loc[mseustr, st8]['meanburstratio']
- msustr = mseustr2msustr(mseustr)
- sbc = celltype.loc[msustr]['sbc']
- if np.isnan(sbc):
- sbc = None # works properly as sbcclrs dict key
- if br.isna().any(): # missing for at least one opto condition
- continue
- brons.append(br[True])
- broffs.append(br[False])
- sbcs.append(sbc)
- #fig3.loc[mseustr, 'meanburstratio'] = br[False], br[True] # save
- brons, broffs, sbcs = np.asarray(brons), np.asarray(broffs), np.asarray(sbcs)
- sbcclrs = [ {True:'r', False:green, None:'black'}[sbc] for sbc in sbcs ]
- # plot y=x line:
- xyline = [10**logmin, 10**logmax], [10**logmin, 10**logmax]
- a.plot(xyline[0], xyline[1], '--', color='gray', zorder=-1)
- # plot all points:
- a.scatter(brons, broffs, marker='.', c='None', edgecolor=sbcclrs, s=DEFSZ)
- # plot mean of points grouped by sbc:
- # filter out 0 value burst ratios before calculating geometric mean:
- sbcbrons = brons[sbcs == True][brons[sbcs == True] > 0]
- sbcbroffs = broffs[sbcs == True][broffs[sbcs == True] > 0]
- notsbcbrons = brons[sbcs == False][brons[sbcs == False] > 0]
- notsbcbroffs = broffs[sbcs == False][broffs[sbcs == False] > 0]
- sbclogmean = gmean(sbcbrons), gmean(sbcbroffs)
- notsbclogmean = gmean(notsbcbrons), gmean(notsbcbroffs)
- a.scatter(sbclogmean[0], sbclogmean[1], marker='+', c='r', s=100)
- a.scatter(notsbclogmean[0], notsbclogmean[1], marker='+', c=green, s=100)
- a.set_xlabel('Suppression BR') # keep it short to maximize space for axes
- a.set_ylabel('Feedback BR')
- a.set_xscale('log')
- a.set_yscale('log')
- a.set_xlim(10**logmin, 10**logmax)
- a.set_ylim(10**logmin, 10**logmax)
- a.set_xticks(10.0**logticks)
- a.set_yticks(a.get_xticks()) # make log scale y ticks the same as x ticks
- a.minorticks_off()
- axes_disable_scientific(a)
- a.set_aspect('equal')
- #t, p = ttest_rel(brons, broffs) # paired t-test
- #a.add_artist(AnchoredText('p$=$%.2g' % p, loc='upper left', frameon=False))
- patch = Rectangle((0, 0), 0, 0)
- l = a.legend([patch, patch], ['SbC', 'Non-SbC'], loc='upper left',
- handlelength=0, handletextpad=0, frameon=False)
- for t, c in zip(l.get_texts(), ['r', green]):
- t.set_color(c)
- # scatter plot movie burst ratio, coloured by sbc:
- figsize = DEFAULTFIGURESIZE
- logmin, logmax = -3.55, 0
- logticks = np.array([-3, -2, -1, 0])
- for st8 in ['none']:#ALLST8S:
- f, a = plt.subplots(figsize=figsize)
- wintitle('opto burst ratio movie nat %s sbc' % st8)
- brons, broffs, sbcs = [], [], []
- for mseustr in mvimseustrs:
- br = mviresp.loc[mseustr, 'nat', st8]['meanburstratio']
- msustr = mseustr2msustr(mseustr)
- sbc = celltype.loc[msustr]['sbc']
- if np.isnan(sbc):
- sbc = None
- if br.isna().any(): # missing for at least one opto condition
- continue
- brons.append(br[True])
- broffs.append(br[False])
- sbcs.append(sbc)
- #fig3.loc[mseustr, 'meanburstratio'] = br[False], br[True] # save
- brons, broffs, sbcs = np.asarray(brons), np.asarray(broffs), np.asarray(sbcs)
- sbcclrs = [ {True:'r', False:green, None:'black'}[sbc] for sbc in sbcs ]
- # plot y=x line:
- xyline = [10**logmin, 10**logmax], [10**logmin, 10**logmax]
- a.plot(xyline[0], xyline[1], '--', color='gray', zorder=-1)
- # plot all points:
- a.scatter(brons, broffs, marker='.', c='None', edgecolor=sbcclrs, s=DEFSZ)
- # plot mean of points grouped by sbc:
- # filter out 0 value burst ratios before calculating geometric mean:
- sbcbrons = brons[sbcs == True][brons[sbcs == True] > 0]
- sbcbroffs = broffs[sbcs == True][broffs[sbcs == True] > 0]
- notsbcbrons = brons[sbcs == False][brons[sbcs == False] > 0]
- notsbcbroffs = broffs[sbcs == False][broffs[sbcs == False] > 0]
- sbclogmean = gmean(sbcbrons), gmean(sbcbroffs)
- notsbclogmean = gmean(notsbcbrons), gmean(notsbcbroffs)
- a.scatter(sbclogmean[0], sbclogmean[1], marker='+', c='r', s=100)
- a.scatter(notsbclogmean[0], notsbclogmean[1], marker='+', c=green, s=100)
- a.set_xlabel('Suppression BR') # keep it short to maximize space for axes
- a.set_ylabel('Feedback BR')
- a.set_xscale('log')
- a.set_yscale('log')
- a.set_xlim(10**logmin, 10**logmax)
- a.set_ylim(10**logmin, 10**logmax)
- a.set_xticks(10.0**logticks)
- a.set_yticks(a.get_xticks()) # make log scale y ticks the same as x ticks
- a.minorticks_off()
- axes_disable_scientific(a)
- a.set_aspect('equal')
- #t, p = ttest_rel(brons, broffs) # paired t-test
- #a.add_artist(AnchoredText('p$=$%.2g' % p, loc='upper left', frameon=False))
- patch = Rectangle((0, 0), 0, 0)
- l = a.legend([patch, patch], ['SbC', 'Non-SbC'], loc='upper left',
- handlelength=0, handletextpad=0, frameon=False)
- for t, c in zip(l.get_texts(), ['r', green]):
- t.set_color(c)
- # scatter plot grating meanrates, coloured by DSI:
- figsize = DEFAULTFIGURESIZE
- logmin, logmax = -1.2, 2
- logticks = np.array([-1, 0, 1, 2])
- #log0min = logmin + 0.05
- for st8 in ['none']:#ALLST8S:
- f, a = plt.subplots(figsize=figsize)
- wintitle('opto meanrate grating %s dsi' % st8)
- rons, roffs, dsis = [], [], []
- for mseustr in grtmseustrs:
- meanrate = grtresp.loc[mseustr, st8]['meanrate']
- msustr = mseustr2msustr(mseustr)
- dsi = celltype.loc[msustr]['dsi']
- if meanrate.isna().any(): # missing one or both meanrates
- #print('%s: missing one or both opto conditions, skipping' % mseustr)
- continue
- rons.append(meanrate[True])
- roffs.append(meanrate[False])
- dsis.append(dsi)
- #fig3.loc[mseustr, 'meanrate'] = meanrate[False], meanrate[True] # save
- rons = np.asarray(rons)
- roffs = np.asarray(roffs)
- dsis = np.asarray(dsis)
- cmap = plt.get_cmap() # use default, normalized from 0 to 1
- dsiclrs = []
- for dsi in dsis:
- if np.isnan(dsi):
- dsiclrs.append('gray')
- else:
- dsiclrs.append(cmap(dsi))
- # plot y=x line:
- xyline = [10**logmin, 10**logmax], [10**logmin, 10**logmax]
- a.plot(xyline[0], xyline[1], '--', color='gray', zorder=-1)
- # plot all points:
- a.scatter(rons, roffs, marker='.', c='None', edgecolor=dsiclrs, s=DEFSZ)
- a.set_ylabel('Feedback FR (spk/s)')
- a.set_xlabel('Suppression FR (spk/s)')
- a.set_xscale('log')
- a.set_yscale('log')
- a.set_xlim(10**logmin, 10**logmax)
- a.set_ylim(10**logmin, 10**logmax)
- a.set_xticks(10.0**logticks)
- a.set_yticks(a.get_xticks()) # make log scale y ticks the same as x ticks
- axes_disable_scientific(a)
- a.minorticks_off()
- a.set_aspect('equal')
- #t, p = ttest_rel(rons, roffs) # paired t-test
- #a.add_artist(AnchoredText('p$=$%.2g' % p, loc='lower right', frameon=False))
- #scalarmappable = mpl.cm.ScalarMappable(norm=None, cmap=cmap)
- #f.colorbar(scalarmappable, label='DSI')
- # scatter plot movie meanrates, coloured by dsi:
- figsize = DEFAULTFIGURESIZE
- logmin, logmax = -1.2, 2
- logticks = np.array([-1, 0, 1, 2])
- #log0min = logmin + 0.05
- for st8 in ['none']:#ALLST8S:
- f, a = plt.subplots(figsize=figsize)
- wintitle('opto meanrate movie nat %s dsi' % st8)
- rons, roffs, dsis = [], [], []
- for mseustr in mvimseustrs:
- meanrate = mviresp.loc[mseustr, 'nat', st8]['meanrate']
- msustr = mseustr2msustr(mseustr)
- dsi = celltype.loc[msustr]['dsi']
- if meanrate.isna().any(): # missing one or both meanrates
- #print('%s: missing one or both opto conditions, skipping' % mseustr)
- continue
- rons.append(meanrate[True])
- roffs.append(meanrate[False])
- dsis.append(dsi)
- #fig3.loc[mseustr, 'meanrate'] = meanrate[False], meanrate[True] # save
- rons = np.asarray(rons)
- roffs = np.asarray(roffs)
- dsis = np.asarray(dsis)
- cmap = plt.get_cmap() # use default, normalized from 0 to 1
- dsiclrs = []
- for dsi in dsis:
- if np.isnan(dsi):
- dsiclrs.append('gray')
- else:
- dsiclrs.append(cmap(dsi))
- # plot y=x line:
- xyline = [10**logmin, 10**logmax], [10**logmin, 10**logmax]
- a.plot(xyline[0], xyline[1], '--', color='gray', zorder=-1)
- # plot all points:
- a.scatter(rons, roffs, marker='.', c='None', edgecolor=dsiclrs, s=DEFSZ)
- a.set_ylabel('Feedback FR (spk/s)')
- a.set_xlabel('Suppression FR (spk/s)')
- a.set_xscale('log')
- a.set_yscale('log')
- a.set_xlim(10**logmin, 10**logmax)
- a.set_ylim(10**logmin, 10**logmax)
- a.set_xticks(10.0**logticks)
- a.set_yticks(a.get_xticks()) # make log scale y ticks the same as x ticks
- axes_disable_scientific(a)
- a.minorticks_off()
- a.set_aspect('equal')
- #t, p = ttest_rel(rons, roffs) # paired t-test
- #a.add_artist(AnchoredText('p$=$%.2g' % p, loc='lower right', frameon=False))
- #scalarmappable = mpl.cm.ScalarMappable(norm=None, cmap=cmap)
- #f.colorbar(scalarmappable, label='DSI')
- # scatter plot grating burst ratio, coloured by dsi:
- figsize = DEFAULTFIGURESIZE
- logmin, logmax = -3.55, 0
- logticks = np.array([-3, -2, -1, 0])
- for st8 in ['none']:#ALLST8S:
- f, a = plt.subplots(figsize=figsize)
- wintitle('opto burst ratio grating %s dsi' % st8)
- brons, broffs, dsis = [], [], []
- for mseustr in grtmseustrs:
- br = grtresp.loc[mseustr, st8]['meanburstratio']
- msustr = mseustr2msustr(mseustr)
- dsi = celltype.loc[msustr]['dsi']
- if br.isna().any(): # missing for at least one opto condition
- continue
- brons.append(br[True])
- broffs.append(br[False])
- dsis.append(dsi)
- #fig3.loc[mseustr, 'meanburstratio'] = br[False], br[True] # save
- brons, broffs, dsis = np.asarray(brons), np.asarray(broffs), np.asarray(dsis)
- cmap = plt.get_cmap() # use default, normalized from 0 to 1
- dsiclrs = []
- for dsi in dsis:
- if np.isnan(dsi):
- dsiclrs.append('gray')
- else:
- dsiclrs.append(cmap(dsi))
- # plot y=x line:
- xyline = [10**logmin, 10**logmax], [10**logmin, 10**logmax]
- a.plot(xyline[0], xyline[1], '--', color='gray', zorder=-1)
- # plot all points:
- a.scatter(brons, broffs, marker='.', c='None', edgecolor=dsiclrs, s=DEFSZ)
- a.set_xlabel('Suppression BR') # keep it short to maximize space for axes
- a.set_ylabel('Feedback BR')
- a.set_xscale('log')
- a.set_yscale('log')
- a.set_xlim(10**logmin, 10**logmax)
- a.set_ylim(10**logmin, 10**logmax)
- a.set_xticks(10.0**logticks)
- a.set_yticks(a.get_xticks()) # make log scale y ticks the same as x ticks
- a.minorticks_off()
- axes_disable_scientific(a)
- a.set_aspect('equal')
- #t, p = ttest_rel(brons, broffs) # paired t-test
- #a.add_artist(AnchoredText('p$=$%.2g' % p, loc='upper left', frameon=False))
- #scalarmappable = mpl.cm.ScalarMappable(norm=None, cmap=cmap)
- #f.colorbar(scalarmappable, label='DSI')
- # scatter plot movie burst ratio, coloured by dsi:
- figsize = DEFAULTFIGURESIZE
- logmin, logmax = -3.55, 0
- logticks = np.array([-3, -2, -1, 0])
- for st8 in ['none']:#ALLST8S:
- f, a = plt.subplots(figsize=figsize)
- wintitle('opto burst ratio movie nat %s dsi' % st8)
- brons, broffs, dsis = [], [], []
- for mseustr in mvimseustrs:
- br = mviresp.loc[mseustr, 'nat', st8]['meanburstratio']
- msustr = mseustr2msustr(mseustr)
- dsi = celltype.loc[msustr]['dsi']
- if br.isna().any(): # missing for at least one opto condition
- continue
- brons.append(br[True])
- broffs.append(br[False])
- dsis.append(dsi)
- #fig3.loc[mseustr, 'meanburstratio'] = br[False], br[True] # save
- brons, broffs, dsis = np.asarray(brons), np.asarray(broffs), np.asarray(dsis)
- cmap = plt.get_cmap() # use default, normalized from 0 to 1
- dsiclrs = []
- for dsi in dsis:
- if np.isnan(dsi):
- dsiclrs.append('gray')
- else:
- dsiclrs.append(cmap(dsi))
- # plot y=x line:
- xyline = [10**logmin, 10**logmax], [10**logmin, 10**logmax]
- a.plot(xyline[0], xyline[1], '--', color='gray', zorder=-1)
- # plot all points:
- a.scatter(brons, broffs, marker='.', c='None', edgecolor=dsiclrs, s=DEFSZ)
- a.set_xlabel('Suppression BR') # keep it short to maximize space for axes
- a.set_ylabel('Feedback BR')
- a.set_xscale('log')
- a.set_yscale('log')
- a.set_xlim(10**logmin, 10**logmax)
- a.set_ylim(10**logmin, 10**logmax)
- a.set_xticks(10.0**logticks)
- a.set_yticks(a.get_xticks()) # make log scale y ticks the same as x ticks
- a.minorticks_off()
- axes_disable_scientific(a)
- a.set_aspect('equal')
- #t, p = ttest_rel(brons, broffs) # paired t-test
- #a.add_artist(AnchoredText('p$=$%.2g' % p, loc='upper left', frameon=False))
- #scalarmappable = mpl.cm.ScalarMappable(norm=None, cmap=cmap)
- #f.colorbar(scalarmappable, label='DSI')
- # scatter plot grating meanrates, coloured by dLGN layer (shell/core):
- figsize = DEFAULTFIGURESIZE
- logmin, logmax = -1.2, 2
- logticks = np.array([-1, 0, 1, 2])
- #log0min = logmin + 0.05
- for st8 in ['none']:#ALLST8S:
- f, a = plt.subplots(figsize=figsize)
- wintitle('opto meanrate grating %s layer' % st8)
- rons, roffs, layers = [], [], []
- for mseustr in grtmseustrs:
- meanrate = grtresp.loc[mseustr, st8]['meanrate']
- msustr = mseustr2msustr(mseustr)
- layer = celltype.loc[msustr]['layer']
- if meanrate.isna().any(): # missing one or both meanrates
- #print('%s: missing one or both opto conditions, skipping' % mseustr)
- continue
- rons.append(meanrate[True])
- roffs.append(meanrate[False])
- layers.append(layer)
- #fig3.loc[mseustr, 'meanrate'] = meanrate[False], meanrate[True] # save
- rons = np.asarray(rons)
- roffs = np.asarray(roffs)
- layers = np.asarray(layers)
- layerclrs = [ {'shell':violet, 'core':green, 'nan':'black'}[layer] for layer in layers ]
- # plot y=x line:
- xyline = [10**logmin, 10**logmax], [10**logmin, 10**logmax]
- a.plot(xyline[0], xyline[1], '--', color='gray', zorder=-1)
- # plot all points:
- a.scatter(rons, roffs, marker='.', c='None', edgecolor=layerclrs, s=DEFSZ)
- # plot mean of points grouped by layer:
- shelllogmean = gmean(rons[layers == 'shell']), gmean(roffs[layers == 'shell'])
- corelogmean = gmean(rons[layers == 'core']), gmean(roffs[layers == 'core'])
- a.scatter(shelllogmean[0], shelllogmean[1], marker='+', c=violet, s=100)
- a.scatter(corelogmean[0], corelogmean[1], marker='+', c=green, s=100)
- a.set_ylabel('Feedback FR (spk/s)')
- a.set_xlabel('Suppression FR (spk/s)')
- a.set_xscale('log')
- a.set_yscale('log')
- a.set_xlim(10**logmin, 10**logmax)
- a.set_ylim(10**logmin, 10**logmax)
- a.set_xticks(10.0**logticks)
- a.set_yticks(a.get_xticks()) # make log scale y ticks the same as x ticks
- axes_disable_scientific(a)
- a.minorticks_off()
- a.set_aspect('equal')
- #t, p = ttest_rel(rons, roffs) # paired t-test
- #a.add_artist(AnchoredText('p$=$%.2g' % p, loc='lower right', frameon=False))
- patch = Rectangle((0, 0), 0, 0)
- l = a.legend([patch, patch], ['Shell', 'Core'], loc='upper left',
- handlelength=0, handletextpad=0, frameon=False)
- for t, c in zip(l.get_texts(), [violet, green]):
- t.set_color(c)
- # scatter plot movie meanrates, coloured by dLGN layer (shell/core):
- figsize = DEFAULTFIGURESIZE
- logmin, logmax = -1.2, 2
- logticks = np.array([-1, 0, 1, 2])
- #log0min = logmin + 0.05
- for st8 in ['none']:#ALLST8S:
- f, a = plt.subplots(figsize=figsize)
- wintitle('opto meanrate movie nat %s layer' % st8)
- rons, roffs, layers = [], [], []
- for mseustr in mvimseustrs:
- meanrate = mviresp.loc[mseustr, 'nat', st8]['meanrate']
- msustr = mseustr2msustr(mseustr)
- layer = celltype.loc[msustr]['layer']
- if meanrate.isna().any(): # missing one or both meanrates
- #print('%s: missing one or both opto conditions, skipping' % mseustr)
- continue
- rons.append(meanrate[True])
- roffs.append(meanrate[False])
- layers.append(layer)
- #fig3.loc[mseustr, 'meanrate'] = meanrate[False], meanrate[True] # save
- rons = np.asarray(rons)
- roffs = np.asarray(roffs)
- layers = np.asarray(layers)
- layerclrs = [ {'shell':violet, 'core':green, 'nan':'black'}[layer] for layer in layers ]
- # plot y=x line:
- xyline = [10**logmin, 10**logmax], [10**logmin, 10**logmax]
- a.plot(xyline[0], xyline[1], '--', color='gray', zorder=-1)
- # plot all points:
- a.scatter(rons, roffs, marker='.', c='None', edgecolor=layerclrs, s=DEFSZ)
- # plot mean of points grouped by layer:
- shelllogmean = gmean(rons[layers == 'shell']), gmean(roffs[layers == 'shell'])
- corelogmean = gmean(rons[layers == 'core']), gmean(roffs[layers == 'core'])
- a.scatter(shelllogmean[0], shelllogmean[1], marker='+', c=violet, s=100)
- a.scatter(corelogmean[0], corelogmean[1], marker='+', c=green, s=100)
- a.set_ylabel('Feedback FR (spk/s)')
- a.set_xlabel('Suppression FR (spk/s)')
- a.set_xscale('log')
- a.set_yscale('log')
- a.set_xlim(10**logmin, 10**logmax)
- a.set_ylim(10**logmin, 10**logmax)
- a.set_xticks(10.0**logticks)
- a.set_yticks(a.get_xticks()) # make log scale y ticks the same as x ticks
- axes_disable_scientific(a)
- a.minorticks_off()
- a.set_aspect('equal')
- #t, p = ttest_rel(rons, roffs) # paired t-test
- #a.add_artist(AnchoredText('p$=$%.2g' % p, loc='lower right', frameon=False))
- patch = Rectangle((0, 0), 0, 0)
- l = a.legend([patch, patch], ['Shell', 'Core'], loc='upper left',
- handlelength=0, handletextpad=0, frameon=False)
- for t, c in zip(l.get_texts(), [violet, green]):
- t.set_color(c)
- # scatter plot grating burst ratio, coloured by dLGN layer (shell/core):
- figsize = DEFAULTFIGURESIZE
- logmin, logmax = -3.55, 0
- logticks = np.array([-3, -2, -1, 0])
- for st8 in ['none']:#ALLST8S:
- f, a = plt.subplots(figsize=figsize)
- wintitle('opto burst ratio grating %s layer' % st8)
- brons, broffs, layers = [], [], []
- for mseustr in grtmseustrs:
- br = grtresp.loc[mseustr, st8]['meanburstratio']
- msustr = mseustr2msustr(mseustr)
- layer = celltype.loc[msustr]['layer']
- if br.isna().any(): # missing for at least one opto condition
- continue
- brons.append(br[True])
- broffs.append(br[False])
- layers.append(layer)
- #fig3.loc[mseustr, 'meanburstratio'] = br[False], br[True] # save
- brons, broffs, layers = np.asarray(brons), np.asarray(broffs), np.asarray(layers)
- layerclrs = [ {'shell':violet, 'core':green, 'nan':'black'}[layer] for layer in layers ]
- # plot y=x line:
- xyline = [10**logmin, 10**logmax], [10**logmin, 10**logmax]
- a.plot(xyline[0], xyline[1], '--', color='gray', zorder=-1)
- # plot all points:
- a.scatter(brons, broffs, marker='.', c='None', edgecolor=layerclrs, s=DEFSZ)
- # plot mean of points grouped by layer:
- # filter out 0 vals before calculating geometric mean:
- shellis = layers == 'shell'
- coreis = layers == 'core'
- shellbrons = brons[shellis][brons[shellis] > 0]
- shellbroffs = broffs[shellis][broffs[shellis] > 0]
- corebrons = brons[coreis][brons[coreis] > 0]
- corebroffs = broffs[coreis][broffs[coreis] > 0]
- shelllogmean = gmean(shellbrons), gmean(shellbroffs)
- corelogmean = gmean(corebrons), gmean(corebroffs)
- a.scatter(shelllogmean[0], shelllogmean[1], marker='+', c=violet, s=100)
- a.scatter(corelogmean[0], corelogmean[1], marker='+', c=green, s=100)
- a.set_xlabel('Suppression BR') # keep it short to maximize space for axes
- a.set_ylabel('Feedback BR')
- a.set_xscale('log')
- a.set_yscale('log')
- a.set_xlim(10**logmin, 10**logmax)
- a.set_ylim(10**logmin, 10**logmax)
- a.set_xticks(10.0**logticks)
- a.set_yticks(a.get_xticks()) # make log scale y ticks the same as x ticks
- a.minorticks_off()
- axes_disable_scientific(a)
- a.set_aspect('equal')
- #t, p = ttest_rel(brons, broffs) # paired t-test
- #a.add_artist(AnchoredText('p$=$%.2g' % p, loc='upper left', frameon=False))
- patch = Rectangle((0, 0), 0, 0)
- l = a.legend([patch, patch], ['Shell', 'Core'], loc='upper left',
- handlelength=0, handletextpad=0, frameon=False)
- for t, c in zip(l.get_texts(), [violet, green]):
- t.set_color(c)
- # scatter plot movie burst ratio, coloured by dLGN layer (shell/core):
- figsize = DEFAULTFIGURESIZE
- logmin, logmax = -3.55, 0
- logticks = np.array([-3, -2, -1, 0])
- for st8 in ['none']:#ALLST8S:
- f, a = plt.subplots(figsize=figsize)
- wintitle('opto burst ratio movie nat %s layer' % st8)
- brons, broffs, layers = [], [], []
- for mseustr in mvimseustrs:
- br = mviresp.loc[mseustr, 'nat', st8]['meanburstratio']
- msustr = mseustr2msustr(mseustr)
- layer = celltype.loc[msustr]['layer']
- if br.isna().any(): # missing for at least one opto condition
- continue
- brons.append(br[True])
- broffs.append(br[False])
- layers.append(layer)
- #fig3.loc[mseustr, 'meanburstratio'] = br[False], br[True] # save
- brons, broffs, layers = np.asarray(brons), np.asarray(broffs), np.asarray(layers)
- layerclrs = [ {'shell':violet, 'core':green, 'nan':'black'}[layer] for layer in layers ]
- # plot y=x line:
- xyline = [10**logmin, 10**logmax], [10**logmin, 10**logmax]
- a.plot(xyline[0], xyline[1], '--', color='gray', zorder=-1)
- # plot all points:
- a.scatter(brons, broffs, marker='.', c='None', edgecolor=layerclrs, s=DEFSZ)
- # plot mean of points grouped by layer:
- # filter out 0 vals before calculating geometric mean:
- shellis = layers == 'shell'
- coreis = layers == 'core'
- shellbrons = brons[shellis][brons[shellis] > 0]
- shellbroffs = broffs[shellis][broffs[shellis] > 0]
- corebrons = brons[coreis][brons[coreis] > 0]
- corebroffs = broffs[coreis][broffs[coreis] > 0]
- shelllogmean = gmean(shellbrons), gmean(shellbroffs)
- corelogmean = gmean(corebrons), gmean(corebroffs)
- a.scatter(shelllogmean[0], shelllogmean[1], marker='+', c=violet, s=100)
- a.scatter(corelogmean[0], corelogmean[1], marker='+', c=green, s=100)
- a.set_xlabel('Suppression BR') # keep it short to maximize space for axes
- a.set_ylabel('Feedback BR')
- a.set_xscale('log')
- a.set_yscale('log')
- a.set_xlim(10**logmin, 10**logmax)
- a.set_ylim(10**logmin, 10**logmax)
- a.set_xticks(10.0**logticks)
- a.set_yticks(a.get_xticks()) # make log scale y ticks the same as x ticks
- a.minorticks_off()
- axes_disable_scientific(a)
- a.set_aspect('equal')
- #t, p = ttest_rel(brons, broffs) # paired t-test
- #a.add_artist(AnchoredText('p$=$%.2g' % p, loc='upper left', frameon=False))
- patch = Rectangle((0, 0), 0, 0)
- l = a.legend([patch, patch], ['Shell', 'Core'], loc='upper left',
- handlelength=0, handletextpad=0, frameon=False)
- for t, c in zip(l.get_texts(), [violet, green]):
- t.set_color(c)
- '''
- '''
- # scatter plot spontaneous meanrates:
- figsize = DEFAULTFIGURESIZE
- logmin, logmax = -1.2, 2
- logticks = np.array([-1, 0, 1, 2])
- #log0min = logmin + 0.05
- for st8 in ['none']:#ALLST8S:
- f, a = plt.subplots(figsize=figsize)
- wintitle('opto meanrate spontaneous %s' % st8)
- rons, roffs = [], []
- for mseustr in sponmseustrs:
- meanrate = sponresp.loc[mseustr]['meanrate']
- if meanrate.isna().any(): # missing one or both meanrates
- #print('%s: missing one or both opto conditions, skipping' % mseustr)
- continue
- rons.append(meanrate[True])
- roffs.append(meanrate[False])
- #fig3.loc[mseustr, 'meanrate'] = meanrate[False], meanrate[True] # save
- rons = np.asarray(rons)
- roffs = np.asarray(roffs)
- # replace off-scale low values with log0min, so the points remain visible:
- #pltrons, pltroffs = rons.copy(), roffs.copy()
- #pltrons[pltrons <= 10**logmin] = 10**log0min
- #pltroffs[pltroffs <= 10**logmin] = 10**log0min
- # plot y=x line:
- xyline = [10**logmin, 10**logmax], [10**logmin, 10**logmax]
- a.plot(xyline[0], xyline[1], '--', color='gray', zorder=-1)
- a.scatter(rons, roffs, marker='.', c='None', edgecolor=st82clr[st8], s=DEFSZ)
- a.set_xlabel('Suppression FR (spk/s)')
- a.set_ylabel('Feedback FR (spk/s)')
- a.set_xscale('log')
- a.set_yscale('log')
- a.set_xlim(10**logmin, 10**logmax)
- a.set_ylim(10**logmin, 10**logmax)
- a.set_xticks(10.0**logticks)
- a.set_yticks(a.get_xticks()) # make log scale y ticks the same as x ticks
- a.minorticks_off()
- axes_disable_scientific(a)
- a.set_aspect('equal')
- t, p = ttest_rel(rons, roffs) # paired t-test
- a.add_artist(AnchoredText('p$=$%.2g' % p, loc='lower right', frameon=False))
- mu = rons.mean(), roffs.mean()
- txt = '$\mathregular{\mu=%.1f, %.1f}$' % mu
- a.add_artist(AnchoredText(txt, loc='upper left', frameon=False))
- # scatter plot spontaneous burst ratio:
- figsize = DEFAULTFIGURESIZE
- logmin, logmax = -3.55, 0
- logticks = np.array([-3, -2, -1, 0])
- for st8 in ['none']:#ALLST8S:
- f, a = plt.subplots(figsize=figsize)
- wintitle('opto burst ratio spontaneous %s' % st8)
- brons, broffs = [], []
- for mseustr in sponmseustrs:
- br = sponresp.loc[mseustr]['meanburstratio']
- if br.isna().any(): # missing for at least one opto condition
- continue
- brons.append(br[True])
- broffs.append(br[False])
- #fig3.loc[mseustr, 'meanburstratio'] = br[False], br[True] # save
- brons, broffs = np.asarray(brons), np.asarray(broffs)
- # plot y=x line:
- xyline = [10**logmin, 10**logmax], [10**logmin, 10**logmax]
- a.plot(xyline[0], xyline[1], '--', color='gray', zorder=-1)
- a.scatter(brons, broffs, marker='.', c='None', edgecolor=st82clr[st8], s=DEFSZ)
- a.set_xlabel('Suppression BR') # keep it short to maximize space for axes
- a.set_ylabel('Feedback BR')
- a.set_xscale('log')
- a.set_yscale('log')
- a.set_xlim(10**logmin, 10**logmax)
- a.set_ylim(10**logmin, 10**logmax)
- a.set_xticks(10.0**logticks)
- a.set_yticks(a.get_xticks()) # make log scale y ticks the same as x ticks
- a.minorticks_off()
- axes_disable_scientific(a)
- a.set_aspect('equal')
- t, p = ttest_rel(brons, broffs) # paired t-test
- a.add_artist(AnchoredText('p$=$%.2g' % p, loc='upper left', frameon=False))
- '''
- ## movie onset ON/OFF/transient classification, also doesn't cluster, but doesn't seem
- ## to match classical sense of ON/OFF/transient from luminance step function in chirp
- ## stimulus (at least in Ntsr mice which had both movie and chirp stim, see fig1S33S1_ntsr.py),
- ## so leaving this out for now:
- '''
- # plot normalized PSTHs wrt movie onset coloured by ON/OFF/transient classification
- figsize = 10, 5
- #logmin, logmax = -1.2, 2
- #logticks = np.array([-1, 0, 1, 2])
- #log0min = logmin + 0.05
- f, a = plt.subplots(figsize=figsize)
- wintitle('mvionsetpsth nat ONOFFTHRESH=%.2f TRANSTHRESH=%.2f' % (ONOFFTHRESH, TRANSTHRESH))
- clr2zorder = {'gray': -3, 'black':-2, green:-1, 'red':0}
- for msustr, row in celltype.iterrows():
- onoff = row['onoff']
- trans = row['trans']
- mvionsetpsth = row['mvionsetpsth']
- t = row['t']
- clr = 'gray'
- if trans >= TRANSTHRESH: # first try and classify by trans
- clr = 'black'
- elif onoff >= ONOFFTHRESH: # try and classify by on/off
- clr = green
- elif onoff < -ONOFFTHRESH:
- clr = 'red'
- zorder = clr2zorder[clr]
- a.plot(t, mvionsetpsth, '-', color=clr, alpha=1, zorder=zorder)
- a.axvline(x=0, ls='--', marker='', color='lightgray', zorder=-np.inf)
- a.axvline(x=0.1, ls='--', marker='', color='lightgray', zorder=-np.inf)
- a.set_ylabel('Normalized firing rate')
- a.set_xlabel('Time from movie onset (s)')
- dt = np.diff(t).mean()
- a.set_xlim(t[0], t[-1]+dt)
- #a.set_ylim(-0.1, 2)
- patch = Rectangle((0, 0), 0, 0)
- l = a.legend([patch, patch, patch], ['On', 'Off', 'Transient'], loc='upper left',
- handlelength=0, handletextpad=0, frameon=False)
- for t, c in zip(l.get_texts(), [green, 'red', 'black']):
- t.set_color(c)
- # scatter plot grating meanrates, coloured by ON/OFF/transient:
- figsize = DEFAULTFIGURESIZE
- logmin, logmax = -1.2, 2
- logticks = np.array([-1, 0, 1, 2])
- #log0min = logmin + 0.05
- for st8 in ['none']:#ALLST8S:
- f, a = plt.subplots(figsize=figsize)
- wintitle('opto meanrate grating %s ONOFFTHRESH=%.2f TRANSTHRESH=%.2f'
- % (st8, ONOFFTHRESH, TRANSTHRESH))
- rons, roffs, onoffs, transs = [], [], [], []
- for mseustr in grtmseustrs:
- meanrate = grtresp.loc[mseustr, st8]['meanrate']
- msustr = mseustr2msustr(mseustr)
- onoff = celltype.loc[msustr]['onoff']
- trans = celltype.loc[msustr]['trans']
- if meanrate.isna().any(): # missing one or both meanrates
- #print('%s: missing one or both opto conditions, skipping' % mseustr)
- continue
- rons.append(meanrate[True])
- roffs.append(meanrate[False])
- onoffs.append(onoff)
- transs.append(trans)
- #fig3.loc[mseustr, 'meanrate'] = meanrate[False], meanrate[True] # save
- rons = np.asarray(rons)
- roffs = np.asarray(roffs)
- clrs = []
- for onoff, trans in zip(onoffs, transs):
- clr = 'gray'
- if trans >= TRANSTHRESH: # first try and classify by trans
- clr = 'black'
- elif onoff >= ONOFFTHRESH: # try and classify by on/off
- clr = green
- elif onoff < -ONOFFTHRESH:
- clr = 'red'
- clrs.append(clr)
- # plot y=x line:
- xyline = [10**logmin, 10**logmax], [10**logmin, 10**logmax]
- a.plot(xyline[0], xyline[1], '--', color='gray', zorder=-1)
- # plot all points:
- a.scatter(rons, roffs, marker='.', c='None', edgecolor=clrs, s=DEFSZ)
- a.set_ylabel('Feedback FR (spk/s)')
- a.set_xlabel('Suppression FR (spk/s)')
- a.set_xscale('log')
- a.set_yscale('log')
- a.set_xlim(10**logmin, 10**logmax)
- a.set_ylim(10**logmin, 10**logmax)
- a.set_xticks(10.0**logticks)
- a.set_yticks(a.get_xticks()) # make log scale y ticks the same as x ticks
- axes_disable_scientific(a)
- a.minorticks_off()
- a.set_aspect('equal')
- #t, p = ttest_rel(rons, roffs) # paired t-test
- #a.add_artist(AnchoredText('p$=$%.2g' % p, loc='lower right', frameon=False))
- patch = Rectangle((0, 0), 0, 0)
- l = a.legend([patch, patch, patch], ['On', 'Off', 'Transient'], loc='upper left',
- handlelength=0, handletextpad=0, frameon=False)
- for t, c in zip(l.get_texts(), [green, 'red', 'black']):
- t.set_color(c)
- # scatter plot movie meanrates, coloured by ON/OFF/transient:
- figsize = DEFAULTFIGURESIZE
- logmin, logmax = -1.2, 2
- logticks = np.array([-1, 0, 1, 2])
- #log0min = logmin + 0.05
- for st8 in ['none']:#ALLST8S:
- f, a = plt.subplots(figsize=figsize)
- wintitle('opto meanrate movie nat %s ONOFFTHRESH=%.2f TRANSTHRESH=%.2f'
- % (st8, ONOFFTHRESH, TRANSTHRESH))
- rons, roffs, onoffs, trans = [], [], [], []
- for mseustr in mvimseustrs:
- meanrate = mviresp.loc[mseustr, 'nat', st8]['meanrate']
- msustr = mseustr2msustr(mseustr)
- onoff = celltype.loc[msustr]['onoff']
- trans = celltype.loc[msustr]['trans']
- if meanrate.isna().any(): # missing one or both meanrates
- #print('%s: missing one or both opto conditions, skipping' % mseustr)
- continue
- rons.append(meanrate[True])
- roffs.append(meanrate[False])
- onoffs.append(onoff)
- transs.append(trans)
- #fig3.loc[mseustr, 'meanrate'] = meanrate[False], meanrate[True] # save
- rons = np.asarray(rons)
- roffs = np.asarray(roffs)
- clrs = []
- for onoff, trans in zip(onoffs, transs):
- clr = 'gray'
- if trans >= TRANSTHRESH: # first try and classify by trans
- clr = 'black'
- elif onoff >= ONOFFTHRESH: # try and classify by on/off
- clr = green
- elif onoff < -ONOFFTHRESH:
- clr = 'red'
- clrs.append(clr)
- # plot y=x line:
- xyline = [10**logmin, 10**logmax], [10**logmin, 10**logmax]
- a.plot(xyline[0], xyline[1], '--', color='gray', zorder=-1)
- # plot all points:
- a.scatter(rons, roffs, marker='.', c='None', edgecolor=clrs, s=DEFSZ)
- a.set_ylabel('Feedback FR (spk/s)')
- a.set_xlabel('Suppression FR (spk/s)')
- a.set_xscale('log')
- a.set_yscale('log')
- a.set_xlim(10**logmin, 10**logmax)
- a.set_ylim(10**logmin, 10**logmax)
- a.set_xticks(10.0**logticks)
- a.set_yticks(a.get_xticks()) # make log scale y ticks the same as x ticks
- axes_disable_scientific(a)
- a.minorticks_off()
- a.set_aspect('equal')
- #t, p = ttest_rel(rons, roffs) # paired t-test
- #a.add_artist(AnchoredText('p$=$%.2g' % p, loc='lower right', frameon=False))
- patch = Rectangle((0, 0), 0, 0)
- l = a.legend([patch, patch, patch], ['On', 'Off', 'Transient'], loc='upper left',
- handlelength=0, handletextpad=0, frameon=False)
- for t, c in zip(l.get_texts(), [green, 'red', 'black']):
- t.set_color(c)
- # scatter plot grating burst ratio, coloured by ON/OFF/transient:
- figsize = DEFAULTFIGURESIZE
- logmin, logmax = -3.55, 0
- logticks = np.array([-3, -2, -1, 0])
- for st8 in ['none']:#ALLST8S:
- f, a = plt.subplots(figsize=figsize)
- wintitle('opto burst ratio grating %s ONOFFTHRESH=%.2f TRANSTHRESH=%.2f'
- % (st8, ONOFFTHRESH, TRANSTHRESH))
- brons, broffs, onoffs, trans = [], [], [], []
- for mseustr in grtmseustrs:
- br = grtresp.loc[mseustr, st8]['meanburstratio']
- msustr = mseustr2msustr(mseustr)
- onoff = celltype.loc[msustr]['onoff']
- trans = celltype.loc[msustr]['trans']
- if br.isna().any(): # missing for at least one opto condition
- continue
- brons.append(br[True])
- broffs.append(br[False])
- onoffs.append(onoff)
- transs.append(trans)
- brons, broffs = np.asarray(brons), np.asarray(broffs)
- clrs = []
- for onoff, trans in zip(onoffs, transs):
- clr = 'gray'
- if trans >= TRANSTHRESH: # first try and classify by trans
- clr = 'black'
- elif onoff >= ONOFFTHRESH: # try and classify by on/off
- clr = green
- elif onoff < -ONOFFTHRESH:
- clr = 'red'
- clrs.append(clr)
- # plot y=x line:
- xyline = [10**logmin, 10**logmax], [10**logmin, 10**logmax]
- a.plot(xyline[0], xyline[1], '--', color='gray', zorder=-1)
- # plot all points:
- a.scatter(brons, broffs, marker='.', c='None', edgecolor=clrs, s=DEFSZ)
- a.set_xlabel('Suppression BR') # keep it short to maximize space for axes
- a.set_ylabel('Feedback BR')
- a.set_xscale('log')
- a.set_yscale('log')
- a.set_xlim(10**logmin, 10**logmax)
- a.set_ylim(10**logmin, 10**logmax)
- a.set_xticks(10.0**logticks)
- a.set_yticks(a.get_xticks()) # make log scale y ticks the same as x ticks
- a.minorticks_off()
- axes_disable_scientific(a)
- a.set_aspect('equal')
- #t, p = ttest_rel(brons, broffs) # paired t-test
- #a.add_artist(AnchoredText('p$=$%.2g' % p, loc='upper left', frameon=False))
- patch = Rectangle((0, 0), 0, 0)
- l = a.legend([patch, patch, patch], ['On', 'Off', 'Transient'], loc='upper left',
- handlelength=0, handletextpad=0, frameon=False)
- for t, c in zip(l.get_texts(), [green, 'red', 'black']):
- t.set_color(c)
- # scatter plot movie burst ratio, coloured by ON/OFF/transient:
- figsize = DEFAULTFIGURESIZE
- logmin, logmax = -3.55, 0
- logticks = np.array([-3, -2, -1, 0])
- for st8 in ['none']:#ALLST8S:
- f, a = plt.subplots(figsize=figsize)
- wintitle('opto burst ratio movie nat %s ONOFFTHRESH=%.2f TRANSTHRESH=%.2f'
- % (st8, ONOFFTHRESH, TRANSTHRESH))
- brons, broffs, onoffs, trans = [], [], [], []
- for mseustr in mvimseustrs:
- br = mviresp.loc[mseustr, 'nat', st8]['meanburstratio']
- msustr = mseustr2msustr(mseustr)
- onoff = celltype.loc[msustr]['onoff']
- trans = celltype.loc[msustr]['trans']
- if br.isna().any(): # missing for at least one opto condition
- continue
- brons.append(br[True])
- broffs.append(br[False])
- onoffs.append(onoff)
- transs.append(trans)
- #fig3.loc[mseustr, 'meanburstratio'] = br[False], br[True] # save
- brons, broffs = np.asarray(brons), np.asarray(broffs)
- for onoff, trans in zip(onoffs, transs):
- clr = 'gray'
- if trans >= TRANSTHRESH: # first try and classify by trans
- clr = 'black'
- elif onoff >= ONOFFTHRESH: # try and classify by on/off
- clr = green
- elif onoff < -ONOFFTHRESH:
- clr = 'red'
- clrs.append(clr)
- # plot y=x line:
- xyline = [10**logmin, 10**logmax], [10**logmin, 10**logmax]
- a.plot(xyline[0], xyline[1], '--', color='gray', zorder=-1)
- # plot all points:
- a.scatter(brons, broffs, marker='.', c='None', edgecolor=clrs, s=DEFSZ)
- a.set_xlabel('Suppression BR') # keep it short to maximize space for axes
- a.set_ylabel('Feedback BR')
- a.set_xscale('log')
- a.set_yscale('log')
- a.set_xlim(10**logmin, 10**logmax)
- a.set_ylim(10**logmin, 10**logmax)
- a.set_xticks(10.0**logticks)
- a.set_yticks(a.get_xticks()) # make log scale y ticks the same as x ticks
- a.minorticks_off()
- axes_disable_scientific(a)
- a.set_aspect('equal')
- #t, p = ttest_rel(brons, broffs) # paired t-test
- #a.add_artist(AnchoredText('p$=$%.2g' % p, loc='upper left', frameon=False))
- patch = Rectangle((0, 0), 0, 0)
- l = a.legend([patch, patch, patch], ['On', 'Off', 'Transient'], loc='upper left',
- handlelength=0, handletextpad=0, frameon=False)
- for t, c in zip(l.get_texts(), [green, 'red', 'black']):
- t.set_color(c)
- # scatter plot grating meanrates, coloured by distance of MUA envl RF from center of screen:
- figsize = 3.5, DEFAULTFIGURESIZE[1] #DEFAULTFIGURESIZE
- logmin, logmax = -1.2, 2
- logticks = np.array([-1, 0, 1, 2])
- #log0min = logmin + 0.05
- for st8 in ['none']:#ALLST8S:
- f, a = plt.subplots(figsize=figsize)
- wintitle('opto meanrate grating %s rfdist' % st8)
- rons, roffs, ds = [], [], []
- for mseustr in grtmseustrs:
- meanrate = grtresp.loc[mseustr, st8]['meanrate']
- msustr = mseustr2msustr(mseustr)
- x0, y0 = cellscreenpos.loc[msustr]
- d = np.sqrt(x0**2 + y0**2) # distance from screen center, deg
- if meanrate.isna().any(): # missing one or both meanrates
- #print('%s: missing one or both opto conditions, skipping' % mseustr)
- continue
- rons.append(meanrate[True])
- roffs.append(meanrate[False])
- ds.append(d)
- #fig3.loc[mseustr, 'meanrate'] = meanrate[False], meanrate[True] # save
- rons = np.asarray(rons)
- roffs = np.asarray(roffs)
- ds = np.asarray(ds)
- maxds = intround(np.nanmax(ds))
- normds = ds / maxds
- cmap = plt.get_cmap() # use default, normalized from 0 to 1
- dclrs = []
- for normd in normds:
- if np.isnan(normd):
- dclrs.append('gray')
- else:
- dclrs.append(cmap(normd))
- # plot y=x line:
- xyline = [10**logmin, 10**logmax], [10**logmin, 10**logmax]
- a.plot(xyline[0], xyline[1], '--', color='gray', zorder=-1)
- # plot all points:
- a.scatter(rons, roffs, marker='.', c='none', edgecolor=dclrs, s=DEFSZ, cmap='viridis')
- a.set_ylabel('Feedback FR (spk/s)')
- a.set_xlabel('Suppression FR (spk/s)')
- a.set_xscale('log')
- a.set_yscale('log')
- a.set_xlim(10**logmin, 10**logmax)
- a.set_ylim(10**logmin, 10**logmax)
- a.set_xticks(10.0**logticks)
- a.set_yticks(a.get_xticks()) # make log scale y ticks the same as x ticks
- axes_disable_scientific(a)
- a.minorticks_off()
- a.set_aspect('equal')
- #t, p = ttest_rel(rons, roffs) # paired t-test
- #a.add_artist(AnchoredText('p$=$%.2g' % p, loc='lower right', frameon=False))
- scalarmappable = mpl.cm.ScalarMappable(norm=None, cmap=cmap)
- scalarmappable.set_clim(0, maxds)
- f.colorbar(scalarmappable, ticks=[0, maxds], label='Dist. from center ($\degree$)')
- # scatter plot movie meanrates, coloured by distance of MUA envl RF from center of screen:
- figsize = 3.5, DEFAULTFIGURESIZE[1] #DEFAULTFIGURESIZE
- logmin, logmax = -1.2, 2
- logticks = np.array([-1, 0, 1, 2])
- #log0min = logmin + 0.05
- for st8 in ['none']:#ALLST8S:
- f, a = plt.subplots(figsize=figsize)
- wintitle('opto meanrate movie nat %s rfdist' % st8)
- rons, roffs, ds = [], [], []
- for mseustr in mvimseustrs:
- meanrate = mviresp.loc[mseustr, 'nat', st8]['meanrate']
- msustr = mseustr2msustr(mseustr)
- x0, y0 = cellscreenpos.loc[msustr]
- d = np.sqrt(x0**2 + y0**2) # distance from screen center, deg
- if meanrate.isna().any(): # missing one or both meanrates
- #print('%s: missing one or both opto conditions, skipping' % mseustr)
- continue
- rons.append(meanrate[True])
- roffs.append(meanrate[False])
- ds.append(d)
- #fig3.loc[mseustr, 'meanrate'] = meanrate[False], meanrate[True] # save
- rons = np.asarray(rons)
- roffs = np.asarray(roffs)
- ds = np.asarray(ds)
- maxds = intround(np.nanmax(ds))
- normds = ds / maxds
- cmap = plt.get_cmap() # use default, normalized from 0 to 1
- dclrs = []
- for normd in normds:
- if np.isnan(normd):
- dclrs.append('gray')
- else:
- dclrs.append(cmap(normd))
- # plot y=x line:
- xyline = [10**logmin, 10**logmax], [10**logmin, 10**logmax]
- a.plot(xyline[0], xyline[1], '--', color='gray', zorder=-1)
- # plot all points:
- a.scatter(rons, roffs, marker='.', c='None', edgecolor=dclrs, s=DEFSZ)
- a.set_ylabel('Feedback FR (spk/s)')
- a.set_xlabel('Suppression FR (spk/s)')
- a.set_xscale('log')
- a.set_yscale('log')
- a.set_xlim(10**logmin, 10**logmax)
- a.set_ylim(10**logmin, 10**logmax)
- a.set_xticks(10.0**logticks)
- a.set_yticks(a.get_xticks()) # make log scale y ticks the same as x ticks
- axes_disable_scientific(a)
- a.minorticks_off()
- a.set_aspect('equal')
- #t, p = ttest_rel(rons, roffs) # paired t-test
- #a.add_artist(AnchoredText('p$=$%.2g' % p, loc='lower right', frameon=False))
- scalarmappable = mpl.cm.ScalarMappable(norm=None, cmap=cmap)
- scalarmappable.set_clim(0, maxds)
- f.colorbar(scalarmappable, ticks=[0, maxds], label='Dist. from center ($\degree$)')
- # scatter plot grating burst ratio, coloured by distance of MUA envl RF from center of screen:
- figsize = 3.6, DEFAULTFIGURESIZE[1] #DEFAULTFIGURESIZE
- logmin, logmax = -3.55, 0
- logticks = np.array([-3, -2, -1, 0])
- for st8 in ['none']:#ALLST8S:
- f, a = plt.subplots(figsize=figsize)
- wintitle('opto burst ratio grating %s rfdist' % st8)
- brons, broffs, ds = [], [], []
- for mseustr in grtmseustrs:
- br = grtresp.loc[mseustr, st8]['meanburstratio']
- msustr = mseustr2msustr(mseustr)
- x0, y0 = cellscreenpos.loc[msustr]
- d = np.sqrt(x0**2 + y0**2) # distance from screen center, deg
- if br.isna().any(): # missing for at least one opto condition
- continue
- brons.append(br[True])
- broffs.append(br[False])
- ds.append(d)
- #fig3.loc[mseustr, 'meanburstratio'] = br[False], br[True] # save
- brons, broffs, ds = np.asarray(brons), np.asarray(broffs), np.asarray(ds)
- maxds = intround(np.nanmax(ds))
- normds = ds / maxds
- cmap = plt.get_cmap() # use default, normalized from 0 to 1
- dclrs = []
- for normd in normds:
- if np.isnan(normd):
- dclrs.append('gray')
- else:
- dclrs.append(cmap(normd))
- # plot y=x line:
- xyline = [10**logmin, 10**logmax], [10**logmin, 10**logmax]
- a.plot(xyline[0], xyline[1], '--', color='gray', zorder=-1)
- # plot all points:
- a.scatter(brons, broffs, marker='.', c='None', edgecolor=dclrs, s=DEFSZ)
- a.set_xlabel('Suppression BR') # keep it short to maximize space for axes
- a.set_ylabel('Feedback BR')
- a.set_xscale('log')
- a.set_yscale('log')
- a.set_xlim(10**logmin, 10**logmax)
- a.set_ylim(10**logmin, 10**logmax)
- a.set_xticks(10.0**logticks)
- a.set_yticks(a.get_xticks()) # make log scale y ticks the same as x ticks
- a.minorticks_off()
- axes_disable_scientific(a)
- a.set_aspect('equal')
- #t, p = ttest_rel(brons, broffs) # paired t-test
- #a.add_artist(AnchoredText('p$=$%.2g' % p, loc='upper left', frameon=False))
- scalarmappable = mpl.cm.ScalarMappable(norm=None, cmap=cmap)
- scalarmappable.set_clim(0, maxds)
- f.colorbar(scalarmappable, ticks=[0, maxds], label='Dist. from center ($\degree$)')
- # scatter plot movie burst ratio, coloured by distance of MUA envl RF from center of screen:
- figsize = 3.6, DEFAULTFIGURESIZE[1] #DEFAULTFIGURESIZE
- logmin, logmax = -3.55, 0
- logticks = np.array([-3, -2, -1, 0])
- for st8 in ['none']:#ALLST8S:
- f, a = plt.subplots(figsize=figsize)
- wintitle('opto burst ratio movie nat %s rfdist' % st8)
- brons, broffs, ds = [], [], []
- for mseustr in mvimseustrs:
- br = mviresp.loc[mseustr, 'nat', st8]['meanburstratio']
- msustr = mseustr2msustr(mseustr)
- x0, y0 = cellscreenpos.loc[msustr]
- d = np.sqrt(x0**2 + y0**2) # distance from screen center, deg
- if br.isna().any(): # missing for at least one opto condition
- continue
- brons.append(br[True])
- broffs.append(br[False])
- ds.append(d)
- #fig3.loc[mseustr, 'meanburstratio'] = br[False], br[True] # save
- brons, broffs, ds = np.asarray(brons), np.asarray(broffs), np.asarray(ds)
- maxds = intround(np.nanmax(ds))
- normds = ds / maxds
- cmap = plt.get_cmap() # use default, normalized from 0 to 1
- dclrs = []
- for normd in normds:
- if np.isnan(normd):
- dclrs.append('gray')
- else:
- dclrs.append(cmap(normd))
- # plot y=x line:
- xyline = [10**logmin, 10**logmax], [10**logmin, 10**logmax]
- a.plot(xyline[0], xyline[1], '--', color='gray', zorder=-1)
- # plot all points:
- a.scatter(brons, broffs, marker='.', c='None', edgecolor=dclrs, s=DEFSZ)
- a.set_xlabel('Suppression BR') # keep it short to maximize space for axes
- a.set_ylabel('Feedback BR')
- a.set_xscale('log')
- a.set_yscale('log')
- a.set_xlim(10**logmin, 10**logmax)
- a.set_ylim(10**logmin, 10**logmax)
- a.set_xticks(10.0**logticks)
- a.set_yticks(a.get_xticks()) # make log scale y ticks the same as x ticks
- a.minorticks_off()
- axes_disable_scientific(a)
- a.set_aspect('equal')
- #t, p = ttest_rel(brons, broffs) # paired t-test
- #a.add_artist(AnchoredText('p$=$%.2g' % p, loc='upper left', frameon=False))
- scalarmappable = mpl.cm.ScalarMappable(norm=None, cmap=cmap)
- scalarmappable.set_clim(0, maxds)
- f.colorbar(scalarmappable, ticks=[0, maxds], label='Dist. from center ($\degree$)')
- '''
|