LSSTApplications  16.0-10-g0ee56ad+5,16.0-11-ga33d1f2+5,16.0-12-g3ef5c14+3,16.0-12-g71e5ef5+18,16.0-12-gbdf3636+3,16.0-13-g118c103+3,16.0-13-g8f68b0a+3,16.0-15-gbf5c1cb+4,16.0-16-gfd17674+3,16.0-17-g7c01f5c+3,16.0-18-g0a50484+1,16.0-20-ga20f992+8,16.0-21-g0e05fd4+6,16.0-21-g15e2d33+4,16.0-22-g62d8060+4,16.0-22-g847a80f+4,16.0-25-gf00d9b8+1,16.0-28-g3990c221+4,16.0-3-gf928089+3,16.0-32-g88a4f23+5,16.0-34-gd7987ad+3,16.0-37-gc7333cb+2,16.0-4-g10fc685+2,16.0-4-g18f3627+26,16.0-4-g5f3a788+26,16.0-5-gaf5c3d7+4,16.0-5-gcc1f4bb+1,16.0-6-g3b92700+4,16.0-6-g4412fcd+3,16.0-6-g7235603+4,16.0-69-g2562ce1b+2,16.0-8-g14ebd58+4,16.0-8-g2df868b+1,16.0-8-g4cec79c+6,16.0-8-gadf6c7a+1,16.0-8-gfc7ad86,16.0-82-g59ec2a54a+1,16.0-9-g5400cdc+2,16.0-9-ge6233d7+5,master-g2880f2d8cf+3,v17.0.rc1
LSSTDataManagementBasePackage
loadAstrometryNetObjects.py
Go to the documentation of this file.
1 from __future__ import absolute_import, division, print_function
2 
3 __all__ = ["LoadAstrometryNetObjectsTask", "LoadAstrometryNetObjectsConfig"]
4 
5 from builtins import object
6 
7 import lsst.pipe.base as pipeBase
8 from lsst.meas.algorithms import LoadReferenceObjectsTask, getRefFluxField
9 from . import astrometry_net
10 from .multiindex import AstrometryNetCatalog, getConfigFromEnvironment
11 
12 LoadAstrometryNetObjectsConfig = LoadReferenceObjectsTask.ConfigClass
13 
14 # The following block adds links to this task from the Task Documentation page.
15 
21 
22 
24  """!Load reference objects from astrometry.net index files
25 
26  @anchor LoadAstrometryNetObjectsTask_
27 
28  @section meas_astrom_loadAstrometryNetObjects_Contents Contents
29 
30  - @ref meas_astrom_loadAstrometryNetObjects_Purpose
31  - @ref meas_astrom_loadAstrometryNetObjects_Initialize
32  - @ref meas_astrom_loadAstrometryNetObjects_IO
33  - @ref meas_algorithms_loadReferenceObjects_Schema
34  - @ref meas_astrom_loadAstrometryNetObjects_Config
35  - @ref meas_astrom_loadAstrometryNetObjects_Example
36  - @ref meas_astrom_loadAstrometryNetObjects_Debug
37 
38  @section meas_astrom_loadAstrometryNetObjects_Purpose Description
39 
40  Load reference objects from astrometry.net index files.
41 
42  @section meas_astrom_loadAstrometryNetObjects_Initialize Task initialisation
43 
44  @copydoc \_\_init\_\_
45 
46  @section meas_astrom_loadAstrometryNetObjects_IO Invoking the Task
47 
48  @copydoc loadObjectsInBBox
49 
50  @section meas_astrom_loadAstrometryNetObjects_Config Configuration parameters
51 
52  See @ref LoadAstrometryNetObjectsConfig
53 
54  @section meas_astrom_loadAstrometryNetObjects_Example A complete example of using
55  LoadAstrometryNetObjectsTask
56 
57  LoadAstrometryNetObjectsTask is a subtask of AstrometryTask, which is called by PhotoCalTask.
58  See \ref pipe_tasks_photocal_Example.
59 
60  @section meas_astrom_loadAstrometryNetObjects_Debug Debug variables
61 
62  LoadAstrometryNetObjectsTask does not support any debug variables.
63  """
64  ConfigClass = LoadAstrometryNetObjectsConfig
65 
66  def __init__(self, config=None, andConfig=None, **kwargs):
67  """!Create a LoadAstrometryNetObjectsTask
68 
69  @param[in] config configuration (an instance of self.ConfigClass); if None use self.ConfigClass()
70  @param[in] andConfig astrometry.net data config (an instance of AstromNetDataConfig, or None);
71  if None then use andConfig.py in the astrometry_net_data product (which must be setup)
72  @param[in] kwargs additional keyword arguments for pipe_base Task.\_\_init\_\_
73 
74  @throw RuntimeError if andConfig is None and the configuration cannot be found,
75  either because astrometry_net_data is not setup in eups
76  or because the setup version does not include the file "andConfig.py"
77  """
78  LoadReferenceObjectsTask.__init__(self, config=config, **kwargs)
79  self.andConfig = andConfig
80  self.haveIndexFiles = False # defer reading index files until we know they are needed
81  # because astrometry may not be used, in which case it may not be properly configured
82 
83  @pipeBase.timeMethod
84  def loadSkyCircle(self, ctrCoord, radius, filterName=None, epoch=None):
85  """!Load reference objects that overlap a circular sky region
86 
87  @param[in] ctrCoord center of search region (an afwGeom.Coord)
88  @param[in] radius radius of search region (an afwGeom.Angle)
89  @param[in] filterName name of filter, or None for the default filter;
90  used for flux values in case we have flux limits (which are not yet implemented)
91  @param[in] epoch Epoch for proper motion and parallax correction
92  (an astropy.time.Time), or None
93 
94  No proper motion correction is made, since our astrometry.net catalogs
95  typically don't support that, and even if they do they format is uncertain.
96  Users interested in proper motion corrections should use the
97  lsst.meas.algorithms.LoadIndexedReferenceObjectsTask or they will need to
98  subclass and define how the proper motion correction is to be done.
99 
100  @return an lsst.pipe.base.Struct containing:
101  - refCat a catalog of reference objects with the
102  \link meas_algorithms_loadReferenceObjects_Schema standard schema \endlink
103  as documented in LoadReferenceObjects, including photometric, resolved and variable;
104  hasCentroid is False for all objects.
105  - fluxField = name of flux field for specified filterName
106  """
107  self._readIndexFiles()
108 
109  names = []
110  mcols = []
111  ecols = []
112  for col, mcol in self.andConfig.magColumnMap.items():
113  names.append(col)
114  mcols.append(mcol)
115  ecols.append(self.andConfig.magErrorColumnMap.get(col, ''))
116  margs = (names, mcols, ecols)
117 
118  solver = self._getSolver()
119 
120  # Find multi-index files within range
121  multiInds = self._getMIndexesWithinRange(ctrCoord, radius)
122 
123  # compute solver.getCatalog arguments that follow the list of star kd-trees:
124  # - center equatorial angle (e.g. RA) in deg
125  # - center polar angle (e.g. Dec) in deg
126  # - radius, in deg
127  # - idColumn
128  # - (margs)
129  # - star-galaxy column
130  # - variability column
131  fixedArgTuple = (
132  ctrCoord,
133  radius,
134  self.andConfig.idColumn,
135  ) + margs + (
136  self.andConfig.starGalaxyColumn,
137  self.andConfig.variableColumn,
138  True, # eliminate duplicate IDs
139  )
140 
141  self.log.debug("search for objects at %s with radius %s deg", ctrCoord, radius.asDegrees())
142  with LoadMultiIndexes(multiInds):
143  # We just want to pass the star kd-trees, so just pass the
144  # first element of each multi-index.
145  inds = tuple(mi[0] for mi in multiInds)
146  refCat = solver.getCatalog(inds, *fixedArgTuple)
147 
148  self._addFluxAliases(schema=refCat.schema)
149 
150  fluxField = getRefFluxField(schema=refCat.schema, filterName=filterName)
151 
152  # NOTE: sourceSelectors require contiguous catalogs, so ensure
153  # contiguity now, so views are preserved from here on.
154  if not refCat.isContiguous():
155  refCat = refCat.copy(deep=True)
156 
157  self.log.debug("found %d objects", len(refCat))
158  return pipeBase.Struct(
159  refCat=refCat,
160  fluxField=fluxField,
161  )
162 
163  @pipeBase.timeMethod
164  def _readIndexFiles(self):
165  """!Read all astrometry.net index files, if not already read
166  """
167  if self.haveIndexFiles:
168  return
169 
170  self.log.debug("read index files")
171  self.haveIndexFiles = True # just try once
172 
173  if self.andConfig is None:
175 
177 
178  def _getMIndexesWithinRange(self, ctrCoord, radius):
179  """!Get list of muti-index objects within range
180 
181  @param[in] ctrCoord center of search region (an afwGeom.Coord)
182  @param[in] radius radius of search region (an afwGeom.Angle)
183 
184  @return list of multiindex objects
185  """
186  return [mi for mi in self.multiInds if mi.isWithinRange(ctrCoord, radius)]
187 
188  def _getSolver(self):
189  solver = astrometry_net.Solver()
190  # HACK, set huge default pixel scale range.
191  lo, hi = 0.01, 3600.
192  solver.setPixelScaleRange(lo, hi)
193  return solver
194 
195 
197  """Context manager for loading and unloading astrometry.net multi-index files
198  """
199 
200  def __init__(self, multiInds):
201  self.multiInds = multiInds
202 
203  def __enter__(self):
204  for mi in self.multiInds:
205  mi.reload()
206  return self.multiInds
207 
208  def __exit__(self, typ, val, trace):
209  for mi in self.multiInds:
210  mi.unload()
def _readIndexFiles(self)
Read all astrometry.net index files, if not already read.
Fit spatial kernel using approximate fluxes for candidates, and solving a linear system of equations...
def _getMIndexesWithinRange(self, ctrCoord, radius)
Get list of muti-index objects within range.
Abstract base class to load objects from reference catalogs.
def loadSkyCircle(self, ctrCoord, radius, filterName=None, epoch=None)
Load reference objects that overlap a circular sky region.
def __init__(self, config=None, andConfig=None, kwargs)
Create a LoadAstrometryNetObjectsTask.