LSSTApplications  11.0-24-g0a022a1,15.0+8,15.0+9,15.0-1-g19261fa+1,15.0-1-g1eca518+10,15.0-1-g60afb23+8,15.0-1-g615e0bb,15.0-1-g6668b0b+5,15.0-1-g788a293+8,15.0-1-ga91101e+8,15.0-1-gae1598d+7,15.0-1-gc45031d+10,15.0-1-gd076f1f+8,15.0-1-gdf18595+1,15.0-1-gf4f1c34+7,15.0-18-g5f205baaa,15.0-2-g100d730+1,15.0-2-g18f3f21,15.0-2-g35685a8+1,15.0-2-g947dc0d+10,15.0-2-ge3d7f4b+1,15.0-2-gf38729e,15.0-3-g150fc43+9,15.0-3-g6f085af+1,15.0-3-g9103c06+7,15.0-3-ga03b4ca+10,15.0-3-gaec6799+5,15.0-3-gb7a597c+8,15.0-3-ge6a6747,15.0-4-g45f767a+7,15.0-4-g654b129+6,15.0-4-gff20472+11,15.0-5-g389937dc+6,15.0-5-ga70c291+1,15.0-6-gbad5ef12+1,15.0-6-ge2d9597+10
LSSTDataManagementBasePackage
Public Member Functions | List of all members
lsst::jointcal::ConstrainedPolyModel Class Reference

This is the model used to fit mappings as the combination of a transformation depending on the chip number (instrument model) and a transformation per visit (anamorphism). More...

#include <ConstrainedPolyModel.h>

Inheritance diagram for lsst::jointcal::ConstrainedPolyModel:
lsst::jointcal::AstrometryModel

Public Member Functions

 ConstrainedPolyModel (CcdImageList const &ccdImageList, ProjectionHandler const *projectionHandler, bool initFromWCS, unsigned nNotFit=0, int chipDegree=3, int visitDegree=2)
 
 ConstrainedPolyModel (ConstrainedPolyModel const &)=delete
 No copy or move: there is only ever one instance of a given model (i.e. per ccd+visit) More...
 
 ConstrainedPolyModel (ConstrainedPolyModel &&)=delete
 
ConstrainedPolyModeloperator= (ConstrainedPolyModel const &)=delete
 
ConstrainedPolyModeloperator= (ConstrainedPolyModel &&)=delete
 
Mapping const * getMapping (CcdImage const &) const
 Mapping associated to a given CcdImage. More...
 
unsigned assignIndices (unsigned firstIndex, std::string const &whatToFit)
 Positions the various parameter sets into the parameter vector, starting at firstIndex. More...
 
void offsetParams (Eigen::VectorXd const &Delta)
 Dispaches the offsets after a fit step into the actual locations of parameters. More...
 
void freezeErrorTransform ()
 From there on, measurement errors are propagated using the current transfos (and no longer evolve). More...
 
Gtransfo const & getChipTransfo (CcdIdType const chip) const
 Access to mappings. More...
 
Gtransfo const & getVisitTransfo (VisitIdType const &visit) const
 Access to mappings. More...
 
std::vector< VisitIdTypegetVisits () const
 Access to array of visits involved in the solution. More...
 
const GtransfogetSky2TP (CcdImage const &ccdImage) const
 The mapping of sky coordinates (i.e. More...
 
std::shared_ptr< TanSipPix2RaDecproduceSipWcs (CcdImage const &ccdImage) const
 Cook up a SIP WCS. More...
 

Detailed Description

This is the model used to fit mappings as the combination of a transformation depending on the chip number (instrument model) and a transformation per visit (anamorphism).

The two-transformation Mapping required for this model is TwoTransfoMapping. This modeling of distortions is meant for a set of images from a single mosaic imager.

Definition at line 31 of file ConstrainedPolyModel.h.

Constructor & Destructor Documentation

◆ ConstrainedPolyModel() [1/3]

lsst::jointcal::ConstrainedPolyModel::ConstrainedPolyModel ( CcdImageList const &  ccdImageList,
ProjectionHandler const *  projectionHandler,
bool  initFromWCS,
unsigned  nNotFit = 0,
int  chipDegree = 3,
int  visitDegree = 2 
)

Definition at line 30 of file ConstrainedPolyModel.cc.

33  : _sky2TP(projectionHandler)
34 
35 {
36  // first loop to initialize all visit and chip transfos.
37  for (auto &ccdImage : ccdImageList) {
38  const CcdImage &im = *ccdImage;
39  auto visit = im.getVisit();
40  auto chip = im.getCcdId();
41  auto visitp = _visitMap.find(visit);
42  if (visitp == _visitMap.end()) {
43  if (_visitMap.size() == 0) {
44  _visitMap[visit] =
45  std::unique_ptr<SimpleGtransfoMapping>(new SimpleGtransfoMapping(GtransfoIdentity()));
46  } else {
47  _visitMap[visit] = std::unique_ptr<SimpleGtransfoMapping>(
48  new SimplePolyMapping(GtransfoLin(), GtransfoPoly(visitDegree)));
49  }
50  }
51  auto chipp = _chipMap.find(chip);
52  if (chipp == _chipMap.end()) {
53  const Frame &frame = im.getImageFrame();
54 
55  GtransfoPoly pol(chipDegree);
56 
57  if (initFromWCS) {
58  pol = GtransfoPoly(im.getPix2TangentPlane(), frame, chipDegree);
59  }
60  GtransfoLin shiftAndNormalize = normalizeCoordinatesTransfo(frame);
61 
62  _chipMap[chip] = std::unique_ptr<SimplePolyMapping>(
63  new SimplePolyMapping(shiftAndNormalize, pol * shiftAndNormalize.invert()));
64  }
65  }
66  // now, second loop to set the mappings of the CCdImages
67  for (auto &ccdImage : ccdImageList) {
68  const CcdImage &im = *ccdImage;
69  auto visit = im.getVisit();
70  auto chip = im.getCcdId();
71  // check that the chip_indexed part was indeed assigned
72  // (i.e. the reference visit was complete)
73  if (_chipMap.find(chip) == _chipMap.end()) {
74  LOGLS_WARN(_log, "Chip " << chip << " is missing in the reference exposure, expect troubles.");
75  GtransfoLin norm = normalizeCoordinatesTransfo(im.getImageFrame());
76  _chipMap[chip] =
77  std::unique_ptr<SimplePolyMapping>(new SimplePolyMapping(norm, GtransfoPoly(chipDegree)));
78  }
79  _mappings[&im] = std::unique_ptr<TwoTransfoMapping>(
80  new TwoTransfoMapping(_chipMap[chip].get(), _visitMap[visit].get()));
81  }
82  LOGLS_INFO(_log, "Constructor got " << _chipMap.size() << " chip mappings and " << _visitMap.size()
83  << " visit mappings.");
84  // DEBUG
85  for (auto i = _visitMap.begin(); i != _visitMap.end(); ++i) LOGLS_DEBUG(_log, i->first);
86 }
#define LOGLS_WARN(logger, message)
Log a warn-level message using an iostream-based interface.
Definition: Log.h:657
T norm(const T &x)
Definition: Integrate.h:194
T end(T... args)
GtransfoLin normalizeCoordinatesTransfo(const Frame &frame)
Returns the transformation that maps the input frame along both axes to [-1,1].
Definition: Gtransfo.cc:725
#define LOGLS_DEBUG(logger, message)
Log a debug-level message using an iostream-based interface.
Definition: Log.h:617
#define LOGLS_INFO(logger, message)
Log a info-level message using an iostream-based interface.
Definition: Log.h:637
T find(T... args)
T size(T... args)
T begin(T... args)

◆ ConstrainedPolyModel() [2/3]

lsst::jointcal::ConstrainedPolyModel::ConstrainedPolyModel ( ConstrainedPolyModel const &  )
delete

No copy or move: there is only ever one instance of a given model (i.e. per ccd+visit)

◆ ConstrainedPolyModel() [3/3]

lsst::jointcal::ConstrainedPolyModel::ConstrainedPolyModel ( ConstrainedPolyModel &&  )
delete

Member Function Documentation

◆ assignIndices()

unsigned lsst::jointcal::ConstrainedPolyModel::assignIndices ( unsigned  firstIndex,
std::string const &  whatToFit 
)
virtual

Positions the various parameter sets into the parameter vector, starting at firstIndex.

This routine decodes "DistortionsChip" and "DistortionsVisit" in whatToFit.

If whatToFit contains "Distortions" and not Distortions<Something>, it is understood as both chips and visits.

Implements lsst::jointcal::AstrometryModel.

Definition at line 98 of file ConstrainedPolyModel.cc.

98  {
99  unsigned index = firstIndex;
100  if (whatToFit.find("Distortions") == std::string::npos) {
101  LOGLS_ERROR(_log, "assignIndices was called and Distortions is *not* in whatToFit");
102  return 0;
103  }
104  // if we get here "Distortions" is in whatToFit
105  _fittingChips = (whatToFit.find("DistortionsChip") != std::string::npos);
106  _fittingVisits = (whatToFit.find("DistortionsVisit") != std::string::npos);
107  // If nothing more than "Distortions" is specified, it means all:
108  if ((!_fittingChips) && (!_fittingVisits)) {
109  _fittingChips = _fittingVisits = true;
110  }
111  if (_fittingChips)
112  for (auto &i : _chipMap) {
113  i.second->setIndex(index);
114  index += i.second->getNpar();
115  }
116  if (_fittingVisits)
117  for (auto &i : _visitMap) {
118  i.second->setIndex(index);
119  index += i.second->getNpar();
120  }
121  // Tell the mappings which derivatives they will have to fill:
122  for (auto &i : _mappings) {
123  i.second->setWhatToFit(_fittingChips, _fittingVisits);
124  }
125  return index;
126 }
#define LOGLS_ERROR(logger, message)
Log a error-level message using an iostream-based interface.
Definition: Log.h:677

◆ freezeErrorTransform()

void lsst::jointcal::ConstrainedPolyModel::freezeErrorTransform ( )
virtual

From there on, measurement errors are propagated using the current transfos (and no longer evolve).

Implements lsst::jointcal::AstrometryModel.

Definition at line 141 of file ConstrainedPolyModel.cc.

141  {
142  for (auto i = _visitMap.begin(); i != _visitMap.end(); ++i) i->second->freezeErrorTransform();
143  for (auto i = _chipMap.begin(); i != _chipMap.end(); ++i) i->second->freezeErrorTransform();
144 }
T end(T... args)
T begin(T... args)

◆ getChipTransfo()

const Gtransfo & lsst::jointcal::ConstrainedPolyModel::getChipTransfo ( CcdIdType const  chip) const

Access to mappings.

Definition at line 146 of file ConstrainedPolyModel.cc.

146  {
147  auto chipp = _chipMap.find(chip);
148  if (chipp == _chipMap.end()) {
149  std::stringstream errMsg;
150  errMsg << "No such chipId: '" << chip << "' found in chipMap of: " << this;
151  throw pexExcept::InvalidParameterError(errMsg.str());
152  }
153  return chipp->second->getTransfo();
154 }
T end(T... args)
T str(T... args)
T find(T... args)

◆ getMapping()

const Mapping * lsst::jointcal::ConstrainedPolyModel::getMapping ( CcdImage const &  ) const
virtual

Mapping associated to a given CcdImage.

Implements lsst::jointcal::AstrometryModel.

Definition at line 88 of file ConstrainedPolyModel.cc.

88  {
89  mappingMapType::const_iterator i = _mappings.find(&ccdImage);
90  if (i == _mappings.end()) return nullptr;
91  return (i->second.get());
92 }
T end(T... args)
T find(T... args)

◆ getSky2TP()

const Gtransfo* lsst::jointcal::ConstrainedPolyModel::getSky2TP ( CcdImage const &  ccdImage) const
inlinevirtual

The mapping of sky coordinates (i.e.

the coordinate system in which fitted stars are reported) onto the Tangent plane (into which the pixel coordinates are transformed).

Implements lsst::jointcal::AstrometryModel.

Definition at line 78 of file ConstrainedPolyModel.h.

78 { return _sky2TP->getSky2TP(ccdImage); }
virtual const Gtransfo * getSky2TP(const CcdImage &ccdImage) const =0

◆ getVisits()

std::vector< VisitIdType > lsst::jointcal::ConstrainedPolyModel::getVisits ( ) const

Access to array of visits involved in the solution.

Definition at line 157 of file ConstrainedPolyModel.cc.

157  {
159  res.reserve(_visitMap.size());
160  for (auto i = _visitMap.begin(); i != _visitMap.end(); ++i) res.push_back(i->first);
161  return res;
162 }
T end(T... args)
T push_back(T... args)
T size(T... args)
STL class.
T begin(T... args)
T reserve(T... args)

◆ getVisitTransfo()

const Gtransfo & lsst::jointcal::ConstrainedPolyModel::getVisitTransfo ( VisitIdType const &  visit) const

Access to mappings.

Definition at line 164 of file ConstrainedPolyModel.cc.

164  {
165  auto visitp = _visitMap.find(visit);
166  if (visitp == _visitMap.end()) {
167  std::stringstream errMsg;
168  errMsg << "No such visitId: '" << visit << "' found in visitMap of: " << this;
169  throw pexExcept::InvalidParameterError(errMsg.str());
170  }
171  return visitp->second->getTransfo();
172 }
T end(T... args)
T str(T... args)
T find(T... args)

◆ offsetParams()

void lsst::jointcal::ConstrainedPolyModel::offsetParams ( Eigen::VectorXd const &  Delta)
virtual

Dispaches the offsets after a fit step into the actual locations of parameters.

Implements lsst::jointcal::AstrometryModel.

Definition at line 128 of file ConstrainedPolyModel.cc.

128  {
129  if (_fittingChips)
130  for (auto &i : _chipMap) {
131  auto mapping = i.second.get();
132  mapping->offsetParams(delta.segment(mapping->getIndex(), mapping->getNpar()));
133  }
134  if (_fittingVisits)
135  for (auto &i : _visitMap) {
136  auto mapping = i.second.get();
137  mapping->offsetParams(delta.segment(mapping->getIndex(), mapping->getNpar()));
138  }
139 }

◆ operator=() [1/2]

ConstrainedPolyModel& lsst::jointcal::ConstrainedPolyModel::operator= ( ConstrainedPolyModel const &  )
delete

◆ operator=() [2/2]

ConstrainedPolyModel& lsst::jointcal::ConstrainedPolyModel::operator= ( ConstrainedPolyModel &&  )
delete

◆ produceSipWcs()

std::shared_ptr< TanSipPix2RaDec > lsst::jointcal::ConstrainedPolyModel::produceSipWcs ( CcdImage const &  ccdImage) const
virtual

Cook up a SIP WCS.

Implements lsst::jointcal::AstrometryModel.

Definition at line 174 of file ConstrainedPolyModel.cc.

174  {
175  const TwoTransfoMapping *mapping;
176  try {
177  mapping = _mappings.at(&ccdImage).get();
178  } catch (std::out_of_range &) {
179  LOGLS_ERROR(_log, "CcdImage with ccd/visit " << ccdImage.getCcdId() << "/" << ccdImage.getVisit()
180  << " not found in constrainedPolyModel mapping list.");
182  for (auto const &i : _mappings) os << i.first << ",";
183  LOGLS_ERROR(_log, "Available CcdImages: " << os.str());
184  return nullptr;
185  }
186 
187  GtransfoPoly pix2Tp;
188  const GtransfoPoly &t1 = dynamic_cast<const GtransfoPoly &>(mapping->getTransfo1());
189  // TODO: This line produces a warning on clang (t1 is always valid: a failed dynamic_cast of a reference
190  // raises bad_cast instead of returning nullptr like a failed pointer cast), but I'll deal with it as
191  // part of DM-10524 (hopefully removing the necessity of the casts).
192  if (!(&t1)) {
193  LOGLS_ERROR(_log, "Problem with transform 1 of ccd/visit " << ccdImage.getCcdId() << "/"
194  << ccdImage.getVisit() << ": T1 "
195  << mapping->getTransfo1());
196  return nullptr;
197  }
198  // NOTE: we currently expect T2 to be an identity for the first visit, so we have to treat it separately.
199  // TODO: We are aware that this is a hack, but it will be fixed as part of DM-10524.
200  try {
201  const GtransfoIdentity &t2 = dynamic_cast<const GtransfoIdentity &>(mapping->getTransfo2());
202  pix2Tp = t1;
203  } catch (std::bad_cast &) {
204  try {
205  const GtransfoPoly &t2_poly = dynamic_cast<const GtransfoPoly &>(mapping->getTransfo2());
206  pix2Tp = t2_poly * t1;
207  } catch (std::bad_cast &) {
208  LOGLS_ERROR(_log, "Problem with transform 2 of ccd/visit " << ccdImage.getCcdId() << "/"
209  << ccdImage.getVisit() << ": T2 "
210  << mapping->getTransfo2());
211  return nullptr;
212  }
213  }
214  const TanRaDec2Pix *proj = dynamic_cast<const TanRaDec2Pix *>(getSky2TP(ccdImage));
215  if (!proj) {
216  LOGLS_ERROR(_log, "Problem with projection of ccd/visit " << ccdImage.getCcdId() << "/"
217  << ccdImage.getVisit() << ": projection "
218  << getSky2TP(ccdImage));
219  return nullptr;
220  }
221 
222  // should be the identity, but who knows? So, let us incorporate it into the pix2TP part.
223  const GtransfoLin &projLinPart = proj->getLinPart();
224  GtransfoPoly wcsPix2Tp = GtransfoPoly(projLinPart.invert()) * pix2Tp;
225 
226  // compute a decent approximation, if higher order corrections get ignored
227  GtransfoLin cdStuff = wcsPix2Tp.linearApproximation(ccdImage.getImageFrame().getCenter());
228 
229  // wcsPix2TP = cdStuff*sip , so
230  GtransfoPoly sip = GtransfoPoly(cdStuff.invert()) * wcsPix2Tp;
231  Point tangentPoint(proj->getTangentPoint());
232  return std::make_shared<TanSipPix2RaDec>(cdStuff, tangentPoint, &sip);
233 }
STL class.
T at(T... args)
T get(T... args)
const Gtransfo * getSky2TP(CcdImage const &ccdImage) const
The mapping of sky coordinates (i.e.
#define LOGLS_ERROR(logger, message)
Log a error-level message using an iostream-based interface.
Definition: Log.h:677
std::ostream * os
Definition: Schema.cc:736

The documentation for this class was generated from the following files: