46 template <
typename KeyType,
typename ValueType>
50 for (
auto const &i : map) {
64 ConstrainedAstrometryModel::ConstrainedAstrometryModel(
66 int chipOrder,
int visitOrder)
68 _skyToTangentPlane(projectionHandler) {
74 for (
auto &
ccdImage : ccdImageList) {
78 auto visitp = _visitMap.find(visit);
79 if (visitp == _visitMap.end()) {
83 auto chipp = _chipMap.find(chip);
84 if (chipp == _chipMap.end()) {
87 if (radius2 < minRadius2) {
89 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.");
122 std::make_unique<ChipVisitAstrometryMapping>(_chipMap[chip], _visitMap[visit]);
124 LOGLS_INFO(
_log,
"Got " << _chipMap.size() <<
" chip mappings and " << _visitMap.size()
125 <<
" visit mappings; holding chip " << constrainedChip <<
" fixed (" 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());
133 return findMapping(ccdImage);
142 Eigen::Index firstIndex
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");
150 _fittingChips = (whatToFit.
find(
"DistortionsChip") != std::string::npos);
151 _fittingVisits = (whatToFit.
find(
"DistortionsVisit") != std::string::npos);
153 if ((!_fittingChips) && (!_fittingVisits)) {
154 _fittingChips = _fittingVisits =
true;
157 for (
auto &i : _chipMap) {
158 i.second->setIndex(index);
159 index += i.second->getNpar();
162 for (
auto &i : _visitMap) {
163 i.second->setIndex(index);
164 index += i.second->getNpar();
167 for (
auto &i : _mappings) {
168 i.second->setWhatToFit(_fittingChips, _fittingVisits);
175 for (
auto &i : _chipMap) {
176 auto mapping = i.second.get();
177 mapping->offsetParams(delta.segment(mapping->getIndex(), mapping->getNpar()));
180 for (
auto &i : _visitMap) {
181 auto mapping = i.second.get();
182 mapping->offsetParams(delta.segment(mapping->getIndex(), mapping->getNpar()));
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();
192 auto chipp = _chipMap.find(chip);
193 if (chipp == _chipMap.end()) {
195 errMsg <<
"No such chipId: " << chip <<
" among ";
196 outputMapKeys(_chipMap, errMsg);
200 return chipp->second->getTransform();
207 for (
auto i = _visitMap.begin(); i != _visitMap.end(); ++i) res.
push_back(i->first);
212 auto visitp = _visitMap.find(visit);
213 if (visitp == _visitMap.end()) {
215 errMsg <<
"No such visitId: " << visit <<
" among ";
216 outputMapKeys(_visitMap, errMsg);
220 return visitp->second->getTransform();
225 for (
auto &i : _chipMap) {
226 total += i.second->getNpar();
228 for (
auto &i : _visitMap) {
229 total += i.second->getNpar();
252 auto iwcToSkyMap = iwcToSkyWcs->getFrameDict()->getMapping(
"PIXELS",
"SKY");
253 auto skyFrame = iwcToSkyWcs->getFrameDict()->getFrame(
"SKY");
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);
263 auto i = _mappings.find(ccdImage.
getHashKey());
264 if (i == _mappings.end())
266 "ConstrainedAstrometryModel cannot find CcdImage " + ccdImage.
getName());
267 return i->second.get();
#define LOGLS_WARN(logger, message)
AstrometryTransform const & getVisitTransform(VisitIdType const &visit) const
Access to mappings.
VisitIdType getVisit() const
returns visit ID
Eigen::Index assignIndices(std::string const &whatToFit, Eigen::Index firstIndex) override
Positions the various parameter sets into the parameter vector, starting at firstIndex.
LOG_LOGGER _log
lsst.logging instance, to be created by a subclass so that messages have consistent name...
std::string getName() const
Return the _name that identifies this ccdImage.
CameraSysPrefix const PIXELS
const std::shared_ptr< AstrometryTransform const > getSkyToTangentPlane(CcdImage const &ccdImage) const override
The mapping of sky coordinates (i.e.
Interface between AstrometryFit and the combinations of Mappings from pixels to some tangent plane (a...
std::vector< VisitIdType > getVisits() const
Access to array of visits involved in the solution.
std::size_t getTotalParameters() const override
Return the total number of parameters in this model.
CcdIdType getCcdId() const
returns ccd ID
AstrometryMapping const * getMapping(CcdImage const &) const override
Mapping associated to a given CcdImage.
rectangle with sides parallel to axes.
AstrometryTransformLinear normalizeCoordinatesTransform(const Frame &frame)
Returns the transformation that maps the input frame along both axes to [-1,1].
#define LOGLS_DEBUG(logger, message)
AngleUnit constexpr degrees
Class for a simple mapping implementing a generic AstrometryTransform.
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 transforms (and no longer evolve)...
This one is the Tangent Plane (called gnomonic) projection (from celestial sphere to tangent plane) ...
T dynamic_pointer_cast(T... args)
#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.
AstrometryTransform const & getChipTransform(CcdIdType const chip) const
Access to mappings.
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.