1 from __future__
import absolute_import, division, print_function
7 from .
import astrometry_net
as astromNet
8 from .astrometryNetDataConfig
import AstrometryNetDataConfig
10 __all__ = [
"LoadAstrometryNetObjectsTask",
"LoadAstrometryNetObjectsConfig"]
12 LoadAstrometryNetObjectsConfig = LoadReferenceObjectsTask.ConfigClass
23 """!Load reference objects from astrometry.net index files
25 @anchor LoadAstrometryNetObjectsTask_
27 @section meas_astrom_loadAstrometryNetObjects_Contents Contents
29 - @ref meas_astrom_loadAstrometryNetObjects_Purpose
30 - @ref meas_astrom_loadAstrometryNetObjects_Initialize
31 - @ref meas_astrom_loadAstrometryNetObjects_IO
32 - @ref meas_algorithms_loadReferenceObjects_Schema
33 - @ref meas_astrom_loadAstrometryNetObjects_Config
34 - @ref meas_astrom_loadAstrometryNetObjects_Example
35 - @ref meas_astrom_loadAstrometryNetObjects_Debug
37 @section meas_astrom_loadAstrometryNetObjects_Purpose Description
39 Load reference objects from astrometry.net index files.
41 @section meas_astrom_loadAstrometryNetObjects_Initialize Task initialisation
45 @section meas_astrom_loadAstrometryNetObjects_IO Invoking the Task
47 @copydoc loadObjectsInBBox
49 @section meas_astrom_loadAstrometryNetObjects_Config Configuration parameters
51 See @ref LoadAstrometryNetObjectsConfig
53 @section meas_astrom_loadAstrometryNetObjects_Example A complete example of using LoadAstrometryNetObjectsTask
55 LoadAstrometryNetObjectsTask is a subtask of AstrometryTask, which is called by PhotoCalTask.
56 See \ref meas_photocal_photocal_Example.
58 @section meas_astrom_loadAstrometryNetObjects_Debug Debug variables
60 LoadAstrometryNetObjectsTask does not support any debug variables.
62 ConfigClass = LoadAstrometryNetObjectsConfig
64 def __init__(self, config, andConfig=None, **kwargs):
65 """!Create a LoadAstrometryNetObjectsTask
67 @param[in] config configuration (an instance of self.ConfigClass)
68 @param[in] andConfig astrometry.net data config (an instance of AstromNetDataConfig, or None);
69 if None then use andConfig.py in the astrometry_net_data product (which must be setup)
71 @throw RuntimeError if andConfig is None and the configuration cannot be found,
72 either because astrometry_net_data is not setup in eups
73 or because the setup version does not include the file "andConfig.py"
75 LoadReferenceObjectsTask.__init__(self, config=config, **kwargs)
82 """!Load reference objects that overlap a circular sky region
84 @param[in] ctrCoord center of search region (an afwGeom.Coord)
85 @param[in] radius radius of search region (an afwGeom.Angle)
86 @param[in] filterName name of filter, or None for the default filter;
87 used for flux values in case we have flux limits (which are not yet implemented)
89 @return an lsst.pipe.base.Struct containing:
90 - refCat a catalog of reference objects with the
91 \link meas_algorithms_loadReferenceObjects_Schema standard schema \endlink
92 as documented in LoadReferenceObjects, including photometric, resolved and variable;
93 hasCentroid is False for all objects.
94 - fluxField = name of flux field for specified filterName
101 for col, mcol
in self.andConfig.magColumnMap.items():
104 ecols.append(self.andConfig.magErrorColumnMap.get(col,
''))
105 margs = (names, mcols, ecols)
123 self.andConfig.idColumn,
125 self.andConfig.starGalaxyColumn,
126 self.andConfig.variableColumn,
130 self.log.info(
"search for objects at %s with radius %s deg" % (ctrCoord, radius.asDegrees()))
134 inds = tuple(mi[0]
for mi
in multiInds)
135 refCat = solver.getCatalog(inds, *fixedArgTuple)
137 self._addFluxAliases(schema=refCat.schema)
139 fluxField =
getRefFluxField(schema=refCat.schema, filterName=filterName)
141 self.log.info(
"found %d objects" % (len(refCat),))
142 return pipeBase.Struct(
144 fluxField = fluxField,
149 """!Read all astrometry.net index files, if not already read
154 self.log.info(
"read index files")
161 anDir = os.environ.get(
'ASTROMETRY_NET_DATA_DIR')
163 raise RuntimeError(
"astrometry_net_data is not setup")
165 andConfig = AstrometryNetDataConfig()
166 andConfigPath = os.path.join(anDir,
"andConfig.py")
167 if not os.path.exists(andConfigPath):
168 raise RuntimeError(
"astrometry_net_data config file \"%s\" required but not found" %
170 andConfig.load(andConfigPath)
174 mifiles = [(
True, [fn,fn])
for fn
in self.andConfig.indexFiles] + \
175 [(
False, fns)
for fns
in self.andConfig.multiIndexFiles]
178 for single, fns
in mifiles:
182 self.log.log(self.log.DEBUG,
'Adding index file %s' % fns[0])
184 self.log.log(self.log.DEBUG,
'Adding multiindex files %s' % str(fns))
188 self.log.logdebug(
'Unable to find index file %s' % fn)
190 self.log.logdebug(
'Unable to find star part of multiindex file %s' % fn)
194 self.log.log(self.log.DEBUG,
'Path: %s' % fn)
196 mi = astromNet.multiindex_new(fn)
198 raise RuntimeError(
'Failed to read objects from multiindex filename "%s"' % fn)
199 for i,fn
in enumerate(fns[1:]):
200 self.log.log(self.log.DEBUG,
'Reading index from multiindex file "%s"' % fn)
203 self.log.logdebug(
'Unable to find index part of multiindex file %s' % fn)
207 self.log.log(self.log.DEBUG,
'Path: %s' % fn)
208 if astromNet.multiindex_add_index(mi, fn, astromNet.INDEX_ONLY_LOAD_METADATA):
209 raise RuntimeError(
'Failed to read index from multiindex filename "%s"' % fn)
211 self.log.log(self.log.DEBUG,
' index %i, hp %i (nside %i), nstars %i, nquads %i' %
212 (ind.indexid, ind.healpix, ind.hpnside, ind.nstars, ind.nquads))
213 astromNet.multiindex_unload_starkd(mi)
214 self.multiInds.append(mi)
217 self.log.warn(
'Unable to find any index files')
219 self.log.warn(
'Unable to find %d index files' % (nMissing,))
222 """!Get the path to the specified astrometry.net index file
224 @param[in] fn path to index file; if relative, then relative to astrometry_net_data
225 if that product is setup, else relative to the current working directory
226 @return the absolute path to the index file, or None if the file was not found
228 if os.path.isabs(fn):
231 anDir = os.environ.get(
'ASTROMETRY_NET_DATA_DIR')
232 if anDir
is not None:
233 absFn = os.path.join(anDir, fn)
235 if os.path.exists(absFn):
236 return os.path.abspath(absFn)
241 """!Get list of muti-index objects within range
243 @param[in] ctrCoord center of search region (an afwGeom.Coord)
244 @param[in] radius radius of search region (an afwGeom.Angle)
246 @return list of multiindex objects
248 longDeg = ctrCoord.getLongitude().asDegrees()
249 latDeg = ctrCoord.getLatitude().asDegrees()
252 if mi.isWithinRange(longDeg, latDeg, radius.asDegrees()):
253 multiIndexList.append(mi)
254 return multiIndexList
257 solver = astromNet.solver_new()
260 solver.setPixelScaleRange(lo, hi)
265 """Context manager for loading astrometry.net multi-index files, then unloading and finalizing a.net
def _getMIndexesWithinRange
Get list of muti-index objects within range.
def __init__
Create a LoadAstrometryNetObjectsTask.
def _getIndexPath
Get the path to the specified astrometry.net index file.
def getRefFluxField
Get name of flux field in schema.
Load reference objects from astrometry.net index files.
def _readIndexFiles
Read all astrometry.net index files, if not already read.
def loadSkyCircle
Load reference objects that overlap a circular sky region.