LSSTApplications  17.0+103,17.0+11,17.0+61,18.0.0+13,18.0.0+25,18.0.0+5,18.0.0+52,18.0.0-4-g68ffd23,18.1.0-1-g0001055+8,18.1.0-1-g03d53ef+1,18.1.0-1-g1349e88+28,18.1.0-1-g2505f39+22,18.1.0-1-g380d4d4+27,18.1.0-1-g5315e5e+1,18.1.0-1-g5e4b7ea+10,18.1.0-1-g7e8fceb+1,18.1.0-1-g85f8cd4+23,18.1.0-1-g9a6769a+13,18.1.0-1-ga1a4c1a+22,18.1.0-1-gd55f500+17,18.1.0-12-g42eabe8e+10,18.1.0-14-gd04256d+15,18.1.0-16-g430f6a53+1,18.1.0-17-gd2166b6e4,18.1.0-18-gb5d19ff+1,18.1.0-2-gfbf3545+7,18.1.0-2-gfefb8b5+16,18.1.0-3-g52aa583+13,18.1.0-3-g62b5e86+14,18.1.0-3-g8f4a2b1+17,18.1.0-3-g9bc06b8+7,18.1.0-3-gb69f684+9,18.1.0-4-g1ee41a7+1,18.1.0-5-g6dbcb01+13,18.1.0-5-gc286bb7+3,18.1.0-6-g48bdcd3+2,18.1.0-6-gd05e160+9,18.1.0-7-gc4d902b+2,18.1.0-7-gebc0338+8,18.1.0-9-gae7190a+10,w.2019.37
LSSTDataManagementBasePackage
Public Member Functions | Public Attributes | Static Public Attributes | List of all members
lsst.meas.astrom.astrometry.AstrometryTask Class Reference
Inheritance diagram for lsst.meas.astrom.astrometry.AstrometryTask:
lsst.meas.astrom.ref_match.RefMatchTask

Public Member Functions

def __init__ (self, refObjLoader, schema=None, kwargs)
 
def run (self, sourceCat, exposure)
 
def solve (self, exposure, sourceCat)
 
def setRefObjLoader (self, refObjLoader)
 
def loadAndMatch (self, exposure, sourceCat)
 

Public Attributes

 usedKey
 
 refObjLoader
 

Static Public Attributes

 ConfigClass = AstrometryConfig
 

Detailed Description

Match an input source catalog with objects from a reference catalog and
solve for the WCS.

This task is broken into two main subasks: matching and WCS fitting which
are very interactive. The matching here can be considered in part a first
pass WCS fitter due to the fitter's sensitivity to outliers.

Parameters
----------
refObjLoader : `lsst.meas.algorithms.ReferenceLoader`
    A reference object loader object
schema : `lsst.afw.table.Schema`
    Used to set "calib_astrometry_used" flag in output source catalog.
**kwargs
    additional keyword arguments for pipe_base
    `lsst.pipe.base.Task.__init__`

Definition at line 73 of file astrometry.py.

Constructor & Destructor Documentation

◆ __init__()

def lsst.meas.astrom.astrometry.AstrometryTask.__init__ (   self,
  refObjLoader,
  schema = None,
  kwargs 
)

Definition at line 94 of file astrometry.py.

94  def __init__(self, refObjLoader, schema=None, **kwargs):
95  RefMatchTask.__init__(self, refObjLoader, **kwargs)
96 
97  if schema is not None:
98  self.usedKey = schema.addField("calib_astrometry_used", type="Flag",
99  doc="set if source was used in astrometric calibration")
100  else:
101  self.usedKey = None
102 
103  self.makeSubtask("wcsFitter")
104 
def __init__(self, minimum, dataRange, Q)

Member Function Documentation

◆ loadAndMatch()

def lsst.meas.astrom.ref_match.RefMatchTask.loadAndMatch (   self,
  exposure,
  sourceCat 
)
inherited
Load reference objects overlapping an exposure and match to sources
detected on that exposure.

Parameters
----------
exposure : `lsst.afw.image.Exposure`
    exposure that the sources overlap
sourceCat : `lsst.afw.table.SourceCatalog.`
    catalog of sources detected on the exposure

Returns
-------
result : `lsst.pipe.base.Struct`
    Result struct with Components:

    - ``refCat`` : reference object catalog of objects that overlap the
      exposure (`lsst.afw.table.SimpleCatalog`)
    - ``matches`` :  Matched sources and references
      (`list` of `lsst.afw.table.ReferenceMatch`)
    - ``matchMeta`` : metadata needed to unpersist matches
      (`lsst.daf.base.PropertyList`)

Notes
-----
ignores config.matchDistanceSigma

Definition at line 116 of file ref_match.py.

