def addCatalog(self, src, filter, visit, ccd, calib, footprints):
        """Add objects from a catalog to the existing MultiMatch

        @param[in]  srcCat      An SourceCatalog of objects to be added.
        @param[in]  filt        The filter of the catalog
        @param[in]  visit       The visit number
        @param[in]  ccd         The ccd number
        @param[in]  footprints  A list of footprints that have been transformed to the
                                WCS of the coadd patch.
        """

        if self.multi_matches is None:
            # The data id for multiMatch does not take strings so we need to convert filter to a string
            self.multi_matches = afwTable.MultiMatch(
                src.schema, {
                    'visit': np.int32,
                    'ccd': np.int32,
                    'filter': np.int32
                },
                radius=geom.Angle(self.config.tolerance / 3600., geom.degrees))
        for s, foot in zip(src, footprints):
            s.setFootprint(foot)
        self.multi_matches.add(
            src, {
                'visit': visit,
                'ccd': ccd,
                'filter': self.config.filters.index(filter)
            })
        self.calibDict[visit][ccd] = calib
    def addCatalog(self, src, filt, visit, ccd, footprints):
        """Add objects from a catalog to the existing MultiMatch

        @param[in]  srcCat      An SourceCatalog of objects to be added.
        @param[in]  filt        The filter of the catalog
        @param[in]  visit       The visit number
        @param[in]  ccd         The ccd number
        @param[in]  footprints  A list of footprints that have been transformed to the
                                WCS of the coadd patch.
        """

        if self.multi_matches is None:
            self.multi_matches = afwTable.MultiMatch(
                src.schema, {
                    'visit': np.int32,
                    'ccd': np.int32
                },
                radius=afwGeom.Angle(self.config.tolerance / 3600.,
                                     geom.degrees))
        for s, foot in zip(src, footprints):
            s.setFootprint(foot)
        self.multi_matches.add(src, {'visit': visit, 'ccd': ccd})
Example #3
0
    def setUp(self):
        self.schema = afwTable.SourceTable.makeMinimalSchema()
        self.schema.addField("flux_instFlux", type=np.float64)
        self.schema.addField("flux_instFluxErr", type=np.float64)
        self.schema.addField("flux_flag", type="Flag")
        self.table = afwTable.SourceTable.make(self.schema)
        self.table.definePsfFlux("flux")

        band = 2  # SDSS r

        # Read SDSS catalogue
        with open(os.path.join(afwdataDir, "CFHT", "D2", "sdss.dat"),
                  "r") as ifd:
            sdss = afwTable.SourceCatalog(self.table)

            PRIMARY = 1  # values of mode

            for line in ifd.readlines():
                if re.search(r"^\s*#", line):
                    continue

                fields = line.split()
                objId = int(fields[0])
                fields[1]
                mode = int(fields[2])
                ra, dec = [float(f) for f in fields[3:5]]
                psfMags = [float(f) for f in fields[5:]]

                if mode == PRIMARY:
                    s = sdss.addNew()

                s.setId(objId)
                s.setRa(ra * lsst.geom.degrees)
                s.setDec(dec * lsst.geom.degrees)
                s.set(self.table.getPsfFluxSlot().getMeasKey(), psfMags[band])

        # Read catalalogue built from the template image
        # Read SDSS catalogue
        with open(os.path.join(afwdataDir, "CFHT", "D2", "template.dat"),
                  "r") as ifd:
            template = afwTable.SourceCatalog(self.table)

            for line in ifd.readlines():
                if re.search(r"^\s*#", line):
                    continue

                fields = line.split()
                id_, flags = [int(f) for f in fields[0:2]]
                ra, dec = [float(f) for f in fields[2:4]]
                flux = [float(f) for f in fields[4:]]

                if flags & 0x1:  # EDGE
                    continue

                s = template.addNew()
                s.setId(id_)
                s.set(afwTable.SourceTable.getCoordKey().getRa(),
                      ra * lsst.geom.degrees)
                s.set(afwTable.SourceTable.getCoordKey().getDec(),
                      dec * lsst.geom.degrees)
                s.set(self.table.getPsfFluxSlot().getMeasKey(), flux[0])

        m = afwTable.MultiMatch(self.schema,
                                dict(visit=np.int64),
                                RecordClass=afwTable.SimpleRecord)
        m.add(sdss, {'visit': 1})
        m.add(template, {'visit': 2})

        self.matchedCatalog = m.finish()
Example #4
0
multi_matches = None
for visit in visits:
    date_catalog = None
    for raft in rafts:
        for detector in detectors:
            print(raft,detector,visit)        
            print (butler.datasetExists("deepDiff_diaSrc", {"raftName":raft,"detectorName":detector,"filter":'r', "visit":visit}))
            if butler.datasetExists("deepDiff_diaSrc", {"raftName":raft,"detectorName":detector,"filter":'r', "visit":visit}) == True:
                catalog = butler.get("deepDiff_diaSrc",{"raftName":raft,"detectorName":detector,"filter":'r', "visit":visit}) 
                if date_catalog is None: 
                    date_catalog = catalog.copy()
                else:
                    date_catalog.extend(catalog)
    if date_catalog != None :
        if multi_matches is None and len(date_catalog)>0:
            multi_matches = afwTable.MultiMatch(date_catalog[0].schema, {'date':float})
    
        #t = Time(date)
        multi_matches.add(date_catalog, {'date':visit})
                
results = multi_matches.finish(removeAmbiguous=False)


def build_lightcurve(source_list):
    """
    Assemble a light curve data table from available files.
    """

    bandpasses = ['r','i']