Beispiel #1
0
    def __init__(self,
                 obs,
                 catalogList,
                 band,
                 excludeList=[
                     "X_IMAGE", "Y_IMAGE", "FWHM_IMAGE", 'CLASS_STAR',
                     'ALPHA_J2000', 'DELTA_J2000'
                 ]):  # WZ
        self.modName = string.split(string.split(str(self))[0],
                                    '.')[0][1:]  # module name
        self.aperData = obs.base.pipeline + "/aperData"  # aperture data files
        self.root = obs.newobspath  # root path observation dir
        self.obsName = obs.newobs
        self.obsCats = obs.catdir
        self.obsPars = obs.newpardir
        self.obsFits = obs.fitsdir  # path to fits files
        self.messagedir = obs.messagedir  # where the module message will go.
        self.logfile = obs.logfile  # append log entries to this file
        self.errorList = []
        self.inputList = []
        self.catalogList = []
        self.outputList = {}
        self.filterPars = {
        }  # this is a dictionary of filter parameter dictionaries
        # like {"filter1":{"par1":val1,par2:val2,...},"filter2":...}
        self.excludeList = excludeList
        self.filterNames = {
        }  # dict of { filter1:fitsimage1, filter2:fitsimage2,...}
        self.columnsPopList = []
        dname = 'detection_' + band + '.fits'  #WZ
        self.detectionImage = os.path.join(obs.fitsdir, dname)
        dname = 'detection_' + band + '.cat'

        for cat in catalogList:  # explicit list of filter catalogs passed
            self.catalogList.append(os.path.basename(cat))

        self.logfile.write('Instantiating colorCatalog object...')

        if not os.path.exists(self.detectionImage):
            errtxt = "Instance of colorCatalog cannot find a detection image in this dataset."
            self.errorList.append((self.modName, errtxt))
            self.logfile.write(errtxt)
            raise IOError, errtxt

        # Now extract the RA and Dec positions (CRVAL1 and CRVAL2 from the header) from the
        # detection Image for use later with the extinction correction.
        ra = float(fUtil.getKeyVal(self.detectionImage, "CRVAL1"))
        dec = float(fUtil.getKeyVal(self.detectionImage, "CRVAL2"))

        # getExtinction function returns a tuple of strings (extinction_correction, data_quality_flags)
        self.logfile.write("Determining E(B-V) for detection Image coords: " +
                           str(ra) + ", " + str(dec))
        extCorr, self.DQflags = extinction.getEBV(ra, dec)
        # convert the extinction correction, extCorr to a float for use in arithmetic
        self.logfile.write("E(B-V) determined: " + extCorr)
        self.eBV = float(extCorr)
        self.eBV_error = self.eBV * 0.16  # This is the expected uncertainty in E(B-V): 16%

        if not os.path.exists(os.path.join(self.obsCats, dname)):
            errtxt = "Instance of colorCatalog cannot find a detection image catalog in this dataset."
            self.errorList.append((self.modName, errtxt))
            self.logfile.write(errtxt)
            raise IOError, errtxt

        for f in self.catalogList:
            self.inputList.append(
                f)  # record all catalogs for this observation as input.

        # This is a list of initial output parameters for the final multicolor catalog
        # final magnitudes are added to the catalog after these appear.

        # 0self.outColumns = ['NUMBER','X_IMAGE','Y_IMAGE','FWHM_IMAGE']
        self.outColumns = [
            'NUMBER', 'X_IMAGE', 'Y_IMAGE', 'FWHM_IMAGE', 'CLASS_STAR',
            'ALPHA_J2000', 'DELTA_J2000'
        ]  # WZ

        # Now read the detection catalog and create the dictionary of headers.
        # selectSet is a dictionary where keys are the column names and values are
        # the column numbers, starting at 1.  We get the columns above from the
        # detection catalog.  All other columns will come from the individual
        # filter catalogs.

        self.detCatalog = os.path.join(self.obsCats, dname)
        catalog = open(self.detCatalog).readlines()
        selectSet = pUtil.makeHeaderDict(catalog)
        detectionList = []
        for key in self.outColumns:
            detectionList.append(selectSet[key] - 1)
        self.detectionColumns = tuple(
            detectionList)  # the get_data function requires a tuple

        # call the private _apcorrSetup to generate the object radii list.
        # This will be used to then create the aperture corrections for the objects
        # in the various filters of the dataset.

        self.iradList = self._apcorrSetup(catalog, selectSet)
