44 LOG_LOGGER _log =
LOG_GET(
"jointcal.ConstrainedAstrometryModel");
49 template <
typename KeyType,
typename ValueType>
53 for (
auto const &i : map) {
67 ConstrainedAstrometryModel::ConstrainedAstrometryModel(
69 int chipOrder,
int visitOrder)
70 : _sky2TP(projectionHandler) {
76 for (
auto &
ccdImage : ccdImageList) {
80 auto visitp = _visitMap.find(visit);
81 if (visitp == _visitMap.end()) {
84 auto chipp = _chipMap.find(chip);
85 if (chipp == _chipMap.end()) {
88 if (radius2 < minRadius2) {
90 constrainedChip = chip;
99 _chipMap[chip] = std::make_shared<SimplePolyMapping>(shiftAndNormalize,
100 pol * shiftAndNormalize.inverted());
105 _chipMap.at(constrainedChip)->setToBeFit(
false);
108 for (
auto &
ccdImage : ccdImageList) {
115 if (_chipMap.find(chip) == _chipMap.end()) {
116 LOGLS_WARN(_log,
"Chip " << chip <<
" is missing in the reference exposure, expect troubles.");
118 _chipMap[chip] = std::make_shared<SimplePolyMapping>(norm,
GtransfoPoly(chipOrder));
121 std::make_unique<TwoTransfoMapping>(_chipMap[chip], _visitMap[visit]);
123 LOGLS_INFO(_log,
"Got " << _chipMap.size() <<
" chip mappings and " << _visitMap.size()
124 <<
" visit mappings; holding chip " << constrainedChip <<
" fixed (" 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());
132 return findMapping(ccdImage);
140 unsigned index = firstIndex;
141 if (whatToFit.
find(
"Distortions") == std::string::npos) {
142 LOGLS_ERROR(_log,
"assignIndices was called and Distortions is *not* in whatToFit");
146 _fittingChips = (whatToFit.
find(
"DistortionsChip") != std::string::npos);
147 _fittingVisits = (whatToFit.
find(
"DistortionsVisit") != std::string::npos);
149 if ((!_fittingChips) && (!_fittingVisits)) {
150 _fittingChips = _fittingVisits =
true;
153 for (
auto &i : _chipMap) {
154 i.second->setIndex(index);
155 index += i.second->getNpar();
158 for (
auto &i : _visitMap) {
159 i.second->setIndex(index);
160 index += i.second->getNpar();
163 for (
auto &i : _mappings) {
164 i.second->setWhatToFit(_fittingChips, _fittingVisits);
171 for (
auto &i : _chipMap) {
172 auto mapping = i.second.get();
173 mapping->offsetParams(delta.segment(mapping->getIndex(), mapping->getNpar()));
176 for (
auto &i : _visitMap) {
177 auto mapping = i.second.get();
178 mapping->offsetParams(delta.segment(mapping->getIndex(), mapping->getNpar()));
183 for (
auto i = _visitMap.begin(); i != _visitMap.end(); ++i) i->second->freezeErrorTransform();
184 for (
auto i = _chipMap.begin(); i != _chipMap.end(); ++i) i->second->freezeErrorTransform();
188 auto chipp = _chipMap.find(chip);
189 if (chipp == _chipMap.end()) {
191 errMsg <<
"No such chipId: " << chip <<
" among ";
192 outputMapKeys(_chipMap, errMsg);
196 return chipp->second->getTransfo();
203 for (
auto i = _visitMap.begin(); i != _visitMap.end(); ++i) res.
push_back(i->first);
208 auto visitp = _visitMap.find(visit);
209 if (visitp == _visitMap.end()) {
211 errMsg <<
"No such visitId: " << visit <<
" among ";
212 outputMapKeys(_visitMap, errMsg);
216 return visitp->second->getTransfo();
221 for (
auto &i : _chipMap) {
222 total += i.second->getNpar();
224 for (
auto &i : _visitMap) {
225 total += i.second->getNpar();
245 afw::geom::Point2D(0, 0),
246 afw::geom::SpherePoint(tangentPoint.x, tangentPoint.y, afw::geom::degrees),
248 auto iwcToSkyMap = iwcToSkyWcs->getFrameDict()->getMapping(
"PIXELS",
"SKY");
249 auto skyFrame = iwcToSkyWcs->getFrameDict()->getFrame(
"SKY");
252 frameDict.
addFrame(
"PIXELS", *pixelsToFocal, focalFrame);
253 frameDict.
addFrame(
"FOCAL", *focalToIwc, iwcFrame);
254 frameDict.
addFrame(
"IWC", *iwcToSkyMap, *skyFrame);
255 return std::make_shared<afw::geom::SkyWcs>(frameDict);
259 auto i = _mappings.find(ccdImage.
getHashKey());
260 if (i == _mappings.end())
262 "ConstrainedAstrometryModel cannot find CcdImage " + ccdImage.
getName());
263 return i->second.get();
#define LOGLS_WARN(logger, message)
unsigned assignIndices(std::string const &whatToFit, unsigned firstIndex) override
Positions the various parameter sets into the parameter vector, starting at firstIndex.
VisitIdType getVisit() const
returns visit ID
implements the linear transformations (6 real coefficients).
const std::shared_ptr< Gtransfo const > getSky2TP(CcdImage const &ccdImage) const override
The mapping of sky coordinates (i.e.
std::string getName() const
Return the _name that identifies this ccdImage.
CameraSysPrefix const PIXELS
std::vector< VisitIdType > getVisits() const
Access to array of visits involved in the solution.
CcdIdType getCcdId() const
returns ccd ID
Gtransfo const & getVisitTransfo(VisitIdType const &visit) const
Access to mappings.
Polynomial transformation class.
GtransfoLin normalizeCoordinatesTransfo(const Frame &frame)
Returns the transformation that maps the input frame along both axes to [-1,1].
AstrometryMapping const * getMapping(CcdImage const &) const override
Mapping associated to a given CcdImage.
rectangle with sides parallel to axes.
#define LOGLS_DEBUG(logger, message)
Class for a simple mapping implementing a generic Gtransfo.
void addFrame(int iframe, Mapping const &map, Frame const &frame) override
std::shared_ptr< afw::geom::SkyWcs > makeSkyWcs(CcdImage const &ccdImage) const override
Make a SkyWcs that contains this model.
void freezeErrorTransform() override
From there on, measurement errors are propagated using the current transfos (and no longer evolve)...
T dynamic_pointer_cast(T... args)
Gtransfo const & getChipTransfo(CcdIdType const chip) const
Access to mappings.
#define LOGLS_INFO(logger, message)
#define LSST_EXCEPT(type,...)
void offsetParams(Eigen::VectorXd const &Delta) override
Dispaches the offsets after a fit step into the actual locations of parameters.
This one is the Tangent Plane (called gnomonic) projection (from celestial sphere to tangent plane) ...
int getTotalParameters() const override
Return the total number of parameters in this model.
a virtual (interface) class for geometric transformations.
std::shared_ptr< SkyWcs > makeSkyWcs(daf::base::PropertySet &metadata, bool strip=false)
Eigen::Matrix2d makeCdMatrix(lsst::geom::Angle const &scale, lsst::geom::Angle const &orientation=0 *lsst::geom::degrees, bool flipX=false)
virtual class needed in the abstraction of the distortion model
CcdImageKey getHashKey() const
std::shared_ptr< afw::cameraGeom::Detector > getDetector() const
Handler of an actual image from a single CCD.
CameraSys const FOCAL_PLANE
#define LOGLS_ERROR(logger, message)
Frame const & getImageFrame() const
Frame in pixels.