LSST Applications g0265f82a02+0e5473021a,g02d81e74bb+bd2ed33bd6,g1470d8bcf6+de7501a2e0,g14a832a312+ff425fae3c,g2079a07aa2+86d27d4dc4,g2305ad1205+91a32aca49,g295015adf3+762506a1ad,g2bbee38e9b+0e5473021a,g337abbeb29+0e5473021a,g3ddfee87b4+c34e8be1fa,g487adcacf7+5fae3daba8,g50ff169b8f+96c6868917,g52b1c1532d+585e252eca,g591dd9f2cf+ea1711114f,g5a732f18d5+53520f316c,g64a986408d+bd2ed33bd6,g858d7b2824+bd2ed33bd6,g8a8a8dda67+585e252eca,g99cad8db69+016a06b37a,g9ddcbc5298+9a081db1e4,ga1e77700b3+15fc3df1f7,ga8c6da7877+ef4e3a5875,gb0e22166c9+60f28cb32d,gb6a65358fc+0e5473021a,gba4ed39666+c2a2e4ac27,gbb8dafda3b+09e12c87ab,gc120e1dc64+bc2e06c061,gc28159a63d+0e5473021a,gcf0d15dbbd+c34e8be1fa,gdaeeff99f8+f9a426f77a,ge6526c86ff+508d0e0a30,ge79ae78c31+0e5473021a,gee10cc3b42+585e252eca,gf18bd8381d+8d59551888,gf1cff7945b+bd2ed33bd6,w.2024.16
LSST Data Management Base Package
Loading...
Searching...
No Matches
Public Member Functions | Protected Attributes | Private Member Functions | 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)
 
 ConstrainedAstrometryModel (ConstrainedAstrometryModel &&)=delete
 
ConstrainedAstrometryModeloperator= (ConstrainedAstrometryModel const &)=delete
 
ConstrainedAstrometryModeloperator= (ConstrainedAstrometryModel &&)=delete
 
AstrometryMapping const * getMapping (CcdImage const &) const override
 Mapping associated to a given CcdImage.
 
Eigen::Index assignIndices (std::string const &whatToFit, Eigen::Index firstIndex) override
 Positions the various parameter sets into the parameter vector, starting at firstIndex.
 
void offsetParams (Eigen::VectorXd const &Delta) override
 Dispaches the offsets after a fit step into the actual locations of parameters.
 
void freezeErrorTransform () override
 From there on, measurement errors are propagated using the current transforms (and no longer evolve).
 
std::size_t getTotalParameters () const override
 Return the total number of parameters in this model.
 
AstrometryTransform const & getChipTransform (CcdIdType chip) const
 Access to mappings.
 
AstrometryTransform const & getVisitTransform (VisitIdType const &visit) const
 Access to mappings.
 
std::vector< VisitIdTypegetVisits () const
 Access to array of visits involved in the solution.
 
const std::shared_ptr< AstrometryTransform const > getSkyToTangentPlane (CcdImage const &ccdImage) const override
 The mapping of sky coordinates (i.e.
 
std::shared_ptr< afw::geom::SkyWcsmakeSkyWcs (CcdImage const &ccdImage) const override
 Make a SkyWcs that contains this model.
 
void print (std::ostream &out) const override
 Print a string representation of the contents of this mapping, for debugging.
 
std::size_t getNpar (CcdImage const &ccdImage) const
 Return the number of parameters in the mapping of CcdImage.
 
bool validate (CcdImageList const &ccdImageList, int ndof) const
 Return true if this is a "reasonable" model.
 

Protected Attributes

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

Private Member Functions

AstrometryMappingfindMapping (CcdImage const &ccdImage) const override
 Return a pointer to the mapping associated with this ccdImage.
 

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

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

◆ 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 141 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}
#define LOGLS_ERROR(logger, message)
Log a error-level message using an iostream-based interface.
Definition Log.h:679

◆ findMapping()

AstrometryMapping * lsst::jointcal::ConstrainedAstrometryModel::findMapping ( CcdImage const & ccdImage) const
overrideprivatevirtual

Return a pointer to the mapping associated with this ccdImage.

Implements lsst::jointcal::AstrometryModel.

Definition at line 271 of file ConstrainedAstrometryModel.cc.