Beispiel #2
0
    def _apcorr(self, detector, filter):
        """Calculate the aperture corrections for this dataset for the given detector and filter.
        This is a factor to be added to the magnitudes calculated above array [m].
        This "apcor" is to be in magnitudes and apcor must be <= 0.  This new magnitude or
        array of magnitudes is then written into the multicolor.cat file and presented to
        BPZ as the magnitude to use, as indicated in the multicolor.columns file.
        Function returns a numeric array of aperture corrections.  The fiducial radius
        specified herein is specified in Bugzilla bug #2708, as are the other specifications
        for this method.
        """
        apcorr = []
        apcorrArray = None
        irad_fiducial = 14
        aperFiles = {
            "UVIS": os.path.join(self.aperData,
                                 "newUVIS_2011.ee_new_csky.dat"),
            "IR": os.path.join(self.aperData, "newIR_1210.ee_new_csky.dat"),
            "WFC": os.path.join(self.aperData, "newWFC_0803.ee_new_csky.dat"),
            #{}"HRC" : os.path.join(self.aperData,"newHRC_0803.ee_new_csky.dat")
        }

        try:
            aperDataFile = aperFiles[detector]
        except KeyError:
            raise KeyError, "No known aperture data for detector, " + detector

        # now get the filter aperture data for the indicated detector.
        # raise a filterError if the lookup fails.

        aperCatalog = open(aperDataFile).readlines()
        selectSet = pUtil.makeHeaderDict(aperCatalog)
        colName = "EE_" + filter
        try:
            aperIndex = selectSet[colName] - 1
        except KeyError:
            raise fUtil.filterError, "No aperture data for filter " + filter

        aperData = tableio.get_data(aperDataFile, aperIndex)

        # the aperData contains the encircled energy as a function of radius in
        # pixels.  Conveniently, the pixel radius = index + 1 of the value we
        # want from the array for that radius.

        eeFiducial = aperData[irad_fiducial - 1]

        for irad in self.iradList:
            if irad > irad_fiducial:
                apcorr.append(0)
                continue

            # irad1, irad2 are the adjacent integers of the radius of the object.
            # used to do a linear interpolation on the encircled energy curve.

            irad1 = int(irad)
            irad2 = irad1 + 1
            iradFrac = irad - irad1
            ee_irad1 = aperData[irad1 - 1]
            ee_irad2 = aperData[irad2 - 1]
            k = (ee_irad2 - ee_irad1)
            ee_irad = k * iradFrac + ee_irad1
            apcorr.append(min(0, +2.5 * math.log10(ee_irad / eeFiducial)))
        apcorrArray = Numeric.array(apcorr)
        return apcorrArray
Beispiel #3
0
            pardict["EBV"] = self.eBV
            pardict["EBV_Error"] = self.eBV_error

            self.filterNames[imfilter] = basefits
            catalog = ''
            catalog = os.path.join(self.obsCats, self.catalogList[i])
            preds.append(self.catalogList[i])  # predecessors list

            # Now we search through each filter's catalog for the keywords below
            # and determine which columns those values are in.
            # Subtract 1 from the column numbers to use as array indices
            # i.e the catalog column numbers start at 1 not zero.

            catalogObj = open(catalog).readlines()
            selectSet = pUtil.makeHeaderDict(catalogObj)

            #Info for flux columns
            fluxList = []
            fluxList.append(selectSet['FLUX_ISO'] - 1)
            fluxList.append(selectSet['FLUXERR_ISO'] - 1)
            self.fluxColumns = tuple(
                fluxList)  # the get_data function interface requires a tuple

            # Build the various columns arrays with the get_data function.
            # We read raw fluxes and errors into the flux,fluxerr arrays.
            # They are afterwards transformed to magnitudes
            t1, t2 = tableio.get_data(catalog, self.fluxColumns)
            if (len(t1) != nsources):
                self.logfile.write("Catalog dimension mismatch: ",
                                   str(len(t1)), ' ', nsources)