47template <
typename KeyType,
typename ValueType>
51 for (
auto const &i : map) {
67 int chipOrder,
int visitOrder)
69 _skyToTangentPlane(
std::
move(projectionHandler)) {
75 for (
auto &ccdImage : ccdImageList) {
79 auto visitp = _visitMap.find(visit);
80 if (visitp == _visitMap.end()) {
84 auto chipp = _chipMap.find(chip);
85 if (chipp == _chipMap.end()) {
86 auto center = ccdImage->getDetector()->getCenter(afw::cameraGeom::FOCAL_PLANE);
88 if (radius2 < minRadius2) {
90 constrainedChip = chip;
94 im.
getDetector()->getTransform(afw::cameraGeom::PIXELS, afw::cameraGeom::FOCAL_PLANE);
100 _chipMap[chip] = std::make_shared<SimplePolyMapping>(shiftAndNormalize,
101 pol * shiftAndNormalize.
inverted());
106 _chipMap.at(constrainedChip)->setToBeFit(
false);
109 for (
auto &ccdImage : ccdImageList) {
116 if (_chipMap.find(chip) == _chipMap.end()) {
117 LOGLS_WARN(
_log,
"Chip " << chip <<
" is missing in the reference exposure, expect troubles.");
122 _mappings[ccdImage->getHashKey()] =
123 std::make_unique<ChipVisitAstrometryMapping>(_chipMap[chip], _visitMap[visit]);
125 LOGLS_INFO(
_log,
"Got " << _chipMap.size() <<
" chip mappings and " << _visitMap.size()
126 <<
" visit mappings; holding chip " << constrainedChip <<
" fixed ("
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());
142 Eigen::Index firstIndex) {
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");
149 _fittingChips = (whatToFit.
find(
"DistortionsChip") != std::string::npos);
150 _fittingVisits = (whatToFit.
find(
"DistortionsVisit") != std::string::npos);
152 if ((!_fittingChips) && (!_fittingVisits)) {
153 _fittingChips = _fittingVisits =
true;
156 for (
auto &i : _chipMap) {
157 i.second->setIndex(index);
158 index += i.second->getNpar();
161 for (
auto &i : _visitMap) {
162 i.second->setIndex(index);
163 index += i.second->getNpar();
166 for (
auto &i : _mappings) {
167 i.second->setWhatToFit(_fittingChips, _fittingVisits);
174 for (
auto &i : _chipMap) {
175 auto mapping = i.second.get();
176 mapping->offsetParams(delta.segment(mapping->getIndex(), mapping->getNpar()));
179 for (
auto &i : _visitMap) {
180 auto mapping = i.second.get();
181 mapping->offsetParams(delta.segment(mapping->getIndex(), mapping->getNpar()));
186 for (
auto & i : _visitMap) i.second->freezeErrorTransform();
187 for (
auto & i : _chipMap) i.second->freezeErrorTransform();
191 auto chipp = _chipMap.find(chip);
192 if (chipp == _chipMap.end()) {
194 errMsg <<
"No such chipId: " << chip <<
" among ";
195 outputMapKeys(_chipMap, errMsg);
199 return chipp->second->getTransform();
206 for (
const auto & i : _visitMap) res.
push_back(i.first);
211 auto visitp = _visitMap.find(visit);
212 if (visitp == _visitMap.end()) {
214 errMsg <<
"No such visitId: " << visit <<
" among ";
215 outputMapKeys(_visitMap, errMsg);
219 return visitp->second->getTransform();
224 for (
auto &i : _chipMap) {
225 total += i.second->getNpar();
227 for (
auto &i : _visitMap) {
228 total += i.second->getNpar();
247 auto iwcToSkyWcs = afw::geom::makeSkyWcs(
250 auto iwcToSkyMap = iwcToSkyWcs->getFrameDict()->getMapping(
"PIXELS",
"SKY");
251 auto skyFrame = iwcToSkyWcs->getFrameDict()->getFrame(
"SKY");
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);
261 out <<
"Constrained Astrometry Model (" << _mappings.size() <<
" composite mappings; " << _chipMap.size()
262 <<
" sensor mappings, " << _visitMap.size() <<
" visit mappings):" <<
std::endl;
264 out <<
"Sensor to sky transforms:" <<
std::endl;
265 for (
auto &i : _mappings) {
272 auto i = _mappings.find(ccdImage.
getHashKey());
273 if (i == _mappings.end())
275 "ConstrainedAstrometryModel cannot find CcdImage " + ccdImage.
getName());
276 return i->second.get();
#define LSST_EXCEPT(type,...)
Create an exception with a given type.
LSST DM logging module built on log4cxx.
#define LOGLS_WARN(logger, message)
Log a warn-level message using an iostream-based interface.
#define LOG_GET(logger)
Returns a Log object associated with logger.
#define LOGLS_INFO(logger, message)
Log a info-level message using an iostream-based interface.
#define LOGLS_ERROR(logger, message)
Log a error-level message using an iostream-based interface.
#define LOGLS_DEBUG(logger, message)
Log a debug-level message using an iostream-based interface.
A FrameSet whose frames can be referenced by domain name.
void addFrame(int iframe, Mapping const &map, Frame const &frame) override
Add a new Frame and an associated Mapping to this FrameSet so as to define a new coordinate system,...
Frame is used to represent a coordinate system.
Point in an unspecified spherical coordinate system.
virtual class needed in the abstraction of the distortion model
Interface between AstrometryFit and the combinations of Mappings from pixels to some tangent plane (a...
LOG_LOGGER _log
lsst.logging instance, to be created by a subclass so that messages have consistent name.
Handler of an actual image from a single CCD.
CcdIdType getCcdId() const
returns ccd ID
std::shared_ptr< afw::cameraGeom::Detector > getDetector() const
VisitIdType getVisit() const
returns visit ID
Frame const & getImageFrame() const
Frame in pixels.
std::string getName() const
Return the _name that identifies this ccdImage.
CcdImageKey getHashKey() const
ConstrainedAstrometryModel(CcdImageList const &ccdImageList, std::shared_ptr< ProjectionHandler const > projectionHandler, int chipOrder, int visitOrder)
std::size_t getTotalParameters() const override
Return the total number of parameters in this model.
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).
void print(std::ostream &out) const override
Print a string representation of the contents of this mapping, for debugging.
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.
AstrometryMapping * findMapping(CcdImage const &ccdImage) const override
Return a pointer to the mapping associated with this ccdImage.
std::vector< VisitIdType > getVisits() const
Access to array of visits involved in the solution.
Eigen::Index assignIndices(std::string const &whatToFit, Eigen::Index firstIndex) override
Positions the various parameter sets into the parameter vector, starting at firstIndex.
std::shared_ptr< afw::geom::SkyWcs > makeSkyWcs(CcdImage const &ccdImage) const override
Make a SkyWcs that contains this model.
AstrometryMapping const * getMapping(CcdImage const &) const override
Mapping associated to a given CcdImage.
rectangle with sides parallel to axes.
Reports invalid arguments.
AngleUnit constexpr degrees
constant with units of degrees
AstrometryTransformLinear normalizeCoordinatesTransform(const Frame &frame)
Returns the transformation that maps the input frame along both axes to [-1,1].