116  def loadAndMatch(self, exposure, sourceCat):
117  """Load reference objects overlapping an exposure and match to sources
118  detected on that exposure.
119 
120  Parameters
121  ----------
122  exposure : `lsst.afw.image.Exposure`
123  exposure that the sources overlap
124  sourceCat : `lsst.afw.table.SourceCatalog.`
125  catalog of sources detected on the exposure
126 
127  Returns
128  -------
129  result : `lsst.pipe.base.Struct`
130  Result struct with Components:
131 
132  - ``refCat`` : reference object catalog of objects that overlap the
133  exposure (`lsst.afw.table.SimpleCatalog`)
134  - ``matches`` : Matched sources and references
135  (`list` of `lsst.afw.table.ReferenceMatch`)
136  - ``matchMeta`` : metadata needed to unpersist matches
137  (`lsst.daf.base.PropertyList`)
138 
139  Notes
140  -----
141  ignores config.matchDistanceSigma
142  """
143  if self.refObjLoader is None:
144  raise RuntimeError("Running matcher task with no refObjLoader set in __ini__ or setRefObjLoader")
145  import lsstDebug
146  debug = lsstDebug.Info(__name__)
147 
148  expMd = self._getExposureMetadata(exposure)
149 
150  sourceSelection = self.sourceSelector.run(sourceCat)
151 
152  sourceFluxField = "slot_%sFlux_instFlux" % (self.config.sourceFluxType)
153 
154  loadRes = self.refObjLoader.loadPixelBox(
155  bbox=expMd.bbox,
156  wcs=expMd.wcs,
157  filterName=expMd.filterName,
158  photoCalib=expMd.photoCalib,
159  )
160 
161  refSelection = self.referenceSelector.run(loadRes.refCat)
162 
163  matchMeta = self.refObjLoader.getMetadataBox(
164  bbox=expMd.bbox,
165  wcs=expMd.wcs,
166  filterName=expMd.filterName,
167  photoCalib=expMd.photoCalib,
168  )
169 
170  matchRes = self.matcher.matchObjectsToSources(
171  refCat=refSelection.sourceCat,
172  sourceCat=sourceSelection.sourceCat,
173  wcs=expMd.wcs,
174  sourceFluxField=sourceFluxField,
175  refFluxField=loadRes.fluxField,
176  match_tolerance=None,
177  )
178 
179  distStats = self._computeMatchStatsOnSky(matchRes.matches)
180  self.log.info(
181  "Found %d matches with scatter = %0.3f +- %0.3f arcsec; " %
182  (len(matchRes.matches), distStats.distMean.asArcseconds(), distStats.distStdDev.asArcseconds())
183  )
184 
185  if debug.display:
186  frame = int(debug.frame)
188  refCat=refSelection.sourceCat,
189  sourceCat=sourceSelection.sourceCat,
190  matches=matchRes.matches,
191  exposure=exposure,
192  bbox=expMd.bbox,
193  frame=frame,
194  title="Matches",
195  )
196 
197  return pipeBase.Struct(
198  refCat=loadRes.refCat,
199  refSelection=refSelection,
200  sourceSelection=sourceSelection,
201  matches=matchRes.matches,
202  matchMeta=matchMeta,
203  )
204 
def displayAstrometry(refCat=None, sourceCat=None, distortedCentroidKey=None, bbox=None, exposure=None, matches=None, frame=1, title="", pause=True)
Definition: display.py:34
def run(self, skyInfo, tempExpRefList, imageScalerList, weightList, altMaskList=None, mask=None, supplementaryData=None)

◆ run()

def lsst.meas.astrom.astrometry.AstrometryTask.run (   self,
  sourceCat,
  exposure 
)
Load reference objects, match sources and optionally fit a WCS.

This is a thin layer around solve or loadAndMatch, depending on
config.forceKnownWcs.

Parameters
----------
exposure : `lsst.afw.image.Exposure`
    exposure whose WCS is to be fit
    The following are read only:

    - bbox
    - photoCalib (may be absent)
    - filter (may be unset)
    - detector (if wcs is pure tangent; may be absent)

    The following are updated:

    - wcs (the initial value is used as an initial guess, and is
      required)

sourceCat : `lsst.afw.table.SourceCatalog`
    catalog of sources detected on the exposure

Returns
-------
result : `lsst.pipe.base.Struct`
    with these fields:

    - ``refCat`` : reference object catalog of objects that overlap the
      exposure (with some margin) (`lsst.afw.table.SimpleCatalog`).
    - ``matches`` : astrometric matches
      (`list` of `lsst.afw.table.ReferenceMatch`).
    - ``scatterOnSky`` :  median on-sky separation between reference
      objects and sources in "matches"
      (`lsst.afw.geom.Angle`) or `None` if config.forceKnownWcs True
    - ``matchMeta`` :  metadata needed to unpersist matches
      (`lsst.daf.base.PropertyList`)

