Beispiel #1
0
 def _getOneWire(self,points,i,rmax=1000):
   inp = 0
   while not inp=='q':
     print inp
     rmin = float(inp)
     tools.nfigure('wire radius selector')
     pl.clf()
     self._plotStripe(points,i,rmin,rmax)
     pl.draw()
     inp = raw_input('Enter radius change, q to finish: ')
     if inp is not 'q': width=int(inp)
   return width
Beispiel #2
0
def histOverview(data,clearFig=True):
  Nax = len(data)
  msk = maskEdge()
  unb = createMaskUnbonded(1)[0]
  fig = nfigure('Cspad histogram overview')
  if clearFig: plt.clf()
  binvec = np.arange(np.round(np.min(data.ravel())),np.round(np.max(data.ravel())),1)
  ah = []
  for n,tdat in enumerate(data):
    hist = getCommonModeFromHist(tdat)
    #tdat = commonModeCorrectTile(tdat)[0]
    unbpx = tdat[unb]
    tdat = tdat[~msk]
    if len(ah)==0:
      ah.append(plt.subplot(8,4,n+1))
    else:
      ah.append(plt.subplot(8,4,n+1,sharex=ah[0]))
    h = np.histogram(tdat,bins=binvec)
    lh = plt.step(binvec[:-1],h[0],where='pre')
    lh = lh[0]
    ub = np.median(unbpx)
    plt.axvline(ub,color=lh.get_color())
    plt.axvline(np.median(tdat),linestyle='--',color=lh.get_color())
    plt.axvline(hist,color="red")
    print "Tile %02d, unbonded %-.2f, hist %-.2f" % (n,ub,hist)
    plt.text(.5,.8,str(n),horizontalalignment='center',transform=ah[-1].transAxes)
    #plt.title(str(n))
  print "Continous BLUE line: unbounded pixels"
  print "Continous RED line: from histogram"
  plt.xlim(-50,50)
  fig.subplots_adjust(hspace=0)
Beispiel #3
0
def getCommonModeFromHist(im,gainAv=30,searchRadiusFrac=.4,debug=False):                       
  im = im.ravel()
  bins = np.arange(-2*gainAv,3*gainAv)
  hst,dum = np.histogram(im.ravel(),bins)
  bins = bins[:-1]
  rad = np.round(gainAv*searchRadiusFrac)
  idx = filtvec(bins,[-rad,rad])
  pk = bins[idx][hst[idx].argmax()]
  idx = filtvec(bins,[pk-rad,pk+rad])
  bins = bins[idx]
  hst = hst[idx]
  bg = np.sum(bins*hst)/np.sum(hst)
  if debug:
    nfigure('debug common mode hist correction')
    plt.clf()
    plt.plot(bins,hst)
    plt.waitforbuttonpress()
  return bg
Beispiel #4
0
def getNoiseMap(Istack,lims_perc=None,lims=None):
  noise = noiseMap(Istack)
  #np.shape(noise)
  if lims_perc is not None:
    lims = np.percentile(noise,lims_perc)
    tools.nfigure('Selected noise limits')
    pl.clf()
    tools.histSmart(noise.ravel()[~np.isnan(noise.ravel())],fac=200)
    pp = plt.axhspan(*lims)
    plt.gca().add_patch(pp)
    plt.draw()

  if lims==None:
    tools.nfigure('Find noise limits')
    pl.clf()
    tools.histSmart(noise.ravel()[~np.isnan(noise.ravel())],fac=200)
    #pl.gca().set_xscale('log')
    pl.draw()
    print "Select noise limits"
    lims = tools.getSpanCoordinates()
  return ~tools.filtvec(noise,lims),noise
