Example #1
0
    def cleandata(self,
                  filename,
                  iminfo=None,
                  prodir='.',
                  interp='linear',
                  cleanup=True,
                  clobber=False,
                  logfile='saltclean.log',
                  reduce_image=True,
                  display_image=False,
                  verbose=True):
        """Start the process to reduce the data and produce a single mosaicked image"""
        #print filename
        status = 0
        #create the input file name
        infile = os.path.basename(filename)
        rawpath = os.path.dirname(filename)
        outpath = './'
        outfile = outpath + 'mbxp' + infile
        #print infile, rawpath, outpath

        #If it is a bin file, pre-process the data
        if filename.count('.bin'):
            print "I can't handle this yet"

        #ignore bcam files
        if infile.startswith('B'):
            return iminfo

        #check to see if it exists and return if clobber is no
        if os.path.isfile(outfile) and not clobber: return iminfo

        #handle HRS data
        print filename
        if infile.startswith('H') or infile.startswith('R'):
            outfile = os.path.basename(filename) + 's'
            print filename, outfile
            if not os.path.isfile(outfile): os.symlink(filename, outfile)

            #display the image
            if display_image:
                print "Displaying %s" % outfile
                try:
                    display(outfile)
                except Exception, e:
                    print e

            try:
                log = None  #open(logfile, 'a')
                sdb = saltmysql.connectdb(self.sdbhost, self.sdbname,
                                          self.sdbuser, self.password)
                sdbloadfits(outfile, sdb, log, False)
                print 'SDBLOADFITS: SUCCESS'
            except Exception, e:
                print 'SDBLOADFITSERROR:', e
Example #2
0
   def cleandata(self, filename, iminfo=None, prodir='.', interp='linear', cleanup=True,
              clobber=False, 
              logfile='saltclean.log', reduce_image=True,
              display_image=False, verbose=True):
      """Start the process to reduce the data and produce a single mosaicked image"""
      #print filename
      status=0
      #create the input file name
      infile=os.path.basename(filename)
      rawpath=os.path.dirname(filename)
      outpath='./'
      outfile=outpath+'mbxp'+infile
      #print infile, rawpath, outpath

      #If it is a bin file, pre-process the data
      if filename.count('.bin'):
          print "I can't handle this yet"

      #ignore bcam files
      if infile.startswith('B'):
          return iminfo


      #check to see if it exists and return if clobber is no
      if os.path.isfile(outfile) and not clobber: return iminfo

      #handle HRS data 
      print filename
      if infile.startswith('H') or infile.startswith('R'):
          outfile = os.path.basename(filename) +'s'
          print filename, outfile
          if not os.path.isfile(outfile): os.symlink(filename, outfile)

          #display the image
          if display_image:
              print "Displaying %s" % outfile
              try:
                 display(outfile)
              except Exception, e:
                 print e

          try:
              log=None #open(logfile, 'a')
              sdb=saltmysql.connectdb(self.sdbhost, self.sdbname, self.sdbuser, self.password)
              sdbloadfits(outfile, sdb, log, False)
              print 'SDBLOADFITS: SUCCESS'
          except Exception, e:
              print 'SDBLOADFITSERROR:', e
Example #3
0

      #reduce the data
      if reduce_image:
         try:
           quickclean(filename, interp, cleanup, clobber, logfile, verbose)
         except Exception, e:
           print e
           return iminfo

      #load the data into the SDB
      if self.sdbhost and self.update:
           try:
               log=None #open(logfile, 'a')
               sdb=saltmysql.connectdb(self.sdbhost, self.sdbname, self.sdbuser, self.password)
               sdbloadfits(filename, sdb, log, False)
               print 'SDBLOADFITS: SUCCESS'
           except Exception, e:
               print 'SDBLOADFITSERROR:', e

      #display the image
      if display_image:
          print "Displaying %s" % outfile
          try:
             display(outfile)
          except Exception, e:
             print e

      #if the images are imaging data, run sextractor on them
      name=iminfo[0]
      propcode=iminfo[headerList.index('PROPID')].strip().upper()
Example #4
0

      #reduce the data
      if reduce_image:
         try:
           quickclean(filename, interp, cleanup, clobber, logfile, verbose)
         except Exception, e:
           print e
           return iminfo

      #load the data into the SDB
      if self.sdbhost and self.update:
           try:
               log=None #open(logfile, 'a')
               sdb=saltmysql.connectdb(self.sdbhost, self.sdbname, self.sdbuser, self.password)
               sdbloadfits(filename, sdb, log, False)
               print 'SDBLOADFITS: SUCCESS'
           except Exception, e:
               print 'SDBLOADFITSERROR:', e

      #display the image
      if display_image:
          print "Displaying %s" % outfile
          try:
             display(outfile)
          except Exception, e:
             print e

      #if the images are imaging data, run sextractor on them
      name=iminfo[0]
      propcode=iminfo[headerList.index('PROPID')].strip().upper()
Example #5
0
   def cleandata(self, filename, iminfo=None, prodir='.', interp='linear', cleanup=True,
              clobber=False, 
              logfile='saltclean.log', reduce_image=True,
              display_image=False, verbose=True):
      """Start the process to reduce the data and produce a single mosaicked image"""
      #print filename
      status=0
      #create the input file name
      infile=os.path.basename(filename)
      rawpath=os.path.dirname(filename)
      outpath='./'
      outfile=outpath+'mbxp'+infile
      #print infile, rawpath, outpath

      #If it is a bin file, pre-process the data
      if filename.count('.bin'):
          print("I can't handle this yet")

      #ignore bcam files
      if infile.startswith('B'):
          return iminfo


      #check to see if it exists and return if clobber is no
      if os.path.isfile(outfile) and not clobber: return iminfo

      #handle HRS data 
      print(filename)
      if infile.startswith('H') or infile.startswith('R'):
          shutil.copy(filename, outfile)
          return iminfo

      if filename.count('.txt'): return iminfo

      #remove frame transfer data
      #detmode=iminfo[headerList.index('DETMODE')].strip().upper()
      #if detmode=='FT' or detmode=='FRAME TRANSFER': return iminfo


      #reduce the data
      if reduce_image:
         try:
           quickclean(filename, interp, cleanup, clobber, logfile, verbose)
         except Exception as e:
           print(e)
           return iminfo

      #load the data into the SDB
      if self.sdbhost and self.update:
           try:
               log=None #open(logfile, 'a')
               sdb=saltmysql.connectdb(self.sdbhost, self.sdbname, self.sdbuser, self.password)
               sdbloadfits(filename, sdb, log, False)
               print('SDBLOADFITS: SUCCESS')
           except Exception as e:
               print('SDBLOADFITSERROR:', e)

      #display the image
      if display_image:
          print("Displaying %s" % outfile)
          try:
             display(outfile)
          except Exception as e:
             print(e)

      #if the images are imaging data, run sextractor on them
      name=iminfo[0]
      propcode=iminfo[headerList.index('PROPID')].strip().upper()
      obsmode=iminfo[headerList.index('OBSMODE')].strip().upper()
      detmode=iminfo[headerList.index('DETMODE')].strip().upper()
      obstype=iminfo[headerList.index('CCDTYPE')].strip().upper()
      target=iminfo[headerList.index('OBJECT')].strip().upper()
      lampid=iminfo[headerList.index('LAMPID')].strip().upper()
      print(detmode)
      if (obsmode=='IMAGING' or obsmode=='FABRY-PEROT' ) and (detmode=='NORMAL' or detmode=='FT' or detmode=='FRAME TRANSFER'):
          i=headerList.index('CCDSUM')
          ccdbin=int(iminfo[i].split()[0])
          pix_scale=0.14*ccdbin
          r_ap=1.5/pix_scale

          #measure the photometry
          print("RUNNING PHOTOMETRY")
          quickphot(outfile, r_ap, pix_scale, self.sexfile, clobber, logfile, verbose)

          #load the regions
          #if display_image: regions(outfile)

          #measure the background statistics
          #hdu=pyfits.open(outfile)
          #bmean, bmidpt, bstd=saltstat.iterstat(hdu[1].data, 5, 3)
	  bmean, bmidpt, bstd=(-1,-1,-1)
          #hdu.close()
          print("---------Background Statistics---------")
          print("%10s %10s %10s" % ('Mean', 'MidPoint', 'STD'))
          print("%10.2f %10.2f %10.2f" % (bmean, bmidpt, bstd))
          iminfo[headerList.index('BMEAN')]='%f' % (bmean)
          iminfo[headerList.index('BMIDPT')]='%f' % (bmidpt)
          iminfo[headerList.index('BSTD')]='%f' % (bstd)

          #measure the seeing
          outtxt=outfile.replace('fits', 'cat')
          try:
              mag_arr, fwhm_arr=np.loadtxt(outtxt, usecols=(2,10), unpack=True)
              mean, std, norm, peak=seeing_stats(fwhm_arr)
              see=mean*pix_scale
              nsources=len(mag_arr)
          except:
              see=-1
              nsources=-1
          iminfo[headerList.index('NSOURCES')]='%i' % nsources
          iminfo[headerList.index('SEEING')]='%f' % see
          #self.emit(QtCore.SIGNAL("updateimlist(str,str,str)"), (name, 'SEEING', '%f' % see))
          #self.emit(QtCore.SIGNAL("updatespec(QString)"), name)

      #If the images are spectral images, run specreduce on them
      if obsmode=='SPECTROSCOPY': # and not(target in ['FLAT', 'BIAS']):
          y1,y2=quickspec(outfile, lampid, objsection=self.objsection, findobj=True, clobber=True, logfile=logfile, verbose=verbose)
          print(y1,y2)
          specfile=outpath+'smbxp'+infile.split('.fits')[0]+'.txt'
          #In here, so it doesn't break when the first checkdata  runs
          try:
              self.specTab.updaterange(y1,y2)
              self.emit(QtCore.SIGNAL("updatespec(QString)"), infile)
          except Exception as e:
              message="SALTFIRST--ERROR:  Could not wavelength calibrate %s because %s" % (infile, e)
              fout=open(logfile, 'a')
              fout.write(message)
              print(message)

      if obsmode=='FABRY-PEROT' and obstype=='ARC':
           try:
              flatimage='/home/ccd/smc/FPFLAT.fits'
              profile=os.path.basename(outfile)
              fpcal(profile, flatimage=flatimage, minflat=18000, niter=5, bthresh=5, displayimage=True, clobber=True, logfile=logfile, verbose=verbose)
           except Exception as e:
              message="SALTFIRST--ERROR:  Could not calibrate FP data te %s because %s" % (infile, e)
              fout=open(logfile, 'a')
              fout.write(message)
              print(message)

      #check for fast mode operation
      if self.update:
          runfast(name, propcode,self.obsdate,self.server, self.readme, self.sdbhost,self.sdbname, self.sdbuser, self.password)
      return iminfo