Пример #1
0
    def alignToMaster(self):
        refList = 'master.lis'

        for ii in range(len(self.images)):
            alignRoot = self.alignDir + 'master_' + str(ii)
            alignRoot += '_' + self.fields[ii]
            
            alignRootBoot = self.alignDir + 'master_boot_' + str(ii)
            alignRootBoot += '_' + self.fields[ii]

            starList = self.images[ii] + '_rms_dist.lis'

            print '*** Aligning to master:'
            print '*** Working on %s ***' % starList
            print

            # ==========
            # Re-order refList to shift common source to the top.
            # ==========
            newRefList = self.lisDir + 'master_%d_%s' % (ii, refList) # Always the same ref list, but with
            							      # different stars at the top
            newStarList = self.lisDir + 'nirc2_%d_%s' % (ii, starList)

            # Ref List
            shiftToTopOfList(self.lisDir + refList, newRefList, 
                             self.refStars[self.fields[ii]])

            # Star List
            shiftToTopOfList(self.lisDir + starList, newStarList, 
                             self.refStars[self.fields[ii]])

            # Get the align data type
            fitsFile = self.dataDir + '../%s.fits' % (self.images[ii])
            alignType = dataUtil.get_align_type(fitsFile, errors=True)

            # Get the angle
            posAngle = dataUtil.get_pos_angle(fitsFile)
            if posAngle != 0 and self.alignOrder == 0:
                print 'You must allow for rotation with alignOrder > 0'

            # ==========
            # Align
            # ==========
            _list = open(alignRoot + '.list', 'w')
            _list.write('%s %d ref\n' % (newRefList, alignType))
            _list.write('%s %d\n' % (newStarList, alignType))
            _list.close()

            print '\n*** Aligning %s ***' % starList
            cmd = 'java align -v -p -a %d -r %s %s.list' % (self.alignOrder, alignRoot, alignRoot)
            os.system(cmd)

            # Bootstrap
            print '\n*** Aligning %s (bootstrap) ***' % starList
            ntrials = 100
            cmd = 'java align -v -p -a %d -n %d -r %s %s.list' % \
                (self.alignOrder, ntrials, alignRootBoot, alignRoot)
            os.system(cmd)
Пример #2
0
    def makeNamedStarlist(self):
        """
        We would like to make a named starlist. We do this with a trick...
        just align a dummy starlist to our *rms.lis and pass in 
        label.dat to align.
        """
        mosaicRoot = 'mag' + self.epoch +'_'+ self.mosaic +'_'+ self.filter

        starlist = self.tableDir + mosaicRoot + '_rms_dist.lis'
        dumblist = self.lisDir + self.images[0] + '_rms_dist.lis' # This is shorter

        newList1 = self.lisDir + mosaicRoot + '_align_label.lis'
        newList2 = self.lisDir + self.images[0] + '_align_label.lis'

        # Match sources at the top
        shiftToTopOfList(starlist, newList1, self.refStars[self.fields[0]])
        shiftToTopOfList(dumblist, newList2, self.refStars[self.fields[0]])

        # Get the align data type
        fitsFile = self.dataDir + '../%s.fits' % (self.images[0])
        alignType = dataUtil.get_align_type(fitsFile, errors=True)

        alignRoot = self.alignDir + 'align_label'

        _list = open(alignRoot + '.list', 'w')
        _list.write('%s %d ref\n' % (newList1, alignType))
        _list.write('%s %d\n' % (newList2, alignType))
        _list.close()

        cmd = 'java align -v -p -a 2 -R 1 '
        cmd += '-N /g/lu/data/orion/source_list/label.dat '
        cmd += '-r %s %s.list' % (alignRoot, alignRoot)
        print cmd
        os.system(cmd)

        # This will be our new starlist
        list = starTables.StarfinderList(None, hasErrors=True)

        # Make a new starlist out of the resulting align output
        s = starset.StarSet(alignRoot)

        # Trim out all stars only detected in the dummy epoch.
        mag = s.getArrayFromEpoch(0, 'mag')
        idx = np.where(mag != 0)[0]
        newStars = []
        for ii in idx:
            newStars.append(s.stars[ii])
        s.stars = newStars

        # Pull the data from the aligned epoch
        list.name = np.array(s.getArray('name'))
        list.epoch = np.zeros(len(s.stars), dtype=float) + s.years[0]
        list.mag = s.getArrayFromEpoch(0, 'mag')
        list.x = s.getArrayFromEpoch(0, 'xpix')
        list.y = s.getArrayFromEpoch(0, 'ypix')
        list.xerr = s.getArrayFromEpoch(0, 'xpixerr_p')
        list.yerr = s.getArrayFromEpoch(0, 'ypixerr_p')
        list.snr = s.getArrayFromEpoch(0, 'snr')
        list.corr = s.getArrayFromEpoch(0, 'corr')
        list.nframes = s.getArrayFromEpoch(0, 'nframes')
        list.counts = s.getArrayFromEpoch(0, 'fwhm')

        list.saveToFile(starlist.replace('rms_dist', 'rms_named'))

        shutil.copyfile(self.tableDir + mosaicRoot + '_rms_named.lis', 
                        self.dataDir + mosaicRoot +  '_rms_named.lis')
