1 #include "lsst/log/Log.h"
10 #include "lsst/pex/exceptions.h"
11 namespace pexExcept = lsst::pex::exceptions;
17 LOG_LOGGER _log = LOG_GET(
"jointcal.ConstrainedPolyModel");
30 static int DistortionDegree = 3;
37 : _sky2TP(projectionHandler)
41 unsigned degree = DistortionDegree;
43 for (
auto &ccdImage : ccdImageList) {
47 auto visitp = _visitMap.find(visit);
48 if (visitp == _visitMap.end()) {
49 if (_visitMap.size() == 0) {
53 _visitMap[visit] = std::unique_ptr<SimpleGtransfoMapping>(
57 auto chipp = _chipMap.find(chip);
58 if (chipp == _chipMap.end()) {
65 _chipMap[chip] = std::unique_ptr<SimplePolyMapping>(
70 for (
auto &ccdImage : ccdImageList) {
76 if (_chipMap.find(chip) == _chipMap.end()) {
77 LOGLS_WARN(_log,
"Chip " << chip <<
" is missing in the reference exposure, expect troubles.");
82 _mappings[&im] = std::unique_ptr<TwoTransfoMapping>(
85 LOGLS_INFO(_log,
"Constructor got " << _chipMap.size() <<
" chip mappings and " << _visitMap.size()
86 <<
" visit mappings.");
88 for (
auto i = _visitMap.begin(); i != _visitMap.end(); ++i) LOGLS_DEBUG(_log, i->first);
92 mappingMapType::const_iterator i = _mappings.find(&ccdImage);
93 if (i == _mappings.end())
return nullptr;
94 return (i->second.get());
102 unsigned index = firstIndex;
103 if (whatToFit.find(
"Distortions") == std::string::npos) {
104 LOGLS_ERROR(_log,
"assignIndices was called and Distortions is *not* in whatToFit");
108 _fittingChips = (whatToFit.find(
"DistortionsChip") != std::string::npos);
109 _fittingVisits = (whatToFit.find(
"DistortionsVisit") != std::string::npos);
111 if ((!_fittingChips) && (!_fittingVisits)) {
112 _fittingChips = _fittingVisits =
true;
115 for (
auto &i : _chipMap) {
116 i.second->setIndex(index);
117 index += i.second->getNpar();
120 for (
auto &i : _visitMap) {
121 i.second->setIndex(index);
122 index += i.second->getNpar();
125 for (
auto &i : _mappings) {
126 i.second->setWhatToFit(_fittingChips, _fittingVisits);
133 for (
auto i = _chipMap.begin(); i != _chipMap.end(); ++i) {
134 auto *p = (&*(i->second));
136 p->offsetParams(&delta(p->getIndex()));
139 for (
auto i = _visitMap.begin(); i != _visitMap.end(); ++i) {
140 auto *p = (&*(i->second));
142 p->offsetParams(&delta(p->getIndex()));
147 for (
auto i = _visitMap.begin(); i != _visitMap.end(); ++i) i->second->freezeErrorScales();
148 for (
auto i = _chipMap.begin(); i != _chipMap.end(); ++i) i->second->freezeErrorScales();
152 auto chipp = _chipMap.find(chip);
153 if (chipp == _chipMap.end()) {
154 std::stringstream errMsg;
155 errMsg <<
"No such chipId: '" << chip <<
"' found in chipMap of: " <<
this;
156 throw pexExcept::InvalidParameterError(errMsg.str());
158 return chipp->second->getTransfo();
163 std::vector<VisitIdType> res;
164 res.reserve(_visitMap.size());
165 for (
auto i = _visitMap.begin(); i != _visitMap.end(); ++i) res.push_back(i->first);
170 auto visitp = _visitMap.find(visit);
171 if (visitp == _visitMap.end()) {
172 std::stringstream errMsg;
173 errMsg <<
"No such visitId: '" << visit <<
"' found in visitMap of: " <<
this;
174 throw pexExcept::InvalidParameterError(errMsg.str());
176 return visitp->second->getTransfo();
182 mapping = _mappings.at(&ccdImage).get();
183 }
catch (std::out_of_range &) {
184 LOGLS_ERROR(_log,
"CcdImage with ccd/visit " << ccdImage.
getCcdId() <<
"/" << ccdImage.
getVisit()
185 <<
" not found in constrainedPolyModel mapping list.");
186 std::ostringstream os;
187 for (
auto const &i : _mappings) os << i.first <<
",";
188 LOGLS_ERROR(_log,
"Available CcdImages: " << os.str());
198 LOGLS_ERROR(_log,
"Problem with transform 1 of ccd/visit " << ccdImage.
getCcdId() <<
"/"
208 }
catch (std::bad_cast &) {
211 pix2Tp = t1 * t2_poly;
212 }
catch (std::bad_cast &) {
213 LOGLS_ERROR(_log,
"Problem with transform 2 of ccd/visit " << ccdImage.
getCcdId() <<
"/"
221 LOGLS_ERROR(_log,
"Problem with projection of ccd/visit " << ccdImage.
getCcdId() <<
"/"
222 << ccdImage.
getVisit() <<
": projection "
237 return std::make_shared<TanSipPix2RaDec>(cdStuff, tangentPoint, &sip);
implements the linear transformations (6 real coefficients).
GtransfoLin getLinPart() const
The Linear part (corresponding to CD's and CRPIX's)
ConstrainedPolyModel(CcdImageList const &ccdImageList, ProjectionHandler const *projectionHandler, bool initFromWCS, unsigned nNotFit=0)
void offsetParams(Eigen::VectorXd const &Delta)
Dispaches the offsets after a fit step into the actual locations of parameters.
virtual class needed in the abstraction of the distortion model
Gtransfo const & getTransfo1() const
access to transfos
Gtransfo const & getChipTransfo(CcdIdType const chip) const
Access to mappings.
Mapping implementation for a polynomial transformation.
virtual GtransfoLin linearApproximation(const Point &where, const double step=0.01) const
linear (local) approximation.
Point getTangentPoint() const
tangent point coordinates (in degrees)
Gtransfo const & getTransfo2() const
access to transfos
Gtransfo const * getPix2CommonTangentPlane() const
The mapping with two transfos in a row.
Polynomial transformation class.
GtransfoLin normalizeCoordinatesTransfo(const Frame &frame)
Returns the transformation that maps the input frame along both axes to [-1,1].
const Gtransfo * getSky2TP(CcdImage const &ccdImage) const
The mapping of sky coordinates (i.e.
Gtransfo const * getPix2TangentPlane() const
rectangle with sides parallel to axes.
std::vector< VisitIdType > getVisits() const
Access to array of visits involved in the solution.
std::shared_ptr< TanSipPix2RaDec > produceSipWcs(CcdImage const &ccdImage) const
Cook up a SIP WCS.
This is a virtual class that allows a lot of freedom in the choice of the projection from "Sky" (wher...
A do-nothing transformation. It anyway has dummy routines to mimick a Gtransfo.
This one is the Tangent Plane (called gnomonic) projection (from celestial sphere to tangent plane) ...
a virtual (interface) class for geometric transformations.
Point getCenter() const
Center of the frame.
Gtransfo const & getVisitTransfo(VisitIdType const &visit) const
Access to mappings.
std::list< std::shared_ptr< CcdImage > > CcdImageList
Frame applyTransfo(const Frame &inputframe, const Gtransfo >ransfo, const WhichTransformed which)
Transform a Frame through a Transfo.
Mapping const * getMapping(CcdImage const &) const
Mapping associated to a given CcdImage.
unsigned assignIndices(unsigned firstIndex, std::string const &whatToFit)
Positions the various parameter sets into the parameter vector, starting at firstIndex.
Handler of an actual image from a single CCD.
GtransfoLin invert() const
returns the inverse: T1 = T2.invert();
Frame const & getImageFrame() const
Frame in pixels.
VisitIdType getVisit() const
returns visit ID
int getCcdId() const
returns ccd ID
void freezeErrorScales()
From there on, measurement errors are propagated using the current transfos (and no longer evolve)...