def EigenClean( shot, roi,  Nbgs=40):
  t0 = time.time()
  bgs,bgshots,shape = GetBackgrounds(Nbgs,shot)
  if ( verbose ):
    print "GetBackgrounds process time = %.2f seconds" % (time.time()-t0)

  mask = makemask( shape, roi)
  B, normfactor =  Bjk( roi, mask, bgs , bgshots)

  if ( verbose ):
    print "# of backgrounds = %d" % len(bgs)
    print "pixels per background = %s" % str(bgs[0].shape)
    print "mask roi = %s" % str(roi)
    print "shape of B matrix = %s" % str(B.shape)

  image, atomsf = Ax(shot)
  y = Yj( mask, bgs, image, normfactor)  

  if ( verbose ):
    print "shape of y vector = %s" % str(y.shape)

  t0 = time.time()
  c, resid, rank, sigma = linalg.lstsq( B, y)
  if ( verbose ):
    print "Coeffs evaluation time = %.2f seconds" % (time.time()-t0)
    print "maximum residual = %.3e" % numpy.max(y-B*c)

  if ( verbose ):
    print "\neigenclean background:\n"  
  for i in range( c.shape[0]  ):
    out =  "% 2.3f * '%s'" % ( c[i], bgshots[i] ) 
    if bgshots[i] == shot :
      out = out + ' <--'
    if ( verbose ):
      print out

  t0 = time.time()
  nb = NewBackground( c, bgs) 
  if ( verbose ):
    print "New background evaluation time = %.2f seconds" % (time.time()-t0)
  t0 = time.time()
  numpy.savetxt( shot + '_eigenclean.ascii' , nb, fmt='%.6e', delimiter='\t')
  if ( verbose ):
    print "New background save to disk time = %.2f seconds" % (time.time()-t0)

  fits2png.makepng( atomsf, 'ABS', 140, prefix = '_noclean')
  fits2png.makepng( atomsf, 'ABS', 140, bg =nb,  prefix = '_clean')
Beispiel #2
0
    def loadImage(self, image):
        """"""
        atomsfile = image
       
        print atomsfile
        
        shot = atomsfile.split('atoms')[0]
        type = atomsfile.split('atoms')[1]

        pngpath = shot + '_' + image_type +  '_falsecolor.png'
        if not os.path.exists( pngpath ):
            print 'Creating ' + pngpath + '...'
            if image_type == 'andor':
                pngpath = fits2png.makepng( atomsfile, 'ABS', 80)
            elif image_type == 'andor2':
                pngpath = fits2png.makepng( atomsfile, 'PHC', 80)
            elif image_type == 'manta': 
                pngpath = manta2png.makepng( atomsfile, 'PHC', 80)

        image_name = os.path.basename(pngpath)
        img = wx.Image(pngpath, wx.BITMAP_TYPE_ANY)
        # scale the image, preserving the aspect ratio
        W = img.GetWidth()
        H = img.GetHeight()
        if W > H:
            NewW = self.photoMaxSize
            NewH = self.photoMaxSize * H / W
        else:
            NewH = self.photoMaxSize
            NewW = self.photoMaxSize * W / H
        img = img.Scale(NewW,NewH)

        self.imageCtrl.SetBitmap(wx.BitmapFromImage(img))
        self.imageLabel.SetLabel(image_name)
        self.Refresh()
        Publisher().sendMessage("resize", "")