LSSTApplications  18.1.0
LSSTDataManagementBasePackage
Public Member Functions | Protected Attributes | List of all members
lsst::jointcal::ConstrainedAstrometryModel Class Reference

A multi-component model, fitting mappings for sensors and visits simultaneously. More...

#include <ConstrainedAstrometryModel.h>

Inheritance diagram for lsst::jointcal::ConstrainedAstrometryModel:
lsst::jointcal::AstrometryModel

Public Member Functions

 ConstrainedAstrometryModel (CcdImageList const &ccdImageList, std::shared_ptr< ProjectionHandler const > projectionHandler, int chipOrder, int visitOrder)
 
 ConstrainedAstrometryModel (ConstrainedAstrometryModel const &)=delete
 No copy or move: there is only ever one instance of a given model (i.e. per ccd+visit) More...
 
 ConstrainedAstrometryModel (ConstrainedAstrometryModel &&)=delete
 
ConstrainedAstrometryModeloperator= (ConstrainedAstrometryModel const &)=delete
 
ConstrainedAstrometryModeloperator= (ConstrainedAstrometryModel &&)=delete
 
AstrometryMapping const * getMapping (CcdImage const &) const override
 Mapping associated to a given CcdImage. More...
 
Eigen::Index assignIndices (std::string const &whatToFit, Eigen::Index firstIndex) override
 Positions the various parameter sets into the parameter vector, starting at firstIndex. More...
 
void offsetParams (Eigen::VectorXd const &Delta) override
 Dispaches the offsets after a fit step into the actual locations of parameters. More...
 
void freezeErrorTransform () override
 From there on, measurement errors are propagated using the current transforms (and no longer evolve). More...
 
std::size_t getTotalParameters () const override
 Return the total number of parameters in this model. More...
 
AstrometryTransform const & getChipTransform (CcdIdType const chip) const
 Access to mappings. More...
 
AstrometryTransform const & getVisitTransform (VisitIdType const &visit) const
 Access to mappings. More...
 
std::vector< VisitIdTypegetVisits () const
 Access to array of visits involved in the solution. More...
 