Beispiel #5
0
 def testCorrfunc(self,order=5,ic=None):
   fig = tools.nfigure('test_correction_func_order_%d'%order)
   plt.clf()
   fig,ax = plt.subplots(1,2,num=fig.number)
   plt.axes(ax[0])
   it = (self.Imat.T/self.I0).T
   tools.imagesc(np.arange(np.shape(self.Imat)[1]),self.I0,(it/np.mean(it,0))-1)
   tools.clim_std(2)
   plt.colorbar()
   plt.draw()
   cf = self.getCorrFunc(order=order,i0_wp=ic,wrapit=False)
   Icorr = cf(self.Imat,self.I0)
   plt.axes(ax[1])
   it = (Icorr.T/self.I0).T
   tools.imagesc((it/np.mean(it,0))-1)
   tools.clim_std(2)
   plt.colorbar()
Beispiel #6
0
def getCorr(order=5,i0=None,Imat=None,i0_wp=1e6,fraclims_dc=[.9,1.1]):
  """ Getting nonlinear correction factors form a calibration dataset consiting of:
  i0     	array of intensities the calibration has been made for
  Imat   	2D array of the corresponding reference patterns, in each row 
  		there is one ravelled array of each intensity bin in i0.
  i0_wp		a working point around which a correction polynomial will be
  		developed for each pixel.
  order		the polynomial order up to which will be deveoped.
  fraclims_dc	relative factor for the i0,Imat data limits which are used to
  		determine the working point location.
  
  Returns

  """

  #i0,Imat = getData()
  msk = tools.filtvec(i0,i0_wp*np.asarray(fraclims_dc))
  p0 = tools.polyFit(i0[msk],Imat[msk,:],2)
  dc = tools.polyVal(p0,i0_wp)
  comps = tools.polyFit(i0-i0_wp,Imat-dc,order,removeOrders=[0])
  compsder = tools.polyDer(comps)
  c = lambda(i): tools.polyVal(comps,i-np.asarray(tools.iterfy(i0_wp)))+dc
  c_prime = lambda(i): tools.polyVal(compsder,i-np.asarray(tools.iterfy(i0_wp)))
  t = lambda(i): (c_prime(i0_wp).T * (i-i0_wp)).T + dc
  
  cprimeic = c_prime(i0_wp)
  dcorr_const = -cprimeic*i0_wp + c(i0_wp) - t(0) 
  def dcorr(i,D):
    return (i*cprimeic.T + dcorr_const.T + ((D-c(i))*cprimeic/c_prime(i)).T).T
    #return (i*cprimeic.T + dcorr_const.T ).T
  return dcorr,comps,t





  tools.nfigure('testplot')
  plt.clf()
  plt.subplot(1,2,1)
  Imean = (Imat.T/i0).T
  tools.imagesc(np.asarray([ti / np.mean(Imean[-10:,:],0) for ti in Imean]))
  tools.clim_std(6)
  cl = plt.gci().get_clim()
  plt.colorbar()
  plt.set_cmap(plt.cm.RdBu_r)
  
  
  plt.subplot(1,2,2)

  cmps = copy.copy(comps)
  cmps[-2,:] = 0
  cc = lambda(i): tools.polyVal(cmps,i-np.asarray(tools.iterfy(i0_wp)))
  Ir = Imat-c(i0)+t(i0)-t(0)
  Ir = dcorr(i0,Imat)
  #Ir = ((Imat-cc(i0)).T/i0).T
  #tools.imagesc(Ir) 
  Ir = (Ir.T/i0).T
  tools.imagesc(np.asarray([ti / np.mean(Ir[-10:,:],0) for ti in Ir]))
  plt.clim(cl)
  plt.colorbar()
  plt.set_cmap(plt.cm.RdBu_r)
  plt.draw()

  tools.nfigure('testplot_components')
  plt.clf()
  ah = None
  for n,comp in enumerate(comps):
    if ah is None:
      ah = plt.subplot(len(comps),1,n+1)
    else:
      plt.subplot(len(comps),1,n+1,sharex=ah)
    plt.plot(comp)
    lims = np.percentile(comp,[1,99])

    plt.ylim(lims)


  return c,c_prime 
Beispiel #7
0
def makeplots(i0,Imat,mask,ind=[27, 29, 37, 67],order=6):
  Imatref = Imat[np.ix_([27, 29, 37, 67])]
  i0ref = i0[np.ix_([27, 29, 37, 67])]
  dcorr,comps,t = getCorr(order,i0,Imat,i0ref[0])
  patt = cspad.CspadPattern(Nx=300,Ny=300)
  
  if 1:
    Dcorr = dcorr(i0ref,Imatref)
    DcorrNorm = (Dcorr.T/i0ref).T
    DcorrNorm = rearrangeData(DcorrNorm,mask)
    ImatrefNorm = (Imatref.T/i0ref).T
    ImatrefNorm = rearrangeData(ImatrefNorm,mask)
    fig = tools.nfigure('figure2')
    #fig.set_size_inches(3.5,3)
    plt.clf()
    ah = None
    for n in range(3):
      if ah is None:
        ah = plt.subplot(2,3,n+1)
	tah = ah
      else:
        tah = plt.subplot(2,3,n+1,sharex=ah,sharey=ah)
      patt.imageShow((ImatrefNorm[1+n]/ImatrefNorm[0]-1)*100)
      plt.set_cmap(plt.cm.RdBu_r)
      plt.clim([-5,5])
      plt.axis('equal')
      plt.axis([60000,13e4,6e4,13e4])
      plt.setp(tah.get_xticklabels(), visible=False) 
      plt.setp(tah.get_yticklabels(), visible=False) 
      plt.text(6.4e4,11.8e4,['(a)','(b)','(c)'][n],fontsize=20,bbox={'facecolor':'white', 'alpha':1, 'pad':10})


      tah = plt.subplot(2,3,n+4,sharex=ah,sharey=ah)
      pp = patt.bin((DcorrNorm[1+n]/DcorrNorm[0]-1)*100)
      im = tools.imagesc(patt.xVec,patt.yVec,pp)
      plt.set_cmap(plt.cm.RdBu_r)
      plt.clim([-5,5])
      plt.axis('equal')
      plt.axis([60000,13e4,6e4,13e4])
      plt.setp(tah.get_xticklabels(), visible=False) 
      plt.setp(tah.get_yticklabels(), visible=False) 
      plt.text(6.4e4,11.8e4,['(d)','(e)','(f)'][n],fontsize=20,bbox={'facecolor':'white', 'alpha':1, 'pad':10})

    fig.subplots_adjust(left=.05,top=.95,bottom=.05,right=0.85,hspace=.05,wspace=.05)
    cbar_ax = fig.add_axes([0.88, 0.05, 0.03, 0.9])
    fig.colorbar(im, cax=cbar_ax,label='Percent')

  # FIGURE 4

  fig = tools.nfigure('figure4')
  #fig.set_size_inches(3.5,1.5)
  plt.clf()
  ah = None
  count=1
  toplot = [t(0),comps[-3],comps[-4]]
  for n,comp in enumerate(toplot):
    if ah is None:
      ah = plt.subplot(1,3,count)
      tah = ah
    else:
      tah = plt.subplot(1,3,count,sharex=ah,sharey=ah)
    timg = rearrangeData([comp],mask)
    patt.imageShow(timg)
    plt.set_cmap(plt.cm.RdBu_r)
    #plt.clim([-5,5])
    plt.axis('equal')
    plt.axis([60000,13e4,6e4,13e4])
    plt.setp(tah.get_xticklabels(), visible=False) 
    plt.setp(tah.get_yticklabels(), visible=False) 
    plt.text(6.4e4,11.8e4,['$t(0)$','$g=2$','$g=3$','d','e','f','g','h','i','j','k'][n],fontsize=20,bbox={'facecolor':'white', 'alpha':1, 'pad':10})
    count += 1

  fig.subplots_adjust(left=.05,top=.95,bottom=.05,right=0.95,hspace=.05,wspace=.05)