LSSTApplications  18.0.0+106,18.0.0+50,19.0.0,19.0.0+1,19.0.0+10,19.0.0+11,19.0.0+13,19.0.0+17,19.0.0+2,19.0.0-1-g20d9b18+6,19.0.0-1-g425ff20,19.0.0-1-g5549ca4,19.0.0-1-g580fafe+6,19.0.0-1-g6fe20d0+1,19.0.0-1-g7011481+9,19.0.0-1-g8c57eb9+6,19.0.0-1-gb5175dc+11,19.0.0-1-gdc0e4a7+9,19.0.0-1-ge272bc4+6,19.0.0-1-ge3aa853,19.0.0-10-g448f008b,19.0.0-12-g6990b2c,19.0.0-2-g0d9f9cd+11,19.0.0-2-g3d9e4fb2+11,19.0.0-2-g5037de4,19.0.0-2-gb96a1c4+3,19.0.0-2-gd955cfd+15,19.0.0-3-g2d13df8,19.0.0-3-g6f3c7dc,19.0.0-4-g725f80e+11,19.0.0-4-ga671dab3b+1,19.0.0-4-gad373c5+3,19.0.0-5-ga2acb9c+2,19.0.0-5-gfe96e6c+2,w.2020.01
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 64 of file ConstrainedAstrometryModel.cc.

67  : AstrometryModel(LOG_GET("jointcal.ConstrainedAstrometryModel")),
68  _skyToTangentPlane(projectionHandler) {
69  // keep track of which chip we want to hold fixed (the one closest to the middle of the focal plane)
70  double minRadius2 = std::numeric_limits<double>::infinity();
71  CcdIdType constrainedChip = -1;
72 
73  // first loop to initialize all visit and chip transforms.
74  for (auto &ccdImage : ccdImageList) {
75  const CcdImage &im = *ccdImage;
76  auto visit = im.getVisit();
77  auto chip = im.getCcdId();
78  auto visitp = _visitMap.find(visit);
79  if (visitp == _visitMap.end()) {
80  _visitMap[visit] = std::make_shared<SimplePolyMapping>(AstrometryTransformLinear(),
81  AstrometryTransformPolynomial(visitOrder));
82  }
83  auto chipp = _chipMap.find(chip);
84  if (chipp == _chipMap.end()) {
85  auto center = ccdImage->getDetector()->getCenter(afw::cameraGeom::FOCAL_PLANE);
86  double radius2 = std::pow(center.getX(), 2) + std::pow(center.getY(), 2);
87  if (radius2 < minRadius2) {
88  minRadius2 = radius2;
89  constrainedChip = chip;
90  }
91 
92  auto pixelsToFocal =
93  im.getDetector()->getTransform(afw::cameraGeom::PIXELS, afw::cameraGeom::FOCAL_PLANE);
94  Frame const &frame = im.getImageFrame();
95  // construct the chip transform by approximating the pixel->Focal afw::geom::Transform.
96  AstrometryTransformPolynomial pol =
97  AstrometryTransformPolynomial(pixelsToFocal, frame, chipOrder);
98  AstrometryTransformLinear shiftAndNormalize = normalizeCoordinatesTransform(frame);
99  _chipMap[chip] = std::make_shared<SimplePolyMapping>(shiftAndNormalize,
100  pol * shiftAndNormalize.inverted());
101  }
102  }
103 
104  // Hold the "central" chip map fixed and don't fit it, to remove a degeneracy.
105  _chipMap.at(constrainedChip)->setToBeFit(false);
106 
107  // now, second loop to set the mappings of the CCdImages
108  for (auto &ccdImage : ccdImageList) {
109  const CcdImage &im = *ccdImage;
110  auto visit = im.getVisit();
111  auto chip = im.getCcdId();
112 
113  // check that the chip_indexed part was indeed assigned
114  // (i.e. the reference visit was complete)
115  if (_chipMap.find(chip) == _chipMap.end()) {
116  LOGLS_WARN(_log, "Chip " << chip << " is missing in the reference exposure, expect troubles.");
117  AstrometryTransformLinear norm = normalizeCoordinatesTransform(im.getImageFrame());
118  _chipMap[chip] =
119  std::make_shared<SimplePolyMapping>(norm, AstrometryTransformPolynomial(chipOrder));
120  }
121  _mappings[ccdImage->getHashKey()] =
122  std::make_unique<ChipVisitAstrometryMapping>(_chipMap[chip], _visitMap[visit]);
123  }
124  LOGLS_INFO(_log, "Got " << _chipMap.size() << " chip mappings and " << _visitMap.size()
125  << " visit mappings; holding chip " << constrainedChip << " fixed ("
126  << getTotalParameters() << " total parameters).");
127  LOGLS_DEBUG(_log, "CcdImage map has " << _mappings.size() << " mappings, with "
128  << _mappings.bucket_count() << " buckets and a load factor of "
129  << _mappings.load_factor());
130 }
#define LOGLS_WARN(logger, message)
Log a warn-level message using an iostream-based interface.
Definition: Log.h:648
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:608
T infinity(T... args)
#define LOGLS_INFO(logger, message)
Log a info-level message using an iostream-based interface.
Definition: Log.h:628
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 140 of file ConstrainedAstrometryModel.cc.

