functions.py 163 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791
  1. # -*- coding: utf-8 -*-
  2. """
  3. Created on Fri Mar 12 11:35:33 2021
  4. @author: User
  5. """
  6. import numpy as np
  7. import matplotlib.pyplot as plt
  8. import scipy.io as sio
  9. from scipy.stats import ranksums, pearsonr, sem, wilcoxon
  10. import addcopyfighandler
  11. import matplotlib.cm as cm
  12. from brian2 import ms, psiemens
  13. import matplotlib.colors as nc
  14. import matplotlib as mpl
  15. from mpl_toolkits.axes_grid1 import make_axes_locatable
  16. from scipy.interpolate import interp2d
  17. mpl.rcParams['font.sans-serif'] = "Arial"
  18. mpl.rcParams['font.family'] = "sans-serif"
  19. mpl.rcParams['font.size'] = 8
  20. mpl.rcParams["xtick.direction"] = "in"
  21. mpl.rcParams["ytick.direction"] = "in"
  22. mpl.rcParams["legend.markerscale"] = 0.9
  23. def simulations(N_units,coefC=0,d_LF=0):
  24. # run 6 simulations varying context and probes
  25. # outputs:
  26. # spike counts of probes
  27. # firing rate during maskers
  28. probe=np.repeat(range(1,N_units+1),20)
  29. masker=np.repeat(range(1,N_units+1),20)
  30. # SIMULATION 1: navigation - after silence
  31. context=0
  32. exp=1
  33. exec(open("./input.py").read())
  34. exec(open("./model.py").read())
  35. col=spike_counts(ac,onset,context)
  36. probe=np.column_stack((probe, col))
  37. # SIMULATION 2: communication - after silence
  38. exp=2
  39. exec(open("./input.py").read())
  40. exec(open("./model.py").read())
  41. col=spike_counts(ac,onset,context)
  42. probe=np.column_stack((probe, col))
  43. # SIMULATION 3: navigation - navigation context
  44. context=1
  45. exp=1
  46. exec(open("./input.py").read())
  47. exec(open("./model.py").read())
  48. col=spike_counts(ac,onset,context)
  49. probe=np.column_stack((probe, col))
  50. col=firing_context(ac,onset,context)
  51. colLF=firing_context(sp_low,onset,context)
  52. colHF=firing_context(sp_high,onset,context)
  53. masker=np.column_stack((masker, col))
  54. masker=np.column_stack((masker, colLF))
  55. masker=np.column_stack((masker, colHF))
  56. # SIMULATION 4: communication - navigation context
  57. exp=2
  58. exec(open("./input.py").read())
  59. exec(open("./model.py").read())
  60. col=spike_counts(ac,onset,context)
  61. probe=np.column_stack((probe, col))
  62. # SIMULATION 5: navigation - communication context
  63. context=2
  64. exp=1
  65. exec(open("./input.py").read())
  66. exec(open("./model.py").read())
  67. col=spike_counts(ac,onset,context)
  68. probe=np.column_stack((probe, col))
  69. col=firing_context(ac,onset,context)
  70. colLF=firing_context(sp_low,onset,context)
  71. colHF=firing_context(sp_high,onset,context)
  72. masker=np.column_stack((masker, col))
  73. masker=np.column_stack((masker, colLF))
  74. masker=np.column_stack((masker, colHF))
  75. # SIMULATION 6: communication - communication context
  76. exp=2
  77. exec(open("./input.py").read())
  78. exec(open("./model.py").read())
  79. col=spike_counts(ac,onset,context)
  80. probe=np.column_stack((probe, col))
  81. return probe,masker
  82. def spike_counts(ac,onset,context):
  83. # spike counts 50 ms after probe onset per trial
  84. spike_trains = ac.spike_trains()
  85. L=len(spike_trains)
  86. output=[]
  87. for u in range(L):
  88. spikes_i = np.asarray(spike_trains[u])*1000
  89. spikes_i = spikes_i[spikes_i>onset[context]]
  90. output.append(len(spikes_i))
  91. return output
  92. def firing_context(ac,onset,context):
  93. # firing rate (#sp/sec) during the context sequences per trial
  94. preT=onset[0]
  95. dur=[1.3311*1000, 1.9266*1000]
  96. spike_trains = ac.spike_trains()
  97. L=len(spike_trains)
  98. output=[]
  99. for u in range(L):
  100. spikes_i = np.asarray(spike_trains[u])*1000
  101. spikes_i = spikes_i[spikes_i>preT]
  102. spikes_i = spikes_i[spikes_i<preT+dur[context-1]]
  103. output.append(len(spikes_i)) #/(dur[context-1]/1000)
  104. return output
  105. def context_effect(sp):
  106. # calculate context effect (c.e.) for each combination per unit
  107. trials=20
  108. N_units=int(len(sp)/trials)
  109. # separate spike counts per protocol
  110. nav_iso=sp[:,1]
  111. com_iso=sp[:,2]
  112. nav_c1=sp[:,3]
  113. com_c1=sp[:,4]
  114. nav_c2=sp[:,5]
  115. com_c2=sp[:,6]
  116. # calculate mean across trials
  117. nav_iso=np.mean(nav_iso.reshape(N_units,trials),axis=1)
  118. com_iso=np.mean(com_iso.reshape(N_units,trials),axis=1)
  119. nav_c1=np.mean(nav_c1.reshape(N_units,trials),axis=1)
  120. com_c1=np.mean(com_c1.reshape(N_units,trials),axis=1)
  121. nav_c2=np.mean(nav_c2.reshape(N_units,trials),axis=1)
  122. com_c2=np.mean(com_c2.reshape(N_units,trials),axis=1)
  123. # calculate context with mean spikes counts
  124. ce_nav_exp=(nav_c1-nav_iso)/(nav_c1+nav_iso)
  125. ce_nav_unexp=(com_c1-com_iso)/(com_c1+com_iso)
  126. ce_com_exp=(com_c2-com_iso)/(com_c2+com_iso)
  127. ce_com_unexp=(nav_c2-nav_iso)/(nav_c2+nav_iso)
  128. output=np.column_stack((ce_nav_exp, ce_nav_unexp, ce_com_exp,ce_com_unexp))
  129. return output
  130. def firing_rate_masker(sp):
  131. # average firing rate (#sp/sec) during the context sequences per unit
  132. trials=20
  133. N_units=int(len(sp)/trials)
  134. if len(sp[0])==3:
  135. # separate rate per masker
  136. nav=sp[:,1]
  137. com=sp[:,2]
  138. # separate rate counts per unit
  139. nav=np.mean(nav.reshape(N_units,trials),axis=1)
  140. com=np.mean(com.reshape(N_units,trials),axis=1)
  141. output=np.column_stack((nav, com))
  142. elif len(sp[0])==7:
  143. # separate rate per masker
  144. nav=sp[:,1]
  145. lf_nav=sp[:,2]
  146. hf_nav=sp[:,3]
  147. com=sp[:,4]
  148. lf_com=sp[:,5]
  149. hf_com=sp[:,6]
  150. # separate rate counts per unit
  151. nav=np.mean(nav.reshape(N_units,trials),axis=1)
  152. lf_nav=np.mean(lf_nav.reshape(N_units,trials),axis=1)
  153. hf_nav=np.mean(hf_nav.reshape(N_units,trials),axis=1)
  154. com=np.mean(com.reshape(N_units,trials),axis=1)
  155. lf_com=np.mean(lf_com.reshape(N_units,trials),axis=1)
  156. hf_com=np.mean(hf_com.reshape(N_units,trials),axis=1)
  157. output=np.column_stack((nav,lf_nav,hf_nav,com,lf_com,hf_com))
  158. return output
  159. def one_simulation(N_units,context=0):
  160. # run 2 simulations varying context
  161. # outputs: raster plot and synaptic depression
  162. # SIMULATION 1: navigation - context
  163. exp=1
  164. exec(open("./input.py").read())
  165. exec(open("./model.py").read())
  166. mpl.rcParams["xtick.direction"] = "out"
  167. mpl.rcParams["ytick.direction"] = "out"
  168. fig, ax = plt.subplots(3,2,sharex=True,sharey=True,figsize=(4,2.5))
  169. ax[0,0].scatter(sp_low.t, sp_low.i,s=0.5,c='r',edgecolors='none')
  170. ax[1,0].scatter(sp_high.t, sp_high.i,s=0.5,c='b',edgecolors='none')
  171. ax[2,0].scatter(ac.t, ac.i,s=0.5,c='gray',edgecolors='none')
  172. ax[0,0].set_ylabel('LF trials')
  173. ax[1,0].set_ylabel('HF trials')
  174. ax[2,0].set_ylabel('cortical trials')
  175. ax[2,0].set_xlabel('Time (s)')
  176. # average presynaptic adaptation across trials
  177. h=N_units*20
  178. dt_=0.1
  179. nav_presyn=mon.x_S
  180. nav_high=nav_presyn[h:]
  181. nav_low=nav_presyn[:h]
  182. nav_pre_high=np.mean(nav_high,0)
  183. nav_pre_low=np.mean(nav_low,0)
  184. # average postsynaptic adaptation across trials
  185. nav_postsyn=pos.V_th*1000 # to mV
  186. nav_post=np.mean(nav_postsyn,0)
  187. # plotting synaptic depression
  188. ax2 = ax[0,0].twinx()
  189. ax2.plot(mon.t, nav_pre_low,color='r',linewidth=0.75)
  190. ax2.set_ylim(0.1,1.01)
  191. for tl in ax2.get_yticklabels():
  192. tl.set_color('r')
  193. ax3 = ax[1,0].twinx()
  194. ax3.plot(mon.t, nav_pre_high,color='b',linewidth=0.75)
  195. ax3.set_ylim(0.1,1.01)
  196. for tl in ax3.get_yticklabels():
  197. tl.set_color('b')
  198. # plotting postsynaptic adaptation
  199. ax4 = ax[2,0].twinx()
  200. ax4.plot(pos.t, nav_post,color='k',linewidth=0.75)
  201. ax4.set_ylim(-50,-40)
  202. fig2, axz = plt.subplots(1,1,figsize=(1,1))
  203. axz.hist(ac.t/ms,bins=50,range=(onset[context],onset[context]++50),rwidth=0.8,color='k')
  204. axz.xaxis.set_visible(False)
  205. axz.yaxis.set_visible(False)
  206. axz.patch.set_facecolor('blue')
  207. axz.patch.set_alpha(0.2)
  208. axz.set_ylim(0,15)
  209. fig2.tight_layout()
  210. # SIMULATION 2: navigation - context
  211. exp=2
  212. exec(open("./input.py").read())
  213. exec(open("./model.py").read())
  214. ax[0,1].scatter(sp_low.t, sp_low.i,s=0.5,c='r',edgecolors='none')
  215. ax[1,1].scatter(sp_high.t, sp_high.i,s=0.5,c='b',edgecolors='none')
  216. ax[2,1].scatter(ac.t, ac.i,s=0.5,c='gray',edgecolors='none')
  217. ax[2,1].set_xlabel('Time (s)')
  218. # average presynaptic adaptation across trials
  219. h=N_units*20
  220. nav_presyn=mon.x_S
  221. nav_high=nav_presyn[h:]
  222. nav_low=nav_presyn[:h]
  223. nav_pre_high=np.mean(nav_high,0)
  224. nav_pre_low=np.mean(nav_low,0)
  225. # average postsynaptic adaptation across trials
  226. com_postsyn=pos.V_th*1000 # to mV
  227. com_post=np.mean(com_postsyn,0)
  228. # plotting synaptic depression
  229. ax4 = ax[0,1].twinx()
  230. ax4.plot(mon.t, nav_pre_low,color='r',linewidth=0.75)
  231. ax4.set_ylim(0.1,1.01)
  232. ax4.set_ylabel('strength\n' + r'LF$_{\rm syn}$', color='r')
  233. for tl in ax4.get_yticklabels():
  234. tl.set_color('r')
  235. ax5 = ax[1,1].twinx()
  236. ax5.plot(mon.t,nav_pre_high,color='b',linewidth=0.75)
  237. ax5.set_ylim(0.1,1.01)
  238. ax5.set_ylabel('strength\n' + r'HF$_{\rm syn}$', color='b')
  239. for tl in ax5.get_yticklabels():
  240. tl.set_color('b')
  241. # plotting postsynaptic adaptation
  242. ax6 = ax[2,1].twinx()
  243. ax6.plot(pos.t,com_post,color='k',linewidth=0.75)
  244. ax6.set_ylim(-50,-40)
  245. ax6.set_ylabel('spiking\n' + 'threshold', color='k')
  246. ax = ax.flatten()
  247. for axi in ax:
  248. axi.spines['top'].set_visible(False)
  249. axi.spines['right'].set_visible(False)
  250. ax2.spines['top'].set_visible(False)
  251. ax3.spines['top'].set_visible(False)
  252. ax4.spines['top'].set_visible(False)
  253. ax5.spines['top'].set_visible(False)
  254. fig.tight_layout(w_pad=3,h_pad=0.1)
  255. fig3, axe = plt.subplots(1,1,figsize=(1,1))
  256. axe.hist(ac.t/ms,bins=50,range=(onset[context],onset[context]++50),rwidth=0.8,color='k')
  257. axe.xaxis.set_visible(False)
  258. axe.yaxis.set_visible(False)
  259. axe.patch.set_facecolor('red')
  260. axe.patch.set_alpha(0.2)
  261. axe.set_ylim(0,15)
  262. fig3.tight_layout()
  263. return fig, fig2, fig3
  264. def di_2parameters(sims):
  265. # import experimental data - cliff delta values for 45 units
  266. mat_contents = sio.loadmat(r'E:\Users\User\Documents\model-context\cliff_data-416.mat')
  267. a=mat_contents['cliff_data']
  268. exp_data_iso = a[:,0]
  269. exp_data_nav = a[:,1]
  270. exp_data_com = a[:,2]
  271. del mat_contents
  272. del a
  273. parameters1=sims[0]
  274. parameters2=sims[1]
  275. sims = np.delete(sims,[0,1], 0)
  276. ntrials=len(sims[0])
  277. nx=len(parameters1)
  278. ny=len(parameters2)
  279. ntot=nx*ny
  280. N_units=ntrials/20
  281. # calculate cliff delta from simulations per unit
  282. sims_iso=[]
  283. sims_nav=[]
  284. sims_com=[]
  285. stats_iso=[]
  286. stats_nav=[]
  287. stats_com=[]
  288. for s in range(ntot):
  289. s_i=sims[s]
  290. units_iso=[]
  291. units_nav=[]
  292. units_com=[]
  293. for u in range(int(N_units)):
  294. sp_e=s_i[20*u:20*u+20,1]
  295. sp_d=s_i[20*u:20*u+20,2]
  296. c,size = cliffsDelta(sp_e, sp_d)
  297. units_iso.append(c)
  298. sp_e=s_i[20*u:20*u+20,3]
  299. sp_d=s_i[20*u:20*u+20,4]
  300. c,size = cliffsDelta(sp_e, sp_d)
  301. units_nav.append(c)
  302. sp_e=s_i[20*u:20*u+20,5]
  303. sp_d=s_i[20*u:20*u+20,6]
  304. c,size = cliffsDelta(sp_e, sp_d)
  305. units_com.append(c)
  306. sims_iso.append(units_iso)
  307. sims_nav.append(units_nav)
  308. sims_com.append(units_com)
  309. # check for fitting experimental data
  310. H,p=ranksums(units_iso, exp_data_iso)
  311. if p>0.05: # equal distributions
  312. stats_iso.append(1)
  313. else:
  314. stats_iso.append(0)
  315. H,p=ranksums(units_nav, exp_data_nav)
  316. if p>0.05: # equal distributions
  317. stats_nav.append(1)
  318. else:
  319. stats_nav.append(0)
  320. H,p=ranksums(units_com, exp_data_com)
  321. if p>0.05: # equal distributions
  322. stats_com.append(1)
  323. else:
  324. stats_com.append(0)
  325. # avearage cliff delta across units
  326. av_iso=np.mean(sims_iso,1)
  327. av_nav=np.mean(sims_nav,1)
  328. av_com=np.mean(sims_com,1)
  329. # convert into 2D matrix results and stats
  330. av_iso=np.reshape(av_iso,(nx,ny)).T
  331. av_nav=np.reshape(av_nav,(nx,ny)).T
  332. av_com=np.reshape(av_com,(nx,ny)).T
  333. stats_iso=np.reshape(stats_iso,(nx,ny)).T
  334. stats_nav=np.reshape(stats_nav,(nx,ny)).T
  335. stats_com=np.reshape(stats_com,(nx,ny)).T
  336. # plotting
  337. fig, ax = plt.subplots(1,3,sharex=True,sharey=True,figsize=(6.5,2.5))
  338. li=0.5 # min and max of colorbar
  339. min_x=min(parameters1)-((parameters1[1]-parameters1[0])/2)
  340. max_x=max(parameters1)+((parameters1[1]-parameters1[0])/2)
  341. min_y=min(parameters2)-((parameters2[1]-parameters2[0])/2)
  342. max_y=max(parameters2)+((parameters2[1]-parameters2[0])/2)
  343. x_iso=np.nonzero(stats_iso)[1]
  344. y_iso=np.nonzero(stats_iso)[0]
  345. ax[0].imshow(av_iso,cmap='RdBu',origin='lower',vmin=-li,vmax=li,extent=[min_x,max_x,min_y,max_y])
  346. ax[0].scatter(parameters1[x_iso],parameters2[y_iso], s=5, c='k', marker="*")
  347. x_nav=np.nonzero(stats_nav)[1]
  348. y_nav=np.nonzero(stats_nav)[0]
  349. ax[1].imshow(av_nav,cmap='RdBu',origin='lower',vmin=-li,vmax=li,extent=[min_x,max_x,min_y,max_y])
  350. ax[1].scatter(parameters1[x_nav],parameters2[y_nav], s=5, c='k', marker="*")
  351. x_com=np.nonzero(stats_com)[1]
  352. y_com=np.nonzero(stats_com)[0]
  353. ax[2].imshow(av_com,cmap='RdBu',origin='lower',vmin=-li,vmax=li,extent=[min_x,max_x,min_y,max_y])
  354. ax[2].scatter(parameters1[x_com],parameters2[y_com], s=5, c='k', marker="*")
  355. # set which combination satisfy all the contexts
  356. xy_iso=np.array(list(zip(x_iso,y_iso)))
  357. xy_nav=np.array(list(zip(x_nav,y_nav)))
  358. xy_com=np.array(list(zip(x_com,y_com)))
  359. combi = np.array([x for x in set(tuple(x) for x in xy_nav) & set(tuple(x) for x in xy_com)])
  360. combi = np.array([x for x in set(tuple(x) for x in combi) & set(tuple(x) for x in xy_iso)])
  361. ax[0].scatter(parameters1[combi[:,0]],parameters2[combi[:,1]], s=50, facecolors='none', edgecolors='k')
  362. ax[1].scatter(parameters1[combi[:,0]],parameters2[combi[:,1]], s=50, facecolors='none', edgecolors='k')
  363. ax[2].scatter(parameters1[combi[:,0]],parameters2[combi[:,1]], s=50, facecolors='none', edgecolors='k')
  364. return fig
  365. def cliffsDelta(lst1, lst2, **dull):
  366. """Returns delta and true if there are more than 'dull' differences"""
  367. if not dull:
  368. dull = {'small': 0.147, 'medium': 0.33, 'large': 0.474} # effect sizes from (Hess and Kromrey, 2004)
  369. m, n = len(lst1), len(lst2)
  370. lst2 = sorted(lst2)
  371. j = more = less = 0
  372. for repeats, x in runs(sorted(lst1)):
  373. while j <= (n - 1) and lst2[j] < x:
  374. j += 1
  375. more += j*repeats
  376. while j <= (n - 1) and lst2[j] == x:
  377. j += 1
  378. less += (n - j)*repeats
  379. d = (more - less) / (m*n)
  380. size = lookup_size(d, dull)
  381. return d, size
  382. def lookup_size(delta: float, dull: dict) -> str:
  383. """
  384. :type delta: float
  385. :type dull: dict, a dictionary of small, medium, large thresholds.
  386. """
  387. delta = abs(delta)
  388. if delta < dull['small']:
  389. return 'negligible'
  390. if dull['small'] <= delta < dull['medium']:
  391. return 'small'
  392. if dull['medium'] <= delta < dull['large']:
  393. return 'medium'
  394. if delta >= dull['large']:
  395. return 'large'
  396. def runs(lst):
  397. """Iterator, chunks repeated values"""
  398. for j, two in enumerate(lst):
  399. if j == 0:
  400. one, i = two, 0
  401. if one != two:
  402. yield j - i, one
  403. i = j
  404. one = two
  405. yield j - i + 1, two
  406. def context_effect_trial(sp):
  407. # calculate context effect (c.e.) for each combination per trial
  408. trials=20
  409. N_units=int(len(sp)/trials)
  410. # separate spike counts per protocol
  411. nav_iso=sp[:,1]
  412. com_iso=sp[:,2]
  413. nav_c1=sp[:,3]
  414. com_c1=sp[:,4]
  415. nav_c2=sp[:,5]
  416. com_c2=sp[:,6]
  417. # calculate mean across trials for isolation only
  418. nav_iso=np.mean(nav_iso.reshape(N_units,trials),axis=1)
  419. com_iso=np.mean(com_iso.reshape(N_units,trials),axis=1)
  420. nav_iso=np.repeat(nav_iso,trials)
  421. com_iso=np.repeat(com_iso,trials)
  422. # calculate context with spikes counts per trial
  423. ce_nav_exp=(nav_c1-nav_iso)/(nav_c1+nav_iso)
  424. ce_nav_unexp=(com_c1-com_iso)/(com_c1+com_iso)
  425. ce_com_exp=(com_c2-com_iso)/(com_c2+com_iso)
  426. ce_com_unexp=(nav_c2-nav_iso)/(nav_c2+nav_iso)
  427. output=np.column_stack((ce_nav_exp, ce_nav_unexp, ce_com_exp,ce_com_unexp))
  428. return output
  429. def plot_sp_vs_supp(sims):
  430. parameters=sims[0]
  431. sims = np.delete(sims,[0], 0)
  432. ntot=len(parameters)
  433. colors = cm.rainbow(np.linspace(0, 1, ntot))
  434. all_simulations=np.empty((0,6), int)
  435. fig=plt.figure(1,figsize=(6,3.5))
  436. ax = plt.gca()
  437. size=2
  438. A=-100
  439. Ny=80
  440. ny=-50
  441. Cy=100
  442. cy=-50
  443. nx=10
  444. Nx=150
  445. cx=280 #510
  446. Cx=545
  447. for sim in range(ntot):
  448. temp=sims[sim]
  449. all_simulations=np.row_stack((all_simulations,temp))
  450. ce_nav_exp=temp[:,0]
  451. ce_nav_unexp=temp[:,1]
  452. ce_com_exp=temp[:,2]
  453. ce_com_unexp=temp[:,3]
  454. rate_nav=temp[:,4]
  455. rate_com=temp[:,5]
  456. ax=plt.subplot(2,2,1)
  457. ax.scatter(rate_nav,A*ce_nav_exp,size,color=colors[sim])
  458. ax.set_ylim(ny, Ny)
  459. ax.set_xlim(nx, Nx)
  460. ax=plt.subplot(2,2,2)
  461. ax.scatter(rate_nav,A*ce_nav_unexp,size,color=colors[sim])
  462. ax.set_ylim(ny, Ny)
  463. ax.set_xlim(nx, Nx)
  464. ax.set_yticks([])
  465. ax=plt.subplot(2,2,3)
  466. ax.scatter(rate_com,A*ce_com_exp,size,color=colors[sim])
  467. ax.set_ylim(cy, Cy)
  468. ax.set_xlim(cx, Cx)
  469. ax=plt.subplot(2,2,4)
  470. ax.scatter(rate_com,A*ce_com_unexp,size,color=colors[sim])
  471. ax.set_ylim(cy, Cy)
  472. ax.set_xlim(cx, Cx)
  473. ax.set_yticks([])
  474. R1,p1=pearsonr(all_simulations[:,4],A*all_simulations[:,0])
  475. R2,p2=pearsonr(all_simulations[:,4],A*all_simulations[:,1])
  476. R3,p3=pearsonr(all_simulations[:,5],A*all_simulations[:,2])
  477. R4,p4=pearsonr(all_simulations[:,5],A*all_simulations[:,3])
  478. ax=plt.subplot(2,2,1)
  479. ax.text(100,-40,str(round(p1, 2))) #9
  480. print(R1)
  481. fit_lin=np.poly1d(np.polyfit(all_simulations[:,4],A*all_simulations[:,0], 1))
  482. ax.plot(all_simulations[:,4],fit_lin(all_simulations[:,4]),'k',linewidth=0.75)
  483. ax.spines['right'].set_visible(False)
  484. ax.spines['top'].set_visible(False)
  485. ax.yaxis.set_ticks_position('left')
  486. ax.xaxis.set_ticks_position('bottom')
  487. ax.spines['bottom'].set_linewidth(1.5)
  488. ax.spines['left'].set_linewidth(1.5)
  489. ax=plt.subplot(2,2,2)
  490. ax.text(100,-40,str(round(p2, 2)))
  491. fit_lin=np.poly1d(np.polyfit(all_simulations[:,4],A*all_simulations[:,1], 1))
  492. ax.plot(all_simulations[:,4],fit_lin(all_simulations[:,4]),'k',linewidth=0.75)
  493. ax.spines['right'].set_visible(False)
  494. ax.spines['top'].set_visible(False)
  495. ax.yaxis.set_ticks_position('left')
  496. ax.xaxis.set_ticks_position('bottom')
  497. ax.spines['bottom'].set_linewidth(1.5)
  498. ax.spines['left'].set_linewidth(1.5)
  499. ax=plt.subplot(2,2,3)
  500. ax.text(530,-40,str(round(p3, 105)))
  501. fit_lin=np.poly1d(np.polyfit(all_simulations[:,5],A*all_simulations[:,2], 1))
  502. ax.plot(all_simulations[:,5],fit_lin(all_simulations[:,5]),'k',linewidth=0.75)
  503. ax.spines['right'].set_visible(False)
  504. ax.spines['top'].set_visible(False)
  505. ax.yaxis.set_ticks_position('left')
  506. ax.xaxis.set_ticks_position('bottom')
  507. ax.spines['bottom'].set_linewidth(1.5)
  508. ax.spines['left'].set_linewidth(1.5)
  509. ax=plt.subplot(2,2,4)
  510. ax.text(530,-40,str(round(p4, 48)))
  511. fit_lin=np.poly1d(np.polyfit(all_simulations[:,5],A*all_simulations[:,3], 1))
  512. ax.plot(all_simulations[:,5],fit_lin(all_simulations[:,5]),'k',linewidth=0.75)
  513. ax.spines['right'].set_visible(False)
  514. ax.spines['top'].set_visible(False)
  515. ax.yaxis.set_ticks_position('left')
  516. ax.xaxis.set_ticks_position('bottom')
  517. ax.spines['bottom'].set_linewidth(1.5)
  518. ax.spines['left'].set_linewidth(1.5)
  519. return fig
  520. def plot_delays_di(sims):
  521. parameters1=sims[0]
  522. sims = np.delete(sims,0, 0)
  523. ntrials=len(sims[0])
  524. ntot=len(parameters1)
  525. N_units=ntrials/20
  526. # calculate cliff delta from simulations per unit
  527. sims_iso=[]
  528. sims_nav=[]
  529. sims_com=[]
  530. for s in range(ntot):
  531. s_i=sims[s]
  532. units_iso=[]
  533. units_nav=[]
  534. units_com=[]
  535. for u in range(int(N_units)):
  536. sp_e=s_i[20*u:20*u+20,1]
  537. sp_d=s_i[20*u:20*u+20,2]
  538. c,size = cliffsDelta(sp_e, sp_d)
  539. units_iso.append(c)
  540. sp_e=s_i[20*u:20*u+20,3]
  541. sp_d=s_i[20*u:20*u+20,4]
  542. c,size = cliffsDelta(sp_e, sp_d)
  543. units_nav.append(c)
  544. sp_e=s_i[20*u:20*u+20,5]
  545. sp_d=s_i[20*u:20*u+20,6]
  546. c,size = cliffsDelta(sp_e, sp_d)
  547. units_com.append(c)
  548. sims_iso.append(units_iso)
  549. sims_nav.append(units_nav)
  550. sims_com.append(units_com)
  551. # plotting mean and error
  552. iso=np.mean(sims_iso,1)
  553. nav=np.mean(sims_nav,1)
  554. com=np.mean(sims_com,1)
  555. yiso=np.std(sims_iso,1)
  556. ynav=np.std(sims_nav,1)
  557. ycom=np.std(sims_com,1)
  558. pvalues_n=[]
  559. pvalues_c=[]
  560. for i in range(ntot):
  561. w_n, p_n = ranksums(np.asarray(sims_iso).flatten(),sims_nav[i])
  562. w_c, p_c = ranksums(np.asarray(sims_iso).flatten(),sims_com[i])
  563. pvalues_n.append(p_n)
  564. pvalues_c.append(p_c)
  565. print(p_c)
  566. pvalues=np.column_stack((pvalues_n, pvalues_c))
  567. np.save('pvalues_di',pvalues)
  568. fig, ax = plt.subplots(2,1,sharex=True,sharey=True,figsize=(2.3,2.2))
  569. ax[0].plot(parameters1,iso,color='k',lw=0.75)
  570. ax[0].plot(parameters1,iso,'.',markersize=3,color='k')
  571. ax[0].fill_between(parameters1, iso-yiso, iso+yiso ,alpha=0.3, facecolor='k')
  572. ax[1].plot(parameters1,nav,color='b',lw=0.75)
  573. ax[1].plot(parameters1,nav,'.',markersize=3,color='b')
  574. ax[1].fill_between(parameters1, nav-ynav, nav+ynav ,alpha=0.3, facecolor='b')
  575. ax[1].plot(parameters1,com,color='r',lw=0.75)
  576. ax[1].plot(parameters1,com,'.',markersize=3,color='r')
  577. ax[1].fill_between(parameters1, com-yiso, com+ycom ,alpha=0.3, facecolor='r')
  578. ax[1].axhline(y=0,color='k',lw=0.5,ls='--')
  579. ## add the real data
  580. # import experimental data - cliff delta values for 45 units
  581. mat_contents = sio.loadmat(r'E:\Users\User\Documents\model-context\cliff_data.mat')
  582. a=mat_contents['cliff_data']
  583. data_iso = np.mean(a[:,0])
  584. data_nav = np.mean(a[:,1])
  585. data_com = np.mean(a[:,2])
  586. ydata_iso = np.std(a[:,0])
  587. ydata_nav = np.std(a[:,1])
  588. ydata_com = np.std(a[:,2])
  589. del mat_contents
  590. del a
  591. # import experimental data - cliff delta values for 45 units
  592. mat_contents = sio.loadmat(r'E:\Users\User\Documents\model-context\cliff_data-416.mat')
  593. a=mat_contents['cliff_data']
  594. data_iso_416 = np.mean(a[:,0])
  595. data_nav_416 = np.mean(a[:,1])
  596. data_com_416 = np.mean(a[:,2])
  597. ydata_iso_416 = np.std(a[:,0])
  598. ydata_nav_416 = np.std(a[:,1])
  599. ydata_com_416 = np.std(a[:,2])
  600. del mat_contents
  601. del a
  602. ax[0].errorbar([60,416],[data_iso, data_iso_416], yerr=[ydata_iso, ydata_iso_416], fmt='o',color='k', mfc='w',ms=4)
  603. ax[0].set_ylim(-1,0.5)
  604. ax[1].errorbar([60,416],[data_nav, data_nav_416], yerr=[ydata_nav, ydata_nav_416], fmt='o',color='b', mfc='w',ms=4)
  605. ax[1].errorbar([60,416],[data_com, data_com_416], yerr=[ydata_com, ydata_com_416], fmt='o',color='r', mfc='w',ms=4)
  606. ax[1].set_ylim(-1,0.5)
  607. ax[1].set_xlim(0,parameters1[-1])
  608. ax[1].set_xlabel('gaps (ms)')
  609. ax = ax.flatten()
  610. for axi in ax:
  611. axi.spines['top'].set_visible(False)
  612. axi.spines['right'].set_visible(False)
  613. axi.spines['bottom'].set_linewidth(1)
  614. axi.spines['left'].set_linewidth(1)
  615. # axi.axhline(y=0,color='gray',lw=2,ls='--')
  616. plt.figtext(0,0.3, 'discriminability index', rotation=90)
  617. fig.tight_layout() #w_pad=0.6,h_pad=0.6
  618. return fig
  619. def plot_pvalues(sims):
  620. # import experimental data - cliff delta values for 45 units
  621. mat_contents = sio.loadmat(r'E:\Users\User\Documents\model-context\cliff_data.mat')
  622. a=mat_contents['cliff_data']
  623. exp_data_iso = a[:,0]
  624. exp_data_nav = a[:,1]
  625. exp_data_com = a[:,2]
  626. del mat_contents
  627. del a
  628. parameters1=sims[0]
  629. parameters2=sims[1]
  630. sims = np.delete(sims,[0,1], 0)
  631. ntrials=len(sims[0])
  632. nx=len(parameters1)
  633. ny=len(parameters2)
  634. ntot=nx*ny
  635. N_units=ntrials/20
  636. # calculate cliff delta from simulations per unit
  637. sims_iso=[]
  638. sims_nav=[]
  639. sims_com=[]
  640. stats_iso=[]
  641. stats_nav=[]
  642. stats_com=[]
  643. for s in range(ntot):
  644. s_i=sims[s]
  645. units_iso=[]
  646. units_nav=[]
  647. units_com=[]
  648. for u in range(int(N_units)):
  649. sp_e=s_i[20*u:20*u+20,1]
  650. sp_d=s_i[20*u:20*u+20,2]
  651. c,size = cliffsDelta(sp_e, sp_d)
  652. units_iso.append(c)
  653. sp_e=s_i[20*u:20*u+20,3]
  654. sp_d=s_i[20*u:20*u+20,4]
  655. c,size = cliffsDelta(sp_e, sp_d)
  656. units_nav.append(c)
  657. sp_e=s_i[20*u:20*u+20,5]
  658. sp_d=s_i[20*u:20*u+20,6]
  659. c,size = cliffsDelta(sp_e, sp_d)
  660. units_com.append(c)
  661. sims_iso.append(units_iso)
  662. sims_nav.append(units_nav)
  663. sims_com.append(units_com)
  664. # check for fitting experimental data
  665. H,p=ranksums(units_iso, exp_data_iso)
  666. stats_iso.append(p)
  667. H,p=ranksums(units_nav, exp_data_nav)
  668. stats_nav.append(p)
  669. H,p=ranksums(units_com, exp_data_com)
  670. stats_com.append(p)
  671. # convert into 2D matrix stats
  672. stats_iso=np.reshape(stats_iso,(nx,ny)).T
  673. stats_nav=np.reshape(stats_nav,(nx,ny)).T
  674. stats_com=np.reshape(stats_com,(nx,ny)).T
  675. # plotting
  676. fig=plt.figure(1,figsize=(10,3))
  677. ax = plt.gca()
  678. xx=1 # factor to change the scale of the units x and y
  679. dc=2 # number of decimals to plot in ticks
  680. ax=plt.subplot(131)
  681. ax.imshow(stats_iso,cmap='RdBu',origin='lower')
  682. ax.set_xticks(np.arange(nx))
  683. ax.set_xticklabels([str(round(float(r), dc)) for r in parameters1*xx])
  684. ax.set_yticks(np.arange(ny))
  685. ax.set_yticklabels([str(round(float(r), dc)) for r in parameters2*xx])
  686. ax=plt.subplot(132)
  687. ax.imshow(stats_nav,cmap='RdBu',origin='lower')
  688. ax.set_xticks(np.arange(nx))
  689. ax.set_xticklabels([str(round(float(r), dc)) for r in parameters1*xx])
  690. ax.set_yticks(np.arange(ny))
  691. ax.set_yticklabels([str(round(float(r), dc)) for r in parameters2*xx])
  692. ax=plt.subplot(133)
  693. ax.imshow(stats_com,cmap='RdBu',origin='lower')
  694. ax.set_xticks(np.arange(nx))
  695. ax.set_xticklabels([str(round(float(r), dc)) for r in parameters1*xx])
  696. ax.set_yticks(np.arange(ny))
  697. ax.set_yticklabels([str(round(float(r), dc)) for r in parameters2*xx])
  698. return fig
  699. def ce_2parameters(sims):
  700. # import experimental data - context effect values for 45 units
  701. mat_contents = sio.loadmat(r'E:\Users\User\Documents\model-context\ei_data-an.mat')
  702. a=mat_contents['ei']
  703. data_exp_nav = a[:,0]
  704. data_unexp_nav = a[:,1]
  705. data_exp_com = a[:,2]
  706. data_unexp_com = a[:,3]
  707. del mat_contents
  708. del a
  709. parameters1=sims[0]
  710. parameters2=sims[1]
  711. sims = np.delete(sims,[0,1], 0)
  712. ntrials=len(sims[0])
  713. nx=len(parameters1)
  714. ny=len(parameters2)
  715. ntot=nx*ny
  716. N_units=ntrials/20
  717. # calculate context effect from simulations per unit
  718. sims_navE=[]
  719. sims_comE=[]
  720. sims_navU=[]
  721. sims_comU=[]
  722. sims_diff_nav=[]
  723. sims_diff_com=[]
  724. stats_diff_nav=[]
  725. stats_diff_com=[]
  726. stats_navE=[]
  727. stats_navU=[]
  728. stats_comE=[]
  729. stats_comU=[]
  730. for s in range(ntot):
  731. s_i=sims[s]
  732. units_navE=[]
  733. units_navU=[]
  734. units_comE=[]
  735. units_comU=[]
  736. units_diff_nav=[]
  737. units_diff_com=[]
  738. for u in range(int(N_units)):
  739. sp_e_iso=np.mean(s_i[20*u:20*u+20,1])
  740. sp_d_iso=np.mean(s_i[20*u:20*u+20,2])
  741. sp_e_nav=np.mean(s_i[20*u:20*u+20,3])
  742. sp_d_nav=np.mean(s_i[20*u:20*u+20,4])
  743. sp_e_com=np.mean(s_i[20*u:20*u+20,5])
  744. sp_d_com=np.mean(s_i[20*u:20*u+20,6])
  745. ce_exp_nav=(sp_e_nav-sp_e_iso)/(sp_e_nav+sp_e_iso)
  746. ce_unexp_nav=(sp_d_nav-sp_d_iso)/(sp_d_nav+sp_d_iso)
  747. ce_exp_com=(sp_d_com-sp_d_iso)/(sp_d_com+sp_d_iso)
  748. ce_unexp_com=(sp_e_com-sp_e_iso)/(sp_e_com+sp_e_iso)
  749. units_navE.append(ce_exp_nav)
  750. units_navU.append(ce_unexp_nav)
  751. units_comE.append(ce_exp_com)
  752. units_comU.append(ce_unexp_com)
  753. units_diff_nav.append(ce_unexp_nav-ce_exp_nav)
  754. units_diff_com.append(ce_unexp_com-ce_exp_com)
  755. sims_diff_nav.append(units_diff_nav)
  756. sims_diff_com.append(units_diff_com)
  757. sims_navE.append(units_navE)
  758. sims_navU.append(units_navU)
  759. sims_comE.append(units_comE)
  760. sims_comU.append(units_comU)
  761. # check for fitting experimental data
  762. H,p=ranksums(units_navE, data_exp_nav)
  763. if p>0.05: # equal distributions
  764. stats_navE.append(1)
  765. else:
  766. stats_navE.append(0)
  767. H,p=ranksums(units_navU, data_unexp_nav)
  768. if p>0.05: # equal distributions
  769. stats_navU.append(1)
  770. else:
  771. stats_navU.append(0)
  772. H,p=ranksums(units_comE, data_exp_com)
  773. if p>0.05: # equal distributions
  774. stats_comE.append(1)
  775. else:
  776. stats_comE.append(0)
  777. H,p=ranksums(units_comU, data_unexp_com)
  778. if p>0.05: # equal distributions
  779. stats_comU.append(1)
  780. else:
  781. stats_comU.append(0)
  782. H,p=ranksums(units_diff_nav, data_unexp_nav-data_exp_nav)
  783. if p>0.05: # equal distributions
  784. stats_diff_nav.append(1)
  785. else:
  786. stats_diff_nav.append(0)
  787. H,p=ranksums(units_diff_com, data_unexp_com-data_exp_com)
  788. if p>0.05: # equal distributions
  789. stats_diff_com.append(1)
  790. else:
  791. stats_diff_com.append(0)
  792. # avearage context effect across units
  793. av_navE=np.mean(sims_navE,1)
  794. av_navU=np.mean(sims_navU,1)
  795. av_comE=np.mean(sims_comE,1)
  796. av_comU=np.mean(sims_comU,1)
  797. av_diff_nav=np.mean(sims_diff_nav,1)
  798. av_diff_com=np.mean(sims_diff_com,1)
  799. # convert into 2D matrix results and stats
  800. av_navE=np.reshape(av_navE,(nx,ny)).T
  801. av_navU=np.reshape(av_navU,(nx,ny)).T
  802. av_comE=np.reshape(av_comE,(nx,ny)).T
  803. av_comU=np.reshape(av_comU,(nx,ny)).T
  804. av_diff_nav=np.reshape(av_diff_nav,(nx,ny)).T
  805. av_diff_com=np.reshape(av_diff_com,(nx,ny)).T
  806. stats_navE=np.reshape(stats_navE,(nx,ny)).T
  807. stats_navU=np.reshape(stats_navU,(nx,ny)).T
  808. stats_comE=np.reshape(stats_comE,(nx,ny)).T
  809. stats_comU=np.reshape(stats_comU,(nx,ny)).T
  810. stats_diff_nav=np.reshape(stats_diff_nav,(nx,ny)).T
  811. stats_diff_com=np.reshape(stats_diff_com,(nx,ny)).T
  812. # plotting
  813. fig, ax = plt.subplots(2,3,sharex=True,sharey=True,figsize=(7,4.5))
  814. li=1 # min and max of colorbar
  815. min_x=min(parameters1)-((parameters1[1]-parameters1[0])/2)
  816. max_x=max(parameters1)+((parameters1[1]-parameters1[0])/2)
  817. min_y=min(parameters2)-((parameters2[1]-parameters2[0])/2)
  818. max_y=max(parameters2)+((parameters2[1]-parameters2[0])/2)
  819. x_isoN=np.nonzero(stats_navE)[1]
  820. y_isoN=np.nonzero(stats_navE)[0]
  821. ax[0,0].imshow(av_navE,cmap='RdBu',origin='lower',vmin=-li,vmax=li,extent=[min_x,max_x,min_y,max_y])
  822. ax[0,0].scatter(parameters1[x_isoN],parameters2[y_isoN], s=5, c='k', marker="*")
  823. x_navN=np.nonzero(stats_navU)[1]
  824. y_navN=np.nonzero(stats_navU)[0]
  825. ax[0,1].imshow(av_navU,cmap='RdBu',origin='lower',vmin=-li,vmax=li,extent=[min_x,max_x,min_y,max_y])
  826. ax[0,1].scatter(parameters1[x_navN],parameters2[y_navN], s=5, c='k', marker="*")
  827. x_comN=np.nonzero(stats_diff_nav)[1]
  828. y_comN=np.nonzero(stats_diff_nav)[0]
  829. ax[0,2].imshow(av_diff_nav,cmap='RdBu',origin='lower',vmin=-li,vmax=li,extent=[min_x,max_x,min_y,max_y])
  830. ax[0,2].scatter(parameters1[x_comN],parameters2[y_comN], s=5, c='k', marker="*")
  831. x_isoC=np.nonzero(stats_comE)[1]
  832. y_isoC=np.nonzero(stats_comE)[0]
  833. ax[1,0].imshow(av_comE,cmap='RdBu',origin='lower',vmin=-li,vmax=li,extent=[min_x,max_x,min_y,max_y])
  834. ax[1,0].scatter(parameters1[x_isoC],parameters2[y_isoC], s=5, c='k', marker="*")
  835. x_navC=np.nonzero(stats_comU)[1]
  836. y_navC=np.nonzero(stats_comU)[0]
  837. ax[1,1].imshow(av_comU,cmap='RdBu',origin='lower',vmin=-li,vmax=li,extent=[min_x,max_x,min_y,max_y])
  838. ax[1,1].scatter(parameters1[x_navC],parameters2[y_navC], s=5, c='k', marker="*")
  839. x_comC=np.nonzero(stats_diff_com)[1]
  840. y_comC=np.nonzero(stats_diff_com)[0]
  841. ax[1,2].imshow(av_diff_com,cmap='RdBu',origin='lower',vmin=-li,vmax=li,extent=[min_x,max_x,min_y,max_y])
  842. ax[1,2].scatter(parameters1[x_comC],parameters2[y_comC], s=5, c='k', marker="*")
  843. # set which combination satisfy all the contexts
  844. xy_isoN=np.array(list(zip(x_isoN,y_isoN)))
  845. xy_navN=np.array(list(zip(x_navN,y_navN)))
  846. xy_comN=np.array(list(zip(x_comN,y_comN)))
  847. xy_isoC=np.array(list(zip(x_isoC,y_isoC)))
  848. xy_navC=np.array(list(zip(x_navC,y_navC)))
  849. xy_comC=np.array(list(zip(x_comC,y_comC)))
  850. combiN = np.array([x for x in set(tuple(x) for x in xy_navN) & set(tuple(x) for x in xy_comN)])
  851. combiN = np.array([x for x in set(tuple(x) for x in combiN) & set(tuple(x) for x in xy_isoN)])
  852. combiC = np.array([x for x in set(tuple(x) for x in xy_navC) & set(tuple(x) for x in xy_comC)])
  853. combiC = np.array([x for x in set(tuple(x) for x in combiC) & set(tuple(x) for x in xy_isoC)])
  854. combi = np.array([x for x in set(tuple(x) for x in combiC) & set(tuple(x) for x in combiN)])
  855. ax[0,0].scatter(parameters1[combi[:,0]],parameters2[combi[:,1]], s=50, facecolors='none', edgecolors='k')
  856. ax[0,1].scatter(parameters1[combi[:,0]],parameters2[combi[:,1]], s=50, facecolors='none', edgecolors='k')
  857. ax[0,2].scatter(parameters1[combi[:,0]],parameters2[combi[:,1]], s=50, facecolors='none', edgecolors='k')
  858. ax[1,0].scatter(parameters1[combi[:,0]],parameters2[combi[:,1]], s=50, facecolors='none', edgecolors='k')
  859. ax[1,1].scatter(parameters1[combi[:,0]],parameters2[combi[:,1]], s=50, facecolors='none', edgecolors='k')
  860. ax[1,2].scatter(parameters1[combi[:,0]],parameters2[combi[:,1]], s=50, facecolors='none', edgecolors='k')
  861. return fig
  862. def plot_delays_ce(sims):
  863. parameters1=sims[0]
  864. sims = np.delete(sims,0, 0)
  865. ntrials=len(sims[0])
  866. ntot=len(parameters1)
  867. N_units=ntrials/20
  868. # calculate cliff delta from simulations per unit
  869. sims_navE=[]
  870. sims_navU=[]
  871. sims_comE=[]
  872. sims_comU=[]
  873. for s in range(ntot):
  874. s_i=sims[s]
  875. units_navE=[]
  876. units_navU=[]
  877. units_comE=[]
  878. units_comU=[]
  879. for u in range(int(N_units)):
  880. sp_e_iso=np.mean(s_i[20*u:20*u+20,1])
  881. sp_d_iso=np.mean(s_i[20*u:20*u+20,2])
  882. sp_e_nav=np.mean(s_i[20*u:20*u+20,3])
  883. sp_d_nav=np.mean(s_i[20*u:20*u+20,4])
  884. sp_e_com=np.mean(s_i[20*u:20*u+20,5])
  885. sp_d_com=np.mean(s_i[20*u:20*u+20,6])
  886. ce_exp_nav=(sp_e_nav-sp_e_iso)/(sp_e_nav+sp_e_iso)
  887. ce_unexp_nav=(sp_d_nav-sp_d_iso)/(sp_d_nav+sp_d_iso)
  888. ce_exp_com=(sp_d_com-sp_d_iso)/(sp_d_com+sp_d_iso)
  889. ce_unexp_com=(sp_e_com-sp_e_iso)/(sp_e_com+sp_e_iso)
  890. units_navE.append(ce_exp_nav)
  891. units_navU.append(ce_unexp_nav)
  892. units_comE.append(ce_exp_com)
  893. units_comU.append(ce_unexp_com)
  894. sims_navE.append(units_navE)
  895. sims_navU.append(units_navU)
  896. sims_comE.append(units_comE)
  897. sims_comU.append(units_comU)
  898. # plotting mean and error
  899. navE=np.mean(sims_navE,1)
  900. navU=np.mean(sims_navU,1)
  901. comE=np.mean(sims_comE,1)
  902. comU=np.mean(sims_comU,1)
  903. ynavE=np.std(sims_navE,1)
  904. ynavU=np.std(sims_navU,1)
  905. ycomE=np.std(sims_comE,1)
  906. ycomU=np.std(sims_comU,1)
  907. pvalues_nexp=[]
  908. pvalues_nunexp=[]
  909. pvalues_cexp=[]
  910. pvalues_cunexp=[]
  911. for i in range(ntot):
  912. w_ne, p_ne = wilcoxon(sims_navE[i])
  913. w_ne, p_nu = wilcoxon(sims_navU[i])
  914. w_ne, p_ce = wilcoxon(sims_comE[i])
  915. w_ne, p_cu = wilcoxon(sims_comU[i])
  916. pvalues_nexp.append(p_ne)
  917. pvalues_nunexp.append(p_nu)
  918. pvalues_cexp.append(p_ce)
  919. pvalues_cunexp.append(p_cu)
  920. print(p_ne)
  921. pvalues=np.column_stack((pvalues_nexp,pvalues_nunexp,pvalues_cexp,pvalues_cunexp))
  922. np.save('pvalues_ce',pvalues)
  923. fig, ax = plt.subplots(2,2,sharex=True,sharey=True,figsize=(2.6,1.9))
  924. ax[0,0].plot(parameters1,navE,color='b',lw=0.75)
  925. ax[0,0].plot(parameters1,navE,'.',markersize=3,color='b')
  926. ax[0,0].fill_between(parameters1, navE-ynavE, navE+ynavE ,alpha=0.3, facecolor='b')
  927. ax[1,0].plot(parameters1,navU,color='b',lw=0.75)
  928. ax[1,0].plot(parameters1,navU,'.',markersize=3,color='b')
  929. ax[1,0].fill_between(parameters1, navU-ynavU, navU+ynavU ,alpha=0.3, facecolor='b')
  930. ax[0,1].plot(parameters1,comE,color='r',lw=0.75)
  931. ax[0,1].plot(parameters1,comE,'.',markersize=3,color='r')
  932. ax[0,1].fill_between(parameters1, comE-ycomE, comE+ycomE ,alpha=0.3, facecolor='r')
  933. ax[1,1].plot(parameters1,comU,color='r',lw=0.75)
  934. ax[1,1].plot(parameters1,comU,'.',markersize=3,color='r')
  935. ax[1,1].fill_between(parameters1, comU-ycomU, comU+ycomU ,alpha=0.3, facecolor='r')
  936. ## add the real data
  937. # import experimental data - context effect values for 45 units after 60 ms
  938. mat_contents = sio.loadmat(r'E:\Users\User\Documents\model-context\ei_data.mat')
  939. a=mat_contents['ei']
  940. data_exp_nav = np.mean(a[:,0])
  941. data_unexp_nav = np.mean(a[:,1])
  942. data_exp_com = np.mean(a[:,2])
  943. data_unexp_com = np.mean(a[:,3])
  944. ydata_exp_nav = np.std(a[:,0])
  945. ydata_unexp_nav = np.std(a[:,1])
  946. ydata_exp_com = np.std(a[:,2])
  947. ydata_unexp_com = np.std(a[:,3])
  948. del mat_contents
  949. del a
  950. # import experimental data - context effect values for 45 units after 416
  951. mat_contents = sio.loadmat(r'E:\Users\User\Documents\model-context\ei_data-416.mat')
  952. a=mat_contents['ei']
  953. data_exp_nav_416 = np.mean(a[:,0])
  954. data_unexp_nav_416 = np.mean(a[:,1])
  955. data_exp_com_416 = np.mean(a[:,2])
  956. data_unexp_com_416 = np.mean(a[:,3])
  957. ydata_exp_nav_416 = np.std(a[:,0])
  958. ydata_unexp_nav_416 = np.std(a[:,1])
  959. ydata_exp_com_416 = np.std(a[:,2])
  960. ydata_unexp_com_416 = np.std(a[:,3])
  961. del mat_contents
  962. del a
  963. ax[0,0].errorbar([60,416],[data_exp_nav, data_exp_nav_416], yerr=[ydata_exp_nav, ydata_exp_nav_416], fmt='o',color='b', mfc='w',label='nav exp',ms=4,lw=0.75)
  964. ax[1,0].errorbar([60,416],[data_unexp_nav, data_unexp_nav_416], yerr=[ydata_unexp_nav, ydata_unexp_nav_416], fmt='o',color='b', mfc='w',label='nav unexp',ms=4,lw=0.75)
  965. ax[0,1].errorbar([60,416],[data_exp_com, data_exp_com_416], yerr=[ydata_exp_com, ydata_exp_com_416], fmt='o',color='r', mfc='w',label='com exp',ms=4,lw=0.75)
  966. ax[1,1].errorbar([60,416],[data_unexp_com, data_unexp_com_416], yerr=[ydata_unexp_com, ydata_unexp_com_416], fmt='o',color='r', mfc='w',label='com unexp',ms=4,lw=0.75)
  967. # ax[0].legend(loc='lower right',frameon=False)
  968. # ax[1].legend(loc='lower right',frameon=False)
  969. # ax[2].legend(loc='lower right',frameon=False)
  970. # ax[3].legend(loc='lower right',frameon=False)
  971. ax = ax.flatten()
  972. for axi in ax:
  973. axi.spines['top'].set_visible(False)
  974. axi.spines['right'].set_visible(False)
  975. axi.spines['bottom'].set_linewidth(0.75)
  976. axi.spines['left'].set_linewidth(0.75)
  977. axi.axhline(y=0,color='k',lw=0.5,ls='--')
  978. plt.figtext(0.525,0.3, 'context effect (com)', rotation=90)
  979. plt.figtext(0,0.3, 'context effect (nav)', rotation=90)
  980. plt.figtext(0.5,0, 'gaps(ms)', rotation=0, verticalalignment='bottom')
  981. fig.tight_layout(h_pad=2) #w_pad=0.6,h_pad=0.6
  982. return fig
  983. def variables_delay(N_units):
  984. delay=3000
  985. trials=20
  986. dt_=0.1
  987. # SIMULATION NAVIGATION CONTEXT
  988. context=1
  989. exp=1
  990. exec(open("./input.py").read())
  991. exec(open("./model.py").read())
  992. nav_postsyn=pos.V_th*1000 # to mV
  993. nav_presyn=mon.x_S
  994. nav_high=nav_presyn[trials*N_units:]
  995. nav_low=nav_presyn[:trials*N_units]
  996. nav_tot=np.shape(nav_presyn)[1]*dt_
  997. nav_time=np.arange(0,nav_tot,dt_)
  998. # average acros trials
  999. nav_post=np.mean(nav_postsyn,0)
  1000. nav_pre_high=np.mean(nav_high,0)
  1001. nav_pre_low=np.mean(nav_low,0)
  1002. # SIMULATION COMMUNICATION CONTEXT
  1003. context=2
  1004. exec(open("./input.py").read())
  1005. exec(open("./model.py").read())
  1006. com_postsyn=pos.V_th*1000
  1007. com_presyn=mon.x_S
  1008. com_high=com_presyn[trials*N_units:]
  1009. com_low=com_presyn[:trials*N_units]
  1010. com_tot=np.shape(com_presyn)[1]*dt_
  1011. com_time=np.arange(0,com_tot,dt_)
  1012. # average across trials
  1013. com_post=np.mean(com_postsyn,0)
  1014. com_pre_high=np.mean(com_high,0)
  1015. com_pre_low=np.mean(com_low,0)
  1016. # plotting
  1017. vm_i=-50
  1018. vm_s=-44
  1019. xs_i=0.3
  1020. xs_s=1
  1021. fig, ax = plt.subplots(2,2,sharex=True,sharey='row',figsize=(3.54,2))
  1022. # navigation postsyn
  1023. width_context=(onset[1]-delay)-onset[0]
  1024. rect_context=mpl.patches.Rectangle((onset[0],vm_i),width_context,(vm_s-vm_i),facecolor='b',alpha=0.2)
  1025. ax[0,0].add_patch(rect_context)
  1026. ax[0,0].plot(nav_time,nav_post,c='k',lw=0.75)
  1027. ax[0,0].vlines(onset[1]-delay+60,vm_i,vm_s,lw=0.75)
  1028. ax[0,0].vlines(onset[1]-delay+416,vm_i,vm_s,lw=0.75)
  1029. ax[0,0].set_ylim(vm_i,vm_s)
  1030. ax[0,0].set_xlim(500,6000)
  1031. ax[0,0].set_ylabel('spiking\n threshold')
  1032. # communication postsyn
  1033. width_context=(onset[2]-delay)-onset[0]
  1034. rect_context=mpl.patches.Rectangle((onset[0],vm_i),width_context,(vm_s-vm_i),facecolor='r',alpha=0.2)
  1035. ax[0,1].add_patch(rect_context)
  1036. ax[0,1].plot(com_time,com_post,c='k',lw=0.75)
  1037. ax[0,1].vlines(onset[2]-delay+60,vm_i,vm_s,lw=0.75)
  1038. ax[0,1].vlines(onset[2]-delay+416,vm_i,vm_s,lw=0.75)
  1039. ax[0,1].set_ylim(vm_i,vm_s)
  1040. ax[0,1].set_xlim(500,6000)
  1041. # navigation presyn
  1042. width_context=(onset[1]-delay)-onset[0]
  1043. rect_context=mpl.patches.Rectangle((onset[0],xs_i),width_context,(xs_s-xs_i),facecolor='b',alpha=0.2)
  1044. ax[1,0].add_patch(rect_context)
  1045. ax[1,0].plot(nav_time,nav_pre_high,c='b',lw=0.75)
  1046. ax[1,0].plot(nav_time,nav_pre_low,c='r',lw=0.75)
  1047. ax[1,0].vlines(onset[1]-delay+60,xs_i,xs_s,lw=0.75)
  1048. ax[1,0].vlines(onset[1]-delay+416,xs_i,xs_s,lw=0.75)
  1049. ax[1,0].set_ylim(xs_i,xs_s)
  1050. ax[1,0].set_xlim(500,6000)
  1051. ax[1,0].set_ylabel('strength\n synapse')
  1052. # communication presyn
  1053. width_context=(onset[2]-delay)-onset[0]
  1054. rect_context=mpl.patches.Rectangle((onset[0],xs_i),width_context,(xs_s-xs_i),facecolor='r',alpha=0.2)
  1055. ax[1,1].add_patch(rect_context)
  1056. ax[1,1].plot(com_time,com_pre_high,c='b',lw=0.75)
  1057. ax[1,1].plot(com_time,com_pre_low,c='r',lw=0.75)
  1058. ax[1,1].vlines(onset[2]-delay+60,xs_i,xs_s,lw=0.75)
  1059. ax[1,1].vlines(onset[2]-delay+416,xs_i,xs_s,lw=0.75)
  1060. ax[1,1].set_ylim(xs_i,xs_s)
  1061. ax[1,1].set_xlim(500,6000)
  1062. ax = ax.flatten()
  1063. for axi in ax:
  1064. axi.spines['top'].set_visible(False)
  1065. axi.spines['right'].set_visible(False)
  1066. axi.spines['bottom'].set_linewidth(0.75)
  1067. axi.spines['left'].set_linewidth(0.75)
  1068. plt.figtext(0.5, 0.01, 'Time (ms)', rotation=0, verticalalignment='bottom')
  1069. fig.tight_layout()
  1070. return fig
  1071. def spikes_input():
  1072. N_units=1
  1073. context=1
  1074. exp=1
  1075. exec(open("./input.py").read())
  1076. exec(open("./model.py").read())
  1077. HF=firing_context(sp_high,onset,context)
  1078. LF=firing_context(sp_low,onset,context)
  1079. output=[x + y for (x, y) in zip(LF, HF)]
  1080. av_spikes_c1=sum(output) / len(output)
  1081. context=2
  1082. exec(open("./input.py").read())
  1083. exec(open("./model.py").read())
  1084. HF=firing_context(sp_high,onset,context)
  1085. LF=firing_context(sp_low,onset,context)
  1086. output=[x + y for (x, y) in zip(LF, HF)]
  1087. av_spikes_c2=sum(output) / len(output)
  1088. return av_spikes_c1,av_spikes_c2
  1089. def sim_isolation(N_units,we_LF=6,we_HF=6):
  1090. probe=np.repeat(range(1,N_units+1),20)
  1091. # SIMULATION 1: navigation - after silence
  1092. context=0
  1093. exp=1
  1094. exec(open("./input.py").read())
  1095. exec(open("./model.py").read())
  1096. col=spike_counts(ac,onset,context)
  1097. probe=np.column_stack((probe, col))
  1098. # SIMULATION 2: communication - after silence
  1099. exp=2
  1100. exec(open("./input.py").read())
  1101. exec(open("./model.py").read())
  1102. col=spike_counts(ac,onset,context)
  1103. probe=np.column_stack((probe, col))
  1104. return probe
  1105. def plot_isolation(sims):
  1106. # import experimental data - cliff delta values for 45 units
  1107. mat_contents = sio.loadmat(r'E:\Users\User\Documents\model-context\cliff_data-pref.mat')
  1108. a=mat_contents['cliff_data']
  1109. exp_data_iso = a[:,0]
  1110. del mat_contents
  1111. del a
  1112. # plot cliff delta and spikecounts for probes in silence
  1113. parameters1=sims[0]
  1114. parameters2=sims[1]
  1115. sims = np.delete(sims,[0,1], 0)
  1116. ntrials=len(sims[0])
  1117. nx=len(parameters1)
  1118. ny=len(parameters2)
  1119. ntot=nx*ny
  1120. N_units=ntrials/20
  1121. # calculate cliff delta and spikecounts from simulations per unit
  1122. sims_iso=[]
  1123. sp_nav=[]
  1124. sp_com=[]
  1125. stats_iso=[]
  1126. for s in range(ntot):
  1127. s_i=sims[s]
  1128. units_iso=[]
  1129. units_sp_nav=[]
  1130. units_sp_com=[]
  1131. for u in range(int(N_units)):
  1132. sp_e=s_i[20*u:20*u+20,1]
  1133. sp_d=s_i[20*u:20*u+20,2]
  1134. c,size = cliffsDelta(sp_e, sp_d)
  1135. units_iso.append(c)
  1136. units_sp_nav.append(np.mean(sp_e)) # average across trials
  1137. units_sp_com.append(np.mean(sp_d))
  1138. sims_iso.append(units_iso)
  1139. sp_nav.append(units_sp_nav)
  1140. sp_com.append(units_sp_com)
  1141. # check for fitting experimental data
  1142. H,p=ranksums(units_iso, exp_data_iso)
  1143. if p>0.05: # equal distributions
  1144. stats_iso.append(1)
  1145. else:
  1146. stats_iso.append(0)
  1147. # avearage cliff delta and spikecounts across units
  1148. av_iso=np.mean(sims_iso,1)
  1149. av_nav=np.mean(sp_nav,1)
  1150. av_com=np.mean(sp_com,1)
  1151. # convert into 2D matrix results and stats
  1152. av_iso=np.reshape(av_iso,(nx,ny)).T
  1153. av_nav=np.reshape(av_nav,(nx,ny)).T
  1154. av_com=np.reshape(av_com,(nx,ny)).T
  1155. stats_iso=np.reshape(stats_iso,(nx,ny)).T
  1156. # plotting
  1157. fig, ax = plt.subplots(1,3,sharex=True,sharey=True,figsize=(6.5,2.5))
  1158. li=1 # min and max of colorbar
  1159. xx=1 # factor to change the scale of the units x and y
  1160. dc=0 # number of decimals to plot in ticks
  1161. mi=10 # max spikecounts to plot in colorbar
  1162. min_x=min(parameters1)-((parameters1[1]-parameters1[0])/2)
  1163. max_x=max(parameters1)+((parameters1[1]-parameters1[0])/2)
  1164. min_y=min(parameters2)-((parameters2[1]-parameters2[0])/2)
  1165. max_y=max(parameters2)+((parameters2[1]-parameters2[0])/2)
  1166. ax[0].imshow(av_iso,cmap='RdBu',origin='lower',vmin=-li,vmax=li,extent=[min_x,max_x,min_y,max_y])
  1167. ax[1].imshow(av_nav,cmap='rainbow',origin='lower',vmin=0,vmax=mi,extent=[min_x,max_x,min_y,max_y])
  1168. ax[2].imshow(av_com,cmap='rainbow',origin='lower',vmin=0,vmax=mi,extent=[min_x,max_x,min_y,max_y])
  1169. x_iso=np.nonzero(stats_iso)[1]
  1170. y_iso=np.nonzero(stats_iso)[0]
  1171. ax[0].scatter(parameters1[x_iso],parameters2[y_iso], s=5, c='k', marker="*")
  1172. return fig
  1173. def discriminability_index(probe):
  1174. # calculate context effect (c.e.) for each combination per unit
  1175. trials=20
  1176. N_units=int(len(probe)/trials)
  1177. output=[]
  1178. for u in range(int(N_units)):
  1179. cliff_iso,size = cliffsDelta(probe[20*u:20*u+20,1], probe[20*u:20*u+20,2])
  1180. cliff_nav,size = cliffsDelta(probe[20*u:20*u+20,3], probe[20*u:20*u+20,4])
  1181. cliff_com,size = cliffsDelta(probe[20*u:20*u+20,5], probe[20*u:20*u+20,6])
  1182. output.append([cliff_nav, cliff_iso, cliff_com])
  1183. output=np.asarray(output)
  1184. return output
  1185. def plot_ce_di_multiple(sims1, sims2, sims3, sims4=None):
  1186. # c.e.
  1187. ce1=context_effect(sims1)
  1188. ce2=context_effect(sims2)
  1189. ce3=context_effect(sims3)
  1190. # d.i.
  1191. di1=discriminability_index(sims1)
  1192. di2=discriminability_index(sims2)
  1193. di3=discriminability_index(sims3)
  1194. fig, ax = plt.subplots(1,1,figsize=(2.85,1.5)) #2.5
  1195. aa=0.5
  1196. colors=[nc.to_rgba('grey', alpha=aa),nc.to_rgba('green', alpha=aa),nc.to_rgba('orange', alpha=aa)]
  1197. ax.axhline(y=0,color='k',lw=0.5,ls='--')
  1198. b1=ax.boxplot(di1,positions=[1,2,3], patch_artist=True,widths=0.8)
  1199. for item in ['whiskers', 'fliers', 'medians', 'caps','boxes']:
  1200. for c in b1[item]:
  1201. c.set(color='k', linewidth=0.5)
  1202. for i in b1['boxes']:
  1203. i.set_facecolor(colors[0])
  1204. for i in b1['fliers']:
  1205. i.set_markersize(2)
  1206. i.set_markeredgewidth(0.5)
  1207. b2=ax.boxplot(di2,positions=[5,6,7], patch_artist=True,widths=0.8)
  1208. for item in ['whiskers', 'fliers', 'medians', 'caps','boxes']:
  1209. for c in b2[item]:
  1210. c.set(color='k', linewidth=0.5)
  1211. for i in b2['boxes']:
  1212. i.set_facecolor(colors[1])
  1213. for i in b2['fliers']:
  1214. i.set_markersize(2)
  1215. i.set_markeredgewidth(0.5)
  1216. b3=ax.boxplot(di3,positions=[9,10,11], patch_artist=True,widths=0.8)
  1217. for item in ['whiskers', 'fliers', 'medians', 'caps','boxes']:
  1218. for c in b3[item]:
  1219. c.set(color='k', linewidth=0.5)
  1220. for i in b3['boxes']:
  1221. i.set_facecolor(colors[2])
  1222. for i in b3['fliers']:
  1223. i.set_markersize(2)
  1224. i.set_markeredgewidth(0.5)
  1225. ax.set_ylim(-1,1)
  1226. ax.spines['top'].set_visible(False)
  1227. ax.spines['right'].set_visible(False)
  1228. ax.yaxis.set_ticks_position('left')
  1229. ax.xaxis.set_ticks_position('bottom')
  1230. for axis in ['top','bottom','left','right']:
  1231. ax.spines[axis].set_linewidth(0.75)
  1232. plt.locator_params(axis='y',nbins=5)
  1233. ax.tick_params(axis='x', rotation=45)
  1234. ax.set_ylabel('discriminability index')
  1235. if sims4 is not None:
  1236. ce4=context_effect(sims4)
  1237. di4=discriminability_index(sims4)
  1238. b4=ax.boxplot(di4,positions=[13,14,15], patch_artist=True,widths=0.8)
  1239. for item in ['whiskers', 'fliers', 'medians', 'caps','boxes']:
  1240. for c in b4[item]:
  1241. c.set(color='k', linewidth=0.5)
  1242. for i in b4['boxes']:
  1243. i.set_facecolor(nc.to_rgba('blue', alpha=aa))
  1244. for i in b4['fliers']:
  1245. i.set_markersize(2)
  1246. i.set_markeredgewidth(0.5)
  1247. ax.set_xticklabels(['ech','silence','com','ech','silence','com','ech','silence','com','ech','silence','com'],ha='right')
  1248. else:
  1249. ax.set_xticklabels(['ech','silence','com','ech','silence','com','ech','silence','com'],ha='right')
  1250. fig.tight_layout()
  1251. # context effect plots
  1252. fig2, ax = plt.subplots(2,1,sharex=True,sharey=True,figsize=(2.5,3))
  1253. aa=0.5
  1254. colors=[nc.to_rgba('grey', alpha=aa),nc.to_rgba('green', alpha=aa),nc.to_rgba('orange', alpha=aa)]
  1255. ax[0].axhline(y=0,color='k',lw=0.5,ls='--')
  1256. ax[1].axhline(y=0,color='k',lw=0.5,ls='--')
  1257. nav1=ce1[:,0:2]
  1258. com1=ce1[:,2:4]
  1259. b1=ax[0].boxplot(nav1,positions=[1,2], patch_artist=True,widths=0.8)
  1260. for item in ['whiskers', 'fliers', 'medians', 'caps','boxes']:
  1261. for c in b1[item]:
  1262. c.set(color='k', linewidth=0.5)
  1263. for i in b1['boxes']:
  1264. i.set_facecolor(colors[0])
  1265. for i in b1['fliers']:
  1266. i.set_markersize(2)
  1267. i.set_markeredgewidth(0.5)
  1268. b1=ax[1].boxplot(com1,positions=[1,2], patch_artist=True,widths=0.8)
  1269. for item in ['whiskers', 'fliers', 'medians', 'caps','boxes']:
  1270. for c in b1[item]:
  1271. c.set(color='k', linewidth=0.5)
  1272. for i in b1['boxes']:
  1273. i.set_facecolor(colors[0])
  1274. for i in b1['fliers']:
  1275. i.set_markersize(2)
  1276. i.set_markeredgewidth(0.5)
  1277. nav2=ce2[:,0:2]
  1278. com2=ce2[:,2:4]
  1279. b2=ax[0].boxplot(nav2,positions=[4,5], patch_artist=True,widths=0.8)
  1280. for item in ['whiskers', 'fliers', 'medians', 'caps','boxes']:
  1281. for c in b2[item]:
  1282. c.set(color='k', linewidth=0.5)
  1283. for i in b2['boxes']:
  1284. i.set_facecolor(colors[1])
  1285. for i in b2['fliers']:
  1286. i.set_markersize(2)
  1287. i.set_markeredgewidth(0.5)
  1288. b2=ax[1].boxplot(com2,positions=[4,5], patch_artist=True,widths=0.8)
  1289. for item in ['whiskers', 'fliers', 'medians', 'caps','boxes']:
  1290. for c in b2[item]:
  1291. c.set(color='k', linewidth=0.5)
  1292. for i in b2['boxes']:
  1293. i.set_facecolor(colors[1])
  1294. for i in b2['fliers']:
  1295. i.set_markersize(2)
  1296. i.set_markeredgewidth(0.5)
  1297. nav3=ce3[:,0:2]
  1298. com3=ce3[:,2:4]
  1299. b3=ax[0].boxplot(nav3,positions=[7,8], patch_artist=True,widths=0.8)
  1300. for item in ['whiskers', 'fliers', 'medians', 'caps','boxes']:
  1301. for c in b3[item]:
  1302. c.set(color='k', linewidth=0.5)
  1303. for i in b3['boxes']:
  1304. i.set_facecolor(colors[2])
  1305. for i in b3['fliers']:
  1306. i.set_markersize(2)
  1307. i.set_markeredgewidth(0.5)
  1308. b3=ax[1].boxplot(com3,positions=[7,8], patch_artist=True,widths=0.8)
  1309. for item in ['whiskers', 'fliers', 'medians', 'caps','boxes']:
  1310. for c in b3[item]:
  1311. c.set(color='k', linewidth=0.5)
  1312. for i in b3['boxes']:
  1313. i.set_facecolor(colors[2])
  1314. for i in b3['fliers']:
  1315. i.set_markersize(2)
  1316. i.set_markeredgewidth(0.5)
  1317. if sims4 is not None:
  1318. nav4=ce4[:,0:2]
  1319. com4=ce4[:,2:4]
  1320. b4=ax[0].boxplot(nav4,positions=[10,11], patch_artist=True,widths=0.8)
  1321. for item in ['whiskers', 'fliers', 'medians', 'caps','boxes']:
  1322. for c in b4[item]:
  1323. c.set(color='k', linewidth=0.5)
  1324. for i in b4['boxes']:
  1325. i.set_facecolor(nc.to_rgba('blue', alpha=aa))
  1326. for i in b4['fliers']:
  1327. i.set_markersize(2)
  1328. i.set_markeredgewidth(0.5)
  1329. b4=ax[1].boxplot(com4,positions=[10,11], patch_artist=True,widths=0.8)
  1330. for item in ['whiskers', 'fliers', 'medians', 'caps','boxes']:
  1331. for c in b4[item]:
  1332. c.set(color='k', linewidth=0.5)
  1333. for i in b4['boxes']:
  1334. i.set_facecolor(nc.to_rgba('blue', alpha=aa))
  1335. for i in b4['fliers']:
  1336. i.set_markersize(2)
  1337. i.set_markeredgewidth(0.5)
  1338. ax[1].set_xticks([1,2,4,5,7,8,10,11])
  1339. ax[1].set_xticklabels(['match','mismatch','match','mismatch','match','mismatch','match','mismatch'],ha='right')
  1340. else:
  1341. ax[1].set_xticks([1,2,4,5,7,8])
  1342. ax[1].set_xticklabels(['match','mismatch','match','mismatch','match','mismatch'],ha='right')
  1343. for axi in ax:
  1344. axi.set_ylim(-1,0.5)
  1345. axi.spines['top'].set_visible(False)
  1346. axi.spines['right'].set_visible(False)
  1347. axi.yaxis.set_ticks_position('left')
  1348. axi.xaxis.set_ticks_position('bottom')
  1349. for axis in ['top','bottom','left','right']:
  1350. axi.spines[axis].set_linewidth(0.75)
  1351. plt.locator_params(axis='y',nbins=5)
  1352. axi.tick_params(axis='x', rotation=45)
  1353. axi.set_ylabel('context effect')
  1354. fig2.tight_layout()
  1355. return fig, fig2
  1356. def plot_experimental():
  1357. # import experimental data - context effect values for 45 units after 60 ms
  1358. mat_contents = sio.loadmat(r'E:\Users\User\Documents\model-context\ei_data.mat')
  1359. a=mat_contents['ei']
  1360. ce_exp_nav = a[:,0]
  1361. ce_unexp_nav = a[:,1]
  1362. ce_exp_com = a[:,2]
  1363. ce_unexp_com = a[:,3]
  1364. ce_nav=[ce_exp_nav, ce_unexp_nav]
  1365. ce_com=[ce_exp_com, ce_unexp_com]
  1366. del mat_contents
  1367. del a
  1368. # import experimental data - cliff delta values for 45 units
  1369. mat_contents = sio.loadmat(r'E:\Users\User\Documents\model-context\cliff_data-pref.mat')
  1370. a=mat_contents['cliff_data']
  1371. di_iso = a[:,0]
  1372. di_nav = a[:,1]
  1373. di_com = a[:,2]
  1374. di=[di_nav, di_iso, di_com]
  1375. del mat_contents
  1376. del a
  1377. # plot discriminability index
  1378. fig, ax = plt.subplots(1,1,figsize=(1.1,1.5))
  1379. aa=0.5
  1380. colors=[nc.to_rgba('white', alpha=aa),nc.to_rgba('green', alpha=aa),nc.to_rgba('orange', alpha=aa)]
  1381. ax.axhline(y=0,color='k',lw=0.5,ls='--')
  1382. b1=ax.boxplot(di,positions=[1,2,3], patch_artist=True,widths=0.7)
  1383. for item in ['whiskers', 'fliers', 'medians', 'caps','boxes']:
  1384. for c in b1[item]:
  1385. c.set(color='k', linewidth=0.5)
  1386. for i in b1['boxes']:
  1387. i.set_facecolor(colors[0])
  1388. for i in b1['fliers']:
  1389. i.set_markersize(2)
  1390. i.set_markeredgewidth(0.5)
  1391. ax.set_ylim(-1,1)
  1392. ax.spines['top'].set_visible(False)
  1393. ax.spines['right'].set_visible(False)
  1394. ax.yaxis.set_ticks_position('left')
  1395. ax.xaxis.set_ticks_position('bottom')
  1396. for axis in ['top','bottom','left','right']:
  1397. ax.spines[axis].set_linewidth(0.75)
  1398. plt.locator_params(axis='y',nbins=5)
  1399. ax.set_xticklabels(['ech','silence','com'],ha='right')
  1400. ax.tick_params(axis='x', rotation=45)
  1401. ax.set_ylabel('discriminability index')
  1402. fig.tight_layout()
  1403. # plot context effect
  1404. fig2, ax = plt.subplots(1,1,figsize=(1.5,1.5))
  1405. aa=0.5
  1406. colors=[nc.to_rgba('white', alpha=aa),nc.to_rgba('green', alpha=aa),nc.to_rgba('orange', alpha=aa)]
  1407. ax.axhline(y=0,color='k',lw=0.5,ls='--')
  1408. b1=ax.boxplot(ce_nav,positions=[1,2], patch_artist=True,widths=0.5)
  1409. for item in ['whiskers', 'fliers', 'medians', 'caps','boxes']:
  1410. for c in b1[item]:
  1411. c.set(color='k', linewidth=0.5)
  1412. for i in b1['boxes']:
  1413. i.set_facecolor(colors[0])
  1414. for i in b1['fliers']:
  1415. i.set_markersize(2)
  1416. i.set_markeredgewidth(0.5)
  1417. b1=ax.boxplot(ce_com,positions=[3,4], patch_artist=True,widths=0.5)
  1418. for item in ['whiskers', 'fliers', 'medians', 'caps','boxes']:
  1419. for c in b1[item]:
  1420. c.set(color='k', linewidth=0.5)
  1421. for i in b1['boxes']:
  1422. i.set_facecolor(colors[0])
  1423. for i in b1['fliers']:
  1424. i.set_markersize(2)
  1425. i.set_markeredgewidth(0.5)
  1426. ax.set_xticks([1,2,3,4])
  1427. ax.set_xticklabels(['match','mismatch','match','mismatch'],ha='right')
  1428. ax.set_ylim(-1,0.5)
  1429. ax.spines['top'].set_visible(False)
  1430. ax.spines['right'].set_visible(False)
  1431. ax.yaxis.set_ticks_position('left')
  1432. ax.xaxis.set_ticks_position('bottom')
  1433. for axis in ['top','bottom','left','right']:
  1434. ax.spines[axis].set_linewidth(0.75)
  1435. plt.locator_params(axis='y',nbins=5)
  1436. ax.tick_params(axis='x', rotation=45)
  1437. ax.set_ylabel('context effect')
  1438. fig2.tight_layout()
  1439. return fig, fig2
  1440. def plot_pref_com(sims):
  1441. # discriminability index from simulations
  1442. di=discriminability_index(sims)
  1443. fig, ax = plt.subplots(1,1,figsize=(1.1,1.5))
  1444. aa=0.5
  1445. colors=[nc.to_rgba('blue', alpha=aa),nc.to_rgba('green', alpha=aa),nc.to_rgba('white', alpha=aa)]
  1446. ax.axhline(y=0,color='k',lw=0.5,ls='--')
  1447. b1=ax.boxplot(di,positions=[1,2,3], patch_artist=True,widths=0.7)
  1448. for item in ['whiskers', 'fliers', 'medians', 'caps','boxes']:
  1449. for c in b1[item]:
  1450. c.set(color='k', linewidth=0.5)
  1451. for i in b1['boxes']:
  1452. i.set_facecolor(colors[0])
  1453. for i in b1['fliers']:
  1454. i.set_markersize(2)
  1455. i.set_markeredgewidth(0.5)
  1456. ax.set_ylim(-1,1)
  1457. ax.spines['top'].set_visible(False)
  1458. ax.spines['right'].set_visible(False)
  1459. ax.yaxis.set_ticks_position('left')
  1460. ax.xaxis.set_ticks_position('bottom')
  1461. for axis in ['top','bottom','left','right']:
  1462. ax.spines[axis].set_linewidth(0.75)
  1463. plt.locator_params(axis='y',nbins=5)
  1464. ax.set_xticklabels(['ech','silence','com'],ha='right')
  1465. ax.tick_params(axis='x', rotation=45)
  1466. ax.set_ylabel('discriminability index')
  1467. fig.tight_layout()
  1468. return fig
  1469. def plot_pvalues_di(sims):
  1470. delays=np.arange(50,2200,150)
  1471. fig, ax = plt.subplots(1,1,figsize=(2.3,1))
  1472. ax.hlines(-np.log(0.05),0,delays[-1],linewidth=0.5)
  1473. ax.vlines(delays[4],-15,85,linewidth=0.5,linestyle=(0,(5,5)))
  1474. ax.vlines(delays[10],-15,85,linewidth=0.5,linestyle=(0,(5,5)))
  1475. ax.plot(delays,-np.log(sims[:,0]),'b.',markersize=3)
  1476. ax.plot(delays,-np.log(sims[:,1]),'r.',markersize=3)
  1477. ax.set_ylabel('-log(p-value)')
  1478. ax.set_xticklabels([])
  1479. # ax.set_xlabel('gaps (ms)')
  1480. ax.spines['top'].set_visible(False)
  1481. ax.spines['right'].set_visible(False)
  1482. ax.yaxis.set_ticks_position('left')
  1483. ax.xaxis.set_ticks_position('bottom')
  1484. for axis in ['top','bottom','left','right']:
  1485. ax.spines[axis].set_linewidth(0.75)
  1486. plt.locator_params(axis='y',nbins=5)
  1487. ax.set_xlim(0,delays[-1])
  1488. ax.set_ylim(-15,85)
  1489. fig.tight_layout()
  1490. return fig
  1491. def plot_pvalues_ce(sims):
  1492. delays=np.arange(50,2200,150)
  1493. fig, ax = plt.subplots(1,2,sharex=True,sharey=True,figsize=(2.8,1))
  1494. ax[0].axhline(y=-np.log(0.05),color='k',lw=0.5,ls='-')
  1495. ax[0].vlines(delays[10],-15,60,linewidth=0.5,linestyle=(0,(5,5)))
  1496. ax[0].plot(delays,-np.log(sims[:,0]),'b.',markersize=3)
  1497. ax[0].plot(delays,-np.log(sims[:,1]),'r.',markersize=3)
  1498. ax[0].set_ylabel('-log(p-value)')
  1499. ax[0].set_xticklabels([])
  1500. ax[0].spines['top'].set_visible(False)
  1501. ax[0].spines['right'].set_visible(False)
  1502. ax[0].yaxis.set_ticks_position('left')
  1503. ax[0].xaxis.set_ticks_position('bottom')
  1504. for axis in ['top','bottom','left','right']:
  1505. ax[0].spines[axis].set_linewidth(0.75)
  1506. plt.locator_params(axis='y',nbins=5)
  1507. ax[0].set_ylim(-5,50)
  1508. ax[1].axhline(y=-np.log(0.05),color='k',lw=0.5,ls='-')
  1509. ax[1].vlines(delays[4],-15,60,linewidth=0.5,linestyle=(0,(5,5)))
  1510. ax[1].plot(delays,-np.log(sims[:,2]),'r.',markersize=3)
  1511. ax[1].plot(delays,-np.log(sims[:,3]),'b.',markersize=3)
  1512. ax[1].spines['top'].set_visible(False)
  1513. ax[1].spines['right'].set_visible(False)
  1514. ax[1].yaxis.set_ticks_position('left')
  1515. ax[1].xaxis.set_ticks_position('bottom')
  1516. for axis in ['top','bottom','left','right']:
  1517. ax[1].spines[axis].set_linewidth(0.75)
  1518. plt.locator_params(axis='y',nbins=5)
  1519. fig.tight_layout()
  1520. return fig
  1521. def dd_2parameters(sims):
  1522. # import experimental data - context effect values for 45 units awake
  1523. mat_contents = sio.loadmat(r'E:\Users\User\Documents\model-context\ei_data-an.mat')
  1524. a=mat_contents['ei']
  1525. data_exp_nav = a[:,0]
  1526. data_unexp_nav = a[:,1]
  1527. data_exp_com = a[:,2]
  1528. data_unexp_com = a[:,3]
  1529. dd_nav=(data_unexp_nav-data_exp_nav)/2
  1530. dd_com=(data_unexp_com-data_exp_com)/2
  1531. del mat_contents
  1532. del a
  1533. parameters1=sims[0]
  1534. parameters2=sims[1]
  1535. sims = np.delete(sims,[0,1], 0)
  1536. ntrials=len(sims[0])
  1537. nx=len(parameters1)
  1538. ny=len(parameters2)
  1539. ntot=nx*ny
  1540. N_units=ntrials/20
  1541. # calculate context effect from simulations per unit
  1542. sims_dd_nav=[]
  1543. sims_dd_com=[]
  1544. stats_dd_nav=[]
  1545. stats_dd_com=[]
  1546. for s in range(ntot):
  1547. s_i=sims[s]
  1548. units_dd_nav=[]
  1549. units_dd_com=[]
  1550. for u in range(int(N_units)):
  1551. sp_e_iso=np.mean(s_i[20*u:20*u+20,1])
  1552. sp_d_iso=np.mean(s_i[20*u:20*u+20,2])
  1553. sp_e_nav=np.mean(s_i[20*u:20*u+20,3])
  1554. sp_d_nav=np.mean(s_i[20*u:20*u+20,4])
  1555. sp_e_com=np.mean(s_i[20*u:20*u+20,5])
  1556. sp_d_com=np.mean(s_i[20*u:20*u+20,6])
  1557. ce_exp_nav=(sp_e_nav-sp_e_iso)/(sp_e_nav+sp_e_iso)
  1558. ce_unexp_nav=(sp_d_nav-sp_d_iso)/(sp_d_nav+sp_d_iso)
  1559. ce_exp_com=(sp_d_com-sp_d_iso)/(sp_d_com+sp_d_iso)
  1560. ce_unexp_com=(sp_e_com-sp_e_iso)/(sp_e_com+sp_e_iso)
  1561. units_dd_nav.append((ce_unexp_nav-ce_exp_nav)/2)
  1562. units_dd_com.append((ce_unexp_com-ce_exp_com)/2)
  1563. sims_dd_nav.append(units_dd_nav)
  1564. sims_dd_com.append(units_dd_com)
  1565. # check for fitting experimental data
  1566. H,p=ranksums(units_dd_nav, dd_nav)
  1567. if p>0.05: # equal distributions
  1568. stats_dd_nav.append(1)
  1569. else:
  1570. stats_dd_nav.append(0)
  1571. H,p=ranksums(units_dd_com, dd_com)
  1572. if p>0.05: # equal distributions
  1573. stats_dd_com.append(1)
  1574. else:
  1575. stats_dd_com.append(0)
  1576. # # avearage context effect across units
  1577. # av_dd_nav=np.mean(sims_dd_nav,1)
  1578. # av_dd_com=np.mean(sims_dd_com,1)
  1579. #
  1580. # # convert into 2D matrix results and stats
  1581. # av_dd_nav=np.reshape(av_dd_nav,(nx,ny)).T
  1582. # av_dd_com=np.reshape(av_dd_com,(nx,ny)).T
  1583. # stats_dd_nav=np.reshape(stats_dd_nav,(nx,ny)).T
  1584. # stats_dd_com=np.reshape(stats_dd_com,(nx,ny)).T
  1585. #
  1586. # # subsets of simulations depending on parameters combinations
  1587. sims_dd_nav=np.array(sims_dd_nav)
  1588. sims_dd_com=np.array(sims_dd_com)
  1589. # # only those that are the same for LF and HF (diagonal)
  1590. # diag_mask=np.eye(nx,dtype=bool)
  1591. # diag=diag_mask.flatten()
  1592. # same_nav=sims_dd_nav[diag]
  1593. # same_com=sims_dd_com[diag]
  1594. # # those that LF > HF (at the bottom of the diag)
  1595. # bottom_mask=np.tril(~diag_mask)
  1596. # bottom=bottom_mask.flatten()
  1597. # lower_nav=sims_dd_nav[bottom]
  1598. # lower_com=sims_dd_com[bottom]
  1599. # # those that HF > LF (on top of the diag)
  1600. # top_mask=np.triu(~diag_mask)
  1601. # top=top_mask.flatten()
  1602. # higher_nav=sims_dd_nav[top]
  1603. # higher_com=sims_dd_com[top]
  1604. # plotting
  1605. A_nav=sims_dd_nav #same_nav #sims_dd_nav # same_nav #
  1606. A_com=sims_dd_com #same_com #sims_dd_com # same_com
  1607. fig, ax = plt.subplots(1,1,sharex=True,sharey=True,figsize=(4,4))
  1608. nsims=A_nav.shape[0]
  1609. colors = cm.rainbow(np.linspace(0, 1, nsims))
  1610. for i in range(nsims):
  1611. ax.scatter(A_nav[i,:],A_com[i,:],s=5,color=colors[i])
  1612. minX=-0.5
  1613. maxX=0.5
  1614. ax.set_xlim(minX,maxX)
  1615. ax.set_ylim(minX,maxX)
  1616. ax.hlines(y=0,xmin=minX,xmax=maxX)
  1617. ax.vlines(x=0,ymin=minX,ymax=maxX)
  1618. return fig
  1619. def changes_dd(sims,ind=2): # ind=2: selectivity; ind=1: selectivity - only one ; ind=3: anesthesia
  1620. # plot d.d and spike counts during context changing either selectivity or synapses
  1621. parameters1=sims[0]
  1622. parameters2=sims[1]
  1623. n_com=len(parameters1)
  1624. if ind==2: # when changing selectivity - includes navigation
  1625. n_nav=len(parameters2)
  1626. sims = np.delete(sims,[0,1], 0)
  1627. elif ind==1: # when changing synaptic properties - do not include navigation
  1628. n_nav=0
  1629. sims = np.delete(sims,[0,1], 0)
  1630. else:
  1631. n_nav=0
  1632. sims = np.delete(sims,[0], 0)
  1633. # simulations changing selectivity of communication context
  1634. sp_nav1=[]
  1635. sp_com1=[]
  1636. dd_nav1=[]
  1637. dd_com1=[]
  1638. for s in range(n_com):
  1639. s_i=sims[s]
  1640. dd_nav_p=((s_i[:,1]-s_i[:,0])/2)
  1641. dd_com_p=((s_i[:,3]-s_i[:,2])/2)
  1642. sp_nav_p=(s_i[:,4])
  1643. sp_com_p=(s_i[:,5])
  1644. dd_nav1.append(dd_nav_p)
  1645. dd_com1.append(dd_com_p)
  1646. sp_nav1.append(sp_nav_p)
  1647. sp_com1.append(sp_com_p)
  1648. # simulations changing selectivity of navigation context
  1649. sp_nav2=[]
  1650. sp_com2=[]
  1651. dd_nav2=[]
  1652. dd_com2=[]
  1653. for j in range(n_nav):
  1654. s_i=sims[s+1+j]
  1655. dd_nav_p=((s_i[:,1]-s_i[:,0])/2)
  1656. dd_com_p=((s_i[:,3]-s_i[:,2])/2)
  1657. sp_nav_p=(s_i[:,4])
  1658. sp_com_p=(s_i[:,5])
  1659. dd_nav2.append(dd_nav_p)
  1660. dd_com2.append(dd_com_p)
  1661. sp_nav2.append(sp_nav_p)
  1662. sp_com2.append(sp_com_p)
  1663. # plotting
  1664. fig, ax = plt.subplots(1,2,sharex=True,figsize=(4,2))
  1665. parameters1=np.linspace(0,1,n_com)
  1666. parameters2=np.linspace(0,1,n_nav)
  1667. ax[0].axhline(y=0,color='k',lw=0.5,ls='--')
  1668. # ax[0].set_ylim(-0.05, 0.20)
  1669. ax[0].set_ylabel('d.d.')
  1670. ax[0].axhline(y=0.09,color='b',lw=0.5,ls='--')
  1671. ax[0].axhline(y=0.05,color='r',lw=0.5,ls='--')
  1672. ax[0].plot(parameters1,np.mean(dd_com1,1),color='r',lw=0.75)
  1673. ax[0].fill_between(parameters1, np.mean(dd_com1,1)-sem(dd_com1,1), np.mean(dd_com1,1)+sem(dd_com1,1), alpha=0.3, facecolor='r')
  1674. if ind==2:
  1675. ax[0].plot(parameters2,np.mean(dd_nav2,1),color='b',lw=0.75)
  1676. ax[0].fill_between(parameters2, np.mean(dd_nav2,1)-sem(dd_nav2,1), np.mean(dd_nav2,1)+sem(dd_nav2,1) ,alpha=0.3, facecolor='b')
  1677. else:
  1678. ax[0].plot(parameters1,np.mean(dd_nav1,1),color='b',lw=0.75)
  1679. ax[0].fill_between(parameters1, np.mean(dd_nav1,1)-sem(dd_nav1,1), np.mean(dd_nav1,1)+sem(dd_nav1,1) ,alpha=0.3, facecolor='b')
  1680. ax[1].set_ylabel('# spikes context')
  1681. # ax[1].set_ylim(80, 200)
  1682. ax[1].axhline(y=59,color='b',lw=0.5,ls='--')
  1683. ax[1].axhline(y=81,color='r',lw=0.5,ls='--')
  1684. ax[1].axhline(y=44,color='b',lw=0.5,ls='--')
  1685. ax[1].axhline(y=72,color='r',lw=0.5,ls='--')
  1686. ax[1].plot(parameters1,np.mean(sp_com1,1),color='r',lw=0.75)
  1687. ax[1].fill_between(parameters1, np.mean(sp_com1,1)-sem(sp_com1,1), np.mean(sp_com1,1)+sem(sp_com1,1) ,alpha=0.3, facecolor='r')
  1688. if ind==2:
  1689. ax[1].plot(parameters2,np.mean(sp_nav2,1),color='b',lw=0.75)
  1690. ax[1].fill_between(parameters2, np.mean(sp_nav2,1)-sem(sp_nav2,1), np.mean(sp_nav2,1)+sem(sp_nav2,1) ,alpha=0.3, facecolor='b')
  1691. else:
  1692. ax[1].plot(parameters1,np.mean(sp_nav1,1),color='b',lw=0.75)
  1693. ax[1].fill_between(parameters1, np.mean(sp_nav1,1)-sem(sp_nav1,1), np.mean(sp_nav1,1)+sem(sp_nav1,1) ,alpha=0.3, facecolor='b')
  1694. ax = ax.flatten()
  1695. for axi in ax:
  1696. axi.spines['top'].set_visible(False)
  1697. axi.spines['right'].set_visible(False)
  1698. axi.spines['bottom'].set_linewidth(0.75)
  1699. axi.spines['left'].set_linewidth(0.75)
  1700. if ind==2 or ind==1:
  1701. plt.figtext(0.5,0, 'input selectivity', rotation=0, verticalalignment='bottom')
  1702. else:
  1703. plt.figtext(0.5,0, 'synaptic stregth', rotation=0, verticalalignment='bottom')
  1704. fig.tight_layout(h_pad=3) #w_pad=0.6,h_pad=0.6
  1705. return fig
  1706. def marbels_dd(sims):
  1707. # plot spike counts during context in: cortex, LF input and HF input
  1708. parameters1=sims[0]
  1709. parameters2=sims[1]
  1710. n_com=len(parameters1)
  1711. n_nav=len(parameters2)
  1712. sims = np.delete(sims,[0,1], 0)
  1713. # simulations changing selectivity of communication context
  1714. dd_com_com=[]
  1715. sp_com_com=[]
  1716. sp_lf_com=[]
  1717. sp_hf_com=[]
  1718. for s in range(n_com):
  1719. s_i=sims[s]
  1720. # dd_nav=((s_i[:,1]-s_i[:,0])/2)
  1721. dd_com=((s_i[:,3]-s_i[:,2])/2)
  1722. # sp_nav=(s_i[:,4])
  1723. # sp_LF=(s_i[:,5])
  1724. # sp_HF=(s_i[:,6])
  1725. sp_com=(s_i[:,7])
  1726. sp_LF=(s_i[:,8])
  1727. sp_HF=(s_i[:,9])
  1728. dd_com_com.append(dd_com)
  1729. sp_com_com.append(sp_com)
  1730. sp_lf_com.append(sp_LF)
  1731. sp_hf_com.append(sp_HF)
  1732. # simulations changing selectivity of navigation context
  1733. dd_nav_nav=[]
  1734. sp_nav_nav=[]
  1735. sp_lf_nav=[]
  1736. sp_hf_nav=[]
  1737. for j in range(n_nav):
  1738. s_i=sims[s+1+j]
  1739. dd_nav=((s_i[:,1]-s_i[:,0])/2)
  1740. # dd_com=((s_i[:,3]-s_i[:,2])/2)
  1741. sp_nav=(s_i[:,4])
  1742. sp_LF=(s_i[:,5])
  1743. sp_HF=(s_i[:,6])
  1744. # sp_com=(s_i[:,7])
  1745. # sp_LF=(s_i[:,8])
  1746. # sp_HF=(s_i[:,9])
  1747. dd_nav_nav.append(dd_nav)
  1748. sp_nav_nav.append(sp_nav)
  1749. sp_lf_nav.append(sp_LF)
  1750. sp_hf_nav.append(sp_HF)
  1751. # plotting
  1752. fig, ax = plt.subplots(1,2,sharex=True,figsize=(4,2))
  1753. parameters1=np.linspace(0,1,n_com)
  1754. parameters2=np.linspace(0,1,n_nav)
  1755. # communication change selectivity
  1756. a=sp_com_com
  1757. color_i='k'
  1758. ax2 = ax[0].twinx()
  1759. ax2.plot(parameters1,np.mean(a,1),color=color_i,lw=0.75)
  1760. ax2.fill_between(parameters1, np.mean(a,1)-sem(a,1), np.mean(a,1)+sem(a,1), alpha=0.3, facecolor=color_i)
  1761. ax2.set_ylim(40,99)
  1762. ax2.spines['top'].set_visible(False)
  1763. ax2.set_ylabel('# spikes cortex')
  1764. a=sp_lf_com
  1765. color_i='r'
  1766. ax[0].plot(parameters1,np.mean(a,1),color=color_i,lw=0.75)
  1767. ax[0].fill_between(parameters1, np.mean(a,1)-sem(a,1), np.mean(a,1)+sem(a,1), alpha=0.3, facecolor=color_i)
  1768. a=sp_hf_com
  1769. color_i='b'
  1770. ax[0].plot(parameters1,np.mean(a,1),color=color_i,lw=0.75)
  1771. ax[0].fill_between(parameters1, np.mean(a,1)-sem(a,1), np.mean(a,1)+sem(a,1), alpha=0.3, facecolor=color_i)
  1772. # ax[0].set_ylim(0,50)
  1773. ax[0].set_ylabel('# spikes inputs')
  1774. ax[0].set_xlabel('input selectivity to com')
  1775. # navigation change selectivity
  1776. a=sp_nav_nav
  1777. color_i='k'
  1778. ax2 = ax[1].twinx()
  1779. ax2.plot(parameters1,np.mean(a,1),color=color_i,lw=0.75)
  1780. ax2.fill_between(parameters1, np.mean(a,1)-sem(a,1), np.mean(a,1)+sem(a,1), alpha=0.3, facecolor=color_i)
  1781. ax2.set_ylim(40,99)
  1782. ax2.spines['top'].set_visible(False)
  1783. ax2.set_ylabel('# spikes cortex')
  1784. a=sp_lf_nav
  1785. color_i='r'
  1786. ax[1].plot(parameters1,np.mean(a,1),color=color_i,lw=0.75)
  1787. ax[1].fill_between(parameters1, np.mean(a,1)-sem(a,1), np.mean(a,1)+sem(a,1), alpha=0.3, facecolor=color_i)
  1788. a=sp_hf_nav
  1789. color_i='b'
  1790. ax[1].plot(parameters1,np.mean(a,1),color=color_i,lw=0.75)
  1791. ax[1].fill_between(parameters1, np.mean(a,1)-sem(a,1), np.mean(a,1)+sem(a,1), alpha=0.3, facecolor=color_i)
  1792. # ax[1].set_ylabel('# spikes context')
  1793. ax[1].set_xlabel('input selectivity to nav')
  1794. ax = ax.flatten()
  1795. for axi in ax:
  1796. axi.spines['top'].set_visible(False)
  1797. axi.spines['right'].set_visible(False)
  1798. axi.spines['bottom'].set_linewidth(0.75)
  1799. axi.spines['left'].set_linewidth(0.75)
  1800. fig.tight_layout(h_pad=3) #w_pad=0.6,h_pad=0.6
  1801. return fig
  1802. def sims_synaptic(N_units,k_low_com=0,k_high_com=0,k_high_nav=0,k_low_nav=0):
  1803. # run 2 simulations varying contexts
  1804. # outputs:
  1805. # average of synaptic depression per synapse
  1806. # average of synaptic weight per synapse
  1807. trials=N_units*20
  1808. dur_ech=int(1.3311*10000)+1500
  1809. dur_com=int(1.9266*10000)+1500
  1810. masker=np.repeat(range(1,N_units+1),20)
  1811. synapses=np.repeat(range(1,N_units+1),20)
  1812. # SIMULATION 1: navigation context
  1813. context=1
  1814. exp=1
  1815. exec(open("./input.py").read())
  1816. exec(open("./model.py").read())
  1817. col=firing_context(ac,onset,context)
  1818. colLF=firing_context(sp_low,onset,context)
  1819. colHF=firing_context(sp_high,onset,context)
  1820. masker=np.column_stack((masker, col))
  1821. masker=np.column_stack((masker, colLF))
  1822. masker=np.column_stack((masker, colHF))
  1823. LF_xs=np.mean(mon.x_S[:trials,:dur_ech],1)
  1824. HF_xs=np.mean(mon.x_S[trials:,:dur_ech],1)
  1825. synapses=np.column_stack((synapses,LF_xs,HF_xs))
  1826. LF_ge=np.mean(syn_w.g_e[:trials,:dur_ech]/psiemens,1)
  1827. HF_ge=np.mean(syn_w.g_e[trials:,:dur_ech]/psiemens,1)
  1828. synapses=np.column_stack((synapses,LF_ge,HF_ge))
  1829. # SIMULATION 2: communication context
  1830. context=2
  1831. exp=1
  1832. exec(open("./input.py").read())
  1833. exec(open("./model.py").read())
  1834. col=firing_context(ac,onset,context)
  1835. colLF=firing_context(sp_low,onset,context)
  1836. colHF=firing_context(sp_high,onset,context)
  1837. masker=np.column_stack((masker, col))
  1838. masker=np.column_stack((masker, colLF))
  1839. masker=np.column_stack((masker, colHF))
  1840. LF_xs=np.mean(mon.x_S[:trials,:dur_com],1)
  1841. HF_xs=np.mean(mon.x_S[trials:,:dur_com],1)
  1842. synapses=np.column_stack((synapses,LF_xs,HF_xs))
  1843. LF_ge=np.mean(syn_w.g_e[:trials,:dur_com]/psiemens,1)
  1844. HF_ge=np.mean(syn_w.g_e[trials:,:dur_com]/psiemens,1)
  1845. synapses=np.column_stack((synapses,LF_ge,HF_ge))
  1846. return masker,synapses
  1847. def syn_variables(sims,con=0):
  1848. # plot spike counts during context in: cortex, LF input and HF input
  1849. # plot synaptic variables recorded: x_S and g_e
  1850. # con=0 : results in response to echolocation context
  1851. # con=1 : results in response to communication context
  1852. parameters1=sims[0]
  1853. n=len(parameters1)
  1854. sims = np.delete(sims,[0], 0)
  1855. if con==0: # in response to echo
  1856. shift_sp=int(0)
  1857. shift_syn=int(0)
  1858. elif con==1: # in response to com
  1859. shift_sp=int(3)
  1860. shift_syn=int(4)
  1861. # simulations changing selectivity of "con" context
  1862. sp_c=[]
  1863. sp_LF=[]
  1864. sp_HF=[]
  1865. xs_av=[]
  1866. xs_av_lf=[]
  1867. xs_av_hf=[]
  1868. ge_av=[]
  1869. for s in range(n):
  1870. s_i=sims[s]
  1871. mean_i=np.mean(s_i,0)
  1872. sp_c_i=mean_i[1+shift_sp] # cortical
  1873. sp_LF_i=mean_i[2+shift_sp] # LF input
  1874. sp_HF_i=mean_i[3+shift_sp] # HF input
  1875. xs_lf=(mean_i[8+shift_syn])
  1876. xs_hf=(mean_i[9+shift_syn])
  1877. xs_i=(mean_i[8+shift_syn]+mean_i[9+shift_syn])/2 # average between LF and HF
  1878. ge_i=(mean_i[10+shift_syn]+mean_i[11+shift_syn])/2 # average between LF and HF
  1879. sp_c.append(sp_c_i)
  1880. sp_LF.append(sp_LF_i)
  1881. sp_HF.append(sp_HF_i)
  1882. xs_av.append(xs_i)
  1883. xs_av_lf.append(xs_lf)
  1884. xs_av_hf.append(xs_hf)
  1885. ge_av.append(ge_i)
  1886. # plotting
  1887. fig, ax=plt.subplots(1,figsize=(3,2))
  1888. sum_inputs=[x + y for x, y in zip(sp_LF, sp_HF)]
  1889. # ax.plot(parameters1,sp_c,'k')
  1890. ax.plot(parameters1,sp_LF,'r')
  1891. ax.plot(parameters1,sp_HF,'b')
  1892. ax.plot(parameters1,sum_inputs,'k')
  1893. ax2=ax.twinx()
  1894. # ax2.plot(parameters1,ge_av/max(ge_av),'--g')
  1895. ax2.plot(parameters1,[j*8 for j in xs_av_lf],'--r')
  1896. ax2.plot(parameters1,[j*8 for j in xs_av_hf],'--b')
  1897. # sum_xs=[x + y for x, y in zip(xs_av_lf, xs_av_hf)]
  1898. # ax2.plot(parameters1,sum_xs,'--k')
  1899. ax.set_xlabel('bandwidth of sound')
  1900. ax.set_ylabel('input spike count')
  1901. ax2.set_ylabel('synaptic strength (nS)',color='k')
  1902. ax2.set_ylim([5.8, 8]) #ax2.get_ylim()[0]
  1903. # for tl in ax2.get_yticklabels():
  1904. # tl.set_color('g')
  1905. ax.spines['top'].set_visible(False)
  1906. ax.spines['right'].set_visible(False)
  1907. ax.spines['bottom'].set_linewidth(0.75)
  1908. ax.spines['left'].set_linewidth(0.75)
  1909. ax2.spines['top'].set_visible(False)
  1910. ax2.spines['left'].set_visible(False)
  1911. ax2.spines['bottom'].set_linewidth(0.75)
  1912. ax2.spines['right'].set_linewidth(0.75)
  1913. fig.tight_layout()
  1914. plt.locator_params(nbins=4)
  1915. return fig
  1916. def compare_synweight(sims1,sims2):
  1917. # plot spike counts during context in: cortex, LF input and HF input
  1918. parameters1=sims1[0]
  1919. parameters2=sims1[1]
  1920. n_com=len(parameters1)
  1921. n_nav=len(parameters2)
  1922. sims1 = np.delete(sims1,[0,1], 0)
  1923. sims2 = np.delete(sims2,[0,1], 0)
  1924. # simulations changing selectivity of communication context
  1925. post_c_com1=[]
  1926. post_c_com2=[]
  1927. for s in range(n_com):
  1928. s_i1=sims1[s]
  1929. s_i2=sims2[s]
  1930. mean_i1=np.mean(s_i1,0)
  1931. mean_i2=np.mean(s_i2,0)
  1932. post_com1=mean_i1[8]
  1933. post_com2=mean_i2[8]
  1934. post_c_com1.append(post_com1)
  1935. post_c_com2.append(post_com2)
  1936. # simulations changing selectivity of navigation context
  1937. post_n_nav1=[]
  1938. post_n_nav2=[]
  1939. for j in range(n_nav):
  1940. s_i1=sims1[s+1+j]
  1941. s_i2=sims2[s+1+j]
  1942. mean_i1=np.mean(s_i1,0)
  1943. mean_i2=np.mean(s_i2,0)
  1944. post_nav1=mean_i1[6]
  1945. post_nav2=mean_i2[6]
  1946. post_n_nav1.append(post_nav1)
  1947. post_n_nav2.append(post_nav2)
  1948. # plotting the postsynaptic weight
  1949. fig, ax = plt.subplots(1,2,sharex=True,figsize=(4,2))
  1950. parameters1=np.linspace(0,1,n_com)
  1951. parameters2=np.linspace(0,1,n_nav)
  1952. # communication change selectivity
  1953. ax[0].plot(parameters1,post_c_com1,color='k',lw=0.75)
  1954. ax[0].plot(parameters1,post_c_com2,color='r',lw=0.75)
  1955. ax[0].set_xlabel('input selectivity to com')
  1956. ax[0].set_ylabel('postsynaptic conductance')
  1957. # navigation change selectivity
  1958. ax[1].plot(parameters2,post_n_nav1,color='k',lw=0.75)
  1959. ax[1].plot(parameters2,post_n_nav2,color='r',lw=0.75)
  1960. ax[1].set_xlabel('input selectivity to nav')
  1961. ax = ax.flatten()
  1962. for axi in ax:
  1963. axi.spines['top'].set_visible(False)
  1964. axi.spines['right'].set_visible(False)
  1965. axi.spines['bottom'].set_linewidth(0.75)
  1966. axi.spines['left'].set_linewidth(0.75)
  1967. fig.tight_layout(h_pad=3) #w_pad=0.6,h_pad=0.6
  1968. return fig
  1969. def ce_synapses(sims):
  1970. # plot c.e changing synaptic weight
  1971. parameters1=sims[0]
  1972. n_com=len(parameters1)
  1973. sims = np.delete(sims,[0], 0)
  1974. # simulations changing selectivity of communication context
  1975. ce_nav_exp=[]
  1976. ce_nav_unexp=[]
  1977. ce_com_exp=[]
  1978. ce_com_unexp=[]
  1979. for s in range(n_com):
  1980. s_i=sims[s]
  1981. a=s_i[:,0]
  1982. b=s_i[:,1]
  1983. c=s_i[:,2]
  1984. d=s_i[:,3]
  1985. ce_nav_exp.append(a)
  1986. ce_nav_unexp.append(b)
  1987. ce_com_exp.append(c)
  1988. ce_com_unexp.append(d)
  1989. # plotting
  1990. fig, ax = plt.subplots(1,2,sharex=True,sharey=True,figsize=(4,2))
  1991. ax[0].axhline(y=0,color='k',lw=0.5,ls='--')
  1992. # ax[0].set_ylim(-0.6, 0)
  1993. ax[0].set_ylabel('c.e.')
  1994. ax[0].set_xlabel('synapse decrement (nav)')
  1995. ax[0].plot(parameters1,np.mean(ce_nav_unexp,1),color='k',lw=0.75)
  1996. ax[0].fill_between(parameters1, np.mean(ce_nav_unexp,1)-sem(ce_nav_unexp,1), np.mean(ce_nav_unexp,1)+sem(ce_nav_unexp,1), alpha=0.3, facecolor='k')
  1997. ax[0].plot(parameters1,np.mean(ce_nav_exp,1),color='b',lw=0.75)
  1998. ax[0].fill_between(parameters1, np.mean(ce_nav_exp,1)-sem(ce_nav_exp,1), np.mean(ce_nav_exp,1)+sem(ce_nav_exp,1), alpha=0.3, facecolor='b')
  1999. ax[1].axhline(y=0,color='k',lw=0.5,ls='--')
  2000. ax[1].set_xlabel('synapse decrement (com)')
  2001. ax[1].plot(parameters1,np.mean(ce_com_unexp,1),color='k',lw=0.75)
  2002. ax[1].fill_between(parameters1, np.mean(ce_com_unexp,1)-sem(ce_com_unexp,1), np.mean(ce_com_unexp,1)+sem(ce_com_unexp,1), alpha=0.3, facecolor='k')
  2003. ax[1].plot(parameters1,np.mean(ce_com_exp,1),color='b',lw=0.75)
  2004. ax[1].fill_between(parameters1, np.mean(ce_com_exp,1)-sem(ce_com_exp,1), np.mean(ce_com_exp,1)+sem(ce_nav_exp,1), alpha=0.3, facecolor='b')
  2005. ax = ax.flatten()
  2006. for axi in ax:
  2007. axi.spines['top'].set_visible(False)
  2008. axi.spines['right'].set_visible(False)
  2009. axi.spines['bottom'].set_linewidth(0.75)
  2010. axi.spines['left'].set_linewidth(0.75)
  2011. fig.tight_layout(h_pad=3) #w_pad=0.6,h_pad=0.6
  2012. return fig
  2013. def plot_we_d(sims):
  2014. parameters1=sims[0]
  2015. parameters2=sims[1]
  2016. sims = np.delete(sims,[0,1], 0)
  2017. ntrials=len(sims[0])
  2018. nx=len(parameters1)
  2019. ny=len(parameters2)
  2020. ntot=nx*ny
  2021. N_units=int(ntrials/20)
  2022. # calculate cliff delta from simulations per unit
  2023. sims_nav=[]
  2024. sims_com=[]
  2025. for s in range(ntot):
  2026. s_i=np.mean(sims[s],0)
  2027. # spikes in response to echolocation context
  2028. sp_n_c=s_i[1] # cortical neurons
  2029. sp_n_LF=s_i[2] # LF-tuned input
  2030. sp_n_HF=s_i[3] # HF-tuned input
  2031. # spikes in response to communication context
  2032. sp_c_c=s_i[4]
  2033. sp_c_LF=s_i[5]
  2034. sp_c_HF=s_i[6]
  2035. sims_nav.append([sp_n_c,sp_n_LF,sp_n_HF])
  2036. sims_com.append([sp_c_c,sp_c_LF,sp_c_HF])
  2037. sims_nav=np.array(sims_nav)
  2038. sims_com=np.array(sims_com)
  2039. # convert into 2D matrix results and stats
  2040. # what to plot? cortical, LF input or HF input
  2041. ind=1 # 1: cortical; 2: LF; 3: HF
  2042. a=sims_nav[:,ind-1]
  2043. b=sims_com[:,ind-1]
  2044. av_nav=np.reshape(a,(nx,ny)).T
  2045. av_com=np.reshape(b,(nx,ny)).T
  2046. # plotting
  2047. fig, ax = plt.subplots(1,2,sharex=True,sharey=True,figsize=(5.5,1.9))
  2048. li=95 # max of colorbar
  2049. nav=ax[0].imshow(av_nav,cmap='jet',origin='lower',vmin=0,vmax=li)
  2050. com=ax[1].imshow(av_com,cmap='jet',origin='lower',vmin=0,vmax=li)
  2051. fig.colorbar(nav, ax=ax[0])
  2052. fig.colorbar(com, ax=ax[1])
  2053. fig.tight_layout()
  2054. fig2, ax = plt.subplots(1,3,sharex=True,sharey=True,figsize=(5.5,1.9))
  2055. li=95 # max of colorbar
  2056. fix_d=8
  2057. ax[0].set_title('increasing synaptic weight')
  2058. ax[0].plot(av_nav[:,fix_d],'b')
  2059. ax[0].plot(av_com[:,fix_d]-20,'r')
  2060. ax[2].set_title('increasing both (we and d)')
  2061. ax[2].plot(np.fliplr(av_nav).diagonal(),'b')
  2062. ax[2].plot(np.fliplr(av_com).diagonal()-20,'r')
  2063. ax[1].set_title('increasing synaptic depression')
  2064. ax[1].plot(av_nav[fix_d,:],'b')
  2065. ax[1].plot(av_com[fix_d,:]-20,'r')
  2066. fig2.tight_layout()
  2067. return fig, fig2
  2068. def plot_v_alpha(sims,sims2):
  2069. ratios=sims[0]
  2070. vmax=sims[1]
  2071. sims_com = np.delete(sims,[0,1], 0)
  2072. sims_nav = np.delete(sims2,[0,1], 0)
  2073. ntrials=len(sims_com[0])
  2074. n_ratios=len(ratios)
  2075. n_v=len(vmax)
  2076. j=0
  2077. ratios_com_c=[] # changing ratios ch1/ch2 in response to communication
  2078. ratios_nav_c=[] # changing ratios ch1/ch2 in response to navigation
  2079. ratios_com_LF=[] # changing ratios ch1/ch2 in response to communication
  2080. ratios_nav_LF=[] # changing ratios ch1/ch2 in response to navigation
  2081. ratios_com_HF=[] # changing ratios ch1/ch2 in response to communication
  2082. ratios_nav_HF=[] # changing ratios ch1/ch2 in response to navigation
  2083. for x in range(n_ratios): # across simulations of ch1/ch2
  2084. vs_per_ratio_com_c=[]
  2085. vs_per_ratio_nav_c=[]
  2086. vs_per_ratio_com_LF=[]
  2087. vs_per_ratio_nav_LF=[]
  2088. vs_per_ratio_com_HF=[]
  2089. vs_per_ratio_nav_HF=[]
  2090. for y in range(n_v): # across simulations of v
  2091. # average across 1000 trials (50units*20trials)
  2092. s_n=np.mean(sims_nav[j],0)
  2093. s_c=np.mean(sims_com[j],0)
  2094. # save average spikes in vectors per ratio
  2095. vs_per_ratio_com_c.append(s_c[11]) # cortical neurons in response to com
  2096. vs_per_ratio_nav_c.append(s_n[8]) # cortical neurons in response to nav
  2097. vs_per_ratio_com_LF.append(s_c[12]) # LF input in response to com
  2098. vs_per_ratio_nav_LF.append(s_n[9]) # LF input in response to nav
  2099. vs_per_ratio_com_HF.append(s_c[13]) # HF input in response to com
  2100. vs_per_ratio_nav_HF.append(s_n[10]) # HF input in response to nav
  2101. j=j+1
  2102. ratios_com_c.append(vs_per_ratio_com_c)
  2103. ratios_nav_c.append(vs_per_ratio_nav_c)
  2104. ratios_com_LF.append(vs_per_ratio_com_LF)
  2105. ratios_nav_LF.append(vs_per_ratio_nav_LF)
  2106. ratios_com_HF.append(vs_per_ratio_com_HF)
  2107. ratios_nav_HF.append(vs_per_ratio_nav_HF)
  2108. ## plotting spike counts during context across different ratios and v ##
  2109. dur_ech=1.3311
  2110. dur_com=1.9266
  2111. ratios_com_c=np.array(ratios_com_c)/dur_com
  2112. ratios_nav_c=np.array(ratios_nav_c)/dur_ech
  2113. fig1, ax=plt.subplots(2,3,sharex=True,figsize=(6.5,3))
  2114. colors = cm.jet(np.linspace(0,1,n_ratios))
  2115. for i in range(n_ratios):
  2116. ax[0,0].plot(vmax,ratios_com_c[i],color=colors[i],lw=1)
  2117. ax[0,0].set_title('response to com')
  2118. ax[0,0].set_ylabel('cortical')
  2119. for i in range(n_ratios):
  2120. ax[0,1].plot(vmax,ratios_com_LF[i],color=colors[i],lw=1)
  2121. ax[0,1].set_title('response to com')
  2122. ax[0,1].set_ylabel('LF inputs')
  2123. for i in range(n_ratios):
  2124. ax[0,2].plot(vmax,ratios_com_HF[i],color=colors[i],lw=1)
  2125. ax[0,2].set_title('response to com')
  2126. ax[0,2].set_ylabel('HF inputs')
  2127. for i in range(n_ratios):
  2128. ax[1,0].plot(vmax,ratios_nav_c[i],color=colors[i],lw=1)
  2129. ax[1,0].set_title('response to nav')
  2130. ax[1,0].set_ylabel('cortical')
  2131. for i in range(n_ratios):
  2132. ax[1,1].plot(vmax,ratios_nav_LF[i],color=colors[i],lw=1)
  2133. ax[1,1].set_title('response to nav')
  2134. ax[1,1].set_ylabel('LF inputs')
  2135. for i in range(n_ratios):
  2136. ax[1,2].plot(vmax,ratios_nav_HF[i],color=colors[i],lw=1)
  2137. ax[1,2].set_title('response to nav')
  2138. ax[1,2].set_ylabel('HF inputs')
  2139. # add experimental data
  2140. # ax[0,0].axhline(y=59,color='b',lw=0.5,ls='--')
  2141. ax[0,0].axhline(y=81/dur_com,color='r',lw=0.5,ls='--')
  2142. # ax[0,0].axhline(y=44,color='b',lw=0.5,ls='--')
  2143. ax[0,0].axhline(y=72/dur_com,color='r',lw=0.5,ls='--')
  2144. ax[1,0].axhline(y=59/dur_ech,color='b',lw=0.5,ls='--')
  2145. # ax[1,0].axhline(y=81,color='r',lw=0.5,ls='--')
  2146. ax[1,0].axhline(y=44/dur_ech,color='b',lw=0.5,ls='--')
  2147. # ax[1,0].axhline(y=72,color='r',lw=0.5,ls='--')
  2148. ax = ax.flatten()
  2149. for axi in ax:
  2150. axi.spines['top'].set_visible(False)
  2151. axi.spines['right'].set_visible(False)
  2152. axi.spines['bottom'].set_linewidth(0.75)
  2153. axi.spines['left'].set_linewidth(0.75)
  2154. fig1.tight_layout()
  2155. ## plotting changes across different ratios for a fixed v ##
  2156. # in response to communication
  2157. fig2, ax=plt.subplots(1,figsize=(3,2))
  2158. v_inx=-1
  2159. alpha_com_c=[vi[v_inx] for vi in ratios_com_c]
  2160. alpha_com_LH=[vi[v_inx] for vi in ratios_com_LF]
  2161. alpha_com_HF=[vi[v_inx] for vi in ratios_com_HF]
  2162. sum_inputs_com=[x + y for x, y in zip(alpha_com_LH, alpha_com_HF)]
  2163. ax.plot(ratios,alpha_com_LH,'r')
  2164. ax.plot(ratios,alpha_com_HF,'b')
  2165. ax.plot(ratios,sum_inputs_com,'k')
  2166. # ax.plot(alpha_com_c,'k')
  2167. ax.set_xlabel('bandwidth of communication')
  2168. ax.set_ylabel('input spike count')
  2169. ax.spines['top'].set_visible(False)
  2170. ax.spines['right'].set_visible(False)
  2171. ax.spines['bottom'].set_linewidth(0.75)
  2172. ax.spines['left'].set_linewidth(0.75)
  2173. fig2.tight_layout()
  2174. # in response to navigation
  2175. fig3, ax=plt.subplots(1,figsize=(3,2))
  2176. alpha_nav_c=[vi[v_inx] for vi in ratios_nav_c]
  2177. alpha_nav_LH=[vi[v_inx] for vi in ratios_nav_LF]
  2178. alpha_nav_HF=[vi[v_inx] for vi in ratios_nav_HF]
  2179. sum_inputs_nav=[x + y for x, y in zip(alpha_nav_LH, alpha_nav_HF)]
  2180. ax.plot(ratios,alpha_nav_LH,'r')
  2181. ax.plot(ratios,alpha_nav_HF,'b')
  2182. ax.plot(ratios,sum_inputs_nav,'k')
  2183. ax.set_ylabel('input spike count')
  2184. ax.set_xlabel('bandwidth of sound')
  2185. ax.spines['top'].set_visible(False)
  2186. ax.spines['right'].set_visible(False)
  2187. ax.spines['bottom'].set_linewidth(0.75)
  2188. ax.spines['left'].set_linewidth(0.75)
  2189. fig3.tight_layout()
  2190. # fig4, ax=plt.subplots(1,1,figsize=(5,2.5))
  2191. # ax.plot(vmax[0:-1],np.diff(ratios_com_c[9])/np.diff(vmax),'r')
  2192. # yy=[f for f in ratios_nav_c[0]]
  2193. # ax.plot(vmax[0:-1],np.diff(yy)/np.diff(vmax),'b')
  2194. fig5, ax=plt.subplots(1,figsize=(3,2))
  2195. ax.plot(ratios,alpha_nav_c,'k')
  2196. ax.set_ylabel('output spike count')
  2197. ax.set_xlabel('bandwidth of echolocation')
  2198. ax.spines['top'].set_visible(False)
  2199. ax.spines['right'].set_visible(False)
  2200. ax.spines['bottom'].set_linewidth(0.75)
  2201. ax.spines['left'].set_linewidth(0.75)
  2202. fig5.tight_layout()
  2203. return fig3
  2204. def first_approx(sims):
  2205. # for the first plots on the paper first approximation to anesthesia effects
  2206. parameters1=sims[0]
  2207. parameters2=sims[1]
  2208. sims = np.delete(sims,[0,1], 0)
  2209. nx=len(parameters1)
  2210. ny=len(parameters2)
  2211. dur_ech=1#1.3311
  2212. dur_com=1#1.9266
  2213. # for plotting 11 parameters average+- std for one fixed x
  2214. x_fixed=10
  2215. dd_nav_fixedx=[]
  2216. dd_com_fixedx=[]
  2217. di_nav_fixedx=[]
  2218. di_iso_fixedx=[]
  2219. di_com_fixedx=[]
  2220. ce_n_e_fixedx=[]
  2221. ce_n_u_fixedx=[]
  2222. ce_c_e_fixedx=[]
  2223. ce_c_u_fixedx=[]
  2224. sp_nav_fixedx=[]
  2225. sp_com_fixedx=[]
  2226. # ...and for one fixed y
  2227. y_fixed=0
  2228. dd_nav_fixedy=[]
  2229. dd_com_fixedy=[]
  2230. di_nav_fixedy=[]
  2231. di_iso_fixedy=[]
  2232. di_com_fixedy=[]
  2233. ce_n_e_fixedy=[]
  2234. ce_n_u_fixedy=[]
  2235. ce_c_e_fixedy=[]
  2236. ce_c_u_fixedy=[]
  2237. sp_nav_fixedy=[]
  2238. sp_com_fixedy=[]
  2239. # for plotting 2D only the average across units
  2240. dd_nav=[]
  2241. dd_com=[]
  2242. di_nav=[]
  2243. di_iso=[]
  2244. di_com=[]
  2245. ce_n_e=[]
  2246. ce_n_u=[]
  2247. ce_c_e=[]
  2248. ce_c_u=[]
  2249. rate_nav=[]
  2250. rate_com=[]
  2251. j=0
  2252. for x in range(nx): # we or v
  2253. y_var_dd_nav=[]
  2254. y_var_dd_com=[]
  2255. y_var_di_nav=[]
  2256. y_var_di_iso=[]
  2257. y_var_di_com=[]
  2258. y_var_ce_n_e=[]
  2259. y_var_ce_n_u=[]
  2260. y_var_ce_c_e=[]
  2261. y_var_ce_c_u=[]
  2262. y_var_sp_nav=[]
  2263. y_var_sp_com=[]
  2264. for y in range(ny): # d
  2265. # j is a particular combinations of parameters
  2266. # 1D needs all the values
  2267. if x==x_fixed:
  2268. # context effect
  2269. ce_fixed=context_effect(sims[j])
  2270. ce_n_e_fixedx.append(ce_fixed[:,0])
  2271. ce_n_u_fixedx.append(ce_fixed[:,1])
  2272. ce_c_e_fixedx.append(ce_fixed[:,2])
  2273. ce_c_u_fixedx.append(ce_fixed[:,3])
  2274. # deviance detection
  2275. dd_nav_fixed=(ce_fixed[:,1]-ce_fixed[:,0])/2
  2276. dd_com_fixed=(ce_fixed[:,3]-ce_fixed[:,2])/2
  2277. dd_nav_fixedx.append(dd_nav_fixed)
  2278. dd_com_fixedx.append(dd_com_fixed)
  2279. # discriminability index
  2280. di_fixed=discriminability_index(sims[j])
  2281. di_nav_fixedx.append(di_fixed[:,0])
  2282. di_iso_fixedx.append(di_fixed[:,1])
  2283. di_com_fixedx.append(di_fixed[:,2])
  2284. # firing rate context
  2285. sp_fixed=sims[j]
  2286. sp_nav=np.reshape(sp_fixed[:,8],(50,20))
  2287. sp_nav_fixedx.append(np.mean(sp_nav,1)/dur_ech)
  2288. sp_com=np.reshape(sp_fixed[:,11],(50,20))
  2289. sp_com_fixedx.append(np.mean(sp_com,1)/dur_com)
  2290. if y==y_fixed:
  2291. # context effect
  2292. ce_fixed=context_effect(sims[j])
  2293. ce_n_e_fixedy.append(ce_fixed[:,0])
  2294. ce_n_u_fixedy.append(ce_fixed[:,1])
  2295. ce_c_e_fixedy.append(ce_fixed[:,2])
  2296. ce_c_u_fixedy.append(ce_fixed[:,3])
  2297. # deviance detection
  2298. dd_nav_fixed=(ce_fixed[:,1]-ce_fixed[:,0])/2
  2299. dd_com_fixed=(ce_fixed[:,3]-ce_fixed[:,2])/2
  2300. dd_nav_fixedy.append(dd_nav_fixed)
  2301. dd_com_fixedy.append(dd_com_fixed)
  2302. # discriminability index
  2303. di_fixed=discriminability_index(sims[j])
  2304. di_nav_fixedy.append(di_fixed[:,0])
  2305. di_iso_fixedy.append(di_fixed[:,1])
  2306. di_com_fixedy.append(di_fixed[:,2])
  2307. # firing rate context
  2308. sp_fixed=sims[j]
  2309. sp_nav=np.reshape(sp_fixed[:,8],(50,20))
  2310. sp_nav_fixedy.append(np.mean(sp_nav,1)/dur_ech)
  2311. sp_com=np.reshape(sp_fixed[:,11],(50,20))
  2312. sp_com_fixedy.append(np.mean(sp_com,1)/dur_com)
  2313. # 2D only needs the average
  2314. ce_i=np.mean(context_effect(sims[j]),0)
  2315. dd_nav_i=(ce_i[1]-ce_i[0])/2
  2316. dd_com_i=(ce_i[3]-ce_i[2])/2
  2317. y_var_dd_nav.append(dd_nav_i)
  2318. y_var_dd_com.append(dd_com_i)
  2319. # context effect
  2320. y_var_ce_n_e.append(ce_i[0])
  2321. y_var_ce_n_u.append(ce_i[1])
  2322. y_var_ce_c_e.append(ce_i[2])
  2323. y_var_ce_c_u.append(ce_i[3])
  2324. # discriminability index
  2325. di_i=np.mean(discriminability_index(sims[j]),0)
  2326. y_var_di_nav.append(di_i[0])
  2327. y_var_di_iso.append(di_i[1])
  2328. y_var_di_com.append(di_i[2])
  2329. # firing rate
  2330. sp_contexts=sims[j]
  2331. y_var_sp_nav.append(np.mean(sp_contexts[:,8])/dur_ech)
  2332. y_var_sp_com.append(np.mean(sp_contexts[:,11])/dur_com)
  2333. j=j+1
  2334. dd_nav.append(y_var_dd_nav)
  2335. dd_com.append(y_var_dd_com)
  2336. di_nav.append(y_var_di_nav)
  2337. di_iso.append(y_var_di_iso)
  2338. di_com.append(y_var_di_com)
  2339. ce_n_e.append(y_var_ce_n_e)
  2340. ce_n_u.append(y_var_ce_n_u)
  2341. ce_c_e.append(y_var_ce_c_e)
  2342. ce_c_u.append(y_var_ce_c_u)
  2343. rate_nav.append(y_var_sp_nav)
  2344. rate_com.append(y_var_sp_com)
  2345. dd_nav=np.array(dd_nav)
  2346. dd_com=np.array(dd_com)
  2347. di_nav=np.array(di_nav)
  2348. di_iso=np.array(di_iso)
  2349. di_com=np.array(di_com)
  2350. ce_n_e=np.array(ce_n_e)
  2351. ce_n_u=np.array(ce_n_u)
  2352. ce_c_e=np.array(ce_c_e)
  2353. ce_c_u=np.array(ce_c_u)
  2354. rate_nav=np.array(rate_nav)
  2355. rate_com=np.array(rate_com)
  2356. # parameters1=np.arange(0.1,1.1,0.1)
  2357. orr=0
  2358. # plotting 1D with one parameter fixed
  2359. fig1, ax = plt.subplots(1,figsize=(1.75,1.1))
  2360. A = dd_nav_fixedx
  2361. B = dd_com_fixedx
  2362. X = parameters2
  2363. ax.plot(X,np.mean(A,1),color='b',lw=0.75,marker="o",markersize=2)
  2364. ax.fill_between(X, np.mean(A,1)-sem(A,1), np.mean(A,1)+sem(A,1), alpha=0.3, facecolor='b')
  2365. ax.plot(X,np.mean(B,1),color='r',lw=0.75,marker="o",markersize=2)
  2366. ax.fill_between(X, np.mean(B,1)-sem(B,1), np.mean(B,1)+sem(B,1), alpha=0.3, facecolor='r')
  2367. # statistics
  2368. # ax2 = ax.twinx()
  2369. # stats=[comp_exp(par,'dd_nav','awake') for par in A]
  2370. # ax2.plot(X,stats,'b--')
  2371. # stats=[comp_exp(par,'dd_nav','anesthesia') for par in A]
  2372. # ax2.plot(X,stats,'r--')
  2373. # add errorbar for experimental data
  2374. mat_contents = sio.loadmat(r'E:\Users\User\Documents\model-context\ei_data-an.mat')
  2375. a=mat_contents['ei']
  2376. exp_n_e = a[:,0]
  2377. exp_n_u = a[:,1]
  2378. exp_c_e = a[:,2]
  2379. exp_c_u = a[:,3]
  2380. exp_dd_navAN=(exp_n_u-exp_n_e)/2
  2381. exp_dd_comAN=(exp_c_u-exp_c_e)/2
  2382. mat_contents = sio.loadmat(r'E:\Users\User\Documents\model-context\ei_data.mat')
  2383. a=mat_contents['ei']
  2384. exp_n_e = a[:,0]
  2385. exp_n_u = a[:,1]
  2386. exp_c_e = a[:,2]
  2387. exp_c_u = a[:,3]
  2388. exp_dd_navAW=(exp_n_u-exp_n_e)/2
  2389. exp_dd_comAW=(exp_c_u-exp_c_e)/2
  2390. # ax.errorbar([2000,1200],[np.mean(exp_dd_navAW),np.mean(exp_dd_navAN)], yerr=[sem(exp_dd_navAW),sem(exp_dd_navAN)], fmt='o',color='b', mfc='w',ms=4)
  2391. # ax.errorbar([2000,1200],[np.mean(exp_dd_comAW),np.mean(exp_dd_comAN)], yerr=[sem(exp_dd_comAW),sem(exp_dd_comAN)], fmt='o',color='r', mfc='w',ms=4)
  2392. # ax.set_ylabel('s.s.s')
  2393. # ax.set_xlabel(r'inputs firing rate')
  2394. # ax.set_xlabel(r'synaptic weight (nS)')
  2395. # ax.set_xlabel(r'synaptic depression ($\Delta_{i,j}$)')
  2396. # ax.set_xlabel(r'synaptic depression ($\Omega_{i,j}$)')
  2397. # ax.set_xlabel(r'neuronal adaptation ($D_{th}$)')
  2398. # ax.set_xlabel('bandwidth of sound')
  2399. # ax.invert_xaxis()
  2400. # ax.set_xticklabels([])
  2401. # ax.axhline(0,linewidth=1, color='k',ls='--')
  2402. ax.spines['top'].set_visible(False)
  2403. ax.spines['right'].set_visible(False)
  2404. ax.spines['bottom'].set_linewidth(0.75)
  2405. ax.spines['left'].set_linewidth(0.75)
  2406. fig1.tight_layout()
  2407. fig2=assymetries_plot(X,A,B,orr,'b','r',30)
  2408. # another parameter
  2409. fig3, ax = plt.subplots(1,figsize=(1.75,1.1))
  2410. A = di_nav_fixedx
  2411. B = di_iso_fixedx
  2412. C = di_com_fixedx
  2413. X = parameters2
  2414. ax.plot(X,np.mean(A,1),color='b',lw=0.75,marker="o",markersize=2)
  2415. ax.fill_between(X, np.mean(A,1)-sem(A,1), np.mean(A,1)+sem(A,1), alpha=0.3, facecolor='b')
  2416. ax.plot(X,np.mean(B,1),color='K',lw=0.75,marker="o",markersize=2)
  2417. ax.fill_between(X, np.mean(B,1)-sem(B,1), np.mean(B,1)+sem(B,1), alpha=0.3, facecolor='K')
  2418. ax.plot(X,np.mean(C,1),color='r',lw=0.75,marker="o",markersize=2)
  2419. ax.fill_between(X, np.mean(C,1)-sem(C,1), np.mean(C,1)+sem(C,1), alpha=0.3, facecolor='r')
  2420. # statistics
  2421. # ax2 = ax.twinx()
  2422. # stats=[comp_exp(par,'di_iso','awake') for par in B]
  2423. # ax2.plot(X,stats,'b--')
  2424. # stats=[comp_exp(par,'di_iso','anesthesia') for par in B]
  2425. # ax2.plot(X,stats,'r--')
  2426. # ax.set_ylabel('d.i.')
  2427. # ax.set_xlabel(r'inputs firing rate')
  2428. # ax.set_xlabel(r'synaptic weight ($w_{e}$)')
  2429. # ax.set_xlabel(r'synaptic depression ($\Delta_{i,j}$)')
  2430. # ax.set_xlabel(r'synaptic depression ($\Omega_{i,j}$)')
  2431. # ax.set_xlabel(r'neuronal adaptation ($D_{th}$)')
  2432. # ax.invert_xaxis()
  2433. ax.spines['top'].set_visible(False)
  2434. ax.spines['right'].set_visible(False)
  2435. ax.spines['bottom'].set_linewidth(0.75)
  2436. ax.spines['left'].set_linewidth(0.75)
  2437. ax.set_xticklabels([])
  2438. fig3.tight_layout()
  2439. fig4=assymetries_plot(X,A,C,orr,'b','r',30)
  2440. # another parameter
  2441. fig5, ax = plt.subplots(1,figsize=(1.75,1.1))
  2442. A = sp_nav_fixedx
  2443. B = sp_com_fixedx
  2444. X = parameters2
  2445. ax.plot(X,np.mean(A,1),color='b',lw=0.75,marker="o",markersize=2)
  2446. ax.fill_between(X, np.mean(A,1)-sem(A,1), np.mean(A,1)+sem(A,1), alpha=0.3, facecolor='b')
  2447. ax.plot(X,np.mean(B,1),color='r',lw=0.75,marker="o",markersize=2)
  2448. ax.fill_between(X, np.mean(B,1)-sem(B,1), np.mean(B,1)+sem(B,1), alpha=0.3, facecolor='r')
  2449. # ax2 = ax.twinx()
  2450. # stats=[comp_exp(par,'rate_nav','awake') for par in A]
  2451. # ax2.plot(X,stats,'b--')
  2452. # stats=[comp_exp(par,'rate_nav','anesthesia') for par in A]
  2453. # ax2.plot(X,stats,'r--')
  2454. # ax.set_ylabel('firing context')
  2455. # ax.set_xlabel(r'inputs firing rate')
  2456. # ax.set_xlabel(r'synaptic weight ($w_{e}$)')
  2457. # ax.set_xlabel(r'synaptic adaptation') #($\Delta_{i,j}$)
  2458. # ax.set_xlabel(r'synaptic depression ($\Omega_{i,j}$)')
  2459. # ax.set_xlabel(r'neuronal adaptation') #($D_{th}$)
  2460. # ax.invert_xaxis()
  2461. ax.spines['top'].set_visible(False)
  2462. ax.spines['right'].set_visible(False)
  2463. ax.spines['bottom'].set_linewidth(0.75)
  2464. ax.spines['left'].set_linewidth(0.75)
  2465. fig5.tight_layout()
  2466. fig6=assymetries_plot(X,A,B,orr,'b','r',45)
  2467. # another parameter
  2468. fig7, ax = plt.subplots(1,1,figsize=(1.75,1.1))
  2469. # ax[0].set_title('echolocation')
  2470. A = ce_n_e_fixedx
  2471. B = ce_n_u_fixedx
  2472. X = parameters2
  2473. ax.plot(X,np.mean(A,1),color='cornflowerblue',lw=0.75,marker="o",markersize=2)
  2474. ax.fill_between(X, np.mean(A,1)-sem(A,1), np.mean(A,1)+sem(A,1), alpha=0.3, facecolor='cornflowerblue')
  2475. ax.plot(X,np.mean(B,1),color='darkblue',lw=0.75,marker="o",markersize=2)
  2476. ax.fill_between(X, np.mean(B,1)-sem(B,1), np.mean(B,1)+sem(B,1), alpha=0.3, facecolor='darkblue')
  2477. # ax2 = ax[0].twinx()
  2478. # stats=[comp_exp(par,'ce_n_e','awake') for par in A]
  2479. # ax2.plot(X,stats,'b--')
  2480. # stats=[comp_exp(par,'ce_n_e','anesthesia') for par in A]
  2481. # ax2.plot(X,stats,'r--')
  2482. # ax.set_ylabel('echolocation effect')
  2483. # ax.set_xlabel(r'inputs firing rate')
  2484. # ax[0].set_xlabel(r'synaptic weight ($w_{e}$)')
  2485. # ax[0].set_xlabel(r'synaptic depression ($\Delta_{i,j}$)')
  2486. # ax[0].set_xlabel(r'synaptic depression ($\Omega_{i,j}$)')
  2487. # ax[0].set_xlabel(r'neuronal adaptation ($D_{th}$)')
  2488. # ax.invert_xaxis()
  2489. # ax.set_xticklabels([])
  2490. # ax[0].axhline(0,linewidth=1, color='k',ls='--')
  2491. ax.spines['top'].set_visible(False)
  2492. ax.spines['right'].set_visible(False)
  2493. ax.spines['bottom'].set_linewidth(0.75)
  2494. ax.spines['left'].set_linewidth(0.75)
  2495. # ax[1].set_title('communication')
  2496. fig7.tight_layout()
  2497. fig8=assymetries_plot(X,A,B,orr,'cornflowerblue','darkblue',30)
  2498. fig9, ax = plt.subplots(1,1,figsize=(1.75,1.1))
  2499. A = ce_c_e_fixedx
  2500. B = ce_c_u_fixedx
  2501. X = parameters2
  2502. ax.plot(X,np.mean(A,1),color='indianred',lw=0.75,marker="o",markersize=2)
  2503. ax.fill_between(X, np.mean(A,1)-sem(A,1), np.mean(A,1)+sem(A,1), alpha=0.3, facecolor='indianred')
  2504. ax.plot(X,np.mean(B,1),color='darkred',lw=0.75,marker="o",markersize=2)
  2505. ax.fill_between(X, np.mean(B,1)-sem(B,1), np.mean(B,1)+sem(B,1), alpha=0.3, facecolor='darkred')
  2506. # ax2 = ax[1].twinx()
  2507. # stats=[comp_exp(par,'ce_c_e','awake') for par in A]
  2508. # ax2.plot(X,stats,'b--')
  2509. # stats=[comp_exp(par,'ce_c_e','anesthesia') for par in A]
  2510. # ax2.plot(X,stats,'r--')
  2511. # ax.set_ylabel('communication effect')
  2512. # ax.set_xlabel(r'inputs firing rate')
  2513. # ax[1].set_xlabel(r'synaptic weight ($w_{e}$)')
  2514. # ax[1].set_xlabel(r'synaptic depression ($\Delta_{i,j}$)')
  2515. # ax[1].set_xlabel(r'synaptic depression ($\Omega_{i,j}$)')
  2516. # ax[1].set_xlabel(r'neuronal adaptation ($D_{th}$)')
  2517. # ax.invert_xaxis()
  2518. # ax[1].axhline(0,linewidth=1, color='k',ls='--')
  2519. # ax.set_xticklabels([])
  2520. ax.spines['top'].set_visible(False)
  2521. ax.spines['right'].set_visible(False)
  2522. ax.spines['bottom'].set_linewidth(0.75)
  2523. ax.spines['left'].set_linewidth(0.75)
  2524. fig9.tight_layout()
  2525. fig10=assymetries_plot(X,A,B,orr,'indianred','darkred',30)
  2526. # plottign 2D
  2527. '''
  2528. fig2, ax = plt.subplots(1,2,figsize=(5,2))
  2529. A=rate_nav
  2530. B=rate_com
  2531. jump=2
  2532. mm=min(np.min(A),np.min(B))
  2533. MM=max(np.max(A),np.max(B))
  2534. ax[0].imshow(A,cmap='jet',origin='lower',vmin=mm,vmax=MM)
  2535. ax[0].set_xticks(np.arange(0,ny,jump))
  2536. ax[0].set_xticklabels(['{:.1f}'.format(x) for x in parameters2[::jump]])
  2537. # ax[0].invert_xaxis()
  2538. # ax[0].set_yticks(np.arange(0,nx,jump))
  2539. ax[0].set_yticklabels(['{:.1f}'.format(x) for x in parameters1[::jump]])
  2540. ax[0].set_title('echolocation')
  2541. im_com=ax[1].imshow(B,cmap='jet',origin='lower',vmin=mm,vmax=MM)
  2542. ax[1].set_xticks(np.arange(0,ny,jump))
  2543. ax[1].set_xticklabels(['{:.1f}'.format(x) for x in parameters2[::jump]])
  2544. # ax[1].invert_xaxis()
  2545. # ax[1].set_yticks(np.arange(0,nx,jump))
  2546. ax[1].set_yticklabels(['{:.1f}'.format(x) for x in parameters1[::jump]])
  2547. ax[1].set_title('communication')
  2548. # ax[0].set_xlabel(r'synaptic weight ($w_{e}$)')
  2549. # ax[1].set_xlabel(r'synaptic weight ($w_{e}$)')
  2550. ax[1].set_xlabel(r'synaptic depression ($\Delta_{i,j}$)')
  2551. ax[0].set_xlabel(r'synaptic depression ($\Delta_{i,j}$)')
  2552. # ax[0].set_ylabel(r'input LF firing rate ($v$)')
  2553. ax[0].set_ylabel(r'postsynaptic adaptation ($V_{th}$)')
  2554. fig2.tight_layout()
  2555. fig2.subplots_adjust(right=0.85)
  2556. cbar_ax = fig2.add_axes([0.88, 0.15, 0.04, 0.7])
  2557. bar=fig2.colorbar(im_com, cax=cbar_ax)
  2558. bar.ax.set_title('rate')
  2559. '''
  2560. return fig1,fig2,fig5,fig6,fig7,fig8,fig9,fig10
  2561. def comp_exp(distribution,parameter,state):
  2562. # compare experimental data with modeling
  2563. # distribution: vector with simulated parameters
  2564. # parameter (11): 'dd_nav','di_nav', 'ce_n_e' or 'rate_nav' and others
  2565. # state: 'awake' or 'anesthesia'
  2566. # outputs: a (whether reject or no same distributions), p-values, effect size
  2567. if (parameter[0:2]=='dd' or parameter[0:2]=='ce') and state=='awake':
  2568. # import experimental awake data
  2569. mat_contents = sio.loadmat(r'E:\Users\User\Documents\model-context\ei_data.mat')
  2570. a=mat_contents['ei']
  2571. exp_n_e = a[:,0]
  2572. exp_n_u = a[:,1]
  2573. exp_c_e = a[:,2]
  2574. exp_c_u = a[:,3]
  2575. exp_dd_nav=(exp_n_u-exp_n_e)/2
  2576. exp_dd_com=(exp_c_u-exp_c_e)/2
  2577. if parameter=='dd_nav':
  2578. H,p=ranksums(distribution, exp_dd_nav)
  2579. a=1 if p>0.05 else 0
  2580. c,e = cliffsDelta(distribution, exp_dd_nav)
  2581. elif parameter=='dd_com':
  2582. H,p=ranksums(distribution, exp_dd_com)
  2583. a=1 if p>0.05 else 0
  2584. c,e = cliffsDelta(distribution, exp_dd_com)
  2585. elif parameter=='ce_n_e':
  2586. H,p=ranksums(distribution, exp_n_e)
  2587. a=1 if p>0.05 else 0
  2588. c,e = cliffsDelta(distribution, exp_n_e)
  2589. elif parameter=='ce_n_u':
  2590. H,p=ranksums(distribution, exp_n_u)
  2591. a=1 if p>0.05 else 0
  2592. c,e = cliffsDelta(distribution, exp_n_u)
  2593. elif parameter=='ce_c_e':
  2594. H,p=ranksums(distribution, exp_c_e)
  2595. a=1 if p>0.05 else 0
  2596. c,e = cliffsDelta(distribution, exp_c_e)
  2597. elif parameter=='ce_c_u':
  2598. H,p=ranksums(distribution, exp_c_u)
  2599. a=1 if p>0.05 else 0
  2600. c,e = cliffsDelta(distribution, exp_c_u)
  2601. elif (parameter[0:2]=='dd' or parameter[0:2]=='ce') and state=='anesthesia':
  2602. # import experimental anesthetized data
  2603. mat_contents = sio.loadmat(r'E:\Users\User\Documents\model-context\ei_data-an.mat')
  2604. a=mat_contents['ei']
  2605. exp_n_e = a[:,0]
  2606. exp_n_u = a[:,1]
  2607. exp_c_e = a[:,2]
  2608. exp_c_u = a[:,3]
  2609. exp_dd_nav=(exp_n_u-exp_n_e)/2
  2610. exp_dd_com=(exp_c_u-exp_c_e)/2
  2611. if parameter=='dd_nav':
  2612. H,p=ranksums(distribution, exp_dd_nav)
  2613. a=1 if p>0.05 else 0
  2614. c,e = cliffsDelta(distribution, exp_dd_nav)
  2615. elif parameter=='dd_com':
  2616. H,p=ranksums(distribution, exp_dd_com)
  2617. a=1 if p>0.05 else 0
  2618. c,e = cliffsDelta(distribution, exp_dd_com)
  2619. elif parameter=='ce_n_e':
  2620. H,p=ranksums(distribution, exp_n_e)
  2621. a=1 if p>0.05 else 0
  2622. c,e = cliffsDelta(distribution, exp_n_e)
  2623. elif parameter=='ce_n_u':
  2624. H,p=ranksums(distribution, exp_n_u)
  2625. a=1 if p>0.05 else 0
  2626. c,e = cliffsDelta(distribution, exp_n_u)
  2627. elif parameter=='ce_c_e':
  2628. H,p=ranksums(distribution, exp_c_e)
  2629. a=1 if p>0.05 else 0
  2630. c,e = cliffsDelta(distribution, exp_c_e)
  2631. elif parameter=='ce_c_u':
  2632. H,p=ranksums(distribution, exp_c_u)
  2633. a=1 if p>0.05 else 0
  2634. c,e = cliffsDelta(distribution, exp_c_u)
  2635. elif parameter[0:2]=='di' and state=='awake':
  2636. # import experimental awake data - cliff delta values for 45 units
  2637. mat_contents = sio.loadmat(r'E:\Users\User\Documents\model-context\cliff_data.mat')
  2638. a=mat_contents['cliff_data']
  2639. exp_di_iso = a[:,0]
  2640. exp_di_nav = a[:,1]
  2641. exp_di_com = a[:,2]
  2642. if parameter=='di_nav':
  2643. H,p=ranksums(distribution, exp_di_nav)
  2644. a=1 if p>0.05 else 0
  2645. c,e = cliffsDelta(distribution, exp_di_nav)
  2646. elif parameter=='di_iso':
  2647. H,p=ranksums(distribution, exp_di_iso)
  2648. a=1 if p>0.05 else 0
  2649. c,e = cliffsDelta(distribution, exp_di_iso)
  2650. elif parameter=='di_com':
  2651. H,p=ranksums(distribution, exp_di_com)
  2652. a=1 if p>0.05 else 0
  2653. c,e = cliffsDelta(distribution, exp_di_com)
  2654. elif parameter[0:2]=='di' and state=='anesthesia':
  2655. # import experimental anesthetized data - cliff delta values for 46 units
  2656. mat_contents = sio.loadmat(r'E:\Users\User\Documents\model-context\cliff_data-an.mat')
  2657. a=mat_contents['cliff_data']
  2658. exp_di_iso = a[:,0]
  2659. exp_di_nav = a[:,1]
  2660. exp_di_com = a[:,2]
  2661. if parameter=='di_nav':
  2662. H,p=ranksums(distribution, exp_di_nav)
  2663. a=1 if p>0.05 else 0
  2664. c,e = cliffsDelta(distribution, exp_di_nav)
  2665. elif parameter=='di_iso':
  2666. H,p=ranksums(distribution, exp_di_iso)
  2667. a=1 if p>0.05 else 0
  2668. c,e = cliffsDelta(distribution, exp_di_iso)
  2669. elif parameter=='di_com':
  2670. H,p=ranksums(distribution, exp_di_com)
  2671. a=1 if p>0.05 else 0
  2672. c,e = cliffsDelta(distribution, exp_di_com)
  2673. elif parameter[0:4]=='rate' and state=='awake':
  2674. # import experimental awake data
  2675. mat_contents = sio.loadmat(r'E:\Users\User\Documents\model-context\rate_context.mat')
  2676. a=mat_contents['rate']
  2677. exp_rate_nav = a[:,0]
  2678. exp_rate_com = a[:,1]
  2679. if parameter=='rate_nav':
  2680. H,p=ranksums(distribution, exp_rate_nav)
  2681. a=1 if p>0.05 else 0
  2682. c,e = cliffsDelta(distribution, exp_rate_nav)
  2683. elif parameter=='rate_com':
  2684. H,p=ranksums(distribution, exp_rate_com)
  2685. a=1 if p>0.05 else 0
  2686. c,e = cliffsDelta(distribution, exp_rate_com)
  2687. elif parameter[0:4]=='rate' and state=='anesthesia':
  2688. # import experimental awake data
  2689. mat_contents = sio.loadmat(r'E:\Users\User\Documents\model-context\rate_context-an.mat')
  2690. a=mat_contents['rate']
  2691. exp_rate_nav = a[:,0]
  2692. exp_rate_com = a[:,1]
  2693. if parameter=='rate_nav':
  2694. H,p=ranksums(distribution, exp_rate_nav)
  2695. a=1 if p>0.05 else 0
  2696. c,e = cliffsDelta(distribution, exp_rate_nav)
  2697. elif parameter=='rate_com':
  2698. H,p=ranksums(distribution, exp_rate_com)
  2699. a=1 if p>0.05 else 0
  2700. c,e = cliffsDelta(distribution, exp_rate_com)
  2701. return a #-np.log(p)
  2702. def second_approx(sims,slope_rows=0,slope_cols=0,n_combis=0):
  2703. # for the second plots on the paper caviets of parameters and solutions, anesthesia effects
  2704. parameters1=sims[0]
  2705. parameters2=sims[1]
  2706. sims = np.delete(sims,[0,1], 0)
  2707. L_rows=len(parameters1)
  2708. L_cols=len(parameters2)
  2709. dur_ech=1.3311
  2710. dur_com=1.9266
  2711. # create a matrix with the combination of parameters used in the same order
  2712. sims_par=[]
  2713. for x in parameters1:
  2714. for y in parameters2:
  2715. sims_par.append((x,y))
  2716. sims_par=np.array(sims_par)
  2717. # picking certain parameters in a diagonal of the 2D parameters arrange
  2718. # to change the slope of the diagonal
  2719. # slope_rows=4
  2720. # slope_cols=1
  2721. # n_combis=3
  2722. ind=np.size(sims_par,0)-1 # position of the original combination -> awake
  2723. diago=[ind] # add this combination as the first of the list
  2724. for par in range(n_combis-1):
  2725. ind_i=ind + slope_cols*L_cols- slope_rows
  2726. diago.append(ind_i)
  2727. ind=ind_i
  2728. # to plot the location of the parameters chosen
  2729. h=[0]*(L_rows*L_cols)
  2730. for i in diago:
  2731. h[i]=1
  2732. h=np.array(h)
  2733. plt.figure()
  2734. plt.imshow(h.reshape((L_rows,L_cols)),origin='lower')
  2735. plt.xlabel('parameters 2')
  2736. plt.ylabel('parameters 1')
  2737. # to print the value of the parameters chosen
  2738. for c in diago:
  2739. print('parameter1='+str(sims_par[c,0])+' parameter2='+str(sims_par[c,1]))
  2740. # vector with parameters to plot
  2741. dd_nav=[]
  2742. dd_com=[]
  2743. di_nav=[]
  2744. di_iso=[]
  2745. di_com=[]
  2746. ce_n_e=[]
  2747. ce_n_u=[]
  2748. ce_c_e=[]
  2749. ce_c_u=[]
  2750. rate_nav=[]
  2751. rate_com=[]
  2752. for j in diago:
  2753. # context effect
  2754. ce_fixed=context_effect(sims[j])
  2755. ce_n_e.append(ce_fixed[:,0])
  2756. ce_n_u.append(ce_fixed[:,1])
  2757. ce_c_e.append(ce_fixed[:,2])
  2758. ce_c_u.append(ce_fixed[:,3])
  2759. # deviance detection
  2760. dd_nav_fixed=(ce_fixed[:,1]-ce_fixed[:,0])/2
  2761. dd_com_fixed=(ce_fixed[:,3]-ce_fixed[:,2])/2
  2762. dd_nav.append(dd_nav_fixed)
  2763. dd_com.append(dd_com_fixed)
  2764. # discriminability index
  2765. di_fixed=discriminability_index(sims[j])
  2766. di_nav.append(di_fixed[:,0])
  2767. di_iso.append(di_fixed[:,1])
  2768. di_com.append(di_fixed[:,2])
  2769. # firing rate context
  2770. sp_fixed=sims[j]
  2771. sp_nav=np.reshape(sp_fixed[:,8],(50,20))
  2772. rate_nav.append(np.mean(sp_nav,1)) #/dur_ech for firing rate
  2773. sp_com=np.reshape(sp_fixed[:,11],(50,20))
  2774. rate_com.append(np.mean(sp_com,1)) #/dur_com
  2775. ## plotting a deviance detection (d.d) variation
  2776. fig, ax = plt.subplots(1,figsize=(3,2))
  2777. A = dd_nav
  2778. B = dd_com
  2779. X = np.linspace(0,1,n_combis)
  2780. ax.plot(X,np.mean(A,1),color='b',lw=0.75)
  2781. ax.fill_between(X, np.mean(A,1)-sem(A,1), np.mean(A,1)+sem(A,1), alpha=0.3, facecolor='b')
  2782. ax.plot(X,np.mean(B,1),color='r',lw=0.75)
  2783. ax.fill_between(X, np.mean(B,1)-sem(B,1), np.mean(B,1)+sem(B,1), alpha=0.3, facecolor='r')
  2784. ax.axhline(0,linewidth=1, color='k',ls='--')
  2785. ax.set_ylabel('d.d.')
  2786. ax.set_xlabel('anesthesia effect')
  2787. # add errorbar for experimental data
  2788. mat_contents = sio.loadmat(r'E:\Users\User\Documents\model-context\ei_data-an.mat')
  2789. a=mat_contents['ei']
  2790. exp_n_e = a[:,0]
  2791. exp_n_u = a[:,1]
  2792. exp_c_e = a[:,2]
  2793. exp_c_u = a[:,3]
  2794. exp_dd_navAN=(exp_n_u-exp_n_e)/2
  2795. exp_dd_comAN=(exp_c_u-exp_c_e)/2
  2796. mat_contents = sio.loadmat(r'E:\Users\User\Documents\model-context\ei_data.mat')
  2797. a=mat_contents['ei']
  2798. exp_n_e = a[:,0]
  2799. exp_n_u = a[:,1]
  2800. exp_c_e = a[:,2]
  2801. exp_c_u = a[:,3]
  2802. exp_dd_navAW=(exp_n_u-exp_n_e)/2
  2803. exp_dd_comAW=(exp_c_u-exp_c_e)/2
  2804. # ax[0].errorbar([0,1],[np.mean(exp_dd_navAW),np.mean(exp_dd_navAN)], yerr=[sem(exp_dd_navAW),sem(exp_dd_navAN)], fmt='o',color='k', mfc='w',ms=4)
  2805. # ax[1].errorbar([0,1],[np.mean(exp_dd_comAW),np.mean(exp_dd_comAN)], yerr=[sem(exp_dd_comAW),sem(exp_dd_comAN)], fmt='o',color='k', mfc='w',ms=4)
  2806. ax.spines['top'].set_visible(False)
  2807. ax.spines['right'].set_visible(False)
  2808. ax.spines['bottom'].set_linewidth(0.75)
  2809. ax.spines['left'].set_linewidth(0.75)
  2810. fig.tight_layout()
  2811. fig6=assymetries_plot(X,A,B,0,'b','r',20)
  2812. ## plotting a discriminability index (d.i) variation
  2813. fig2, ax = plt.subplots(1,figsize=(3,2))
  2814. A = di_nav
  2815. B = di_com
  2816. X = np.linspace(0,1,n_combis)
  2817. ax.plot(X,np.mean(A,1),color='b',lw=0.75)
  2818. ax.fill_between(X, np.mean(A,1)-sem(A,1), np.mean(A,1)+sem(A,1), alpha=0.3, facecolor='b')
  2819. ax.plot(X,np.mean(B,1),color='r',lw=0.75)
  2820. ax.fill_between(X, np.mean(B,1)-sem(B,1), np.mean(B,1)+sem(B,1), alpha=0.3, facecolor='r')
  2821. ax.set_ylabel('d.i.')
  2822. ax.set_xlabel('anesthesia effect')
  2823. # add errorbar for experimental data
  2824. mat_contents = sio.loadmat(r'E:\Users\User\Documents\model-context\cliff_data-an.mat')
  2825. a=mat_contents['cliff_data']
  2826. # exp_di_isoAN = a[:,0]
  2827. exp_di_navAN = a[:,1]
  2828. exp_di_comAN = a[:,2]
  2829. mat_contents = sio.loadmat(r'E:\Users\User\Documents\model-context\cliff_data.mat')
  2830. a=mat_contents['cliff_data']
  2831. # exp_di_isoAW = a[:,0]
  2832. exp_di_navAW = a[:,1]
  2833. exp_di_comAW = a[:,2]
  2834. # ax[0].errorbar([0,1],[np.mean(exp_di_navAW),np.mean(exp_di_navAN)], yerr=[np.std(exp_di_navAW),np.std(exp_di_navAN)], fmt='o',color='k', mfc='w',ms=4)
  2835. # ax[1].errorbar([0,1],[np.mean(exp_di_comAW),np.mean(exp_di_comAN)], yerr=[np.std(exp_di_comAW),np.std(exp_di_comAN)], fmt='o',color='k', mfc='w',ms=4)
  2836. ax.spines['top'].set_visible(False)
  2837. ax.spines['right'].set_visible(False)
  2838. ax.spines['bottom'].set_linewidth(0.75)
  2839. ax.spines['left'].set_linewidth(0.75)
  2840. fig2.tight_layout()
  2841. fig7=assymetries_plot(X,A,B,0,'b','r',20)
  2842. ## plotting a context effect (c.e) variation
  2843. fig3, ax = plt.subplots(1,2,figsize=(6,2))
  2844. A = ce_n_e
  2845. B = ce_n_u
  2846. X = np.linspace(0,1,n_combis)
  2847. ax[0].plot(X,np.mean(A,1),color='gray',lw=0.75)
  2848. ax[0].plot(X,np.mean(A,1),'.',markersize=3,color='gray')
  2849. ax[0].fill_between(X, np.mean(A,1)-sem(A,1), np.mean(A,1)+sem(A,1), alpha=0.3, facecolor='gray')
  2850. ax[0].plot(X,np.mean(B,1),color='k',lw=0.75)
  2851. ax[0].plot(X,np.mean(B,1),'.',markersize=3,color='k')
  2852. ax[0].fill_between(X, np.mean(B,1)-sem(B,1), np.mean(B,1)+sem(B,1), alpha=0.3, facecolor='k')
  2853. fig7=assymetries_plot(X,A,B,0,'gray','k',20)
  2854. A = ce_c_e
  2855. B = ce_c_u
  2856. X = np.linspace(0,1,n_combis)
  2857. ax[1].plot(X,np.mean(A,1),color='gray',lw=0.75)
  2858. ax[1].plot(X,np.mean(A,1),'.',markersize=3,color='gray')
  2859. ax[1].fill_between(X, np.mean(A,1)-sem(A,1), np.mean(A,1)+sem(A,1), alpha=0.3, facecolor='gray')
  2860. ax[1].plot(X,np.mean(B,1),color='k',lw=0.75)
  2861. ax[1].plot(X,np.mean(B,1),'.',markersize=3,color='k')
  2862. ax[1].fill_between(X, np.mean(B,1)-sem(B,1), np.mean(B,1)+sem(B,1), alpha=0.3, facecolor='k')
  2863. ax[0].set_ylabel('c.e.')
  2864. ax[0].set_xlabel('anesthesia effect')
  2865. ax[1].set_xlabel('anesthesia effect')
  2866. # ax[0].axhline(0,linewidth=1, color='k',ls='--')
  2867. # ax[1].axhline(0,linewidth=1, color='k',ls='--')
  2868. # ax[1,1].set_ylim([-0.85, 0])
  2869. # add errorbar for experimental data
  2870. mat_contents = sio.loadmat(r'E:\Users\User\Documents\model-context\ei_data-an.mat')
  2871. a=mat_contents['ei']
  2872. exp_n_eAN = a[:,0]
  2873. exp_n_uAN = a[:,1]
  2874. exp_c_eAN = a[:,2]
  2875. exp_c_uAN = a[:,3]
  2876. mat_contents = sio.loadmat(r'E:\Users\User\Documents\model-context\ei_data.mat')
  2877. a=mat_contents['ei']
  2878. exp_n_eAW = a[:,0]
  2879. exp_n_uAW = a[:,1]
  2880. exp_c_eAW = a[:,2]
  2881. exp_c_uAW = a[:,3]
  2882. # ax[0,0].errorbar([0,1],[np.mean(exp_n_eAW),np.mean(exp_n_eAN)], yerr=[np.std(exp_n_eAW),np.std(exp_n_eAN)], fmt='o',color='k', mfc='w',ms=4)
  2883. # ax[1,0].errorbar([0,1],[np.mean(exp_n_uAW),np.mean(exp_n_uAN)], yerr=[np.std(exp_n_uAW),np.std(exp_n_uAN)], fmt='o',color='k', mfc='w',ms=4)
  2884. # ax[0,1].errorbar([0,1],[np.mean(exp_c_eAW),np.mean(exp_c_eAN)], yerr=[np.std(exp_c_eAW),np.std(exp_c_eAN)], fmt='o',color='k', mfc='w',ms=4)
  2885. # ax[1,1].errorbar([0,1],[np.mean(exp_c_uAW),np.mean(exp_c_uAN)], yerr=[np.std(exp_c_uAW),np.std(exp_c_uAN)], fmt='o',color='k', mfc='w',ms=4)
  2886. ax = ax.flatten()
  2887. for axi in ax:
  2888. axi.spines['top'].set_visible(False)
  2889. axi.spines['right'].set_visible(False)
  2890. axi.spines['bottom'].set_linewidth(0.75)
  2891. axi.spines['left'].set_linewidth(0.75)
  2892. fig3.tight_layout()
  2893. fig8=assymetries_plot(X,A,B,0,'gray','k',20)
  2894. ## plotting a firing rate context(rate) variation
  2895. fig4, ax = plt.subplots(1,figsize=(3,2))
  2896. A = rate_nav
  2897. B = rate_com
  2898. X = np.linspace(0,1,n_combis)
  2899. ax.plot(X,np.mean(A,1),color='b',lw=0.75)
  2900. ax.plot(X,np.mean(A,1),'.',markersize=3,color='b')
  2901. ax.fill_between(X, np.mean(A,1)-np.std(A,1), np.mean(A,1)+np.std(A,1), alpha=0.3, facecolor='b')
  2902. ax.plot(X,np.mean(B,1),color='r',lw=0.75)
  2903. ax.plot(X,np.mean(B,1),'.',markersize=3,color='r')
  2904. ax.fill_between(X, np.mean(B,1)-np.std(B,1), np.mean(B,1)+np.std(B,1), alpha=0.3, facecolor='r')
  2905. ax.set_ylabel('spike count during context')
  2906. ax.set_xlabel('anesthesia effect')
  2907. # add errorbar for experimental data
  2908. mat_contents = sio.loadmat(r'E:\Users\User\Documents\model-context\rate_context-an.mat')
  2909. a=mat_contents['rate']
  2910. exp_rate_navAN = a[:,0]
  2911. exp_rate_comAN = a[:,1]
  2912. mat_contents = sio.loadmat(r'E:\Users\User\Documents\model-context\rate_context.mat')
  2913. a=mat_contents['rate']
  2914. exp_rate_navAW = a[:,0]
  2915. exp_rate_comAW = a[:,1]
  2916. # ax[0].errorbar([0,1],[np.mean(exp_rate_navAW),np.mean(exp_rate_navAN)], yerr=[np.std(exp_rate_navAW),np.std(exp_rate_navAN)], fmt='o',color='k', mfc='w',ms=4)
  2917. # ax[1].errorbar([0,1],[np.mean(exp_rate_comAW),np.mean(exp_rate_comAN)], yerr=[np.std(exp_rate_comAW),np.std(exp_rate_comAN)], fmt='o',color='k', mfc='w',ms=4)
  2918. ax.spines['top'].set_visible(False)
  2919. ax.spines['right'].set_visible(False)
  2920. ax.spines['bottom'].set_linewidth(0.75)
  2921. ax.spines['left'].set_linewidth(0.75)
  2922. fig4.tight_layout()
  2923. fig9=assymetries_plot(X,A,B,0,'b','r',45)
  2924. return fig3, fig4
  2925. def dif_2d(sims):
  2926. # for 2D showing differences between com and nav
  2927. parameters1=sims[0]
  2928. parameters2=sims[1]
  2929. sims = np.delete(sims,[0,1], 0)
  2930. nx=len(parameters1)
  2931. ny=len(parameters2)
  2932. or_par1=1.0000000000000004
  2933. or_par2=1#7.9999999999999964
  2934. ind_par1=np.where(parameters1==or_par1)[0]
  2935. ind_par2=np.where(parameters2==or_par2)[0]
  2936. # dur_ech=1.3311
  2937. # dur_com=1.9266
  2938. # for plotting 2D difference between context averages
  2939. dd_nav=[]
  2940. dd_com=[]
  2941. di_nav=[]
  2942. di_iso=[]
  2943. di_com=[]
  2944. ce_n_e=[]
  2945. ce_n_u=[]
  2946. ce_c_e=[]
  2947. ce_c_u=[]
  2948. rate_nav=[]
  2949. rate_com=[]
  2950. for j in range(nx*ny):
  2951. # j is a particular combinations of parameters
  2952. # 2D only needs the average
  2953. ce_i=np.mean(context_effect(sims[j]),0)
  2954. dd_nav_i=(ce_i[1]-ce_i[0])/2
  2955. dd_com_i=(ce_i[3]-ce_i[2])/2
  2956. dd_nav.append(dd_nav_i)
  2957. dd_com.append(dd_com_i)
  2958. # context effect
  2959. ce_n_e.append(ce_i[0])
  2960. ce_n_u.append(ce_i[1])
  2961. ce_c_e.append(ce_i[2])
  2962. ce_c_u.append(ce_i[3])
  2963. # discriminability index
  2964. di_i=np.mean(discriminability_index(sims[j]),0)
  2965. di_nav.append(di_i[0])
  2966. di_iso.append(di_i[1])
  2967. di_com.append(di_i[2])
  2968. # firing rate
  2969. sp_contexts=sims[j]
  2970. rate_nav.append(np.mean(sp_contexts[:,8])) #/dur_ech
  2971. rate_com.append(np.mean(sp_contexts[:,11])) #/dur_com
  2972. dd_nav=np.array(dd_nav).reshape(nx,ny)
  2973. dd_com=np.array(dd_com).reshape(nx,ny)
  2974. di_nav=np.array(di_nav).reshape(nx,ny)
  2975. di_iso=np.array(di_iso).reshape(nx,ny)
  2976. di_com=np.array(di_com).reshape(nx,ny)
  2977. ce_n_e=np.array(ce_n_e).reshape(nx,ny)
  2978. ce_n_u=np.array(ce_n_u).reshape(nx,ny)
  2979. ce_c_e=np.array(ce_c_e).reshape(nx,ny)
  2980. ce_c_u=np.array(ce_c_u).reshape(nx,ny)
  2981. rate_nav=np.array(rate_nav).reshape(nx,ny)
  2982. rate_com=np.array(rate_com).reshape(nx,ny)
  2983. ## echolocation
  2984. # difference with awake state
  2985. dd=dd_nav-dd_nav[ind_par1,ind_par2]
  2986. ce_e=ce_n_e-ce_n_e[ind_par1,ind_par2]
  2987. ce_u=ce_n_u-ce_n_u[ind_par1,ind_par2]
  2988. rate=rate_nav-rate_nav[ind_par1,ind_par2]
  2989. # smoothing data
  2990. x=parameters2
  2991. y=parameters1
  2992. f_dd = interp2d(x,y,dd, kind='cubic')
  2993. f_ce_e = interp2d(x,y,ce_e, kind='cubic')
  2994. f_ce_u = interp2d(x,y,ce_u, kind='cubic')
  2995. f_rate = interp2d(x,y,rate, kind='cubic')
  2996. # increasing resolution axes
  2997. alpha=5 # smoothing factor
  2998. x_in=parameters2[0]
  2999. x_end=parameters2[-1]
  3000. x_n=len(parameters2)
  3001. y_in=parameters1[0]
  3002. y_end=parameters1[-1]
  3003. y_n=len(parameters1)
  3004. x_nn=x_n + (x_n-1)*(alpha-1)
  3005. y_nn=y_n + (y_n-1)*(alpha-1)
  3006. xnew = np.linspace(x_in,x_end,x_nn)
  3007. ynew = np.linspace(y_in,y_end,y_nn)
  3008. Xn, Yn = np.meshgrid(xnew, ynew)
  3009. # generate smooth data for the new axes
  3010. dd_smooth = f_dd(xnew,ynew)
  3011. ce_e_smooth = f_ce_e(xnew,ynew)
  3012. ce_u_smooth = f_ce_u(xnew,ynew)
  3013. rate_smooth = f_rate(xnew,ynew)
  3014. fig, ax = plt.subplots(1,2,sharex=True,sharey=True,figsize=(2.1,1))
  3015. mm=0.2
  3016. # c.e. match
  3017. q1=ax[0].pcolor(Xn,Yn,ce_e_smooth,cmap='RdBu',vmin=-mm,vmax=mm)
  3018. # ax[0].set_title('c.e. match')
  3019. # c.e. mismatch
  3020. q2=ax[1].pcolor(Xn,Yn,ce_u_smooth,cmap='RdBu',vmin=-mm,vmax=mm)
  3021. # ax[1].set_title('c.e. mismatch')
  3022. # adding colorbars
  3023. divider = make_axes_locatable(ax[0])
  3024. cax = divider.append_axes("right", size="5%", pad=0.075)
  3025. fig.colorbar(q1,cax=cax)
  3026. cax.remove()
  3027. divider = make_axes_locatable(ax[1])
  3028. cax = divider.append_axes("right", size="5%", pad=0.075)
  3029. fig.colorbar(q2,cax=cax)
  3030. fig.tight_layout()
  3031. fig2, ax2 = plt.subplots(1,figsize=(1.15,1))
  3032. # s.s.s
  3033. q1=ax2.pcolormesh(Xn,Yn,dd_smooth,cmap='RdBu',vmin=-mm,vmax=mm)
  3034. # ax2[0].set_title('s.s.s.')
  3035. divider = make_axes_locatable(ax2)
  3036. cax = divider.append_axes("right", size="5%", pad=0.075)
  3037. fig2.colorbar(q1,cax=cax)
  3038. fig2.tight_layout()
  3039. fig3, ax3 = plt.subplots(1,figsize=(1.15,1))
  3040. # firing rate
  3041. mm=30
  3042. q1=ax3.pcolor(Xn,Yn,rate_smooth,cmap='RdBu',vmin=-mm,vmax=mm)
  3043. ax3.contour(Xn,Yn,rate_smooth,levels = [-23],origin='lower',colors=['k'],linewidths=0.75)
  3044. # ax2[3].set_title('firing rate')
  3045. divider = make_axes_locatable(ax3)
  3046. cax = divider.append_axes("right", size="5%", pad=0.075)
  3047. fig3.colorbar(q1,cax=cax)
  3048. fig3.tight_layout()
  3049. ## communication
  3050. # difference with awake state
  3051. dd=dd_com-dd_com[ind_par1,ind_par2]
  3052. ce_e=ce_c_e-ce_c_e[ind_par1,ind_par2]
  3053. ce_u=ce_c_u-ce_c_u[ind_par1,ind_par2]
  3054. rate=rate_com-rate_com[ind_par1,ind_par2]
  3055. #smoothing data
  3056. f_dd = interp2d(x,y,dd, kind='cubic')
  3057. f_ce_e = interp2d(x,y,ce_e, kind='cubic')
  3058. f_ce_u = interp2d(x,y,ce_u, kind='cubic')
  3059. f_rate = interp2d(x,y,rate, kind='cubic')
  3060. dd_smooth = f_dd(xnew,ynew)
  3061. ce_e_smooth = f_ce_e(xnew,ynew)
  3062. ce_u_smooth = f_ce_u(xnew,ynew)
  3063. rate_smooth = f_rate(xnew,ynew)
  3064. fig4, ax4 = plt.subplots(1,2,sharex=True,sharey=True,figsize=(2.1,1))
  3065. mm=0.2
  3066. # c.e. match
  3067. q1=ax4[0].pcolor(Xn,Yn,ce_e_smooth,cmap='RdBu',vmin=-mm,vmax=mm)
  3068. # ax4[0].set_title('c.e. match')
  3069. # c.e. mismatch
  3070. q2=ax4[1].pcolor(Xn,Yn,ce_u_smooth,cmap='RdBu',vmin=-mm,vmax=mm)
  3071. # ax4[1].set_title('c.e. mismatch')
  3072. divider = make_axes_locatable(ax4[0])
  3073. cax = divider.append_axes("right", size="5%", pad=0.075)
  3074. fig4.colorbar(q1,cax=cax)
  3075. cax.remove()
  3076. divider = make_axes_locatable(ax4[1])
  3077. cax = divider.append_axes("right", size="5%", pad=0.075)
  3078. fig4.colorbar(q2,cax=cax)
  3079. fig4.tight_layout()
  3080. fig5, ax5 = plt.subplots(1,figsize=(1.15,1))
  3081. # s.s.s
  3082. q1=ax5.pcolor(Xn,Yn,dd_smooth,cmap='RdBu',vmin=-mm,vmax=mm)
  3083. # ax5.set_title('s.s.s.')
  3084. divider = make_axes_locatable(ax5)
  3085. cax = divider.append_axes("right", size="5%", pad=0.075)
  3086. fig5.colorbar(q1,cax=cax)
  3087. fig5.tight_layout()
  3088. fig6, ax6 = plt.subplots(1,figsize=(1.15,1))
  3089. # firing rate
  3090. mm=30
  3091. q1=ax6.pcolor(Xn,Yn,rate_smooth,cmap='RdBu',vmin=-mm,vmax=mm)
  3092. ax6.contour(Xn,Yn,rate_smooth,levels = [-16],origin='lower',colors=['k'],linewidths=0.75)
  3093. # ax6.set_title('firing rate')
  3094. divider = make_axes_locatable(ax6)
  3095. cax = divider.append_axes("right", size="5%", pad=0.075)
  3096. fig6.colorbar(q1,cax=cax)
  3097. fig6.tight_layout()
  3098. # plotting for difference between communication and echolocation
  3099. jump=3
  3100. fig7, ax7 = plt.subplots(2,2,figsize=(6,4))
  3101. fig7.canvas.manager.set_window_title('Difference between contexts')
  3102. # difference with awake state
  3103. # communication
  3104. dd2=dd_com-dd_com[ind_par1,ind_par2]
  3105. ce_e2=ce_c_e-ce_c_e[ind_par1,ind_par2]
  3106. ce_u2=ce_c_u-ce_c_u[ind_par1,ind_par2]
  3107. rate2=rate_com-rate_com[ind_par1,ind_par2]
  3108. # echolocation
  3109. dd1=dd_nav-dd_nav[ind_par1,ind_par2]
  3110. ce_e1=ce_n_e-ce_n_e[ind_par1,ind_par2]
  3111. ce_u1=ce_n_u-ce_n_u[ind_par1,ind_par2]
  3112. rate1=rate_nav-rate_nav[ind_par1,ind_par2]
  3113. # difference between communication and echolocation
  3114. dd=dd2-dd1
  3115. ce_e=ce_e2-ce_e1
  3116. ce_u=ce_u2-ce_u1
  3117. rate=rate2-rate1
  3118. # first plot: s.s.s
  3119. mm=0.2
  3120. q1=ax7[0,0].imshow(dd,cmap='RdBu',origin='lower',vmin=-mm,vmax=mm,interpolation='hamming')
  3121. ax7[0,0].set_xticks(np.arange(0,ny,jump))
  3122. ax7[0,0].set_xticklabels(['{:.1f}'.format(x) for x in parameters2[::jump]])
  3123. ax7[0,0].set_yticks(np.arange(0,nx,jump))
  3124. ax7[0,0].set_yticklabels(['{:.1f}'.format(x) for x in parameters1[::jump]])
  3125. ax7[0,0].set_title('s.s.s.')
  3126. # third plot: c.e. mismatch
  3127. q3=ax7[1,0].imshow(ce_e,cmap='RdBu',origin='lower',vmin=-mm,vmax=mm,interpolation='hamming')
  3128. ax7[1,0].set_xticks(np.arange(0,ny,jump))
  3129. ax7[1,0].set_xticklabels(['{:.1f}'.format(x) for x in parameters2[::jump]])
  3130. ax7[1,0].set_yticks(np.arange(0,nx,jump))
  3131. ax7[1,0].set_yticklabels(['{:.1f}'.format(x) for x in parameters1[::jump]])
  3132. ax7[1,0].set_title('c.e. match')
  3133. # forth plot: firing rate
  3134. q4=ax7[1,1].imshow(ce_u,cmap='RdBu',origin='lower',vmin=-mm,vmax=mm,interpolation='hamming')
  3135. ax7[1,1].set_xticks(np.arange(0,ny,jump))
  3136. ax7[1,1].set_xticklabels(['{:.1f}'.format(x) for x in parameters2[::jump]])
  3137. ax7[1,1].set_yticks(np.arange(0,nx,jump))
  3138. ax7[1,1].set_yticklabels(['{:.1f}'.format(x) for x in parameters1[::jump]])
  3139. ax7[1,1].set_title('c.e. mismatch')
  3140. # second plot: c.e. match
  3141. mm=30
  3142. q2=ax7[0,1].imshow(rate,cmap='RdBu',origin='lower',vmin=-mm,vmax=mm,interpolation='hamming')
  3143. ax7[0,1].set_xticks(np.arange(0,ny,jump))
  3144. ax7[0,1].set_xticklabels(['{:.1f}'.format(x) for x in parameters2[::jump]])
  3145. ax7[0,1].set_yticks(np.arange(0,nx,jump))
  3146. ax7[0,1].set_yticklabels(['{:.1f}'.format(x) for x in parameters1[::jump]])
  3147. ax7[0,1].set_title('firing context')
  3148. # add colorbars
  3149. fig7.colorbar(q1,ax=ax7[0,0])
  3150. fig7.colorbar(q2,ax=ax7[0,1])
  3151. fig7.colorbar(q3,ax=ax7[1,0])
  3152. fig7.colorbar(q4,ax=ax7[1,1])
  3153. fig7.tight_layout()
  3154. return fig,ax,fig2,ax2,fig3,ax3,fig4,ax4,fig5,ax5,fig6,ax6
  3155. def adapt_supp(N_units):
  3156. delay=1000
  3157. trials=20*N_units
  3158. dt_=0.1
  3159. # SIMULATION NAVIGATION CONTEXT AWAKE
  3160. tau_th=550
  3161. # d_LF=0.045
  3162. d_HF=0.040
  3163. coefC=1
  3164. context=1
  3165. exp=1
  3166. exec(open("./input.py").read())
  3167. exec(open("./model.py").read())
  3168. nav_postsyn=pos.V_th*1000 # to mV
  3169. nav_presyn=mon.x_S
  3170. nav_high=nav_presyn[trials:]
  3171. nav_low=nav_presyn[:trials]
  3172. nav_tot=np.shape(nav_presyn)[1]*dt_
  3173. nav_time=np.arange(0,nav_tot,dt_)
  3174. # average acros trials
  3175. nav_post=np.mean(nav_postsyn,0)
  3176. nav_pre_high=np.mean(nav_high,0)
  3177. nav_pre_low=np.mean(nav_low,0)
  3178. # SIMULATION COMMUNICATION CONTEXT AWAKE
  3179. context=2
  3180. exec(open("./input.py").read())
  3181. exec(open("./model.py").read())
  3182. com_postsyn=pos.V_th*1000
  3183. com_presyn=mon.x_S
  3184. com_high=com_presyn[trials:]
  3185. com_low=com_presyn[:trials]
  3186. com_tot=np.shape(com_presyn)[1]*dt_
  3187. com_time=np.arange(0,com_tot,dt_)
  3188. # average across trials
  3189. com_post=np.mean(com_postsyn,0)
  3190. com_pre_high=np.mean(com_high,0)
  3191. com_pre_low=np.mean(com_low,0)
  3192. # SIMULATION NAVIGATION CONTEXT ANEST
  3193. tau_th=2.0*550
  3194. # d_LF=0.045
  3195. d_HF=1.8*0.040
  3196. coefC=0.6
  3197. context=1
  3198. exp=1
  3199. exec(open("./input.py").read())
  3200. exec(open("./model.py").read())
  3201. nav_postsyn=pos.V_th*1000 # to mV
  3202. nav_presyn=mon.x_S
  3203. nav_high=nav_presyn[trials:]
  3204. nav_low=nav_presyn[:trials]
  3205. nav_tot=np.shape(nav_presyn)[1]*dt_
  3206. nav_time=np.arange(0,nav_tot,dt_)
  3207. # average acros trials
  3208. nav_post2=np.mean(nav_postsyn,0)
  3209. nav_pre_high2=np.mean(nav_high,0)
  3210. nav_pre_low2=np.mean(nav_low,0)
  3211. # SIMULATION COMMUNICATION CONTEXT ANEST
  3212. context=2
  3213. exec(open("./input.py").read())
  3214. exec(open("./model.py").read())
  3215. com_postsyn=pos.V_th*1000
  3216. com_presyn=mon.x_S
  3217. com_high=com_presyn[trials:]
  3218. com_low=com_presyn[:trials]
  3219. com_tot=np.shape(com_presyn)[1]*dt_
  3220. com_time=np.arange(0,com_tot,dt_)
  3221. # average across trials
  3222. com_post2=np.mean(com_postsyn,0)
  3223. com_pre_high2=np.mean(com_high,0)
  3224. com_pre_low2=np.mean(com_low,0)
  3225. ## plotting
  3226. vm_i=-50
  3227. vm_s=-20
  3228. xs_i=-1.1
  3229. xs_s=-0.0
  3230. fig, ax = plt.subplots(2,2,sharex=True,sharey='row',figsize=(3.54,2))
  3231. # navigation postsyn
  3232. ax[0,0].plot(nav_time,nav_post,c='k',lw=0.75)
  3233. ax[0,0].plot(nav_time,nav_post2,c='k',lw=0.75,ls='--')
  3234. # ax[0,0].vlines(onset[1],vm_i,vm_s,lw=0.75)
  3235. ax[0,0].vlines(onset[1]-delay+60,vm_i,vm_s,lw=0.75)
  3236. ax[0,0].set_ylim(vm_i,vm_s)
  3237. ax[0,0].set_xlim(0,onset[1]+50)
  3238. ax[0,0].set_ylabel('spiking\n threshold')
  3239. # communication postsyn
  3240. ax[0,1].plot(com_time,com_post,c='k',lw=0.75)
  3241. ax[0,1].plot(com_time,com_post2,c='k',lw=0.75,ls='--')
  3242. # ax[0,1].vlines(onset[2],vm_i,vm_s,lw=0.75)
  3243. ax[0,1].vlines(onset[2]-delay+60,vm_i,vm_s,lw=0.75)
  3244. ax[0,1].set_ylim(vm_i,vm_s)
  3245. ax[0,1].set_xlim(0,onset[2]+50)
  3246. # navigation presyn
  3247. ax[1,0].plot(nav_time,-1*nav_pre_high,c='b',lw=0.75)
  3248. ax[1,0].plot(nav_time,-1*nav_pre_high2,c='b',lw=0.75,ls='--')
  3249. ax[1,0].plot(nav_time,-1*nav_pre_low,c='r',lw=0.75)
  3250. ax[1,0].plot(nav_time,-1*nav_pre_low2,c='r',lw=0.75,ls='--')
  3251. # ax[1,0].vlines(onset[1],xs_i,xs_s,lw=0.75)
  3252. ax[1,0].vlines(onset[1]-delay+60,xs_i,xs_s,lw=0.75)
  3253. ax[1,0].set_ylim(xs_i,xs_s)
  3254. ax[1,0].set_xlim(0,onset[1]+50)
  3255. ax[1,0].set_ylabel('strength\n synapse')
  3256. # communication presyn
  3257. ax[1,1].plot(com_time,-1*com_pre_high,c='b',lw=0.75)
  3258. ax[1,1].plot(com_time,-1*com_pre_high2,c='b',lw=0.75,ls='--')
  3259. ax[1,1].plot(com_time,-1*com_pre_low,c='r',lw=0.75)
  3260. ax[1,1].plot(com_time,-1*com_pre_low2,c='r',lw=0.75,ls='--')
  3261. # ax[1,1].vlines(onset[2],xs_i,xs_s,lw=0.75)
  3262. ax[1,1].vlines(onset[2]-delay+60,xs_i,xs_s,lw=0.75)
  3263. ax[1,1].set_ylim(xs_i,xs_s)
  3264. ax[1,1].set_xlim(0,onset[2]+50)
  3265. ax = ax.flatten()
  3266. for axi in ax:
  3267. axi.spines['top'].set_visible(False)
  3268. axi.spines['right'].set_visible(False)
  3269. axi.spines['bottom'].set_linewidth(0.75)
  3270. axi.spines['left'].set_linewidth(0.75)
  3271. plt.figtext(0.5, 0.01, 'Time (ms)', rotation=0, verticalalignment='bottom')
  3272. fig.tight_layout()
  3273. return fig
  3274. def assymetries_plot(x,nav_data,com_data,original_pos,c1,c2,maxY):
  3275. # comparison between distributions across several parameters and original awake distribution
  3276. # original awake distribution
  3277. original_nav=nav_data[original_pos]
  3278. original_com=com_data[original_pos]
  3279. # context: echolocation
  3280. p_navs=[]
  3281. for i in range(len(nav_data)): # across several parameters
  3282. # h,p=ranksums(original_nav,nav_data[i])
  3283. p,size = cliffsDelta(original_nav,nav_data[i])
  3284. p_navs.append(abs(p))
  3285. # context: communication
  3286. p_coms=[]
  3287. for i in range(len(com_data)):
  3288. # h,p=ranksums(original_com,com_data[i])
  3289. p,size = cliffsDelta(original_com,com_data[i])
  3290. p_coms.append(abs(p))
  3291. # plotting
  3292. fig, ax = plt.subplots(1,1,figsize=(0.75,1)) # for insets: (1.3,0.75)
  3293. # plot pvalues
  3294. # ax.plot(x,-np.log(p_navs),linestyle="--",lw=0.5,marker="o",markersize=2,color=c1)
  3295. ax.plot(x,p_navs,linestyle="-",lw=0.75,marker="o",markersize=2,color=c1)
  3296. # ax.plot(x,-np.log(p_coms),linestyle="--",lw=0.5,marker="o",markersize=2,color=c2)
  3297. ax.plot(x,p_coms,linestyle="-",lw=0.75,marker="o",markersize=2,color=c2)
  3298. # plot significance level
  3299. # minY=-0.5
  3300. # maxY=40
  3301. # ax.set_ylim(ax.get_ylim()[0],maxY)
  3302. ax.set_ylim(-0.1,1)
  3303. # ax.axhspan(ax.get_ylim()[0],-np.log(0.05),facecolor='0.95')
  3304. # ax.axhspan(-np.log(0.05),ax.get_ylim()[1],facecolor='0.85')
  3305. # plot cliff delta interpretation as background color
  3306. neg=0.147
  3307. small=0.33
  3308. med=0.47
  3309. larg=1
  3310. upper_color='black'
  3311. down_color='orange'
  3312. # ax.axhline(0,ls='--',c='k',lw=0.75)
  3313. # ax.axhspan(-neg,0,alpha=0.05,color=down_color)
  3314. ax.axhspan(0,neg,alpha=0.05,color=upper_color)
  3315. # ax.axhspan(-small,-neg,alpha=0.1,color=down_color)
  3316. ax.axhspan(neg,small,alpha=0.1,color=upper_color)
  3317. # ax.axhspan(-med,-small,alpha=0.2,color=down_color)
  3318. ax.axhspan(small,med,alpha=0.2,color=upper_color)
  3319. # ax.axhspan(-larg,-med,alpha=0.3,color=down_color)
  3320. ax.axhspan(med,larg,alpha=0.3,color=upper_color)
  3321. # ax.set_ylabel('effect size') #('-log(p-value)')
  3322. # ax.set_xlabel(r'$\tau$ adaptation')
  3323. # ax.set_xticklabels([])
  3324. # ax.set_yticks([])
  3325. # ax.invert_xaxis()
  3326. ax.axis('off')
  3327. # ax.set_xlim(x[0],x[-1])
  3328. # ax.set_ylim(minY,maxY)
  3329. fig.tight_layout()
  3330. return fig
  3331. def ns_region(sims,fig1,ax1,fig2,ax2,fig3,ax3,fig4,ax4,fig5,ax5,fig6,ax6,sims_original=None):
  3332. # for 2D non significant regions of anesthesia effect
  3333. parameters1=sims[0]
  3334. parameters2=sims[1]
  3335. sims = np.delete(sims,[0,1], 0)
  3336. nx=len(parameters1)
  3337. ny=len(parameters2)
  3338. # original parameters (no anesthesia)
  3339. or_par1=1.0000000000000004
  3340. or_par2=1
  3341. ind_par1=np.where(parameters1==or_par1)[0]
  3342. ind_par2=np.where(parameters2==or_par2)[0]
  3343. original_pos=int(ind_par1)*(ny)+int(ind_par2)
  3344. # original distribution of output
  3345. if sims_original is None:
  3346. o_sims=sims[original_pos]
  3347. else:
  3348. sims_original = np.delete(sims_original,[0,1], 0)
  3349. o_sims=sims_original[original_pos]
  3350. # original context effect
  3351. o_ce=context_effect(o_sims)
  3352. o_ce_n_e=o_ce[:,0]
  3353. o_ce_n_u=o_ce[:,1]
  3354. o_ce_c_e=o_ce[:,2]
  3355. o_ce_c_u=o_ce[:,3]
  3356. # original deviance detection
  3357. o_dd_nav=(o_ce_n_u-o_ce_n_e)/2
  3358. o_dd_com=(o_ce_c_u-o_ce_c_e)/2
  3359. # original spiking rate during context
  3360. o_rate_n=o_sims[:,8]
  3361. o_rate_c=o_sims[:,11]
  3362. # duration nof context
  3363. # dur_ech=1.3311
  3364. # dur_com=1.9266
  3365. # for plotting 2D non-significant regions between anesthesia and non-anesthesia
  3366. ce_n_e=[]
  3367. ce_n_u=[]
  3368. ce_c_e=[]
  3369. ce_c_u=[]
  3370. dd_nav=[]
  3371. dd_com=[]
  3372. rate_nav=[]
  3373. rate_com=[]
  3374. for j in range(nx*ny):
  3375. # j is a particular combinations of parameters
  3376. j_sims=sims[j]
  3377. # original context effect
  3378. j_ce=context_effect(j_sims)
  3379. j_ce_n_e=j_ce[:,0]
  3380. j_ce_n_u=j_ce[:,1]
  3381. j_ce_c_e=j_ce[:,2]
  3382. j_ce_c_u=j_ce[:,3]
  3383. # original deviance detection
  3384. j_dd_nav=(j_ce_n_u-j_ce_n_e)/2
  3385. j_dd_com=(j_ce_c_u-j_ce_c_e)/2
  3386. # original spiking rate during context
  3387. j_rate_n=j_sims[:,8]
  3388. j_rate_c=j_sims[:,11]
  3389. # comparison between anesthesia and no-anesthesia - p-value
  3390. # h,p=ranksums(j_ce_n_e,o_ce_n_e)
  3391. # ce_n_e.append(1)if p<0.05 else ce_n_e.append(0)
  3392. # h,p=ranksums(j_ce_n_u,o_ce_n_u)
  3393. # ce_n_u.append(1)if p<0.05 else ce_n_u.append(0)
  3394. # h,p=ranksums(j_ce_c_e,o_ce_c_e)
  3395. # ce_c_e.append(1)if p<0.05 else ce_c_e.append(0)
  3396. # h,p=ranksums(j_ce_c_u,o_ce_c_u)
  3397. # ce_c_u.append(1) if p<0.05 else ce_c_u.append(0)
  3398. #
  3399. # h,p=ranksums(j_dd_nav,o_dd_nav)
  3400. # dd_nav.append(1) if p<0.05 else dd_nav.append(0)
  3401. # h,p=ranksums(j_dd_com,o_dd_com)
  3402. # dd_com.append(1) if p<0.05 else dd_com.append(0)
  3403. #
  3404. # h,p=ranksums(j_rate_n,o_rate_n)
  3405. # rate_nav.append(1) if p<0.05 else rate_nav.append(0)
  3406. # h,p=ranksums(j_rate_c,o_rate_c)
  3407. # rate_com.append(1) if p<0.05 else rate_com.append(0)
  3408. # comparison between anesthesia and no-anesthesia - effect size
  3409. h,p=cliffsDelta(j_ce_n_e,o_ce_n_e)
  3410. ce_n_e.append(h)
  3411. h,p=cliffsDelta(j_ce_n_u,o_ce_n_u)
  3412. ce_n_u.append(h)
  3413. h,p=cliffsDelta(j_ce_c_e,o_ce_c_e)
  3414. ce_c_e.append(h)
  3415. h,p=cliffsDelta(j_ce_c_u,o_ce_c_u)
  3416. ce_c_u.append(h)
  3417. h,p=cliffsDelta(j_dd_nav,o_dd_nav)
  3418. dd_nav.append(h)
  3419. h,p=cliffsDelta(j_dd_com,o_dd_com)
  3420. dd_com.append(h)
  3421. h,p=cliffsDelta(j_rate_n,o_rate_n)
  3422. rate_nav.append(h)
  3423. h,p=cliffsDelta(j_rate_c,o_rate_c)
  3424. rate_com.append(h)
  3425. ce_n_e=np.array(ce_n_e).reshape(nx,ny)
  3426. ce_n_u=np.array(ce_n_u).reshape(nx,ny)
  3427. ce_c_e=np.array(ce_c_e).reshape(nx,ny)
  3428. ce_c_u=np.array(ce_c_u).reshape(nx,ny)
  3429. dd_nav=np.array(dd_nav).reshape(nx,ny)
  3430. dd_com=np.array(dd_com).reshape(nx,ny)
  3431. rate_nav=np.array(rate_nav).reshape(nx,ny)
  3432. rate_com=np.array(rate_com).reshape(nx,ny)
  3433. ## plotting
  3434. # fig, ax = plt.subplots(1,4,sharex=True,sharey=True,figsize=(5,1.5))
  3435. Xn, Yn = np.meshgrid(parameters2,parameters1)
  3436. c_='gray'
  3437. ls_=0.75
  3438. # cliff_interpret=[-1,-0.47,-0.33,-0.147,0.147,0.33,0.47,1]
  3439. cliff_interpret=[-0.147,0.147]
  3440. plt.figure(1,figsize=fig1.get_size_inches())
  3441. ax1[0].contour(Xn,Yn,ce_n_e,levels=cliff_interpret,origin='lower',colors=[c_],linewidths=ls_)
  3442. ax1[1].contour(Xn,Yn,ce_n_u,levels=cliff_interpret,origin='lower',colors=[c_],linewidths=ls_)
  3443. plt.figure(2,figsize=fig2.get_size_inches())
  3444. # ax.imshow(dd_nav,origin='lower')
  3445. ax2.contour(Xn,Yn,dd_nav,levels =cliff_interpret,origin='lower',colors=[c_],linewidths=ls_)
  3446. # plt.figure(3,figsize=fig3.get_size_inches())
  3447. # ax3.contour(Xn,Yn,rate_nav,levels=cliff_interpret,origin='lower',colors=[c_],linewidths=ls_)
  3448. plt.figure(4,figsize=fig4.get_size_inches())
  3449. ax4[0].contour(Xn,Yn,ce_c_e,levels=cliff_interpret,origin='lower',colors=[c_],linewidths=ls_)
  3450. ax4[1].contour(Xn,Yn,ce_c_u,levels=cliff_interpret,origin='lower',colors=[c_],linewidths=ls_)
  3451. plt.figure(5,figsize=fig5.get_size_inches())
  3452. ax5.contour(Xn,Yn,dd_com,levels=cliff_interpret,origin='lower',colors=[c_],linewidths=ls_)
  3453. # plt.figure(6,figsize=fig6.get_size_inches())
  3454. # ax6.contour(Xn,Yn,rate_com,levels =cliff_interpret,origin='lower',colors=[c_],linewidths=ls_)
  3455. return fig1,fig2,fig3,fig4,fig5,fig6
  3456. def effect_tauth(sims, sims_tauth):
  3457. # distribution of outputs for model awake using sims
  3458. parameters1=sims[0]
  3459. parameters2=sims[1]
  3460. sims = np.delete(sims,[0,1], 0)
  3461. nx=len(parameters1)
  3462. ny=len(parameters2)
  3463. or_par1=1.0000000000000004
  3464. or_par2=1#7.9999999999999964
  3465. ind_par1=np.where(parameters1==or_par1)[0]
  3466. ind_par2=np.where(parameters2==or_par2)[0]
  3467. # dur_ech=1.3311
  3468. # dur_com=1.9266
  3469. dd_nav=[]
  3470. dd_com=[]
  3471. di_nav=[]
  3472. di_iso=[]
  3473. di_com=[]
  3474. ce_n_e=[]
  3475. ce_n_u=[]
  3476. ce_c_e=[]
  3477. ce_c_u=[]
  3478. rate_nav=[]
  3479. rate_com=[]
  3480. for j in range(nx*ny):
  3481. # j is a particular combinations of parameters
  3482. # 2D only needs the average
  3483. ce_i=np.mean(context_effect(sims[j]),0)
  3484. dd_nav_i=(ce_i[1]-ce_i[0])/2
  3485. dd_com_i=(ce_i[3]-ce_i[2])/2
  3486. dd_nav.append(dd_nav_i)
  3487. dd_com.append(dd_com_i)
  3488. # context effect
  3489. ce_n_e.append(ce_i[0])
  3490. ce_n_u.append(ce_i[1])
  3491. ce_c_e.append(ce_i[2])
  3492. ce_c_u.append(ce_i[3])
  3493. # discriminability index
  3494. di_i=np.mean(discriminability_index(sims[j]),0)
  3495. di_nav.append(di_i[0])
  3496. di_iso.append(di_i[1])
  3497. di_com.append(di_i[2])
  3498. # firing rate
  3499. sp_contexts=sims[j]
  3500. rate_nav.append(np.mean(sp_contexts[:,8])) #/dur_ech
  3501. rate_com.append(np.mean(sp_contexts[:,11])) #/dur_com
  3502. dd_nav=np.array(dd_nav).reshape(nx,ny)
  3503. dd_com=np.array(dd_com).reshape(nx,ny)
  3504. di_nav=np.array(di_nav).reshape(nx,ny)
  3505. di_iso=np.array(di_iso).reshape(nx,ny)
  3506. di_com=np.array(di_com).reshape(nx,ny)
  3507. ce_n_e=np.array(ce_n_e).reshape(nx,ny)
  3508. ce_n_u=np.array(ce_n_u).reshape(nx,ny)
  3509. ce_c_e=np.array(ce_c_e).reshape(nx,ny)
  3510. ce_c_u=np.array(ce_c_u).reshape(nx,ny)
  3511. rate_nav=np.array(rate_nav).reshape(nx,ny)
  3512. rate_com=np.array(rate_com).reshape(nx,ny)
  3513. ## original awake distributions
  3514. dd_nav_o=dd_nav[ind_par1,ind_par2]
  3515. ce_n_e_o=ce_n_e[ind_par1,ind_par2]
  3516. ce_n_u_o=ce_n_u[ind_par1,ind_par2]
  3517. rate_nav_o=rate_nav[ind_par1,ind_par2]
  3518. dd_com_o=dd_com[ind_par1,ind_par2]
  3519. ce_c_e_o=ce_c_e[ind_par1,ind_par2]
  3520. ce_c_u_o=ce_c_u[ind_par1,ind_par2]
  3521. rate_com_o=rate_com[ind_par1,ind_par2]
  3522. # distribution of outputs for model anesthesia using sims_tauth
  3523. sims_tauth = np.delete(sims_tauth,[0,1], 0)
  3524. dd_nav=[]
  3525. dd_com=[]
  3526. di_nav=[]
  3527. di_iso=[]
  3528. di_com=[]
  3529. ce_n_e=[]
  3530. ce_n_u=[]
  3531. ce_c_e=[]
  3532. ce_c_u=[]
  3533. rate_nav=[]
  3534. rate_com=[]
  3535. for j in range(nx*ny):
  3536. # j is a particular combinations of parameters
  3537. # 2D only needs the average
  3538. ce_i=np.mean(context_effect(sims_tauth[j]),0)
  3539. dd_nav_i=(ce_i[1]-ce_i[0])/2
  3540. dd_com_i=(ce_i[3]-ce_i[2])/2
  3541. dd_nav.append(dd_nav_i)
  3542. dd_com.append(dd_com_i)
  3543. # context effect
  3544. ce_n_e.append(ce_i[0])
  3545. ce_n_u.append(ce_i[1])
  3546. ce_c_e.append(ce_i[2])
  3547. ce_c_u.append(ce_i[3])
  3548. # discriminability index
  3549. di_i=np.mean(discriminability_index(sims_tauth[j]),0)
  3550. di_nav.append(di_i[0])
  3551. di_iso.append(di_i[1])
  3552. di_com.append(di_i[2])
  3553. # firing rate
  3554. sp_contexts=sims_tauth[j]
  3555. rate_nav.append(np.mean(sp_contexts[:,8])) #/dur_ech
  3556. rate_com.append(np.mean(sp_contexts[:,11])) #/dur_com
  3557. dd_nav=np.array(dd_nav).reshape(nx,ny)
  3558. dd_com=np.array(dd_com).reshape(nx,ny)
  3559. di_nav=np.array(di_nav).reshape(nx,ny)
  3560. di_iso=np.array(di_iso).reshape(nx,ny)
  3561. di_com=np.array(di_com).reshape(nx,ny)
  3562. ce_n_e=np.array(ce_n_e).reshape(nx,ny)
  3563. ce_n_u=np.array(ce_n_u).reshape(nx,ny)
  3564. ce_c_e=np.array(ce_c_e).reshape(nx,ny)
  3565. ce_c_u=np.array(ce_c_u).reshape(nx,ny)
  3566. rate_nav=np.array(rate_nav).reshape(nx,ny)
  3567. rate_com=np.array(rate_com).reshape(nx,ny)
  3568. # difference with awake state for echolocation
  3569. dd=dd_nav-dd_nav_o
  3570. ce_e=ce_n_e-ce_n_e_o
  3571. ce_u=ce_n_u-ce_n_u_o
  3572. rate=rate_nav-rate_nav_o
  3573. # smoothing data
  3574. x=parameters2
  3575. y=parameters1
  3576. f_dd = interp2d(x,y,dd, kind='cubic')
  3577. f_ce_e = interp2d(x,y,ce_e, kind='cubic')
  3578. f_ce_u = interp2d(x,y,ce_u, kind='cubic')
  3579. f_rate = interp2d(x,y,rate, kind='cubic')
  3580. # increasing resolution axes
  3581. alpha=5 # smoothing factor
  3582. x_in=parameters2[0]
  3583. x_end=parameters2[-1]
  3584. x_n=len(parameters2)
  3585. y_in=parameters1[0]
  3586. y_end=parameters1[-1]
  3587. y_n=len(parameters1)
  3588. x_nn=x_n + (x_n-1)*(alpha-1)
  3589. y_nn=y_n + (y_n-1)*(alpha-1)
  3590. xnew = np.linspace(x_in,x_end,x_nn)
  3591. ynew = np.linspace(y_in,y_end,y_nn)
  3592. Xn, Yn = np.meshgrid(xnew, ynew)
  3593. # generate smooth data for the new axes
  3594. dd_smooth = f_dd(xnew,ynew)
  3595. ce_e_smooth = f_ce_e(xnew,ynew)
  3596. ce_u_smooth = f_ce_u(xnew,ynew)
  3597. rate_smooth = f_rate(xnew,ynew)
  3598. # c.e. matching and mismatching
  3599. fig1, ax1 = plt.subplots(1,2,sharex=True,sharey=True,figsize=(2.1,1))
  3600. mm=0.2
  3601. q1=ax1[0].pcolor(Xn,Yn,ce_e_smooth,cmap='RdBu',vmin=-mm,vmax=mm)
  3602. q2=ax1[1].pcolor(Xn,Yn,ce_u_smooth,cmap='RdBu',vmin=-mm,vmax=mm)
  3603. # adding colorbars
  3604. divider = make_axes_locatable(ax1[0])
  3605. cax = divider.append_axes("right", size="5%", pad=0.075)
  3606. fig1.colorbar(q1,cax=cax)
  3607. cax.remove()
  3608. divider = make_axes_locatable(ax1[1])
  3609. cax = divider.append_axes("right", size="5%", pad=0.075)
  3610. fig1.colorbar(q2,cax=cax)
  3611. fig1.tight_layout()
  3612. # s.s.s.
  3613. fig2, ax2 = plt.subplots(1,figsize=(1.15,1))
  3614. q1=ax2.pcolormesh(Xn,Yn,dd_smooth,cmap='RdBu',vmin=-mm,vmax=mm)
  3615. divider = make_axes_locatable(ax2)
  3616. cax = divider.append_axes("right", size="5%", pad=0.075)
  3617. fig2.colorbar(q1,cax=cax)
  3618. fig2.tight_layout()
  3619. # firing rate of inputs
  3620. fig3, ax3 = plt.subplots(1,figsize=(1.15,1))
  3621. mm=30
  3622. q1=ax3.pcolor(Xn,Yn,rate_smooth,cmap='RdBu',vmin=-mm,vmax=mm)
  3623. ax3.contour(Xn,Yn,rate_smooth,levels = [-23],origin='lower',colors=['k'],linewidths=0.75)
  3624. divider = make_axes_locatable(ax3)
  3625. cax = divider.append_axes("right", size="5%", pad=0.075)
  3626. fig3.colorbar(q1,cax=cax)
  3627. fig3.tight_layout()
  3628. # difference with awake state for communication
  3629. dd=dd_com-dd_com_o
  3630. ce_e=ce_c_e-ce_c_e_o
  3631. ce_u=ce_c_u-ce_c_u_o
  3632. rate=rate_com-rate_com_o
  3633. #smoothing data
  3634. f_dd = interp2d(x,y,dd, kind='cubic')
  3635. f_ce_e = interp2d(x,y,ce_e, kind='cubic')
  3636. f_ce_u = interp2d(x,y,ce_u, kind='cubic')
  3637. f_rate = interp2d(x,y,rate, kind='cubic')
  3638. dd_smooth = f_dd(xnew,ynew)
  3639. ce_e_smooth = f_ce_e(xnew,ynew)
  3640. ce_u_smooth = f_ce_u(xnew,ynew)
  3641. rate_smooth = f_rate(xnew,ynew)
  3642. # c.e matching and mismatching
  3643. fig4, ax4 = plt.subplots(1,2,sharex=True,sharey=True,figsize=(2.1,1))
  3644. mm=0.2
  3645. # c.e. match
  3646. q1=ax4[0].pcolor(Xn,Yn,ce_e_smooth,cmap='RdBu',vmin=-mm,vmax=mm)
  3647. # ax4[0].set_title('c.e. match')
  3648. # c.e. mismatch
  3649. q2=ax4[1].pcolor(Xn,Yn,ce_u_smooth,cmap='RdBu',vmin=-mm,vmax=mm)
  3650. # ax4[1].set_title('c.e. mismatch')
  3651. divider = make_axes_locatable(ax4[0])
  3652. cax = divider.append_axes("right", size="5%", pad=0.075)
  3653. fig4.colorbar(q1,cax=cax)
  3654. cax.remove()
  3655. divider = make_axes_locatable(ax4[1])
  3656. cax = divider.append_axes("right", size="5%", pad=0.075)
  3657. fig4.colorbar(q2,cax=cax)
  3658. fig4.tight_layout()
  3659. fig5, ax5 = plt.subplots(1,figsize=(1.15,1))
  3660. # s.s.s
  3661. q1=ax5.pcolor(Xn,Yn,dd_smooth,cmap='RdBu',vmin=-mm,vmax=mm)
  3662. # ax5.set_title('s.s.s.')
  3663. divider = make_axes_locatable(ax5)
  3664. cax = divider.append_axes("right", size="5%", pad=0.075)
  3665. fig5.colorbar(q1,cax=cax)
  3666. fig5.tight_layout()
  3667. fig6, ax6 = plt.subplots(1,figsize=(1.15,1))
  3668. # firing rate
  3669. mm=30
  3670. q1=ax6.pcolor(Xn,Yn,rate_smooth,cmap='RdBu',vmin=-mm,vmax=mm)
  3671. ax6.contour(Xn,Yn,rate_smooth,levels = [-16],origin='lower',colors=['k'],linewidths=0.75)
  3672. # ax6.set_title('firing rate')
  3673. divider = make_axes_locatable(ax6)
  3674. cax = divider.append_axes("right", size="5%", pad=0.075)
  3675. fig6.colorbar(q1,cax=cax)
  3676. fig6.tight_layout()
  3677. # plotting for difference between communication and echolocation
  3678. jump=3
  3679. fig7, ax7 = plt.subplots(2,2,figsize=(6,4))
  3680. fig7.canvas.manager.set_window_title('Difference between contexts')
  3681. # difference with awake state
  3682. # communication
  3683. dd2=dd_com-dd_com_o
  3684. ce_e2=ce_c_e-ce_c_e_o
  3685. ce_u2=ce_c_u-ce_c_u_o
  3686. rate2=rate_com-rate_com_o
  3687. # echolocation
  3688. dd1=dd_nav-dd_nav_o
  3689. ce_e1=ce_n_e-ce_n_e_o
  3690. ce_u1=ce_n_u-ce_n_u_o
  3691. rate1=rate_nav-rate_nav_o
  3692. # difference between communication and echolocation
  3693. dd=dd2-dd1
  3694. ce_e=ce_e2-ce_e1
  3695. ce_u=ce_u2-ce_u1
  3696. rate=rate2-rate1
  3697. # first plot: s.s.s
  3698. mm=0.2
  3699. q1=ax7[0,0].imshow(dd,cmap='RdBu',origin='lower',vmin=-mm,vmax=mm,interpolation='hamming')
  3700. ax7[0,0].set_xticks(np.arange(0,ny,jump))
  3701. ax7[0,0].set_xticklabels(['{:.1f}'.format(x) for x in parameters2[::jump]])
  3702. ax7[0,0].set_yticks(np.arange(0,nx,jump))
  3703. ax7[0,0].set_yticklabels(['{:.1f}'.format(x) for x in parameters1[::jump]])
  3704. ax7[0,0].set_title('s.s.s.')
  3705. # third plot: c.e. mismatch
  3706. q3=ax7[1,0].imshow(ce_e,cmap='RdBu',origin='lower',vmin=-mm,vmax=mm,interpolation='hamming')
  3707. ax7[1,0].set_xticks(np.arange(0,ny,jump))
  3708. ax7[1,0].set_xticklabels(['{:.1f}'.format(x) for x in parameters2[::jump]])
  3709. ax7[1,0].set_yticks(np.arange(0,nx,jump))
  3710. ax7[1,0].set_yticklabels(['{:.1f}'.format(x) for x in parameters1[::jump]])
  3711. ax7[1,0].set_title('c.e. match')
  3712. # forth plot: firing rate
  3713. q4=ax7[1,1].imshow(ce_u,cmap='RdBu',origin='lower',vmin=-mm,vmax=mm,interpolation='hamming')
  3714. ax7[1,1].set_xticks(np.arange(0,ny,jump))
  3715. ax7[1,1].set_xticklabels(['{:.1f}'.format(x) for x in parameters2[::jump]])
  3716. ax7[1,1].set_yticks(np.arange(0,nx,jump))
  3717. ax7[1,1].set_yticklabels(['{:.1f}'.format(x) for x in parameters1[::jump]])
  3718. ax7[1,1].set_title('c.e. mismatch')
  3719. # second plot: c.e. match
  3720. mm=30
  3721. q2=ax7[0,1].imshow(rate,cmap='RdBu',origin='lower',vmin=-mm,vmax=mm,interpolation='hamming')
  3722. ax7[0,1].set_xticks(np.arange(0,ny,jump))
  3723. ax7[0,1].set_xticklabels(['{:.1f}'.format(x) for x in parameters2[::jump]])
  3724. ax7[0,1].set_yticks(np.arange(0,nx,jump))
  3725. ax7[0,1].set_yticklabels(['{:.1f}'.format(x) for x in parameters1[::jump]])
  3726. ax7[0,1].set_title('firing context')
  3727. # add colorbars
  3728. fig7.colorbar(q1,ax=ax7[0,0])
  3729. fig7.colorbar(q2,ax=ax7[0,1])
  3730. fig7.colorbar(q3,ax=ax7[1,0])
  3731. fig7.colorbar(q4,ax=ax7[1,1])
  3732. fig7.tight_layout()
  3733. return fig1,ax1,fig2,ax2,fig3,ax3,fig4,ax4,fig5,ax5,fig6,ax6
  3734. def one_combi(sims,x,y,sims_original=None):
  3735. # get output from a particular combination of parameters (x and y) from sims
  3736. parameters1=sims[0]
  3737. parameters2=sims[1]
  3738. sims = np.delete(sims,[0,1], 0)
  3739. ny=len(parameters2)
  3740. or_par1=x
  3741. or_par2=y
  3742. ind_par1=np.where(np.round(parameters1,2)==or_par1)[0]
  3743. ind_par2=np.where(np.round(parameters2,2)==or_par2)[0]
  3744. # from 2D to 1D
  3745. pos_2d=int(ind_par1)*(ny)+int(ind_par2)
  3746. # particular combination in x, y
  3747. comb_sim=sims[pos_2d]
  3748. # combination for awake model
  3749. ind_par1_awake=np.where(np.round(parameters1,2)==1.0)[0]
  3750. ind_par2_awake=np.where(np.round(parameters2,2)==1.0)[0]
  3751. pos_2d_awake=int(ind_par1_awake)*(ny)+int(ind_par2_awake)
  3752. if sims_original is None:
  3753. # take the awake values from the same matrix sims
  3754. comb_sim_awake=sims[pos_2d_awake]
  3755. print('using same matrix to find awake state')
  3756. else:
  3757. print('using second matrix provided in the function')
  3758. # take the awake values from the given matrix 'sims_original'
  3759. sims_original = np.delete(sims_original,[0,1], 0)
  3760. comb_sim_awake=sims_original[pos_2d_awake]
  3761. if np.array_equal(comb_sim,comb_sim_awake):
  3762. print('equals')
  3763. # calculation of outputs for combination x,y
  3764. ce_comb=context_effect(comb_sim)
  3765. ce_n_e_comb=ce_comb[:,0]
  3766. ce_n_u_comb=ce_comb[:,1]
  3767. ce_c_e_comb=ce_comb[:,2]
  3768. ce_c_u_comb=ce_comb[:,3]
  3769. p_anest_nav=ranksums(ce_n_e_comb, ce_n_u_comb)[1]
  3770. p_anest_com=ranksums(ce_c_e_comb, ce_c_u_comb)[1]
  3771. dd_nav_comb=(ce_n_u_comb-ce_n_e_comb)/2
  3772. dd_com_comb=(ce_c_u_comb-ce_c_e_comb)/2
  3773. rate_nav_comb=np.mean(comb_sim[:,8].reshape(50,20),1)
  3774. rate_com_comb=np.mean(comb_sim[:,11].reshape(50,20),1)
  3775. # calculation of outputs for combination awake
  3776. ce_awake=context_effect(comb_sim_awake)
  3777. ce_n_e_awake=ce_awake[:,0]
  3778. ce_n_u_awake=ce_awake[:,1]
  3779. ce_c_e_awake=ce_awake[:,2]
  3780. ce_c_u_awake=ce_awake[:,3]
  3781. p_awake_nav=ranksums(ce_n_e_awake, ce_n_u_awake)[1]
  3782. p_awake_com=ranksums(ce_c_e_awake, ce_c_u_awake)[1]
  3783. dd_nav_awake=(ce_n_u_awake-ce_n_e_awake)/2
  3784. dd_com_awake=(ce_c_u_awake-ce_c_e_awake)/2
  3785. rate_nav_awake=np.mean(comb_sim_awake[:,8].reshape(50,20),1)
  3786. rate_com_awake=np.mean(comb_sim_awake[:,11].reshape(50,20),1)
  3787. # stats
  3788. # print('anesthedsia')
  3789. # print(wilcoxon(dd_com_comb))
  3790. # print('awake')
  3791. # print(wilcoxon(dd_com_awake))
  3792. if p_awake_nav<0.05:
  3793. stats1='*'
  3794. else:
  3795. stats1='ns'
  3796. if p_anest_nav<0.05:
  3797. stats2='*'
  3798. else:
  3799. stats2='ns'
  3800. if p_awake_com<0.05:
  3801. stats3='*'
  3802. else:
  3803. stats3='ns'
  3804. if p_anest_com<0.05:
  3805. stats4='*'
  3806. k=0
  3807. else:
  3808. stats4='ns'
  3809. k=1
  3810. ## plotting
  3811. red_ =(0.8500,0.3250, 0.0980)
  3812. blue_=(0,0.4470,0.7410)
  3813. aa=0.5
  3814. red_light=(0.8500,0.3250*aa, 0.0980*aa)
  3815. blue_light=(0,0.4470*aa,0.7410*aa)
  3816. colors=[blue_,blue_light,red_,red_light]
  3817. v=0 # capsize
  3818. t=1 # thick of the cap
  3819. ss=2 # size of the marker 'o'
  3820. fH=1.4 # figure size weight
  3821. fW=1.7 # figure size height
  3822. rot=30 # rotation of xlabels
  3823. ew=1 # thickness of errorbars
  3824. # context effect echolocation
  3825. fig1, ax = plt.subplots(1,figsize=(fH,fW))
  3826. # add boxplot
  3827. colorsb1=[nc.to_rgba(i, alpha=0.5) for i in colors]
  3828. b1=ax.boxplot([ce_n_e_awake,ce_n_u_awake,ce_n_e_comb,ce_n_u_comb],positions=[1,2,3,4], patch_artist=True,widths=0.5,notch=True)
  3829. for item in ['whiskers', 'fliers', 'medians', 'caps','boxes']:
  3830. for c in b1[item]:
  3831. c.set(color='k', linewidth=0.5)
  3832. for patch, color in zip(b1['boxes'], colorsb1):
  3833. patch.set_facecolor(color)
  3834. for i in b1['fliers']:
  3835. i.set_markersize(2)
  3836. i.set_markeredgewidth(0.5)
  3837. ax.errorbar(1, np.median(ce_n_e_awake), yerr = sem(ce_n_e_awake),c=colors[0], fmt='o',ms=ss, capsize=v, capthick=t,elinewidth=ew)
  3838. ax.errorbar(2, np.median(ce_n_u_awake), yerr = sem(ce_n_u_awake),c=colors[1], fmt='o',ms=ss, capsize=v, capthick=t,elinewidth=ew)
  3839. ax.errorbar(3, np.median(ce_n_e_comb), yerr = sem(ce_n_e_comb),c=colors[2], fmt='o',ms=ss, capsize=v, capthick=t,elinewidth=ew)
  3840. ax.errorbar(4, np.median(ce_n_u_comb), yerr = sem(ce_n_u_comb),c=colors[3], fmt='o',ms=ss, capsize=v, capthick=t,elinewidth=ew)
  3841. # add stats
  3842. y=0.1 #-0.2
  3843. h=0.01
  3844. ax.plot([1, 1, 2, 2], [y, y+h, y+h, y], lw=0.75,c='k')
  3845. ax.plot([3, 3, 4, 4], [y, y+h, y+h, y], lw=0.75,c='k')
  3846. ax.text((1+2)*.5, y+h, stats1, ha='center', va='center',c='k',fontsize=12)
  3847. ax.text((3+4)*.5, y+h, stats2, ha='center', va='center',c='k',fontsize=12)
  3848. ax.set_ylabel('echolocation effect')
  3849. ax.spines['top'].set_visible(False)
  3850. ax.spines['right'].set_visible(False)
  3851. ax.spines['bottom'].set_linewidth(1)
  3852. ax.spines['left'].set_linewidth(1)
  3853. ax.set_xlim([0.5, 4.5])
  3854. # ax.set_ylim([-0.9, 0.175])
  3855. ax.set_xticks(np.arange(1,5,1))
  3856. ax.set_xticklabels(['match','mismatch','match','mismatch'],ha='right')
  3857. ax.tick_params(axis='x', rotation=rot)
  3858. fig1.tight_layout()
  3859. # context effect communication
  3860. fig2, ax = plt.subplots(1,figsize=(fH,fW))
  3861. # add boxplot
  3862. colorsb1=[nc.to_rgba(i, alpha=0.5) for i in colors]
  3863. b1=ax.boxplot([ce_c_e_awake,ce_c_u_awake,ce_c_e_comb,ce_c_u_comb],positions=[1,2,3,4], patch_artist=True,widths=0.5,notch=True)
  3864. for item in ['whiskers', 'fliers', 'medians', 'caps','boxes']:
  3865. for c in b1[item]:
  3866. c.set(color='k', linewidth=0.5)
  3867. for patch, color in zip(b1['boxes'], colorsb1):
  3868. patch.set_facecolor(color)
  3869. for i in b1['fliers']:
  3870. i.set_markersize(2)
  3871. i.set_markeredgewidth(0.5)
  3872. ax.errorbar(1, np.median(ce_c_e_awake), yerr = sem(ce_c_e_awake),c=colors[0], fmt='o',ms=ss, capsize=v, capthick=t,elinewidth=ew)
  3873. ax.errorbar(2, np.median(ce_c_u_awake), yerr = sem(ce_c_u_awake),c=colors[1], fmt='o',ms=ss, capsize=v, capthick=t,elinewidth=ew)
  3874. ax.errorbar(3, np.median(ce_c_e_comb), yerr = sem(ce_c_e_comb),c=colors[2], fmt='o',ms=ss, capsize=v, capthick=t,elinewidth=ew)
  3875. ax.errorbar(4, np.median(ce_c_u_comb), yerr = sem(ce_c_u_comb),c=colors[3], fmt='o',ms=ss, capsize=v, capthick=t,elinewidth=ew)
  3876. # add stats
  3877. y=0.1 #-0.25 #-0.3
  3878. h=0.01
  3879. ax.plot([1, 1, 2, 2], [y, y+h, y+h, y], lw=0.75,c='k')
  3880. ax.plot([3, 3, 4, 4], [y, y+h, y+h, y], lw=0.75,c='k')
  3881. ax.text((1+2)*.5, y+h, stats3, ha='center', va='center',c='k',fontsize=12)
  3882. ax.text((3+4)*.5, y+h, stats4, ha='center', va='center',c='k',fontsize=12)
  3883. ax.set_ylabel('communication effect')
  3884. ax.spines['top'].set_visible(False)
  3885. ax.spines['right'].set_visible(False)
  3886. ax.spines['bottom'].set_linewidth(1)
  3887. ax.spines['left'].set_linewidth(1)
  3888. ax.set_xlim([0.5, 4.5])
  3889. # ax.set_ylim([-0.5, -0.275])
  3890. ax.set_xticks(np.arange(1,5,1))
  3891. ax.set_xticklabels(['match','mismatch','match','mismatch'],ha='right')
  3892. ax.tick_params(axis='x', rotation=rot)
  3893. fig2.tight_layout()
  3894. # deviance detection both context
  3895. fig3, ax = plt.subplots(1,figsize=(fH,fW))
  3896. ax.axhline(y=0,color='gray',lw=1,ls='--')
  3897. # add boxplot
  3898. colorsb1=[nc.to_rgba(i, alpha=0.5) for i in colors]
  3899. b1=ax.boxplot([dd_nav_awake,dd_com_awake,dd_nav_comb,dd_com_comb],positions=[1,2,3,4], patch_artist=True,widths=0.5,notch=True)
  3900. for item in ['whiskers', 'fliers', 'medians', 'caps','boxes']:
  3901. for c in b1[item]:
  3902. c.set(color='k', linewidth=0.5)
  3903. for patch, color in zip(b1['boxes'], colorsb1):
  3904. patch.set_facecolor(color)
  3905. for i in b1['fliers']:
  3906. i.set_markersize(2)
  3907. i.set_markeredgewidth(0.5)
  3908. ax.errorbar(1, np.median(dd_nav_awake), yerr = sem(dd_nav_awake),c=colors[0], fmt='o',ms=ss, capsize=v, capthick=t,elinewidth=ew)
  3909. ax.errorbar(2, np.median(dd_com_awake), yerr = sem(dd_nav_comb),c=colors[1], fmt='o',ms=ss, capsize=v, capthick=t,elinewidth=ew)
  3910. ax.errorbar(3, np.median(dd_nav_comb), yerr = sem(dd_com_awake),c=colors[2], fmt='o',ms=ss, capsize=v, capthick=t,elinewidth=ew)
  3911. ax.errorbar(4, np.median(dd_com_comb), yerr = sem(dd_com_comb),c=colors[3], fmt='o',ms=ss, capsize=v, capthick=t,elinewidth=ew)
  3912. ax.set_ylabel('s.s.s')
  3913. # ax.set_ylim([0,0.2])
  3914. ax.spines['top'].set_visible(False)
  3915. ax.spines['right'].set_visible(False)
  3916. ax.spines['bottom'].set_linewidth(1)
  3917. ax.spines['left'].set_linewidth(1)
  3918. ax.set_xlim([0.5, 4.5])
  3919. ax.set_ylim([-0.2, 0.4])
  3920. ax.set_xticks(np.arange(1,5,1))
  3921. ax.set_xticklabels(['ech','com','ech','com'],ha='right')
  3922. ax.tick_params(axis='x', rotation=rot)
  3923. fig3.tight_layout()
  3924. # rate firing both context
  3925. fig4, ax = plt.subplots(1,figsize=(fH,fW))
  3926. # ax.errorbar(1, np.mean(rate_nav_awake), yerr = sem(rate_nav_awake),c=colors[0], fmt='o',ms=ss, capsize=v, capthick=t,elinewidth=ew)
  3927. # ax.errorbar(2, np.mean(rate_nav_comb), yerr = sem(rate_nav_comb),c=colors[2], fmt='o',ms=ss, capsize=v, capthick=t,elinewidth=ew)
  3928. # ax.errorbar(3, np.mean(rate_com_awake), yerr = sem(rate_com_awake),c=colors[1], fmt='o',ms=ss, capsize=v, capthick=t,elinewidth=ew)
  3929. # ax.errorbar(4, np.mean(rate_com_comb), yerr = sem(rate_com_comb),c=colors[3], fmt='o',ms=ss, capsize=v, capthick=t,elinewidth=ew)
  3930. ax.bar(1, np.mean(rate_nav_awake),color=colors[0],alpha=0.5,edgecolor=(0,0,0,1))
  3931. ax.bar(2, np.mean(rate_nav_comb),color=colors[2],alpha=0.5,edgecolor=(0,0,0,1))
  3932. ax.bar(4, np.mean(rate_com_awake),color=colors[1],alpha=0.5,edgecolor=(0,0,0,1))
  3933. ax.bar(5, np.mean(rate_com_comb),color=colors[3],alpha=0.5,edgecolor=(0,0,0,1))
  3934. print(p_awake_nav) # (wilcoxon(dd_nav_awake))
  3935. print(p_anest_nav) #(wilcoxon(dd_nav_comb))
  3936. print(p_awake_com) #(wilcoxon(dd_com_awake))
  3937. print(p_anest_com) #(wilcoxon(dd_com_comb))
  3938. # print(cliffsDelta(rate_nav_awake,rate_nav_comb)[0])
  3939. # print(cliffsDelta(rate_com_awake,rate_com_comb)[0])
  3940. ax.set_ylabel('spike count')
  3941. # ax.set_ylim([-1,0])
  3942. ax.spines['top'].set_visible(False)
  3943. ax.spines['right'].set_visible(False)
  3944. ax.spines['bottom'].set_linewidth(1)
  3945. ax.spines['left'].set_linewidth(1)
  3946. ax.set_xlim([0, 6])
  3947. ax.set_xticks([1,2,4,5])
  3948. ax.set_xticklabels(['ech-aw','ech-an','com-aw','com-an'],ha='right')
  3949. ax.tick_params(axis='x', rotation=rot)
  3950. fig4.tight_layout()
  3951. plt.locator_params(axis='y',nbins=5)
  3952. # plotting with boxplots
  3953. # fig1, ax1 = plt.subplots(1,1,figsize=(1.5,1.5))
  3954. # colors=[nc.to_rgba(i, alpha=0.5) for i in colors]
  3955. # b1=ax1.boxplot([ce_c_e_awake,ce_c_u_awake,ce_c_e_comb,ce_c_u_comb],positions=[1,2,3,4], patch_artist=True,widths=0.5,notch=True)
  3956. # for item in ['whiskers', 'fliers', 'medians', 'caps','boxes']:
  3957. # for c in b1[item]:
  3958. # c.set(color='k', linewidth=0.5)
  3959. # for patch, color in zip(b1['boxes'], colors):
  3960. # patch.set_facecolor(color)
  3961. # for i in b1['fliers']:
  3962. # i.set_markersize(2)
  3963. # i.set_markeredgewidth(0.5)
  3964. return fig1, fig2, fig3, fig4, k