LSSTApplications  11.0-22-g33de520,12.1+21,13.0
LSSTDataManagementBasePackage
Public Member Functions | Public Attributes | Static Public Attributes | Private Member Functions | Static Private Attributes | List of all members
lsst.meas.astrom.matchOptimisticB.MatchOptimisticBTask Class Reference

Match sources to reference objects. More...

Inheritance diagram for lsst.meas.astrom.matchOptimisticB.MatchOptimisticBTask:

Public Member Functions

def __init__
 
def filterStars
 
def matchObjectsToSources
 Match sources to position reference stars. More...
 

Public Attributes

 edgeKey
 
 interpolatedCenterKey
 
 saturatedKey
 

Static Public Attributes

 ConfigClass = MatchOptimisticBConfig
 

Private Member Functions

def _getIsGoodKeys
 
def _isGoodTest
 
def _doMatch
 Implementation of matching sources to position reference stars. More...
 

Static Private Attributes

string _DefaultName = "matchObjectsToSources"
 

Detailed Description

Match sources to reference objects.

Contents

Description

Match sources to reference objects. This is often done as a preliminary step to fitting an astrometric or photometric solution. For details about the matching algorithm see matchOptimisticB.h

Task initialisation

Invoking the Task

Match sources to position reference stars.

Parameters
[in]refCatcatalog of reference objects that overlap the exposure; reads fields for:
  • coord
  • the specified flux field
[in]sourceCatcatalog of sources found on an exposure; reads fields for:
  • centroid
  • centroid flag
  • edge flag
  • saturated flag
  • aperture flux, if found, else PSF flux
[in]wcsestimated WCS
[in]refFluxFieldfield of refCat to use for flux
[in]maxMatchDistmaximum on-sky distance between reference objects and sources (an lsst.afw.geom.Angle); if specified then the smaller of config.maxMatchDistArcSec or maxMatchDist is used; if None then config.maxMatchDistArcSec is used
Returns
an lsst.pipe.base.Struct with fields:
  • matches a list of matches, each instance of lsst.afw.table.ReferenceMatch
  • usableSourcCat a catalog of sources potentially usable for matching. For this fitter usable sources include unresolved sources not too near the edge. It includes saturated sources, even those these are removed from the final match list, because saturated sources may be used to determine the match list.

Configuration parameters

See MatchOptimisticBConfig

To modify the tests for usable sources and good sources, subclass SourceInfo and set MatchOptimisticBTask.SourceInfoClass to your subclass.

A complete example of using MatchOptimisticBTask

MatchOptimisticBTask is a subtask of AstrometryTask, which is called by PhotoCalTask. See meas_photocal_photocal_Example.

Debug variables

The command line task interface supports a flag -d to import debug.py from your PYTHONPATH; see Using lsstDebug to control debugging output for more about debug.py files.

The available variables in MatchOptimisticBTask are:

verbose (bool)
If True then the matcher prints debug messages to stdout

To investigate the Debug variables, put something like

1 import lsstDebug
2 def DebugInfo(name):
3  debug = lsstDebug.getInfo(name) # N.b. lsstDebug.Info(name) would call us recursively
4  if name == "lsst.pipe.tasks.astrometry":
5  debug.verbose = True
6 
7  return debug
8 
9 lsstDebug.Info = DebugInfo

into your debug.py file and run this task with the –debug flag.

Definition at line 93 of file matchOptimisticB.py.

Constructor & Destructor Documentation

def lsst.meas.astrom.matchOptimisticB.MatchOptimisticBTask.__init__ (   self,
  kwargs 
)

Definition at line 161 of file matchOptimisticB.py.

162  def __init__(self, **kwargs):
163  pipeBase.Task.__init__(self, **kwargs)
164  self.makeSubtask("sourceSelector")

Member Function Documentation

def lsst.meas.astrom.matchOptimisticB.MatchOptimisticBTask._doMatch (   self,
  refCat,
  sourceCat,
  wcs,
  refFluxField,
  numUsableSources,
  minMatchedPairs,
  maxMatchDist,
  sourceFluxField,
  verbose 
)
private

Implementation of matching sources to position reference stars.

Unlike matchObjectsToSources, this method does not check if the sources are suitable.

Parameters
[in]refCatcatalog of position reference stars that overlap an exposure
[in]sourceCatcatalog of sources found on the exposure
[in]wcsestimated WCS of exposure
[in]refFluxFieldfield of refCat to use for flux
[in]numUsableSourcesnumber of usable sources (sources with known centroid that are not near the edge, but may be saturated)
[in]minMatchedPairsminimum number of matches
[in]maxMatchDistmaximum on-sky distance between reference objects and sources (an lsst.afw.geom.Angle); if specified then the smaller of config.maxMatchDistArcSec or maxMatchDist is used; if None then config.maxMatchDistArcSec is used
[in]sourceInfoSourceInfo for the sourceCat
[in]verbosetrue to print diagnostic information to std::cout
Returns
a list of matches, an instance of lsst.afw.table.ReferenceMatch

Definition at line 275 of file matchOptimisticB.py.

276  maxMatchDist, sourceFluxField, verbose):
277  """!Implementation of matching sources to position reference stars
278 
279  Unlike matchObjectsToSources, this method does not check if the sources are suitable.
280 
281  @param[in] refCat catalog of position reference stars that overlap an exposure
282  @param[in] sourceCat catalog of sources found on the exposure
283  @param[in] wcs estimated WCS of exposure
284  @param[in] refFluxField field of refCat to use for flux
285  @param[in] numUsableSources number of usable sources (sources with known centroid
286  that are not near the edge, but may be saturated)
287  @param[in] minMatchedPairs minimum number of matches
288  @param[in] maxMatchDist maximum on-sky distance between reference objects and sources
289  (an lsst.afw.geom.Angle); if specified then the smaller of config.maxMatchDistArcSec or
290  maxMatchDist is used; if None then config.maxMatchDistArcSec is used
291  @param[in] sourceInfo SourceInfo for the sourceCat
292  @param[in] verbose true to print diagnostic information to std::cout
293 
294  @return a list of matches, an instance of lsst.afw.table.ReferenceMatch
295  """
296  numSources = len(sourceCat)
297  posRefBegInd = numUsableSources - numSources
298  if maxMatchDist is None:
299  maxMatchDistArcSec = self.config.maxMatchDistArcSec
300  else:
301  maxMatchDistArcSec = min(maxMatchDist.asArcseconds(), self.config.maxMatchDistArcSec)
302  configMatchDistPix = maxMatchDistArcSec/wcs.pixelScale().asArcseconds()
303 
304  matchControl = MatchOptimisticBControl()
305  matchControl.refFluxField = refFluxField
306  matchControl.sourceFluxField = sourceFluxField
307  matchControl.numBrightStars = self.config.numBrightStars
308  matchControl.minMatchedPairs = self.config.minMatchedPairs
309  matchControl.maxOffsetPix = self.config.maxOffsetPix
310  matchControl.numPointsForShape = self.config.numPointsForShape
311  matchControl.maxDeterminant = self.config.maxDeterminant
312 
313  for maxRotInd in range(4):
314  matchControl.maxRotationDeg = self.config.maxRotationDeg * math.pow(2.0, 0.5*maxRotInd)
315  for matchRadInd in range(3):
316  matchControl.matchingAllowancePix = configMatchDistPix * math.pow(1.25, matchRadInd)
317 
318  for angleDiffInd in range(3):
319  matchControl.allowedNonperpDeg = self.config.allowedNonperpDeg*(angleDiffInd+1)
320  matches = matchOptimisticB(
321  refCat,
322  sourceCat,
323  matchControl,
324  wcs,
325  posRefBegInd,
326  verbose,
327  )
328  if matches is not None and len(matches) > 0:
329  setMatchDistance(matches)
330  return matches
331  return matches
lsst::afw::table::ReferenceMatchVector matchOptimisticB(lsst::afw::table::SimpleCatalog const &posRefCat, lsst::afw::table::SourceCatalog const &sourceCat, MatchOptimisticBControl const &control, afw::image::Wcs const &wcs, int posRefBegInd=0, bool verbose=false)
Match sources to stars in a position reference catalog using optimistic pattern matching B...
def lsst.meas.astrom.matchOptimisticB.MatchOptimisticBTask._getIsGoodKeys (   self,
  schema 
)
private

Definition at line 258 of file matchOptimisticB.py.

259  def _getIsGoodKeys(self, schema):
260  self.edgeKey = schema["base_PixelFlags_flag_edge"].asKey()
261  self.interpolatedCenterKey = schema["base_PixelFlags_flag_interpolatedCenter"].asKey()
262  self.saturatedKey = schema["base_PixelFlags_flag_saturated"].asKey()
def lsst.meas.astrom.matchOptimisticB.MatchOptimisticBTask._isGoodTest (   self,
  source 
)
private
This is a hard coded version of the isGood flag from the old SourceInfo class that used to be
part of this class. This is done current as the API for sourceSelector does not currently
support matchLists.

Definition at line 263 of file matchOptimisticB.py.

264  def _isGoodTest(self, source):
265  """
266  This is a hard coded version of the isGood flag from the old SourceInfo class that used to be
267  part of this class. This is done current as the API for sourceSelector does not currently
268  support matchLists.
269  """
270  return (not source.get(self.edgeKey) and
271  not source.get(self.interpolatedCenterKey) and
272  not source.get(self.saturatedKey))
def lsst.meas.astrom.matchOptimisticB.MatchOptimisticBTask.filterStars (   self,
  refCat 
)
Extra filtering pass; subclass if desired

Definition at line 165 of file matchOptimisticB.py.

166  def filterStars(self, refCat):
167  """Extra filtering pass; subclass if desired
168  """
169  return refCat
def lsst.meas.astrom.matchOptimisticB.MatchOptimisticBTask.matchObjectsToSources (   self,
  refCat,
  sourceCat,
  wcs,
  refFluxField,
  maxMatchDist = None 
)

Match sources to position reference stars.

Parameters
[in]refCatcatalog of reference objects that overlap the exposure; reads fields for:
  • coord
  • the specified flux field
[in]sourceCatcatalog of sources found on an exposure; reads fields for:
  • centroid
  • centroid flag
  • edge flag
  • saturated flag
  • aperture flux, if found, else PSF flux
[in]wcsestimated WCS
[in]refFluxFieldfield of refCat to use for flux
[in]maxMatchDistmaximum on-sky distance between reference objects and sources (an lsst.afw.geom.Angle); if specified then the smaller of config.maxMatchDistArcSec or maxMatchDist is used; if None then config.maxMatchDistArcSec is used
Returns
an lsst.pipe.base.Struct with fields:
  • matches a list of matches, each instance of lsst.afw.table.ReferenceMatch
  • usableSourcCat a catalog of sources potentially usable for matching. For this fitter usable sources include unresolved sources not too near the edge. It includes saturated sources, even those these are removed from the final match list, because saturated sources may be used to determine the match list.

Definition at line 171 of file matchOptimisticB.py.