Definition at line 106 of file astrometry.py.

106  def run(self, sourceCat, exposure):
107  """Load reference objects, match sources and optionally fit a WCS.
108 
109  This is a thin layer around solve or loadAndMatch, depending on
110  config.forceKnownWcs.
111 
112  Parameters
113  ----------
114  exposure : `lsst.afw.image.Exposure`
115  exposure whose WCS is to be fit
116  The following are read only:
117 
118  - bbox
119  - photoCalib (may be absent)
120  - filter (may be unset)
121  - detector (if wcs is pure tangent; may be absent)
122 
123  The following are updated:
124 
125  - wcs (the initial value is used as an initial guess, and is
126  required)
127 
128  sourceCat : `lsst.afw.table.SourceCatalog`
129  catalog of sources detected on the exposure
130 
131  Returns
132  -------
133  result : `lsst.pipe.base.Struct`
134  with these fields:
135 
136  - ``refCat`` : reference object catalog of objects that overlap the
137  exposure (with some margin) (`lsst.afw.table.SimpleCatalog`).
138  - ``matches`` : astrometric matches
139  (`list` of `lsst.afw.table.ReferenceMatch`).
140  - ``scatterOnSky`` : median on-sky separation between reference
141  objects and sources in "matches"
142  (`lsst.afw.geom.Angle`) or `None` if config.forceKnownWcs True
143  - ``matchMeta`` : metadata needed to unpersist matches
144  (`lsst.daf.base.PropertyList`)
145  """
146  if self.refObjLoader is None:
147  raise RuntimeError("Running matcher task with no refObjLoader set in __init__ or setRefObjLoader")
148  if self.config.forceKnownWcs:
149  res = self.loadAndMatch(exposure=exposure, sourceCat=sourceCat)
150  res.scatterOnSky = None
151  else:
152  res = self.solve(exposure=exposure, sourceCat=sourceCat)
153  return res
154 
def run(self, skyInfo, tempExpRefList, imageScalerList, weightList, altMaskList=None, mask=None, supplementaryData=None)

◆ setRefObjLoader()

def lsst.meas.astrom.ref_match.RefMatchTask.setRefObjLoader (   self,
  refObjLoader 
)
inherited
Sets the reference object loader for the task

Parameters
----------
refObjLoader
    An instance of a reference object loader task or class

Definition at line 105 of file ref_match.py.

105  def setRefObjLoader(self, refObjLoader):
106  """Sets the reference object loader for the task
107 
108  Parameters
109  ----------
110  refObjLoader
111  An instance of a reference object loader task or class
112  """
113  self.refObjLoader = refObjLoader
114 

◆ solve()

def lsst.meas.astrom.astrometry.AstrometryTask.solve (   self,
  exposure,
  sourceCat 
)
Load reference objects overlapping an exposure, match to sources and
fit a WCS

Returns
-------
result : `lsst.pipe.base.Struct`
    Result struct with components:

    - ``refCat`` : reference object catalog of objects that overlap the
      exposure (with some margin) (`lsst::afw::table::SimpleCatalog`).
    - ``matches`` :  astrometric matches
      (`list` of `lsst.afw.table.ReferenceMatch`).
    - ``scatterOnSky`` :  median on-sky separation between reference
      objects and sources in "matches" (`lsst.geom.Angle`)
    - ``matchMeta`` :  metadata needed to unpersist matches
      (`lsst.daf.base.PropertyList`)

Notes
-----
ignores config.forceKnownWcs

Definition at line 156 of file astrometry.py.

156  def solve(self, exposure, sourceCat):
157  """Load reference objects overlapping an exposure, match to sources and
158  fit a WCS
159 
160  Returns
161  -------
162  result : `lsst.pipe.base.Struct`
163  Result struct with components:
164 
165  - ``refCat`` : reference object catalog of objects that overlap the
166  exposure (with some margin) (`lsst::afw::table::SimpleCatalog`).
167  - ``matches`` : astrometric matches
168  (`list` of `lsst.afw.table.ReferenceMatch`).
169  - ``scatterOnSky`` : median on-sky separation between reference
170  objects and sources in "matches" (`lsst.geom.Angle`)
171  - ``matchMeta`` : metadata needed to unpersist matches
172  (`lsst.daf.base.PropertyList`)
173 
174  Notes
175  -----
176  ignores config.forceKnownWcs
177  """
178  if self.refObjLoader is None:
179  raise RuntimeError("Running matcher task with no refObjLoader set in __init__ or setRefObjLoader")
180  import lsstDebug
181  debug = lsstDebug.Info(__name__)
182 
183  expMd = self._getExposureMetadata(exposure)
184 
185  sourceSelection = self.sourceSelector.run(sourceCat)
186 
187  self.log.info("Purged %d sources, leaving %d good sources" %
188  (len(sourceCat) - len(sourceSelection.sourceCat),
189  len(sourceSelection.sourceCat)))
190 
191  loadRes = self.refObjLoader.loadPixelBox(
192  bbox=expMd.bbox,
193  wcs=expMd.wcs,
194  filterName=expMd.filterName,
195  photoCalib=expMd.photoCalib,
196  epoch=expMd.epoch,
197  )
198 
199  refSelection = self.referenceSelector.run(loadRes.refCat)
200 
201  matchMeta = self.refObjLoader.getMetadataBox(
202  bbox=expMd.bbox,
203  wcs=expMd.wcs,
204  filterName=expMd.filterName,
205  photoCalib=expMd.photoCalib,
206  epoch=expMd.epoch,
207  )
208 
209  if debug.display:
210  frame = int(debug.frame)
212  refCat=refSelection.sourceCat,
213  sourceCat=sourceSelection.sourceCat,
214  exposure=exposure,
215  bbox=expMd.bbox,
216  frame=frame,
217  title="Reference catalog",
218  )
219 
220  res = None
221  wcs = expMd.wcs
222  match_tolerance = None
223  for i in range(self.config.maxIter):
224  iterNum = i + 1
225  try:
226  tryRes = self._matchAndFitWcs(
227  refCat=refSelection.sourceCat,
228  sourceCat=sourceCat,
229  goodSourceCat=sourceSelection.sourceCat,
230  refFluxField=loadRes.fluxField,
231  bbox=expMd.bbox,
232  wcs=wcs,
233  exposure=exposure,
234  match_tolerance=match_tolerance,
235  )
236  except Exception as e:
237  # if we have had a succeessful iteration then use that; otherwise fail
238  if i > 0:
239  self.log.info("Fit WCS iter %d failed; using previous iteration: %s" % (iterNum, e))
240  iterNum -= 1
241  break
242  else:
243  raise
244 
245  match_tolerance = tryRes.match_tolerance
246  tryMatchDist = self._computeMatchStatsOnSky(tryRes.matches)
247  self.log.debug(
248  "Match and fit WCS iteration %d: found %d matches with scatter = %0.3f +- %0.3f arcsec; "
249  "max match distance = %0.3f arcsec",
250  iterNum, len(tryRes.matches), tryMatchDist.distMean.asArcseconds(),
251  tryMatchDist.distStdDev.asArcseconds(), tryMatchDist.maxMatchDist.asArcseconds())
252 
253  maxMatchDist = tryMatchDist.maxMatchDist
254  res = tryRes
255  wcs = res.wcs
256  if maxMatchDist.asArcseconds() < self.config.minMatchDistanceArcSec:
257  self.log.debug(
258  "Max match distance = %0.3f arcsec < %0.3f = config.minMatchDistanceArcSec; "
259  "that's good enough",
260  maxMatchDist.asArcseconds(), self.config.minMatchDistanceArcSec)
261  break
262  match_tolerance.maxMatchDist = maxMatchDist
263 
264  self.log.info(
265  "Matched and fit WCS in %d iterations; "
266  "found %d matches with scatter = %0.3f +- %0.3f arcsec" %
267  (iterNum, len(tryRes.matches), tryMatchDist.distMean.asArcseconds(),
268  tryMatchDist.distStdDev.asArcseconds()))
269  for m in res.matches:
270  if self.usedKey:
271  m.second.set(self.usedKey, True)
272  exposure.setWcs(res.wcs)
273 
274  return pipeBase.Struct(
275  refCat=refSelection.sourceCat,
276  matches=res.matches,
277  scatterOnSky=res.scatterOnSky,
278  matchMeta=matchMeta,
279  )
280 
def displayAstrometry(refCat=None, sourceCat=None, distortedCentroidKey=None, bbox=None, exposure=None, matches=None, frame=1, title="", pause=True)
Definition: display.py:34
def run(self, skyInfo, tempExpRefList, imageScalerList, weightList, altMaskList=None, mask=None, supplementaryData=None)

Member Data Documentation

◆ ConfigClass

lsst.meas.astrom.astrometry.AstrometryTask.ConfigClass = AstrometryConfig
static

Definition at line 91 of file astrometry.py.

◆ refObjLoader

lsst.meas.astrom.ref_match.RefMatchTask.refObjLoader
inherited

Definition at line 92 of file ref_match.py.

◆ usedKey

lsst.meas.astrom.astrometry.AstrometryTask.usedKey

Definition at line 98 of file astrometry.py.


The documentation for this class was generated from the following file: