lsst.jointcal  14.0-28-ge87de3a
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 
81  virtual void offsetParams(Eigen::VectorXd const &delta) = 0;
82 
84  void setFixed(bool _fixed) { fixed = _fixed; }
85  bool isFixed() { return fixed; }
86 
87  virtual Eigen::VectorXd getParameters() = 0;
88 
93  virtual void getMappingIndices(std::vector<unsigned> &indices) const = 0;
94 
96  virtual void dump(std::ostream &stream = std::cout) const = 0;
97 
99  unsigned getIndex() { return index; }
100 
102  void setIndex(unsigned i) { index = i; }
103 
104 protected:
105  // Start index of this mapping in the "grand" fit
106  unsigned index;
107  // Should this mapping be varied during fitting?
108  bool fixed;
109 };
110 
115 public:
122  : PhotometryMappingBase(), _transfo(std::move(transfo)), _transfoErrors(_transfo) {}
123 
125  unsigned getNpar() const override {
126  if (fixed) {
127  return 0;
128  } else {
129  return _transfo->getNpar();
130  }
131  }
132 
134  double transform(MeasuredStar const &measuredStar, double instFlux) const override {
135  return _transfo->transform(measuredStar.x, measuredStar.y, instFlux);
136  }
137 
139  double transformError(MeasuredStar const &measuredStar, double instFluxErr) const override {
140  return _transfoErrors->transform(measuredStar.x, measuredStar.y, instFluxErr);
141  }
142 
144  void freezeErrorTransform() override {
145  _transfoErrors = std::shared_ptr<PhotometryTransfo>(_transfo->clone());
146  }
147 
149  void computeParameterDerivatives(MeasuredStar const &measuredStar, double instFlux,
150  Eigen::Ref<Eigen::VectorXd> derivatives) const override {
151  if (fixed) {
152  return;
153  } else {
154  _transfo->computeParameterDerivatives(measuredStar.x, measuredStar.y, instFlux, derivatives);
155  }
156  }
157 
159  void offsetParams(Eigen::VectorXd const &delta) override { _transfo->offsetParams(delta); }
160 
162  Eigen::VectorXd getParameters() override { return _transfo->getParameters(); }
163 
165  void getMappingIndices(std::vector<unsigned> &indices) const override {
166  if (indices.size() < getNpar()) indices.resize(getNpar());
167  for (unsigned k = 0; k < getNpar(); ++k) {
168  indices[k] = index + k;
169  }
170  }
171 
173  void dump(std::ostream &stream = std::cout) const override {
174  stream << "index: " << index << " fixed: " << fixed << " transfo parameters: ";
175  _transfo->dump(stream);
176  }
177 
178  std::shared_ptr<PhotometryTransfo> getTransfo() const { return _transfo; }
179 
180  std::shared_ptr<PhotometryTransfo> getTransfoErrors() const { return _transfoErrors; }
181 
182 private:
183  // the actual transformation to be fit
185  // the transformation used for errors
186  std::shared_ptr<PhotometryTransfo> _transfoErrors;
187 };
188 
193 public:
197  _chipMapping(std::move(chipMapping)),
198  _visitMapping(std::move(visitMapping)) {}
199 
201  unsigned getNpar() const override { return _chipMapping->getNpar() + _visitMapping->getNpar(); }
202 
204  double transform(MeasuredStar const &measuredStar, double instFlux) const override {
205  double tempFlux = _chipMapping->getTransfo()->transform(measuredStar.x, measuredStar.y, instFlux);
206  return _visitMapping->getTransfo()->transform(measuredStar.getXFocal(), measuredStar.getYFocal(),
207  tempFlux);
208  }
209 
211  double transformError(MeasuredStar const &measuredStar, double instFluxErr) const override {
212  double tempFluxErr = _chipMapping->transformError(measuredStar, instFluxErr);
213  return _visitMapping->getTransfoErrors()->transform(measuredStar.getXFocal(),
214  measuredStar.getYFocal(), tempFluxErr);
215  }
216 
218  void freezeErrorTransform() override {
219  _chipMapping->freezeErrorTransform();
220  _visitMapping->freezeErrorTransform();
221  }
222 
224  void computeParameterDerivatives(MeasuredStar const &measuredStar, double instFlux,
225  Eigen::Ref<Eigen::VectorXd> derivatives) const override;
226 
228  void offsetParams(Eigen::VectorXd const &delta) override {
229  _chipMapping->offsetParams(delta.segment(0, _chipMapping->getNpar()));
230  _visitMapping->offsetParams(delta.segment(_chipMapping->getNpar(), _visitMapping->getNpar()));
231  }
232 
234  Eigen::VectorXd getParameters() override {
235  Eigen::VectorXd joined(getNpar());
236  joined << _chipMapping->getParameters(), _visitMapping->getParameters();
237  return joined;
238  }
239 
241  void getMappingIndices(std::vector<unsigned> &indices) const override;
242 
244  void dump(std::ostream &stream = std::cout) const override {
245  stream << "index: " << index << " chipMapping: ";
246  _chipMapping->dump(stream);
247  stream << "visitMapping: ";
248  _visitMapping->dump(stream);
249  }
250 
251  std::shared_ptr<PhotometryMapping> getChipMapping() const { return _chipMapping; }
252  std::shared_ptr<PhotometryMapping> getVisitMapping() const { return _visitMapping; }
253 
254 private:
255  // the actual transformation to be fit
258 };
259 
260 } // namespace jointcal
261 } // namespace lsst
262 
263 #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
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.
void offsetParams(Eigen::VectorXd const &delta) override
Offset the transfo parameters by delta.
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.
void offsetParams(Eigen::VectorXd const &delta) override
Offset the transfo parameters by delta.
objects measured on actual images.
Definition: MeasuredStar.h:18
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
virtual void offsetParams(Eigen::VectorXd const &delta)=0
Offset the transfo parameters by delta.
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