def testConvertOldFluxes(self): """Check that we can convert old style fluxes in a catalog.""" flux = 1.234 fluxErr = 5.678 log = lsst.log.Log() def make_catalog(): schema = LoadReferenceObjectsTask.makeMinimalSchema(['r', 'z']) schema.addField('bad_flux', doc='old flux units', type=float, units='') schema.addField('bad_fluxErr', doc='old flux units', type=float, units='Jy') refCat = afwTable.SimpleCatalog(schema) refObj = refCat.addNew() refObj["bad_flux"] = flux refObj["bad_fluxErr"] = fluxErr return refCat oldRefCat = make_catalog() newRefCat = convertToNanojansky(oldRefCat, log) self.assertEqual(newRefCat['bad_flux'], [flux*1e9, ]) self.assertEqual(newRefCat['bad_fluxErr'], [fluxErr*1e9, ]) self.assertEqual(newRefCat.schema['bad_flux'].asField().getUnits(), 'nJy') self.assertEqual(newRefCat.schema['bad_fluxErr'].asField().getUnits(), 'nJy') # check that doConvert=False returns None (it also logs a summary) oldRefCat = make_catalog() newRefCat = convertToNanojansky(oldRefCat, log, doConvert=False) self.assertIsNone(newRefCat)
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}")
def loadSkyCircle(self, ctrCoord, radius, filterName=None, epoch=None, centroids=True): """!Load reference objects that overlap a circular sky region @param[in] ctrCoord center of search region (an afwGeom.Coord) @param[in] radius radius of search region (an geom.Angle) @param[in] filterName name of filter, or None for the default filter; used for flux values in case we have flux limits (which are not yet implemented) @param[in] epoch Epoch for proper motion and parallax correction (an astropy.time.Time), or None centroids : `bool` (optional) Ignored: a.net refcats always have centroid fields. No proper motion correction is made, since our astrometry.net catalogs typically don't support that, and even if they do they format is uncertain. Users interested in proper motion corrections should use the lsst.meas.algorithms.LoadIndexedReferenceObjectsTask or they will need to subclass and define how the proper motion correction is to be done. @return an lsst.pipe.base.Struct containing: - refCat a catalog of reference objects with the \link meas_algorithms_loadReferenceObjects_Schema standard schema \endlink as documented in LoadReferenceObjects, including photometric, resolved and variable; hasCentroid is False for all objects. - fluxField = name of flux field for specified filterName """ self._readIndexFiles() names = [] mcols = [] ecols = [] for col, mcol in self.andConfig.magColumnMap.items(): names.append(col) mcols.append(mcol) ecols.append(self.andConfig.magErrorColumnMap.get(col, '')) margs = (names, mcols, ecols) solver = self._getSolver() # Find multi-index files within range multiInds = self._getMIndexesWithinRange(ctrCoord, radius) # compute solver.getCatalog arguments that follow the list of star kd-trees: # - center equatorial angle (e.g. RA) in deg # - center polar angle (e.g. Dec) in deg # - radius, in deg # - idColumn # - (margs) # - star-galaxy column # - variability column fixedArgTuple = ( ctrCoord, radius, self.andConfig.idColumn, ) + margs + ( self.andConfig.starGalaxyColumn, self.andConfig.variableColumn, True, # eliminate duplicate IDs ) self.log.debug("search for objects at %s with radius %s deg", ctrCoord, radius.asDegrees()) with LoadMultiIndexes(multiInds): # We just want to pass the star kd-trees, so just pass the # first element of each multi-index. inds = tuple(mi[0] for mi in multiInds) refCat = solver.getCatalog(inds, *fixedArgTuple) self._addFluxAliases(schema=refCat.schema) fluxField = getRefFluxField(schema=refCat.schema, filterName=filterName) # NOTE: sourceSelectors require contiguous catalogs, so ensure # contiguity now, so views are preserved from here on. if not refCat.isContiguous(): refCat = refCat.copy(deep=True) # Update flux fields to be nJy. a.net catalogs do not have a conversion script. self.log.warn( "Loading A.net reference catalog with old style units in schema.") self.log.warn( "A.net reference catalogs will not be supported in the future.") self.log.warn("See RFC-562 and RFC-575 for more details.") refCat = convertToNanojansky(refCat, self.log) self.log.debug("found %d objects", len(refCat)) return pipeBase.Struct( refCat=refCat, fluxField=fluxField, )