コード例 #1
0
    def run(self): 
        """Make the multicolor catalog."""
        # define the zero point error
        zpoint_err = 0.01

        self.logfile.write('Processing catalogs...')

        detection_variables = tableio.get_data(self.detCatalog,self.detectionColumns)
        nsources = len(detection_variables[0])
        ncats    = len(self.catalogList)

        #Create a series of arrays to keep the relevant data
        flux    = Numeric.zeros((ncats,nsources))*1.0          # ISO flux ... for now.
        fluxerr = Numeric.zeros((ncats,nsources))*1.0          # ISO flux error... for now.
        m       = Numeric.zeros((ncats,nsources))*1.0          # MAG_ISO
        em      = Numeric.zeros((ncats,nsources))*1.0          # MAGERR_ISO
        m_corr  = Numeric.zeros((ncats,nsources))*1.0          # extinction corrected magnitude
        em_corr = Numeric.zeros((ncats,nsources))*1.0          # extinction corrected magnitude error
        ap_corr = Numeric.zeros((ncats,nsources))*1.0          # aperture   correction
        m_bpz   = Numeric.zeros((ncats,nsources))*1.0          # MAG_BPZ    extinction/aperture corrected
        em_bpz  = Numeric.zeros((ncats,nsources))*1.0          # MAGERR_BPZ extinction/aperture corrected


        preds = [os.path.basename(self.detCatalog)]

        # this is a list of those indices of the catalogList which raised the filterError exception
        # i think i need to know this, but i'm not sure why yet....
        self.badcats = []
        for i in range(ncats):
            selectSet = {}
            pardict = {}
            imname  =  os.path.splitext(self.catalogList[i])[0]
            basefits=  imname + '.fits'    
            fitsfile= os.path.join(self.obsFits,basefits)
            detector= fUtil.getDetector(fitsfile)

            try:
                imfilter= fUtil.filterResponseName(fitsfile)

            except fUtil.filterError:
                self.badcats.append(i)
                imfilter = fUtil.twoFilterName(fitsfile)

            try:
                filterXCorr       = extinction.filterFactor(imfilter) * self.eBV
                filterXCorrError  = filterXCorr*0.16
            except fUtil.filterError,err:
                self.errorList.append(("extintion.py","filterError: "+str(err)))
                self.logfile.write("filterError: "+str(err))
                filterXCorr       = 0.0
                filterXCorrError  = 0.0

            try:
                filter = fUtil.filterName(fitsfile)
                ap_corr[i,:] = self._apcorr(detector,filter)
            except KeyError,err:
                print str(err)
                self.logfile.write(str(err))
                # if we can't do it, well, we can't do it.
                pass
コード例 #2
0
    def bandcounts(self):
        """Count the filter number in band (['opt','nir','red','uv']) .
	"""
        # pdb.set_trace()

        for fitsfile in self.sciImageList:
            # Use user-defined detector for the detection image
            det = fUtil.getDetector(os.path.join(self.obsFits, fitsfile))
            if det == self.det:
                if (self.band == 'red'):
                    if string.find(fitsfile, '160') > -1 or string.find(
                            fitsfile, '140') > -1:
                        yes = 1
                        self.bandlist.append(fitsfile)
                    else:
                        print 'Not including ' + fitsfile + ' in detection image.'
                        yes = 0
                else:
                    yes = 1
                    self.bandlist.append(fitsfile)
            else:
                print 'Not including ' + fitsfile + ' in detection image.'
                yes = 0
        print len(self.bandlist), ' filters are detected under ' + self.band
        print self.bandlist