172  def matchObjectsToSources(self, refCat, sourceCat, wcs, refFluxField, maxMatchDist=None):
173  """!Match sources to position reference stars
174 
175  @param[in] refCat catalog of reference objects that overlap the exposure; reads fields for:
176  - coord
177  - the specified flux field
178  @param[in] sourceCat catalog of sources found on an exposure; reads fields for:
179  - centroid
180  - centroid flag
181  - edge flag
182  - saturated flag
183  - aperture flux, if found, else PSF flux
184  @param[in] wcs estimated WCS
185  @param[in] refFluxField field of refCat to use for flux
186  @param[in] maxMatchDist maximum on-sky distance between reference objects and sources
187  (an lsst.afw.geom.Angle); if specified then the smaller of config.maxMatchDistArcSec or
188  maxMatchDist is used; if None then config.maxMatchDistArcSec is used
189  @return an lsst.pipe.base.Struct with fields:
190  - matches a list of matches, each instance of lsst.afw.table.ReferenceMatch
191  - usableSourcCat a catalog of sources potentially usable for matching.
192  For this fitter usable sources include unresolved sources not too near the edge.
193  It includes saturated sources, even those these are removed from the final match list,
194  because saturated sources may be used to determine the match list.
195  """
196  import lsstDebug
197  debug = lsstDebug.Info(__name__)
198 
199  preNumObj = len(refCat)
200  refCat = self.filterStars(refCat)
201  numRefObj = len(refCat)
202 
203  if self.log:
204  self.log.info("filterStars purged %d reference stars, leaving %d stars" %
205  (preNumObj - numRefObj, numRefObj))
206 
207  # usableSourceCat: sources that are good but may be saturated
208  numSources = len(sourceCat)
209  selectedSources = self.sourceSelector.selectSources(sourceCat)
210  usableSourceCat = selectedSources.sourceCat
211  numUsableSources = len(usableSourceCat)
212  self.log.info("Purged %d unusable sources, leaving %d usable sources" %
213  (numSources - numUsableSources, numUsableSources))
214 
215  if len(usableSourceCat) == 0:
216  raise pipeBase.TaskError("No sources are usable")
217 
218  del sourceCat # avoid accidentally using sourceCat; use usableSourceCat or goodSourceCat from now on
219 
220  minMatchedPairs = min(self.config.minMatchedPairs,
221  int(self.config.minFracMatchedPairs * min([len(refCat), len(usableSourceCat)])))
222 
223  # match usable (possibly saturated) sources and then purge saturated sources from the match list
224  usableMatches = self._doMatch(
225  refCat=refCat,
226  sourceCat=usableSourceCat,
227  wcs=wcs,
228  refFluxField=refFluxField,
229  numUsableSources=numUsableSources,
230  minMatchedPairs=minMatchedPairs,
231  maxMatchDist=maxMatchDist,
232  sourceFluxField=self.sourceSelector.fluxField,
233  verbose=debug.verbose,
234  )
235 
236  # cull non-good sources
237  matches = []
238  self._getIsGoodKeys(usableSourceCat.schema)
239  for match in usableMatches:
240  if self._isGoodTest(match.second):
241  # Append the isGood match.
242  matches.append(match)
243 
244  self.log.debug("Found %d usable matches, of which %d had good sources",
245  len(usableMatches), len(matches))
246 
247  if len(matches) == 0:
248  raise RuntimeError("Unable to match sources")
249 
250  self.log.info("Matched %d sources" % len(matches))
251  if len(matches) < minMatchedPairs:
252  self.log.warn("Number of matches is smaller than request")
253 
254  return pipeBase.Struct(
255  matches=matches,
256  usableSourceCat=usableSourceCat,
257  )
def matchObjectsToSources
Match sources to position reference stars.
def _doMatch
Implementation of matching sources to position reference stars.

Member Data Documentation

string lsst.meas.astrom.matchOptimisticB.MatchOptimisticBTask._DefaultName = "matchObjectsToSources"
staticprivate

Definition at line 159 of file matchOptimisticB.py.

lsst.meas.astrom.matchOptimisticB.MatchOptimisticBTask.ConfigClass = MatchOptimisticBConfig
static

Definition at line 158 of file matchOptimisticB.py.

lsst.meas.astrom.matchOptimisticB.MatchOptimisticBTask.edgeKey

Definition at line 259 of file matchOptimisticB.py.

lsst.meas.astrom.matchOptimisticB.MatchOptimisticBTask.interpolatedCenterKey

Definition at line 260 of file matchOptimisticB.py.

lsst.meas.astrom.matchOptimisticB.MatchOptimisticBTask.saturatedKey

Definition at line 261 of file matchOptimisticB.py.


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