Esempio n. 1
0
    def _outputStandardStars(self, butler, stdCat, offsets, datasetConfig):
        """
        Output standard stars in indexed reference catalog format.

        Parameters
        ----------
        butler: `lsst.daf.persistence.Butler`
        stdCat: `lsst.afw.table.SimpleCatalog`
           FGCM standard star catalog from fgcmFitCycleTask
        offsets: `numpy.array` of floats
           Per band zeropoint offsets
        datasetConfig: `lsst.meas.algorithms.DatasetConfig`
           Config for reference dataset
        """

        self.log.info("Outputting standard stars to %s" %
                      (datasetConfig.ref_dataset_name))

        # We determine the conversion from the native units (typically radians) to
        # degrees for the first star.  This allows us to treat coord_ra/coord_dec as
        # numpy arrays rather than Angles, which would we approximately 600x slower.
        # TODO: Fix this after DM-16524 (HtmIndexer.indexPoints should take coords
        # (as Angles) for input
        conv = stdCat[0]['coord_ra'].asDegrees() / float(stdCat[0]['coord_ra'])
        indices = np.array(
            self.indexer.indexPoints(stdCat['coord_ra'] * conv,
                                     stdCat['coord_dec'] * conv))

        formattedCat = self._formatCatalog(stdCat, offsets)

        # Write the master schema
        dataId = self.indexer.makeDataId('master_schema',
                                         datasetConfig.ref_dataset_name)
        masterCat = afwTable.SimpleCatalog(formattedCat.schema)
        addRefCatMetadata(masterCat)
        butler.put(masterCat, 'ref_cat', dataId=dataId)

        # Break up the pixels using a histogram
        h, rev = esutil.stat.histogram(indices, rev=True)
        gd, = np.where(h > 0)
        selected = np.zeros(len(formattedCat), dtype=np.bool)
        for i in gd:
            i1a = rev[rev[i]:rev[i + 1]]

            # the formattedCat afwTable can only be indexed with boolean arrays,
            # and not numpy index arrays (see DM-16497).  This little trick
            # converts the index array into a boolean array
            selected[:] = False
            selected[i1a] = True

            # Write the individual pixel
            dataId = self.indexer.makeDataId(indices[i1a[0]],
                                             datasetConfig.ref_dataset_name)
            butler.put(formattedCat[selected], 'ref_cat', dataId=dataId)

        # And save the dataset configuration
        dataId = self.indexer.makeDataId(None, datasetConfig.ref_dataset_name)
        butler.put(datasetConfig, 'ref_cat_config', dataId=dataId)

        self.log.info("Done outputting standard stars.")
Esempio n. 2
0
def process_one(filename, write=False, quiet=False):
    """Convert one file in-place from Jy (or no units) to nJy fluxes.

    Parameters
    ----------
    filename : `str`
        The file to convert.
    write : `bool`, optional
        Write the converted catalog out, overwriting the read in catalog?
    quiet : `bool`, optional
        Do not print messages about files read/written or fields found?
    """
    log = lsst.log.Log()
    if quiet:
        log.setLevel(lsst.log.WARN)

    log.info(f"Reading: {filename}")
    catalog = lsst.afw.table.SimpleCatalog.readFits(filename)

    output = convertToNanojansky(catalog, log, doConvert=write)

    if write:
        addRefCatMetadata(output)
        output.writeFits(filename)
        log.info(f"Wrote: {filename}")
Esempio n. 3
0
    def _formatCatalog(self, fgcmStarCat, offsets, bands):
        """
        Turn an FGCM-formatted star catalog, applying zeropoint offsets.

        Parameters
        ----------
        fgcmStarCat : `lsst.afw.Table.SimpleCatalog`
            SimpleCatalog as output by fgcmcal
        offsets : `list` with len(self.bands) entries
            Zeropoint offsets to apply
        bands : `list` [`str`]
            List of band names from FGCM output

        Returns
        -------
        formattedCat: `lsst.afw.table.SimpleCatalog`
           SimpleCatalog suitable for using as a reference catalog
        """

        sourceMapper = afwTable.SchemaMapper(fgcmStarCat.schema)
        minSchema = LoadIndexedReferenceObjectsTask.makeMinimalSchema(
            bands, addCentroid=False, addIsResolved=True, coordErrDim=0)
        sourceMapper.addMinimalSchema(minSchema)
        for band in bands:
            sourceMapper.editOutputSchema().addField('%s_nGood' % (band),
                                                     type=np.int32)
            sourceMapper.editOutputSchema().addField('%s_nTotal' % (band),
                                                     type=np.int32)
            sourceMapper.editOutputSchema().addField('%s_nPsfCandidate' %
                                                     (band),
                                                     type=np.int32)

        formattedCat = afwTable.SimpleCatalog(sourceMapper.getOutputSchema())
        formattedCat.reserve(len(fgcmStarCat))
        formattedCat.extend(fgcmStarCat, mapper=sourceMapper)

        # Note that we don't have to set `resolved` because the default is False

        for b, band in enumerate(bands):
            mag = fgcmStarCat['mag_std_noabs'][:, b].astype(
                np.float64) + offsets[b]
            # We want fluxes in nJy from calibrated AB magnitudes
            # (after applying offset).  Updated after RFC-549 and RFC-575.
            flux = (mag * units.ABmag).to_value(units.nJy)
            fluxErr = (np.log(10.) /
                       2.5) * flux * fgcmStarCat['magErr_std'][:, b].astype(
                           np.float64)

            formattedCat['%s_flux' % (band)][:] = flux
            formattedCat['%s_fluxErr' % (band)][:] = fluxErr
            formattedCat['%s_nGood' % (band)][:] = fgcmStarCat['ngood'][:, b]
            formattedCat['%s_nTotal' % (band)][:] = fgcmStarCat['ntotal'][:, b]
            formattedCat['%s_nPsfCandidate' %
                         (band)][:] = fgcmStarCat['npsfcand'][:, b]

        addRefCatMetadata(formattedCat)

        return formattedCat