143  {
144  Eigen::Index index = firstIndex;
145  if (whatToFit.find("Distortions") == std::string::npos) {
146  LOGLS_ERROR(_log, "assignIndices was called and Distortions is *not* in whatToFit");
147  return 0;
148  }
149  // if we get here "Distortions" is in whatToFit
150  _fittingChips = (whatToFit.find("DistortionsChip") != std::string::npos);
151  _fittingVisits = (whatToFit.find("DistortionsVisit") != std::string::npos);
152  // If nothing more than "Distortions" is specified, it means all:
153  if ((!_fittingChips) && (!_fittingVisits)) {
154  _fittingChips = _fittingVisits = true;
155  }
156  if (_fittingChips)
157  for (auto &i : _chipMap) {
158  i.second->setIndex(index);
159  index += i.second->getNpar();
160  }
161  if (_fittingVisits)
162  for (auto &i : _visitMap) {
163  i.second->setIndex(index);
164  index += i.second->getNpar();
165  }
166  // Tell the mappings which derivatives they will have to fill:
167  for (auto &i : _mappings) {
168  i.second->setWhatToFit(_fittingChips, _fittingVisits);
169  }
170  return index;
171 }
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:668

◆ 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 186 of file ConstrainedAstrometryModel.cc.

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

◆ getChipTransform()

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

Access to mappings.

Definition at line 191 of file ConstrainedAstrometryModel.cc.

191  {
192  auto chipp = _chipMap.find(chip);
193  if (chipp == _chipMap.end()) {
194  std::stringstream errMsg;
195  errMsg << "No such chipId: " << chip << " among ";
196  outputMapKeys(_chipMap, errMsg);
197  std::cout << std::endl;
198  throw pexExcept::InvalidParameterError(errMsg.str());
199  }
200  return chipp->second->getTransform();
201 }
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 132 of file ConstrainedAstrometryModel.cc.

132  {
133  return findMapping(ccdImage);
134 }

◆ 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 223 of file ConstrainedAstrometryModel.cc.

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

◆ getVisits()

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

Access to array of visits involved in the solution.

Definition at line 204 of file ConstrainedAstrometryModel.cc.

204  {
206  res.reserve(_visitMap.size());
207  for (auto i = _visitMap.begin(); i != _visitMap.end(); ++i) res.push_back(i->first);
208  return res;
209 }
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 211 of file ConstrainedAstrometryModel.cc.

211  {
212  auto visitp = _visitMap.find(visit);
213  if (visitp == _visitMap.end()) {
214  std::stringstream errMsg;
215  errMsg << "No such visitId: " << visit << " among ";
216  outputMapKeys(_visitMap, errMsg);
217  std::cout << std::endl;
218  throw pexExcept::InvalidParameterError(errMsg.str());
219  }
220  return visitp->second->getTransform();
221 }
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 234 of file ConstrainedAstrometryModel.cc.

234  {
235  auto proj = std::dynamic_pointer_cast<const TanRaDecToPixel>(getSkyToTangentPlane(ccdImage));
236  jointcal::Point tangentPoint(proj->getTangentPoint());
237 
238  auto imageFrame = ccdImage.getImageFrame();
239  auto pixelsToFocal = getChipTransform(ccdImage.getCcdId()).toAstMap(imageFrame);
240  jointcal::Frame focalBox = getChipTransform(ccdImage.getCcdId()).apply(imageFrame, false);
241  auto focalToIwc = getVisitTransform(ccdImage.getVisit()).toAstMap(focalBox);
242 
243  ast::Frame pixelFrame(2, "Domain=PIXELS");
244  ast::Frame focalFrame(2, "Domain=FOCAL");
245  ast::Frame iwcFrame(2, "Domain=IWC");
246 
247  // make a basic SkyWcs and extract the IWC portion
248  auto iwcToSkyWcs = afw::geom::makeSkyWcs(
249  geom::Point2D(0, 0),
250  geom::SpherePoint(tangentPoint.x, tangentPoint.y, geom::degrees),
252  auto iwcToSkyMap = iwcToSkyWcs->getFrameDict()->getMapping("PIXELS", "SKY");
253  auto skyFrame = iwcToSkyWcs->getFrameDict()->getFrame("SKY");
254 
255  ast::FrameDict frameDict(pixelFrame);
256  frameDict.addFrame("PIXELS", *pixelsToFocal, focalFrame);
257  frameDict.addFrame("FOCAL", *focalToIwc, iwcFrame);
258  frameDict.addFrame("IWC", *iwcToSkyMap, *skyFrame);
259  return std::make_shared<afw::geom::SkyWcs>(frameDict);
260 }
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.
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)
Point in an unspecified spherical coordinate system.
Definition: SpherePoint.h:57
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:506
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:138
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 173 of file ConstrainedAstrometryModel.cc.

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

◆ 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:668
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: