lsst.jointcal  16.0-5-g82b7855
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 instFlux) const = 0;
44 
54  virtual double transformError(MeasuredStar const &measuredStar, double instFluxErr) const = 0;
55 
63  virtual void freezeErrorTransform() = 0;
64 
72  virtual void computeParameterDerivatives(MeasuredStar const &measuredStar, double instFlux,
73  Eigen::Ref<Eigen::VectorXd> derivatives) const = 0;
74 
76  void setFixed(bool _fixed) { fixed = _fixed; }
77  bool isFixed() { return fixed; }
78 
79  virtual Eigen::VectorXd getParameters() = 0;
80 
85  virtual void getMappingIndices(std::vector<unsigned> &indices) const = 0;
86 
88  virtual void dump(std::ostream &stream = std::cout) const = 0;
89 
91  unsigned getIndex() { return index; }
92 
94  void setIndex(unsigned i) { index = i; }
95 
96 protected:
97  // Start index of this mapping in the "grand" fit
98  unsigned index;
99  // Should this mapping be varied during fitting?
100  bool fixed;
101 };
102 
107 public:
114  : PhotometryMappingBase(), _transfo(std::move(transfo)), _transfoErrors(_transfo) {}
115 
117  unsigned getNpar() const override {
118  if (fixed) {
119  return 0;
120  } else {
121  return _transfo->getNpar();
122  }
123  }
124 
126  double transform(MeasuredStar const &measuredStar, double instFlux) const override {
127  return _transfo->transform(measuredStar.x, measuredStar.y, instFlux);
128  }
129 
131  double transformError(MeasuredStar const &measuredStar, double instFluxErr) const override {
132  return _transfoErrors->transform(measuredStar.x, measuredStar.y, instFluxErr);
133  }
134 
136  void freezeErrorTransform() override {
137  _transfoErrors = std::shared_ptr<PhotometryTransfo>(_transfo->clone());
138  }
139 
141  void computeParameterDerivatives(MeasuredStar const &measuredStar, double instFlux,
142  Eigen::Ref<Eigen::VectorXd> derivatives) const override {
143  if (fixed) {
144  return;
145  } else {
146  _transfo->computeParameterDerivatives(measuredStar.x, measuredStar.y, instFlux, derivatives);
147  }
148  }
149 
156  void offsetParams(Eigen::VectorXd const &delta) { _transfo->offsetParams(delta); }
157 
159  Eigen::VectorXd getParameters() override { return _transfo->getParameters(); }
160 
162  void getMappingIndices(std::vector<unsigned> &indices) const override {
163  if (indices.size() < getNpar()) indices.resize(getNpar());
164  for (unsigned k = 0; k < getNpar(); ++k) {
165  indices[k] = index + k;
166  }
167  }
168 
170  void dump(std::ostream &stream = std::cout) const override {
171  stream << "index: " << index << " fixed: " << fixed << " transfo parameters: ";
172  _transfo->dump(stream);
173  }
174 
175  std::shared_ptr<PhotometryTransfo> getTransfo() const { return _transfo; }
176 
177  std::shared_ptr<PhotometryTransfo> getTransfoErrors() const { return _transfoErrors; }
178 
179 private:
180  // the actual transformation to be fit
182  // the transformation used for errors
183  std::shared_ptr<PhotometryTransfo> _transfoErrors;
184 };
185 
190 public:
194  _nParChips(0),
195  _nParVisits(0),
196  _chipMapping(std::move(chipMapping)),
197  _visitMapping(std::move(visitMapping)) {}
198 
200  unsigned getNpar() const override { return _nParChips + _nParVisits; }
201 
203  double transform(MeasuredStar const &measuredStar, double instFlux) const override {
204  double tempFlux = _chipMapping->getTransfo()->transform(measuredStar.x, measuredStar.y, instFlux);
205  return _visitMapping->getTransfo()->transform(measuredStar.getXFocal(), measuredStar.getYFocal(),
206  tempFlux);
207  }
208 
210  double transformError(MeasuredStar const &measuredStar, double instFluxErr) const override {
211  double tempFluxErr = _chipMapping->transformError(measuredStar, instFluxErr);
212  return _visitMapping->getTransfoErrors()->transform(measuredStar.getXFocal(),
213  measuredStar.getYFocal(), tempFluxErr);
214  }
215 
217  void freezeErrorTransform() override {
218  _chipMapping->freezeErrorTransform();
219  _visitMapping->freezeErrorTransform();
220  }
221 
223  void computeParameterDerivatives(MeasuredStar const &measuredStar, double instFlux,
224  Eigen::Ref<Eigen::VectorXd> derivatives) const override;
225 
227  Eigen::VectorXd getParameters() override {
228  Eigen::VectorXd joined(getNpar());
229  joined << _chipMapping->getParameters(), _visitMapping->getParameters();
230  return joined;
231  }
232 
234  void getMappingIndices(std::vector<unsigned> &indices) const override;
235 
245  void setWhatToFit(bool const fittingChips, bool const fittingVisits);
246 
248  void dump(std::ostream &stream = std::cout) const override {
249  stream << "index: " << index << " chipMapping: ";
250  _chipMapping->dump(stream);
251  stream << "visitMapping: ";
252  _visitMapping->dump(stream);
253  }
254 
255  std::shared_ptr<PhotometryMapping> getChipMapping() const { return _chipMapping; }
256  std::shared_ptr<PhotometryMapping> getVisitMapping() const { return _visitMapping; }
257 
258 private:
259  // These are either transfo.getNpar() or 0, depending on whether we are fitting that component or not.
260  unsigned _nParChips, _nParVisits;
261 
262  // the actual transformation to be fit
265 };
266 
267 } // namespace jointcal
268 } // namespace lsst
269 
270 #endif // LSST_JOINTCAL_PHOTOMETRY_MAPPING_H
virtual double transform(MeasuredStar const &measuredStar, double instFlux) const =0
Return the on-sky transformed flux for measuredStar on ccdImage.
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.
void computeParameterDerivatives(MeasuredStar const &measuredStar, double instFlux, Eigen::Ref< Eigen::VectorXd > derivatives) const override
Compute the derivatives with respect to the parameters (i.e.
Relates transfo(s) to their position in the fitting matrix and allows interaction with the transfo(s)...
virtual Eigen::VectorXd getParameters()=0
double transformError(MeasuredStar const &measuredStar, double instFluxErr) const override
Return the on-sky transformed flux uncertainty for measuredStar on ccdImage.
std::shared_ptr< PhotometryMapping > getChipMapping() const
void offsetParams(Eigen::VectorXd const &delta)
Offset the transfo parameters by delta.
double transformError(MeasuredStar const &measuredStar, double instFluxErr) const override
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.
STL namespace.
double transform(MeasuredStar const &measuredStar, double instFlux) const override
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.
objects measured on actual images.
Definition: MeasuredStar.h:19
T move(T... args)
double transform(MeasuredStar const &measuredStar, double instFlux) 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 double transformError(MeasuredStar const &measuredStar, double instFluxErr) const =0
Return the on-sky transformed flux uncertainty for measuredStar on ccdImage.
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 void computeParameterDerivatives(MeasuredStar const &measuredStar, double instFlux, Eigen::Ref< Eigen::VectorXd > derivatives) const =0
Compute the derivatives with respect to the parameters (i.e.
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().
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