コード例 #3
0
ファイル: combFilter.py プロジェクト: XingxingHuang/APLUS
    def getStats(self,Band):
        """Runs SExtractor with phoney pars to get noise and background stats. 
       Now implement this using the Popen4 class, which sends both stdout
       and stderr to the fromchild file object.  We suppress stdout from 
       SExtractor by shunting stuff to /dev/null via the par file, so we
       will only get stderr anyway, at least, in theory.  The Popen3 class
       or rather, the factory function is uses, popen3, has proved
       to be buggy at times, so this is an attempt to move away from it.
        """ 

        self.logfile.write('Generating background and noise statistics for fits images')
        self.statsList = []

        # pdb.set_trace()
        for fitsfile in self.sciImageList:
            # Use user-defined detector for the detection image
            det = fUtil.getDetector(os.path.join(self.obsFits,fitsfile))
            if det == self.det:
                if (Band =='red'):     
                    if string.find(fitsfile,'160') > -1 or string.find(fitsfile,'140') > -1:
                        yes = 1
                    else:
                        self.logfile.write('Not including '+fitsfile+' in detection image.')
                        yes = 0
                else:
                    yes = 1
            else:
                self.logfile.write('Not including '+fitsfile+' in detection image.')
                yes = 0

            if self.excludeFilters:
                # pass on user excluded filters for the detection image
                filt = fUtil.getFilter2(os.path.join(self.obsFits,fitsfile))
                if filt in self.excludeFilters:
                    self.logfile.write('User requested exclude filter found in data.')
                    self.logfile.write('Not including'+filt+' in detection image.')
                    yes = 0

            if (yes == 1):
                self.logfile.write('running SExtractor on ' + fitsfile)
                cmd     = 'sex ' +  os.path.join(self.obsFits, fitsfile) + ' -c ' + self.inParFileName
                subproc = popen2.Popen4(cmd)
                lines   = subproc.fromchild.readlines()
                self.logfile.write('logging background and noise stats.')
        
                for line in lines:
                    if string.find(line,'(M+D) Background:') != -1:
                        # pdb.set_trace()
                        linef = string.split(line)
                        self.logfile.write(fitsfile+': '+linef[1]+linef[2]+'  '+linef[3]+linef[4])
                        self.statsList.append((fitsfile,linef[2],linef[4]))          # linef[2] is background, linef[4] is noise.    ############ attention here by XX
                    elif string.find(line,'*ERROR*') != -1:
                        self.errorList.append((self.modName,line))
                        self.logfile.write('Error in running SExtractor: '+ line)
        return 
コード例 #4
0
ファイル: xmlUtil.py プロジェクト: XingxingHuang/APLUS
def xmlStartCat(outfile, name, imgfile=None):
    """Initialise the xml header of a catalog file. imgfile is a passed fits file.
    """
    xmlcatalog = open(outfile, 'w+')
    xmlcatalog.write(
        "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n")
    xmlcatalog.write('<!DOCTYPE catalog SYSTEM ' +\
            '\n\t"http://acs.pha.jhu.edu/science/pipeline/DTD/Catalog.dtd">\n')
    if imgfile == None:
        xmlcatalog.write("<catalog type=\"xml/text\" dataset=\"" + name +
                         "\" date=\"" + ptime() + "\">\n")
    else:
        img = os.path.basename(imgfile)
        tel = fUtil.getTel(imgfile)
        inst = fUtil.getInstr(imgfile)
        det = fUtil.getDetector(imgfile)
        filter1 = fUtil.getFilter1(imgfile)
        filter2 = fUtil.getFilter2(imgfile)
        acs = filters.ACSFilterInfo()
        if filter1 and filter2:
            if filter1 not in acs.clear and filter2 not in acs.clear:
                xmlcatalog.write("<catalog type=\"xml/text\" imgsrc=\"" +img+ \
                         "\" dataset=\""+name+"\" telescope=\"" +tel+  \
                         "\" instrument=\""+inst+"\" detector=\"" +det+\
                         "\" filtername=\""+filter1+"/"+filter2+"\" date=\""+ptime()+"\">\n")
            elif filter1 in acs.clear:
                xmlcatalog.write("<catalog type=\"xml/text\" imgsrc=\"" +img+ \
                         "\" dataset=\""+name+"\" telescope=\"" +tel+  \
                         "\" instrument=\""+inst+"\" detector=\"" +det+\
                         "\" filtername=\""+filter2+"\" date=\""+ptime()+"\">\n")
            elif filter2 in acs.clear:
                xmlcatalog.write("<catalog type=\"xml/text\" imgsrc=\"" +img+ \
                         "\" dataset=\""+name+"\" telescope=\"" +tel+  \
                         "\" instrument=\""+inst+"\" detector=\"" +det+\
                         "\" filtername=\""+filter1+"\" date=\""+ptime()+"\">\n")
        else:
            print "No filters found in image:", img, "for markup."
            xmlcatalog.write("<catalog type=\"xml/text\" dataset=\""+name+"\" imgsrc=\"" \
                     +img+ "\" date=\""+ptime()+"\">\n")
    xmlcatalog.close()
    return
