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;
34 ConstrainedPolyModel::ConstrainedPolyModel(
CcdImageList const &ccdImageList,
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) {
134 auto mapping = i.second.get();
135 mapping->offsetParams(delta.segment(mapping->getIndex(), mapping->getNpar()));
138 for (
auto &i : _visitMap) {
139 auto mapping = i.second.get();
140 mapping->offsetParams(delta.segment(mapping->getIndex(), mapping->getNpar()));
145 for (
auto i = _visitMap.begin(); i != _visitMap.end(); ++i) i->second->freezeErrorScales();
146 for (
auto i = _chipMap.begin(); i != _chipMap.end(); ++i) i->second->freezeErrorScales();
150 auto chipp = _chipMap.find(chip);
151 if (chipp == _chipMap.end()) {
152 std::stringstream errMsg;
153 errMsg <<
"No such chipId: '" << chip <<
"' found in chipMap of: " <<
this;
154 throw pexExcept::InvalidParameterError(errMsg.str());
156 return chipp->second->getTransfo();
161 std::vector<VisitIdType> res;
162 res.reserve(_visitMap.size());
163 for (
auto i = _visitMap.begin(); i != _visitMap.end(); ++i) res.push_back(i->first);
168 auto visitp = _visitMap.find(visit);
169 if (visitp == _visitMap.end()) {
170 std::stringstream errMsg;
171 errMsg <<
"No such visitId: '" << visit <<
"' found in visitMap of: " <<
this;
172 throw pexExcept::InvalidParameterError(errMsg.str());
174 return visitp->second->getTransfo();
180 mapping = _mappings.at(&ccdImage).get();
181 }
catch (std::out_of_range &) {
182 LOGLS_ERROR(_log,
"CcdImage with ccd/visit " << ccdImage.
getCcdId() <<
"/" << ccdImage.
getVisit()
183 <<
" not found in constrainedPolyModel mapping list.");
184 std::ostringstream os;
185 for (
auto const &i : _mappings) os << i.first <<
",";
186 LOGLS_ERROR(_log,
"Available CcdImages: " << os.str());
196 LOGLS_ERROR(_log,
"Problem with transform 1 of ccd/visit " << ccdImage.
getCcdId() <<
"/" 206 }
catch (std::bad_cast &) {
209 pix2Tp = t1 * t2_poly;
210 }
catch (std::bad_cast &) {
211 LOGLS_ERROR(_log,
"Problem with transform 2 of ccd/visit " << ccdImage.
getCcdId() <<
"/" 219 LOGLS_ERROR(_log,
"Problem with projection of ccd/visit " << ccdImage.
getCcdId() <<
"/" 220 << ccdImage.
getVisit() <<
": projection " 235 return std::make_shared<TanSipPix2RaDec>(cdStuff, tangentPoint, &sip);
VisitIdType getVisit() const
returns visit ID
implements the linear transformations (6 real coefficients).
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
GtransfoLin invert() const
returns the inverse: T1 = T2.invert();
Mapping implementation for a polynomial transformation.
Gtransfo const * getPix2CommonTangentPlane() const
Gtransfo const & getVisitTransfo(VisitIdType const &visit) const
Access to mappings.
CcdIdType getCcdId() const
returns ccd ID
The mapping with two transfos in a row.
Gtransfo const * getPix2TangentPlane() const
Polynomial transformation class.
GtransfoLin normalizeCoordinatesTransfo(const Frame &frame)
Returns the transformation that maps the input frame along both axes to [-1,1].
rectangle with sides parallel to axes.
Class for a simple mapping implementing a generic Gtransfo.
std::shared_ptr< TanSipPix2RaDec > produceSipWcs(CcdImage const &ccdImage) const
Cook up a SIP WCS.
Point getTangentPoint() const
tangent point coordinates (in degrees)
This is a virtual class that allows a lot of freedom in the choice of the projection from "Sky" (wher...
Point getCenter() const
Center of the frame.
A do-nothing transformation. It anyway has dummy routines to mimick a Gtransfo.
virtual GtransfoLin linearApproximation(const Point &where, const double step=0.01) const
linear (local) approximation.
std::vector< VisitIdType > getVisits() const
Access to array of visits involved in the solution.
This one is the Tangent Plane (called gnomonic) projection (from celestial sphere to tangent plane) ...
GtransfoLin getLinPart() const
The Linear part (corresponding to CD's and CRPIX's)
a virtual (interface) class for geometric transformations.
Mapping const * getMapping(CcdImage const &) const
Mapping associated to a given CcdImage.
const Gtransfo * getSky2TP(CcdImage const &ccdImage) const
The mapping of sky coordinates (i.e.
std::list< std::shared_ptr< CcdImage > > CcdImageList
Frame applyTransfo(const Frame &inputframe, const Gtransfo >ransfo, const WhichTransformed which)
Transform a Frame through a Transfo.
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.
Gtransfo const & getTransfo1() const
access to transfos
Gtransfo const & getTransfo2() const
access to transfos
Frame const & getImageFrame() const
Frame in pixels.
void freezeErrorScales()
From there on, measurement errors are propagated using the current transfos (and no longer evolve)...
Gtransfo const & getChipTransfo(CcdIdType const chip) const
Access to mappings.