lsst.jointcal  16.0-15-g8e16a51+11
PhotometryMapping.h
Go to the documentation of this file.
1 // -*- LSST-C++ -*-
2 #ifndef LSST_JOINTCAL_PHOTOMETRY_MAPPING_H
3 #define LSST_JOINTCAL_PHOTOMETRY_MAPPING_H
4 
5 #include <memory>
6 
8 
12 #include "lsst/jointcal/Point.h"
14 
15 namespace lsst {
16 namespace jointcal {
17 
22 public:
23  PhotometryMappingBase() : index(-1), fixed(false) {}
25 
31 
33  virtual unsigned getNpar() const = 0;
34 
43  virtual double transform(MeasuredStar const &measuredStar, double value) const = 0;
44 
55  virtual double transformError(MeasuredStar const &measuredStar, double value, double valueErr) const = 0;
56 
64  virtual void freezeErrorTransform() = 0;
65 
73  virtual void computeParameterDerivatives(MeasuredStar const &measuredStar, double value,
74  Eigen::Ref<Eigen::VectorXd> derivatives) const = 0;
75 
77  void setFixed(bool _fixed) { fixed = _fixed; }
78  bool isFixed() { return fixed; }
79 
80  virtual Eigen::VectorXd getParameters() = 0;
81 
86  virtual void getMappingIndices(std::vector<unsigned> &indices) const = 0;
87 
89  virtual void dump(std::ostream &stream = std::cout) const = 0;
90 
92  unsigned getIndex() { return index; }
93 
95  void setIndex(unsigned i) { index = i; }
96 
97 protected:
98  // Start index of this mapping in the "grand" fit
99  unsigned index;
100  // Should this mapping be varied during fitting?
101  bool fixed;
102 };
103 
108 public:
115  : PhotometryMappingBase(), _transfo(std::move(transfo)), _transfoErrors(_transfo) {}
116 
118  unsigned getNpar() const override {
119  if (fixed) {
120  return 0;
121  } else {
122  return _transfo->getNpar();
123  }
124  }
125 
127  double transform(MeasuredStar const &measuredStar, double value) const override {
128  return _transfo->transform(measuredStar.x, measuredStar.y, value);
129  }
130 
132  double transformError(MeasuredStar const &measuredStar, double value, double valueErr) const override {
133  return _transfoErrors->transformError(measuredStar.x, measuredStar.y, value, valueErr);
134  }
135 
137  void freezeErrorTransform() override {
138  _transfoErrors = std::shared_ptr<PhotometryTransfo>(_transfo->clone());
139  }
140 
142  void computeParameterDerivatives(MeasuredStar const &measuredStar, double value,
143  Eigen::Ref<Eigen::VectorXd> derivatives) const override {
144  if (fixed) {
145  return;
146  } else {
147  _transfo->computeParameterDerivatives(measuredStar.x, measuredStar.y, value, derivatives);
148  }
149  }
150 
157  void offsetParams(Eigen::VectorXd const &delta) { _transfo->offsetParams(delta); }
158 
160  Eigen::VectorXd getParameters() override { return _transfo->getParameters(); }
161 
163  void getMappingIndices(std::vector<unsigned> &indices) const override {
164  if (indices.size() < getNpar()) indices.resize(getNpar());
165  for (unsigned k = 0; k < getNpar(); ++k) {
166  indices[k] = index + k;
167  }
168  }
169 
171  void dump(std::ostream &stream = std::cout) const override {
172  stream << "index: " << index << " fixed: " << fixed << " transfo parameters: ";
173  _transfo->dump(stream);
174  }
175 
176  std::shared_ptr<PhotometryTransfo> getTransfo() const { return _transfo; }
177 
178  std::shared_ptr<PhotometryTransfo> getTransfoErrors() const { return _transfoErrors; }
179 
180 private:
181  // the actual transformation to be fit
183  // the transformation used for errors
184  std::shared_ptr<PhotometryTransfo> _transfoErrors;
185 };
186 
191 public:
195  _nParChip(0),
196  _nParVisit(0),
197  _chipMapping(std::move(chipMapping)),
198  _visitMapping(std::move(visitMapping)) {}
199 
201  unsigned getNpar() const override { return _nParChip + _nParVisit; }
202 
204  double transform(MeasuredStar const &measuredStar, double value) const override {
205  double temp = _chipMapping->getTransfo()->transform(measuredStar.x, measuredStar.y, value);
206  return _visitMapping->getTransfo()->transform(measuredStar.getXFocal(), measuredStar.getYFocal(),
207  temp);
208  }
209 
211  void freezeErrorTransform() override {
212  _chipMapping->freezeErrorTransform();
213  _visitMapping->freezeErrorTransform();
214  }
215 
217  Eigen::VectorXd getParameters() override {
218  Eigen::VectorXd joined(getNpar());
219  joined << _chipMapping->getParameters(), _visitMapping->getParameters();
220  return joined;
221  }
222 
224  void getMappingIndices(std::vector<unsigned> &indices) const override;
225 
235  void setWhatToFit(bool const fittingChips, bool const fittingVisits);
236 
238  void dump(std::ostream &stream = std::cout) const override {
239  stream << "index: " << index << " chipMapping: ";
240  _chipMapping->dump(stream);
241  stream << "visitMapping: ";
242  _visitMapping->dump(stream);
243  }
244 
245  std::shared_ptr<PhotometryMapping> getChipMapping() const { return _chipMapping; }
246  std::shared_ptr<PhotometryMapping> getVisitMapping() const { return _visitMapping; }
247 
248  unsigned getNParChip() const { return _nParChip; }
249  unsigned getNParVisit() const { return _nParVisit; }
250 
251 protected:
252  // These are either transfo.getNpar() or 0, depending on whether we are fitting that component or not.
253  unsigned _nParChip, _nParVisit;
254 
255  // the actual transformation to be fit
258 };
259 
261 public:
264  : ChipVisitPhotometryMapping(chipMapping, visitMapping) {}
265 
267  double transformError(MeasuredStar const &measuredStar, double value, double valueErr) const override;
268 
270  void computeParameterDerivatives(MeasuredStar const &measuredStar, double value,
271  Eigen::Ref<Eigen::VectorXd> derivatives) const override;
272 };
273 
275 public:
278  : ChipVisitPhotometryMapping(chipMapping, visitMapping) {}
279 
286  double transformError(MeasuredStar const &measuredStar, double value, double valueErr) const override;
287 
289  void computeParameterDerivatives(MeasuredStar const &measuredStar, double value,
290  Eigen::Ref<Eigen::VectorXd> derivatives) const override;
291 };
292 
293 } // namespace jointcal
294 } // namespace lsst
295 
296 #endif // LSST_JOINTCAL_PHOTOMETRY_MAPPING_H
virtual void freezeErrorTransform()=0
Once this routine has been called, the error transform is not modified by offsetParams().
std::shared_ptr< PhotometryTransfo > getTransfoErrors() const
PhotometryMapping(std::shared_ptr< PhotometryTransfo > transfo)
Value transform takes ownership of transfo, error transform aliases it.
ChipVisitFluxMapping(std::shared_ptr< PhotometryMapping > chipMapping, std::shared_ptr< PhotometryMapping > visitMapping)
Relates transfo(s) to their position in the fitting matrix and allows interaction with the transfo(s)...
std::shared_ptr< PhotometryMapping > _visitMapping
virtual Eigen::VectorXd getParameters()=0
double transform(MeasuredStar const &measuredStar, double value) const override
Return the on-sky transformed flux for measuredStar on ccdImage.
std::shared_ptr< PhotometryMapping > getChipMapping() const
void offsetParams(Eigen::VectorXd const &delta)
Offset the transfo parameters by delta.
virtual double transformError(MeasuredStar const &measuredStar, double value, double valueErr) const =0
Return the on-sky transformed flux uncertainty for measuredStar on ccdImage.
void dump(std::ostream &stream=std::cout) const override
Dump the contents of the transfos, for debugging.
double transformError(MeasuredStar const &measuredStar, double value, double valueErr) const override
Return the on-sky transformed flux uncertainty for measuredStar on ccdImage.
STL namespace.
std::shared_ptr< PhotometryMapping > _chipMapping
virtual double transform(MeasuredStar const &measuredStar, double value) const =0
Return the on-sky transformed flux for measuredStar on ccdImage.
void freezeErrorTransform() override
Once this routine has been called, the error transform is not modified by offsetParams().
T resize(T... args)
double x
coordinate
Definition: Point.h:18
std::shared_ptr< PhotometryMapping > getVisitMapping() const
void setIndex(unsigned i)
Set the index of this mapping in the grand fit.
void getMappingIndices(std::vector< unsigned > &indices) const override
Gets how this set of parameters (of length getNpar()) map into the "grand" fit.
Class for a simple mapping implementing a generic Gtransfo.
void dump(std::ostream &stream=std::cout) const override
Dump the contents of the transfos, for debugging.
void computeParameterDerivatives(MeasuredStar const &measuredStar, double value, Eigen::Ref< Eigen::VectorXd > derivatives) const override
Compute the derivatives with respect to the parameters (i.e.
objects measured on actual images.
Definition: MeasuredStar.h:19
T move(T... args)
double transform(MeasuredStar const &measuredStar, double value) const override
Return the on-sky transformed flux for measuredStar on ccdImage.
T size(T... args)
ChipVisitPhotometryMapping(std::shared_ptr< PhotometryMapping > chipMapping, std::shared_ptr< PhotometryMapping > visitMapping)
unsigned getNpar() const override
Number of total parameters in this mapping.
PhotometryMappingBase & operator=(PhotometryMappingBase const &)=delete
virtual void computeParameterDerivatives(MeasuredStar const &measuredStar, double value, Eigen::Ref< Eigen::VectorXd > derivatives) const =0
Compute the derivatives with respect to the parameters (i.e.
void setFixed(bool _fixed)
Make this mapping&#39;s parameters fixed (i.e. not varied during fitting).
unsigned getIndex()
Get the index of this mapping in the grand fit.
std::shared_ptr< PhotometryTransfo > getTransfo() const
A mapping containing a single photometryTransfo.
STL class.
virtual void dump(std::ostream &stream=std::cout) const =0
Dump the contents of the transfos, for debugging.
virtual unsigned getNpar() const =0
Number of total parameters in this mapping.
void freezeErrorTransform() override
Once this routine has been called, the error transform is not modified by offsetParams().
ChipVisitMagnitudeMapping(std::shared_ptr< PhotometryMapping > chipMapping, std::shared_ptr< PhotometryMapping > visitMapping)
virtual void getMappingIndices(std::vector< unsigned > &indices) const =0
Gets how this set of parameters (of length getNpar()) map into the "grand" fit.
A two-level photometric transform: one for the ccd and one for the visit.
unsigned getNpar() const override
Number of total parameters in this mapping.
Eigen::VectorXd getParameters() override