LSSTApplications  1.1.2+25,10.0+13,10.0+132,10.0+133,10.0+224,10.0+41,10.0+8,10.0-1-g0f53050+14,10.0-1-g4b7b172+19,10.0-1-g61a5bae+98,10.0-1-g7408a83+3,10.0-1-gc1e0f5a+19,10.0-1-gdb4482e+14,10.0-11-g3947115+2,10.0-12-g8719d8b+2,10.0-15-ga3f480f+1,10.0-2-g4f67435,10.0-2-gcb4bc6c+26,10.0-28-gf7f57a9+1,10.0-3-g1bbe32c+14,10.0-3-g5b46d21,10.0-4-g027f45f+5,10.0-4-g86f66b5+2,10.0-4-gc4fccf3+24,10.0-40-g4349866+2,10.0-5-g766159b,10.0-5-gca2295e+25,10.0-6-g462a451+1
LSSTDataManagementBasePackage
fitTanSipWcs.py
Go to the documentation of this file.
1 from __future__ import absolute_import, division, print_function
2 
3 import lsst.afw.geom as afwGeom
4 import lsst.afw.table as afwTable
5 import lsst.pex.config as pexConfig
6 import lsst.pipe.base as pipeBase
7 from .sip import makeCreateWcsWithSip
8 
9 __all__ = ["FitTanSipWcsTask", "FitTanSipWcsConfig"]
10 
11 class FitTanSipWcsConfig(pexConfig.Config):
12  order = pexConfig.RangeField(
13  doc = "order of SIP polynomial (0 for pure TAN WCS)",
14  dtype = int,
15  default = 3,
16  min = 0,
17  )
18 
19 # The following block adds links to this task from the Task Documentation page.
20 ## \addtogroup LSST_task_documentation
21 ## \{
22 ## \page measAstrom_fitTanSipWcsTask
23 ## \ref FitTanSipWcsTask "FitTanSipWcsTask"
24 ## Fit a TAN-SIP WCS given a list of reference object/source matches
25 ## \}
26 
27 class FitTanSipWcsTask(pipeBase.Task):
28  """!Fit a TAN-SIP WCS given a list of reference object/source matches
29 
30  @anchor FitTanSipWcsTask_
31 
32  @section meas_astrom_fitTanSipWcs_Contents Contents
33 
34  - @ref meas_astrom_fitTanSipWcs_Purpose
35  - @ref meas_astrom_fitTanSipWcs_Initialize
36  - @ref meas_astrom_fitTanSipWcs_IO
37  - @ref meas_astrom_fitTanSipWcs_Schema
38  - @ref meas_astrom_fitTanSipWcs_Config
39  - @ref meas_astrom_fitTanSipWcs_Example
40  - @ref meas_astrom_fitTanSipWcs_Debug
41 
42  @section meas_astrom_fitTanSipWcs_Purpose Description
43 
44  Fit a TAN-SIP WCS given a list of reference object/source matches.
45  See CreateWithSip.h for information about the fitting algorithm.
46 
47  @section meas_astrom_fitTanSipWcs_Initialize Task initialisation
48 
49  @copydoc \_\_init\_\_
50 
51  @section meas_astrom_fitTanSipWcs_IO Invoking the Task
52 
53  @copydoc fitWcs
54 
55  @section meas_astrom_fitTanSipWcs_Config Configuration parameters
56 
57  See @ref FitTanSipWcsConfig
58 
59  @section meas_astrom_fitTanSipWcs_Example A complete example of using FitTanSipWcsTask
60 
61  FitTanSipWcsTask is a subtask of AstrometryTask, which is called by PhotoCalTask.
62  See \ref meas_photocal_photocal_Example.
63 
64  @section meas_astrom_fitTanSipWcs_Debug Debug variables
65 
66  FitTanSipWcsTask does not support any debug variables.
67  """
68  ConfigClass = FitTanSipWcsConfig
69  _DefaultName = "fitWcs"
70 
71  @pipeBase.timeMethod
72  def fitWcs(self, matches, initWcs, bbox=None, refCat=None, sourceCat=None):
73  """!Fit a TAN-SIP WCS from a list of reference object/source matches
74 
75  @param[in,out] matches a list of reference object/source matches
76  (an lsst::afw::table::ReferenceMatchVector)
77  The centroids of the reference objects in matches may be updated for the new WCS,
78  but it is strongly recommended that you provide the refCat and sourceCat arguments
79  so that all matches are fully updated, as well as any sources or reference objects
80  not in matches.
81  @param[in] initWcs initial WCS
82  @param[in] bbox the region over which the WCS will be valid (an lsst:afw::geom::Box2I);
83  if None or an empty box then computed from matches
84  @param[in,out] refCat reference object catalog, or None.
85  If provided then all centroids are updated with the new WCS,
86  otherwise the centroids in matches might be updated but the others will not be touched.
87  Required fields are "centroid_x", "centroid_y" and "coord".
88  @param[in,out] sourceCat source catalog, or None.
89  If provided then coords are updated with the new WCS.
90  Required fields are "slot_Centroid_x", "slot_Centroid_y" and "coord".
91 
92  @return an lsst.pipe.base.Struct with the following fields:
93  - wcs the fit WCS as an lsst.afw.image.Wcs
94  - scatterOnSky median on-sky separation between reference objects and sources in "matches",
95  as an lsst.afw.geom.Angle
96  """
97  if bbox is None:
98  bbox = afwGeom.Box2I()
99  sipObject = makeCreateWcsWithSip(matches, initWcs, self.config.order, bbox)
100  wcs = sipObject.getNewWcs()
101 
102  if refCat is not None:
103  self.updateRefCat(wcs, refCat)
104 
105  if sourceCat is not None:
106  self.updateSrcCat(wcs, sourceCat)
107 
108  return pipeBase.Struct(
109  wcs = wcs,
110  scatterOnSky = sipObject.getScatterOnSky(),
111  )
112 
113  @staticmethod
114  def updateRefCat(wcs, refCat):
115  """Update centroids in a reference catalog, given a WCS
116  """
117  coordKey = refCat.schema["coord"].asKey()
118  centroidKey = afwTable.Point2DKey(refCat.schema["centroid"])
119  for refObj in refCat:
120  refObj.set(centroidKey, wcs.skyToPixel(refObj.get(coordKey)))
121 
122  @staticmethod
123  def updateSrcCat(wcs, sourceCat):
124  """Update coords in a source catalog, given a WCS
125  """
126  srcCoordKey = sourceCat.schema["coord"].asKey()
127  for src in sourceCat:
128  src.set(srcCoordKey, wcs.pixelToSky(src.getCentroid()))
129 
def fitWcs
Fit a TAN-SIP WCS from a list of reference object/source matches.
Definition: fitTanSipWcs.py:72
An integer coordinate rectangle.
Definition: Box.h:53
CreateWcsWithSip< MatchT > makeCreateWcsWithSip(std::vector< MatchT > const &matches, afw::image::Wcs const &linearWcs, int const order, afw::geom::Box2I const &bbox=afw::geom::Box2I(), int const ngrid=0)
Factory function for CreateWcsWithSip.
Fit a TAN-SIP WCS given a list of reference object/source matches.
Definition: fitTanSipWcs.py:27