Beispiel #1
0
def plotdframebyarbandhist (ddf,kcol,lband=['delta','theta','alpha','beta','lgamma','gamma','hgamma'],xl=None,xlab=None,ylab=None,\
                            lar=['A1','Thal'],llschan=[['s2','g','i1'],['Th']],\
                            llclr=[['r','g','b'],['c']],\
                            llab=['A1 supragran','A1 gran','A1 infragran','Thal'],lcflat=['r','g','b','c'],bins=20):
  import matplotlib.patches as mpatches
  dtitle = {b:'' for b in lband}
  dlm = {ar:{ch:[] for ch in lsch} for ar,lsch in zip(lar,llschan)} # mean
  dls = {ar:{ch:[] for ch in lsch} for ar,lsch in zip(lar,llschan)} # standard error
  dlmin =  {ar:{ch:[] for ch in lsch} for ar,lsch in zip(lar,llschan)} # min
  dlmax  =  {ar:{ch:[] for ch in lsch} for ar,lsch in zip(lar,llschan)} # max
  dlmed =  {ar:{ch:[] for ch in lsch} for ar,lsch in zip(lar,llschan)} # median
  dlN =  {ar:{ch:[] for ch in lsch} for ar,lsch in zip(lar,llschan)} # median  
  from nhpdat import dbands
  xfreq = [(dbands[k][1]+dbands[k][0])/2. for k in dbands.keys()]
  for ar,lsch,lclr in zip(lar,llschan,llclr):
    for schan,clr in zip(lsch,lclr):
      for bdx,b in enumerate(lband):
        subplot(3,2,bdx+1); title(b)
        hist(ddf[ar][schan][b][kcol],density=True,histtype='step',linewidth=10,color=clr,bins=bins)
        if xl is not None: xlim(xl)
        if xlab is not None: xlabel(xlab)
        if ylab is not None: ylabel(ylab)
        dlm[ar][schan].append(mean(ddf[ar][schan][b][kcol]))
        dls[ar][schan].append(std(ddf[ar][schan][b][kcol])/sqrt(len(ddf[ar][schan][b][kcol])))
        dlmin[ar][schan].append(min(ddf[ar][schan][b][kcol]))
        dlmax[ar][schan].append(max(ddf[ar][schan][b][kcol]))
        dlmed[ar][schan].append(median(ddf[ar][schan][b][kcol]))
        dlN[ar][schan].append(len(ddf[ar][schan][b][kcol]))
        print(ar,schan,clr,b,kcol,dlN[ar][schan][-1],dlmin[ar][schan][-1],dlmax[ar][schan][-1],dlmed[ar][schan][-1],dlm[ar][schan][-1],dls[ar][schan][-1])
  ax=gca()
  lpatch = [mpatches.Patch(color=c,label=s) for c,s in zip(lcflat,llab)]
  ax.legend(handles=lpatch,handlelength=1)  
  return dlm,dls,dlmin,dlmax,dlmed,dlN
Beispiel #2
0
def plotdlcoh (dlcoh,lband=['delta','theta','alpha','beta','gamma','hgamma'],\
               ar='A1',lschan=['s2','g','i1'],lclr=['r','g','b'],dolegend=True):
  # plot lagged coherence output as line plot  
  import matplotlib.patches as mpatches
  dlm = {ar:{schan:[] for schan in lschan}}
  dls = {ar:{schan:[] for schan in lschan}}
  from nhpdat import dbands
  xfreq = [(dbands[k][1]+dbands[k][0])/2. for k in dbands.keys()]
  for ar,lsch,lclr in zip([ar],[lschan],[lclr]):
    for schan in lsch:
      for bdx,b in enumerate(lband):
        dlm[ar][schan].append(mean(dlcoh[ar][schan][b]))
        dls[ar][schan].append(std(dlcoh[ar][schan][b])/sqrt(len(dlcoh[ar][schan][b])))      
  for ar,lsch,lclr in zip([ar],[lschan],[lclr]):
    for schan,clr in zip(lsch,lclr):
      plot(xfreq,np.array(dlm[ar][schan])-dls[ar][schan],clr+'--')
      plot(xfreq,np.array(dlm[ar][schan])+dls[ar][schan],clr+'--')
      plot(xfreq,dlm[ar][schan],clr)
      plot(xfreq,dlm[ar][schan],clr+'o',markersize=40)
  xlabel('Frequency (Hz)',fontsize=45); ylabel('Lagged Coherence',fontsize=45)
  if dolegend:
    ax=gca()
    lpatch = [mpatches.Patch(color=c,label=s) for c,s in zip(lclr,['NHP A1 supragranular','NHP A1 granular','NHP A1 infragranular'])]
    ax.legend(handles=lpatch,handlelength=1)  
  return dlm,dls
Beispiel #3
0
def plotdframebyarband (ddf,kcol,lband=['delta','theta','alpha','beta','lgamma','gamma','hgamma'],\
                        lar=['A1','STG'],llschan=[['s2','g','i1'],['104']],\
                        llclr=[['r','g','b'],['c']],\
                        llab=['A1 supragran','A1 gran','A1 infragran','Human STG'],lcflat=['r','g','b','c'],drawlegend=True,ylab=None,msz=40):
  import matplotlib.patches as mpatches
  dtitle = {b:'' for b in lband}
  dlm = {ar:{ch:[] for ch in lsch} for ar,lsch in zip(lar,llschan)} # 'A1':{'s2':[],'g':[],'i1':[]},'Thal':{'Th':[]}}
  dls = {ar:{ch:[] for ch in lsch} for ar,lsch in zip(lar,llschan)}
  from nhpdat import dbands
  xfreq = [(dbands[k][1]+dbands[k][0])/2. for k in dbands.keys()]
  for ar,lsch,lclr in zip(lar,llschan,llclr):
    for schan in lsch:
      for bdx,b in enumerate(lband):
        dlm[ar][schan].append(mean(ddf[ar][schan][b][kcol]))
        dls[ar][schan].append(std(ddf[ar][schan][b][kcol])/sqrt(len(ddf[ar][schan][b][kcol])))  
  for ar,lsch,lclr in zip(lar,llschan,llclr):
    for schan,clr in zip(lsch,lclr):
      plot(xfreq,np.array(dlm[ar][schan])-dls[ar][schan],clr+'--')
      plot(xfreq,np.array(dlm[ar][schan])+dls[ar][schan],clr+'--')
      plot(xfreq,dlm[ar][schan],clr)
      plot(xfreq,dlm[ar][schan],clr+'o',markersize=msz)
  xlabel('Frequency (Hz)');
  if ylab is None:
    ylabel(kcol)
  else:
    ylabel(ylab)
  ax=gca()
  lpatch = [mpatches.Patch(color=c,label=s) for c,s in zip(lcflat,llab)]
  if drawlegend: ax.legend(handles=lpatch,handlelength=1)  
  return dlm,dls