const std::shared_ptr< AstrometryTransform const > getSkyToTangentPlane (CcdImage const &ccdImage) const override
 The mapping of sky coordinates (i.e. More...
 
std::shared_ptr< afw::geom::SkyWcsmakeSkyWcs (CcdImage const &ccdImage) const override
 Make a SkyWcs that contains this model. More...
 
std::size_t getNpar (CcdImage const &ccdImage) const
 Return the number of parameters in the mapping of CcdImage. More...
 
bool validate (CcdImageList const &ccdImageList, int ndof) const
 Return true if this is a "reasonable" model. More...
 

Protected Attributes

LOG_LOGGER _log
 lsst.logging instance, to be created by a subclass so that messages have consistent name. More...
 

Detailed Description

A multi-component model, fitting mappings for sensors and visits simultaneously.

This is the model used to fit mappings as the combination of a transformation depending on the chip number (instrument model) and a transformation per visit (anamorphism). The two-transformation Mapping required for this model is ChipVisitAstrometryMapping. This modeling of distortions is meant for a set of images from a single mosaic imager.

Parameters
ccdImageListThe exposures that will be fit.
projectionHandlerThe projection from "Sky" (where the "true" coordinates live) to "Tangent Plane" (where the fitting occurs).
chipOrderThe polynomial order of the pixel->focal plane mapping for each sensor.
visitOrderThe polynomial order of the focal plane->tangent plane mapping for each visit.

Definition at line 62 of file ConstrainedAstrometryModel.h.

Constructor & Destructor Documentation

◆ ConstrainedAstrometryModel() [1/3]

lsst::jointcal::ConstrainedAstrometryModel::ConstrainedAstrometryModel ( CcdImageList const &  ccdImageList,
std::shared_ptr< ProjectionHandler const >  projectionHandler,
int  chipOrder,
int  visitOrder 
)

Definition at line 63 of file ConstrainedAstrometryModel.cc.

66  : AstrometryModel(LOG_GET("jointcal.ConstrainedAstrometryModel")),
67  _skyToTangentPlane(projectionHandler) {
68  // keep track of which chip we want to hold fixed (the one closest to the middle of the focal plane)
69  double minRadius2 = std::numeric_limits<double>::infinity();
70  CcdIdType constrainedChip = -1;
71 
72  // first loop to initialize all visit and chip transforms.
73  for (auto &ccdImage : ccdImageList) {
74  const CcdImage &im = *ccdImage;
75  auto visit = im.getVisit();
76  auto chip = im.getCcdId();
77  auto visitp = _visitMap.find(visit);
78  if (visitp == _visitMap.end()) {
79  _visitMap[visit] = std::make_shared<SimplePolyMapping>(AstrometryTransformLinear(),
80  AstrometryTransformPolynomial(visitOrder));
81  }
82  auto chipp = _chipMap.find(chip);
83  if (chipp == _chipMap.end()) {
84  auto center = ccdImage->getDetector()->getCenter(afw::cameraGeom::FOCAL_PLANE);
85  double radius2 = std::pow(center.getX(), 2) + std::pow(center.getY(), 2);
86  if (radius2 < minRadius2) {
87  minRadius2 = radius2;
88  constrainedChip = chip;
89  }
90 
91  auto pixelsToFocal =
92  im.getDetector()->getTransform(afw::cameraGeom::PIXELS, afw::cameraGeom::FOCAL_PLANE);
93  Frame const &frame = im.getImageFrame();
94  // construct the chip transform by approximating the pixel->Focal afw::geom::Transform.
95  AstrometryTransformPolynomial pol =
96  AstrometryTransformPolynomial(pixelsToFocal, frame, chipOrder);
97  AstrometryTransformLinear shiftAndNormalize = normalizeCoordinatesTransform(frame);
98  _chipMap[chip] = std::make_shared<SimplePolyMapping>(shiftAndNormalize,
99  pol * shiftAndNormalize.inverted());
100  }
101  }
102 
103  // Hold the "central" chip map fixed and don't fit it, to remove a degeneracy.
104  _chipMap.at(constrainedChip)->setToBeFit(false);
105 
106  // now, second loop to set the mappings of the CCdImages
107  for (auto &ccdImage : ccdImageList) {
108  const CcdImage &im = *ccdImage;
109  auto visit = im.getVisit();
110  auto chip = im.getCcdId();
111 
112  // check that the chip_indexed part was indeed assigned
113  // (i.e. the reference visit was complete)
114  if (_chipMap.find(chip) == _chipMap.end()) {
115  LOGLS_WARN(_log, "Chip " << chip << " is missing in the reference exposure, expect troubles.");
116  AstrometryTransformLinear norm = normalizeCoordinatesTransform(im.getImageFrame());
117  _chipMap[chip] =
118  std::make_shared<SimplePolyMapping>(norm, AstrometryTransformPolynomial(chipOrder));
119  }
120  _mappings[ccdImage->getHashKey()] =
121  std::make_unique<ChipVisitAstrometryMapping>(_chipMap[chip], _visitMap[visit]);
122  }
123  LOGLS_INFO(_log, "Got " << _chipMap.size() << " chip mappings and " << _visitMap.size()
124  << " visit mappings; holding chip " << constrainedChip << " fixed ("
125  << getTotalParameters() << " total parameters).");
126  LOGLS_DEBUG(_log, "CcdImage map has " << _mappings.size() << " mappings, with "
127  << _mappings.bucket_count() << " buckets and a load factor of "
128  << _mappings.load_factor());
129 }
#define LOGLS_WARN(logger, message)
Log a warn-level message using an iostream-based interface.
Definition: Log.h:633
LOG_LOGGER _log
lsst.logging instance, to be created by a subclass so that messages have consistent name...
CameraSysPrefix const PIXELS
Pixel coordinates: Nominal position on the entry surface of a given detector (x, y unbinned pixels)...
Definition: CameraSys.cc:34
T norm(const T &x)
Definition: Integrate.h:194
std::size_t getTotalParameters() const override
Return the total number of parameters in this model.
AstrometryTransformLinear normalizeCoordinatesTransform(const Frame &frame)
Returns the transformation that maps the input frame along both axes to [-1,1].
#define LOGLS_DEBUG(logger, message)
Log a debug-level message using an iostream-based interface.
Definition: Log.h:593
T infinity(T... args)
#define LOGLS_INFO(logger, message)
Log a info-level message using an iostream-based interface.
Definition: Log.h:613
T pow(T... args)
#define LOG_GET(logger)
Returns a Log object associated with logger.
Definition: Log.h:75
CameraSys const FOCAL_PLANE
Focal plane coordinates: Position on a 2-d planar approximation to the focal plane (x...
Definition: CameraSys.cc:30

◆ ConstrainedAstrometryModel() [2/3]

lsst::jointcal::ConstrainedAstrometryModel::ConstrainedAstrometryModel ( ConstrainedAstrometryModel const &  )
delete

No copy or move: there is only ever one instance of a given model (i.e. per ccd+visit)

◆ ConstrainedAstrometryModel() [3/3]

lsst::jointcal::ConstrainedAstrometryModel::ConstrainedAstrometryModel ( ConstrainedAstrometryModel &&  )
delete

Member Function Documentation

◆ assignIndices()

Eigen::Index lsst::jointcal::ConstrainedAstrometryModel::assignIndices ( std::string const &  whatToFit,
Eigen::Index  firstIndex 
)
overridevirtual

Positions the various parameter sets into the parameter vector, starting at firstIndex.

This routine decodes "DistortionsChip" and "DistortionsVisit" in whatToFit.

If whatToFit contains "Distortions" and not Distortions<Something>, it is understood as both chips and visits.

Implements lsst::jointcal::AstrometryModel.

Definition at line 139 of file ConstrainedAstrometryModel.cc.

142  {
143  Eigen::Index index = firstIndex;
144  if (whatToFit.find("Distortions") == std::string::npos) {
145  LOGLS_ERROR(_log, "assignIndices was called and Distortions is *not* in whatToFit");
146  return 0;
147  }
148  // if we get here "Distortions" is in whatToFit
149  _fittingChips = (whatToFit.find("DistortionsChip") != std::string::npos);
150  _fittingVisits = (whatToFit.find("DistortionsVisit") != std::string::npos);
151  // If nothing more than "Distortions" is specified, it means all:
152  if ((!_fittingChips) && (!_fittingVisits)) {
153  _fittingChips = _fittingVisits = true;
154  }
155  if (_fittingChips)
156  for (auto &i : _chipMap) {
157  i.second->setIndex(index);
158  index += i.second->getNpar();
159  }
160  if (_fittingVisits)
161  for (auto &i : _visitMap) {
162  i.second->setIndex(index);
163  index += i.second->getNpar();
164  }
165  // Tell the mappings which derivatives they will have to fill:
166  for (auto &i : _mappings) {
167  i.second->setWhatToFit(_fittingChips, _fittingVisits);
168  }
169  return index;
170 }
LOG_LOGGER _log
lsst.logging instance, to be created by a subclass so that messages have consistent name...
#define LOGLS_ERROR(logger, message)
Log a error-level message using an iostream-based interface.
Definition: Log.h:653

◆ freezeErrorTransform()

void lsst::jointcal::ConstrainedAstrometryModel::freezeErrorTransform ( )
overridevirtual

From there on, measurement errors are propagated using the current transforms (and no longer evolve).

Implements lsst::jointcal::AstrometryModel.

Definition at line 185 of file ConstrainedAstrometryModel.cc.

185  {
186  for (auto i = _visitMap.begin(); i != _visitMap.end(); ++i) i->second->freezeErrorTransform();
187  for (auto i = _chipMap.begin(); i != _chipMap.end(); ++i) i->second->freezeErrorTransform();
188 }

◆ getChipTransform()

const AstrometryTransform & lsst::jointcal::ConstrainedAstrometryModel::getChipTransform ( CcdIdType const  chip) const

Access to mappings.

Definition at line 190 of file ConstrainedAstrometryModel.cc.

190  {
191  auto chipp = _chipMap.find(chip);
192  if (chipp == _chipMap.end()) {
193  std::stringstream errMsg;
194  errMsg << "No such chipId: " << chip << " among ";
195  outputMapKeys(_chipMap, errMsg);
196  std::cout << std::endl;
197  throw pexExcept::InvalidParameterError(errMsg.str());
198  }
199  return chipp->second->getTransform();
200 }
T endl(T... args)
T str(T... args)
Reports invalid arguments.
Definition: Runtime.h:66

◆ getMapping()

const AstrometryMapping * lsst::jointcal::ConstrainedAstrometryModel::getMapping ( CcdImage const &  ) const
overridevirtual

Mapping associated to a given CcdImage.

Implements lsst::jointcal::AstrometryModel.

Definition at line 131 of file ConstrainedAstrometryModel.cc.

131  {
132  return findMapping(ccdImage);
133 }

◆ getNpar()

std::size_t lsst::jointcal::AstrometryModel::getNpar ( CcdImage const &  ccdImage) const
inlineinherited

Return the number of parameters in the mapping of CcdImage.

Definition at line 54 of file AstrometryModel.h.

54 { return findMapping(ccdImage)->getNpar(); }
virtual AstrometryMapping * findMapping(CcdImage const &ccdImage) const =0
Return a pointer to the mapping associated with this ccdImage.
virtual std::size_t getNpar() const =0
Number of parameters in total.

◆ getSkyToTangentPlane()

const std::shared_ptr<AstrometryTransform const> lsst::jointcal::ConstrainedAstrometryModel::getSkyToTangentPlane ( CcdImage const &  ccdImage) const
inlineoverridevirtual

The mapping of sky coordinates (i.e.

the coordinate system in which fitted stars are reported) onto the Tangent plane (into which the pixel coordinates are transformed).

Implements lsst::jointcal::AstrometryModel.

Definition at line 113 of file ConstrainedAstrometryModel.h.

114  {
115  return _skyToTangentPlane->getSkyToTangentPlane(ccdImage);
116  }

◆ getTotalParameters()

std::size_t lsst::jointcal::ConstrainedAstrometryModel::getTotalParameters ( ) const
overridevirtual

Return the total number of parameters in this model.

Implements lsst::jointcal::AstrometryModel.

Definition at line 222 of file ConstrainedAstrometryModel.cc.

222  {
223  std::size_t total = 0;
224  for (auto &i : _chipMap) {
225  total += i.second->getNpar();
226  }
227  for (auto &i : _visitMap) {
228  total += i.second->getNpar();
229  }
230  return total;
231 }

◆ getVisits()

std::vector< VisitIdType > lsst::jointcal::ConstrainedAstrometryModel::getVisits ( ) const

Access to array of visits involved in the solution.

Definition at line 203 of file ConstrainedAstrometryModel.cc.

203  {
205  res.reserve(_visitMap.size());
206  for (auto i = _visitMap.begin(); i != _visitMap.end(); ++i) res.push_back(i->first);
207  return res;
208 }
T push_back(T... args)
STL class.
T reserve(T... args)

◆ getVisitTransform()

const AstrometryTransform & lsst::jointcal::ConstrainedAstrometryModel::getVisitTransform ( VisitIdType const &  visit) const

Access to mappings.

Definition at line 210 of file ConstrainedAstrometryModel.cc.

210  {
211  auto visitp = _visitMap.find(visit);
212  if (visitp == _visitMap.end()) {
213  std::stringstream errMsg;
214  errMsg << "No such visitId: " << visit << " among ";
215  outputMapKeys(_visitMap, errMsg);
216  std::cout << std::endl;
217  throw pexExcept::InvalidParameterError(errMsg.str());
218  }
219  return visitp->second->getTransform();
220 }
T endl(T... args)
T str(T... args)
Reports invalid arguments.
Definition: Runtime.h:66

◆ makeSkyWcs()

std::shared_ptr< afw::geom::SkyWcs > lsst::jointcal::ConstrainedAstrometryModel::makeSkyWcs ( CcdImage const &  ccdImage) const
overridevirtual

Make a SkyWcs that contains this model.

Parameters
ccdImageThe exposure to create the SkyWcs for.
Returns
SkyWcs containing this model.

Implements lsst::jointcal::AstrometryModel.

Definition at line 233 of file ConstrainedAstrometryModel.cc.

233  {
234  auto proj = std::dynamic_pointer_cast<const TanRaDecToPixel>(getSkyToTangentPlane(ccdImage));
235  jointcal::Point tangentPoint(proj->getTangentPoint());
236 
237  auto imageFrame = ccdImage.getImageFrame();
238  auto pixelsToFocal = getChipTransform(ccdImage.getCcdId()).toAstMap(imageFrame);
239  jointcal::Frame focalBox = getChipTransform(ccdImage.getCcdId()).apply(imageFrame, false);
240  auto focalToIwc = getVisitTransform(ccdImage.getVisit()).toAstMap(focalBox);
241 
242  ast::Frame pixelFrame(2, "Domain=PIXELS");
243  ast::Frame focalFrame(2, "Domain=FOCAL");
244  ast::Frame iwcFrame(2, "Domain=IWC");
245 
246  // make a basic SkyWcs and extract the IWC portion
247  auto iwcToSkyWcs = afw::geom::makeSkyWcs(
248  afw::geom::Point2D(0, 0),
249  afw::geom::SpherePoint(tangentPoint.x, tangentPoint.y, afw::geom::degrees),
251  auto iwcToSkyMap = iwcToSkyWcs->getFrameDict()->getMapping("PIXELS", "SKY");
252  auto skyFrame = iwcToSkyWcs->getFrameDict()->getFrame("SKY");
253 
254  ast::FrameDict frameDict(pixelFrame);
255  frameDict.addFrame("PIXELS", *pixelsToFocal, focalFrame);
256  frameDict.addFrame("FOCAL", *focalToIwc, iwcFrame);
257  frameDict.addFrame("IWC", *iwcToSkyMap, *skyFrame);
258  return std::make_shared<afw::geom::SkyWcs>(frameDict);
259 }
AstrometryTransform const & getVisitTransform(VisitIdType const &visit) const
Access to mappings.
A point in a plane.
Definition: Point.h:36
const std::shared_ptr< AstrometryTransform const > getSkyToTangentPlane(CcdImage const &ccdImage) const override
The mapping of sky coordinates (i.e.
Point< double, 2 > Point2D
Definition: Point.h:324
rectangle with sides parallel to axes.
Definition: Frame.h:38
AngleUnit constexpr degrees
constant with units of degrees
Definition: Angle.h:109
Frame is used to represent a coordinate system.
Definition: Frame.h:157
T dynamic_pointer_cast(T... args)
AstrometryTransform const & getChipTransform(CcdIdType const chip) const
Access to mappings.
std::shared_ptr< SkyWcs > makeSkyWcs(daf::base::PropertySet &metadata, bool strip=false)
Construct a SkyWcs from FITS keywords.
Definition: SkyWcs.cc:486
Eigen::Matrix2d makeCdMatrix(lsst::geom::Angle const &scale, lsst::geom::Angle const &orientation=0 *lsst::geom::degrees, bool flipX=false)
Make a WCS CD matrix.
Definition: SkyWcs.cc:139
lsst::geom::SpherePoint SpherePoint
Definition: misc.h:35
A FrameSet whose frames can be referenced by domain name.
Definition: FrameDict.h:67

◆ offsetParams()

void lsst::jointcal::ConstrainedAstrometryModel::offsetParams ( Eigen::VectorXd const &  Delta)
overridevirtual

Dispaches the offsets after a fit step into the actual locations of parameters.

Implements lsst::jointcal::AstrometryModel.

Definition at line 172 of file ConstrainedAstrometryModel.cc.

172  {
173  if (_fittingChips)
174  for (auto &i : _chipMap) {
175  auto mapping = i.second.get();
176  mapping->offsetParams(delta.segment(mapping->getIndex(), mapping->getNpar()));
177  }
178  if (_fittingVisits)
179  for (auto &i : _visitMap) {
180  auto mapping = i.second.get();
181  mapping->offsetParams(delta.segment(mapping->getIndex(), mapping->getNpar()));
182  }
183 }

◆ operator=() [1/2]

ConstrainedAstrometryModel& lsst::jointcal::ConstrainedAstrometryModel::operator= ( ConstrainedAstrometryModel const &  )
delete

◆ operator=() [2/2]

ConstrainedAstrometryModel& lsst::jointcal::ConstrainedAstrometryModel::operator= ( ConstrainedAstrometryModel &&  )
delete

◆ validate()

bool lsst::jointcal::AstrometryModel::validate ( CcdImageList const &  ccdImageList,
int  ndof 
) const
inherited

Return true if this is a "reasonable" model.

Parameters
ccdImageListThe ccdImages to test the model validity on.
ndofThe number of degrees of freedom in the fit, e.g. from Fitterbase.computeChi2().
Returns
True if the model is valid on all ccdImages.

Definition at line 30 of file AstrometryModel.cc.

30  {
31  bool check = true;
32  if (ndof < 0) {
33  check &= false;
34  LOGLS_ERROR(_log, "This model only has "
35  << ndof << " degrees of freedom, with " << getTotalParameters()
36  << " total parameters. Reduce the model complexity (e.g. polynomial order)"
37  " to better match the number of measured sources.");
38  }
39  return check;
40 }
LOG_LOGGER _log
lsst.logging instance, to be created by a subclass so that messages have consistent name...
#define LOGLS_ERROR(logger, message)
Log a error-level message using an iostream-based interface.
Definition: Log.h:653
virtual std::size_t getTotalParameters() const =0
Return the total number of parameters in this model.

Member Data Documentation

◆ _log

LOG_LOGGER lsst::jointcal::AstrometryModel::_log
protectedinherited

lsst.logging instance, to be created by a subclass so that messages have consistent name.

Definition at line 107 of file AstrometryModel.h.


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