コード例 #5
0
    def run(self, band):
        """Make the multicolor catalog."""
        # define the zero point error
        zpoint_err = 0.01

        self.logfile.write('Processing catalogs...')

        detection_variables = tableio.get_data(self.detCatalog,
                                               self.detectionColumns)
        nsources = len(detection_variables[0])
        # WZ Should be a dimension check here with the filter catalogs before crashing
        ncats = len(self.catalogList)

        #Create a series of arrays to keep the relevant data
        flux = Numeric.zeros((ncats, nsources)) * 1.0  # ISO flux ... for now.
        fluxerr = Numeric.zeros(
            (ncats, nsources)) * 1.0  # ISO flux error... for now.
        m = Numeric.zeros((ncats, nsources)) * 1.0  # MAG_ISO
        em = Numeric.zeros((ncats, nsources)) * 1.0  # MAGERR_ISO
        m_corr = Numeric.zeros(
            (ncats, nsources)) * 1.0  # extinction corrected magnitude
        em_corr = Numeric.zeros(
            (ncats, nsources)) * 1.0  # extinction corrected magnitude error
        ap_corr = Numeric.zeros(
            (ncats, nsources)) * 1.0  # aperture   correction
        m_bpz = Numeric.zeros(
            (ncats,
             nsources)) * 1.0  # MAG_BPZ    extinction/aperture corrected
        em_bpz = Numeric.zeros(
            (ncats,
             nsources)) * 1.0  # MAGERR_BPZ extinction/aperture corrected

        preds = [os.path.basename(self.detCatalog)]

        # this is a list of those indices of the catalogList which raised the filterError exception
        # i think i need to know this, but i'm not sure why yet....
        self.badcats = []
        for i in range(ncats):
            selectSet = {}
            pardict = {}
            imname = os.path.splitext(self.catalogList[i])[0]
            j = string.rfind(imname, '_')
            basefits = imname[0:j] + '_sci.fits'
            fitsfile = os.path.join(self.obsFits, basefits)
            detector = fUtil.getDetector(fitsfile)
            try:
                imfilter = fUtil.filterResponseName(fitsfile)

            except fUtil.filterError:
                self.badcats.append(i)
                imfilter = fUtil.twoFilterName(fitsfile)

            try:
                filterXCorr = extinction.filterFactor(imfilter) * self.eBV
                filterXCorrError = filterXCorr * 0.16
            except fUtil.filterError, err:
                self.errorList.append(
                    ("extintion.py", "filterError: " + str(err)))
                self.logfile.write("filterError: " + str(err))
                filterXCorr = 0.0
                filterXCorrError = 0.0

            try:
                f = pyfits.open(fitsfile)  # WZ
                instr = f[0].header.get('INSTRUME')
                f.close()
                del f
                if instr == 'ACS':
                    #filter = 'F814W'   #WZ
                    filter = fUtil.filterNameACS(fitsfile)
                elif instr == 'WFC3':
                    #filter = fUtil.filterName(fitsfile)
                    filter = fUtil.filterNameWFC3(fitsfile)
                if filter:
                    print "Find filter ", filter
                else:
                    raise filterError, "No filter found for fits image: " + fitsfile
                #filter = fUtil.filterName(fitsfile)
                ap_corr[i, :] = self._apcorr(detector, filter)
            except KeyError, err:
                print str(err)
                self.logfile.write(str(err))
                # if we can't do it, well, we can't do it.
                pass