271 {
272 auto i = _mappings.find(ccdImage.getHashKey());
273 if (i == _mappings.end())
274 throw LSST_EXCEPT(pex::exceptions::InvalidParameterError,
275 "ConstrainedAstrometryModel cannot find CcdImage " + ccdImage.getName());
276 return i->second.get();
277}
#define LSST_EXCEPT(type,...)
Create an exception with a given type.
Definition Exception.h:48

◆ 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) i.second->freezeErrorTransform();
187 for (auto & i : _chipMap) i.second->freezeErrorTransform();
188}
void freezeErrorTransform() override
From there on, measurement errors are propagated using the current transforms (and no longer evolve).

◆ getChipTransform()

const AstrometryTransform & lsst::jointcal::ConstrainedAstrometryModel::getChipTransform ( CcdIdType 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);
198 }
199 return chipp->second->getTransform();
200}
Reports invalid arguments.
Definition Runtime.h:66
T endl(T... args)
T str(T... args)

◆ getMapping()

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

Mapping associated to a given CcdImage.

Implements lsst::jointcal::AstrometryModel.

Definition at line 133 of file ConstrainedAstrometryModel.cc.

133 {
134 return findMapping(ccdImage);
135}
AstrometryMapping * findMapping(CcdImage const &ccdImage) const override
Return a pointer to the mapping associated with this ccdImage.

◆ 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 56 of file AstrometryModel.h.

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

◆ 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 (const auto & i : _visitMap) res.push_back(i.first);
207 return res;
208}
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);
218 }
219 return visitp->second->getTransform();
220}

◆ 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 geom::Point2D(0, 0), geom::SpherePoint(tangentPoint.x, tangentPoint.y, geom::degrees),
250 auto iwcToSkyMap = iwcToSkyWcs->getFrameDict()->getMapping("PIXELS", "SKY");
251 auto skyFrame = iwcToSkyWcs->getFrameDict()->getFrame("SKY");
252
253 ast::FrameDict frameDict(pixelFrame);
254 frameDict.addFrame("PIXELS", *pixelsToFocal, focalFrame);
255 frameDict.addFrame("FOCAL", *focalToIwc, iwcFrame);
256 frameDict.addFrame("IWC", *iwcToSkyMap, *skyFrame);
257 return std::make_shared<afw::geom::SkyWcs>(frameDict);
258}
A FrameSet whose frames can be referenced by domain name.
Definition FrameDict.h:67
Frame is used to represent a coordinate system.
Definition Frame.h:157
Point in an unspecified spherical coordinate system.
Definition SpherePoint.h:57
virtual void apply(double xIn, double yIn, double &xOut, double &yOut) const =0
virtual std::shared_ptr< ast::Mapping > toAstMap(jointcal::Frame const &domain) const
Create an equivalent AST mapping for this transformation, including an analytic inverse if possible.
AstrometryTransform const & getVisitTransform(VisitIdType const &visit) const
Access to mappings.
AstrometryTransform const & getChipTransform(CcdIdType chip) const
Access to mappings.
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
A point in a plane.
Definition Point.h:37
std::shared_ptr< SkyWcs > makeSkyWcs(daf::base::PropertySet &metadata, bool strip=false)
Construct a SkyWcs from FITS keywords.
Definition SkyWcs.cc:521
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:133
AngleUnit constexpr degrees
constant with units of degrees
Definition Angle.h:110

◆ 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 && )
delete

◆ operator=() [2/2]

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

◆ print()

void lsst::jointcal::ConstrainedAstrometryModel::print ( std::ostream & out) const
overridevirtual

Print a string representation of the contents of this mapping, for debugging.

This string representation can be very verbose, as it contains all of the parameters of all of the transforms in this model.

Implements lsst::jointcal::AstrometryModel.

Definition at line 260 of file ConstrainedAstrometryModel.cc.

260 {
261 out << "Constrained Astrometry Model (" << _mappings.size() << " composite mappings; " << _chipMap.size()
262 << " sensor mappings, " << _visitMap.size() << " visit mappings):" << std::endl;
263 out << *_skyToTangentPlane << std::endl;
264 out << "Sensor to sky transforms:" << std::endl;
265 for (auto &i : _mappings) {
266 out << i.first << std::endl;
267 out << *(i.second) << std::endl;
268 }
269}

◆ 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}
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 117 of file AstrometryModel.h.


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