Пример #3
0
    def alignToMakeMaster(self):
        """
        Loop through and align the images to the master list that
        is slowly being built up.
        Include the alignment of central to central field in order to
        include the distortion error in that image and to include those
        positions when computing the average
        """
        # Define a running variable that contains the refList. This
        # will be updated after each loop.
        refList = self.firstRefList


        for ii in range(0, len(self.images)):
            alignRoot = self.alignDir + 'align_'
            alignRoot += str(ii) + '_' + self.fields[ii]

            alignRootBoot = self.alignDir + 'align_boot_'
            alignRootBoot += str(ii) + '_' + self.fields[ii]

            starList = self.images[ii] + '_rms_dist.lis'

            # ==========
            # Re-order refList to shift common source to the top.
            # ==========
            newRefList = self.lisDir + 'ref_%d_%s' % (ii, refList)
            newStarList = self.lisDir + 'nirc2_%d_%s' % (ii, starList)

            # Ref List
            shiftToTopOfList(self.lisDir + refList, newRefList, 
                             self.refStars[self.fields[ii]])

            # Star List
            shiftToTopOfList(self.lisDir + starList, newStarList, 
                             self.refStars[self.fields[ii]])

            # Get the align data type
            fitsFile = self.dataDir + '../%s.fits' % (self.images[ii])
            alignType = dataUtil.get_align_type(fitsFile, errors=True)

            # Get the angle
            posAngle = dataUtil.get_pos_angle(fitsFile)
            if posAngle != 0 and self.alignOrder == 0:
                print 'You must allow for rotation with alignOrder > 0'

            # ==========
            # Align
            # ==========
            _list = open(alignRoot + '.list', 'w')
            _list.write('%s %s ref\n' % (newRefList, alignType))
            _list.write('%s %d\n' % (newStarList, alignType))
            _list.close()

            print '\n*** Aligning %s ***' % starList
            cmd = 'java align -v -p -a %d -r %s %s.list' % (self.alignOrder, alignRoot, alignRoot)
            os.system(cmd)

            # Bootstrap
            print '\n*** Aligning %s (bootstrap) ***' % starList
            ntrials = 100
            cmd = 'java align -v -p -a %d -n %d -r %s %s.list' % \
                (self.alignOrder, ntrials, alignRootBoot, alignRoot)
            os.system(cmd)

            # ==========
            # Make a new reference list out of the previous align results
            # This builds up a list after each alignment
            # ==========
            refList = 'aligned_%d_%s' % (ii, starList)
            starPrefix = 'ep%d' % ii

            makeNewRefList(alignRootBoot, self.lisDir + refList, 
                           starPrefix=starPrefix)

        shutil.copyfile(self.lisDir + refList, self.lisDir + 'master.lis')