LSSTApplications  18.0.0+106,18.0.0+50,19.0.0,19.0.0+1,19.0.0+10,19.0.0+11,19.0.0+13,19.0.0+17,19.0.0+2,19.0.0-1-g20d9b18+6,19.0.0-1-g425ff20,19.0.0-1-g5549ca4,19.0.0-1-g580fafe+6,19.0.0-1-g6fe20d0+1,19.0.0-1-g7011481+9,19.0.0-1-g8c57eb9+6,19.0.0-1-gb5175dc+11,19.0.0-1-gdc0e4a7+9,19.0.0-1-ge272bc4+6,19.0.0-1-ge3aa853,19.0.0-10-g448f008b,19.0.0-12-g6990b2c,19.0.0-2-g0d9f9cd+11,19.0.0-2-g3d9e4fb2+11,19.0.0-2-g5037de4,19.0.0-2-gb96a1c4+3,19.0.0-2-gd955cfd+15,19.0.0-3-g2d13df8,19.0.0-3-g6f3c7dc,19.0.0-4-g725f80e+11,19.0.0-4-ga671dab3b+1,19.0.0-4-gad373c5+3,19.0.0-5-ga2acb9c+2,19.0.0-5-gfe96e6c+2,w.2020.01
LSSTDataManagementBasePackage
PhotometryMapping.h
Go to the documentation of this file.
1 // -*- LSST-C++ -*-
2 /*
3  * This file is part of jointcal.
4  *
5  * Developed for the LSST Data Management System.
6  * This product includes software developed by the LSST Project
7  * (https://www.lsst.org).
8  * See the COPYRIGHT file at the top-level directory of this distribution
9  * for details of code ownership.
10  *
11  * This program is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation, either version 3 of the License, or
14  * (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program. If not, see <https://www.gnu.org/licenses/>.
23  */
24 
25 #ifndef LSST_JOINTCAL_PHOTOMETRY_MAPPING_H
26 #define LSST_JOINTCAL_PHOTOMETRY_MAPPING_H
27 
28 #include <memory>
29 
31 
32 #include "lsst/jointcal/CcdImage.h"
35 #include "lsst/jointcal/Point.h"
37 
38 namespace lsst {
39 namespace jointcal {
40 
45 public:
46  PhotometryMappingBase() : index(-1), fixed(false) {}
48 
54 
56  virtual std::size_t getNpar() const = 0;
57 
66  virtual double transform(MeasuredStar const &measuredStar, double value) const = 0;
67 
78  virtual double transformError(MeasuredStar const &measuredStar, double value, double valueErr) const = 0;
79 
87  virtual void freezeErrorTransform() = 0;
88 
96  virtual void computeParameterDerivatives(MeasuredStar const &measuredStar, double value,
97  Eigen::Ref<Eigen::VectorXd> derivatives) const = 0;
98 
100  void setFixed(bool _fixed) { fixed = _fixed; }
101  bool isFixed() { return fixed; }
102 
103  virtual Eigen::VectorXd getParameters() = 0;
104 
109  virtual void getMappingIndices(IndexVector &indices) const = 0;
110 
112  virtual void dump(std::ostream &stream = std::cout) const = 0;
113 
115  Eigen::Index getIndex() { return index; }
116 
118  void setIndex(Eigen::Index i) { index = i; }
119 
120 protected:
121  // Start index of this mapping in the "grand" fit
122  Eigen::Index index;
123  // Should this mapping be varied during fitting?
124  bool fixed;
125 };
126 
131 public:
138  : PhotometryMappingBase(), _transform(std::move(transform)), _transformErrors(_transform) {}
139 
141  std::size_t getNpar() const override {
142  if (fixed) {
143  return 0;
144  } else {
145  return _transform->getNpar();
146  }
147  }
148 
150  double transform(MeasuredStar const &measuredStar, double value) const override {
151  return _transform->transform(measuredStar.x, measuredStar.y, value);
152  }
153 
155  double transformError(MeasuredStar const &measuredStar, double value, double valueErr) const override {
156  return _transformErrors->transformError(measuredStar.x, measuredStar.y, value, valueErr);
157  }
158 
160  void freezeErrorTransform() override {
161  _transformErrors = std::shared_ptr<PhotometryTransform>(_transform->clone());
162  }
163 
165  void computeParameterDerivatives(MeasuredStar const &measuredStar, double value,
166  Eigen::Ref<Eigen::VectorXd> derivatives) const override {
167  if (fixed) {
168  return;
169  } else {
170  _transform->computeParameterDerivatives(measuredStar.x, measuredStar.y, value, derivatives);
171  }
172  }
173 
180  void offsetParams(Eigen::VectorXd const &delta) { _transform->offsetParams(delta); }
181 
183  Eigen::VectorXd getParameters() override { return _transform->getParameters(); }
184 
186  void getMappingIndices(IndexVector &indices) const override {
187  if (indices.size() < getNpar()) indices.resize(getNpar());
188  for (std::size_t k = 0; k < getNpar(); ++k) {
189  indices[k] = index + k;
190  }
191  }
192 
194  void dump(std::ostream &stream = std::cout) const override {
195  stream << "index: " << index << " fixed: " << fixed << " transform parameters: ";
196  _transform->dump(stream);
197  }
198 
199  std::shared_ptr<PhotometryTransform> getTransform() const { return _transform; }
200 
201  std::shared_ptr<PhotometryTransform> getTransformErrors() const { return _transformErrors; }
202 
203 private:
204  // the actual transformation to be fit
206  // the transformation used for errors
207  std::shared_ptr<PhotometryTransform> _transformErrors;
208 };
209 
214 public:
218  _nParChip(0),
219  _nParVisit(0),
220  _chipMapping(std::move(chipMapping)),
221  _visitMapping(std::move(visitMapping)) {}
222 
224  std::size_t getNpar() const override { return _nParChip + _nParVisit; }
225 
227  double transform(MeasuredStar const &measuredStar, double value) const override {
228  double temp = _chipMapping->getTransform()->transform(measuredStar.x, measuredStar.y, value);
229  return _visitMapping->getTransform()->transform(measuredStar.getXFocal(), measuredStar.getYFocal(),
230  temp);
231  }
232 
234  void freezeErrorTransform() override {
235  _chipMapping->freezeErrorTransform();
236  _visitMapping->freezeErrorTransform();
237  }
238 
240  Eigen::VectorXd getParameters() override {
241  Eigen::VectorXd joined(getNpar());
242  joined << _chipMapping->getParameters(), _visitMapping->getParameters();
243  return joined;
244  }
245 
247  void getMappingIndices(IndexVector &indices) const override;
248 
258  void setWhatToFit(bool const fittingChips, bool const fittingVisits);
259 
261  void dump(std::ostream &stream = std::cout) const override {
262  stream << "index: " << index << " chipMapping: ";
263  _chipMapping->dump(stream);
264  stream << "visitMapping: ";
265  _visitMapping->dump(stream);
266  }
267 
268  std::shared_ptr<PhotometryMapping> getChipMapping() const { return _chipMapping; }
269  std::shared_ptr<PhotometryMapping> getVisitMapping() const { return _visitMapping; }
270 
271  std::size_t getNParChip() const { return _nParChip; }
272  std::size_t getNParVisit() const { return _nParVisit; }
273 
274 protected:
275  // These are either transform.getNpar() or 0, depending on whether we are fitting that component or not.
277 
278  // the actual transformation to be fit
281 };
282 
284 public:
287  : ChipVisitPhotometryMapping(chipMapping, visitMapping) {}
288 
290  double transformError(MeasuredStar const &measuredStar, double value, double valueErr) const override;
291 
293  void computeParameterDerivatives(MeasuredStar const &measuredStar, double value,
294  Eigen::Ref<Eigen::VectorXd> derivatives) const override;
295 };
296 
298 public:
301  : ChipVisitPhotometryMapping(chipMapping, visitMapping) {}
302 
309  double transformError(MeasuredStar const &measuredStar, double value, double valueErr) const override;
310 
312  void computeParameterDerivatives(MeasuredStar const &measuredStar, double value,
313  Eigen::Ref<Eigen::VectorXd> derivatives) const override;
314 };
315 
316 } // namespace jointcal
317 } // namespace lsst
318 
319 #endif // LSST_JOINTCAL_PHOTOMETRY_MAPPING_H
virtual void freezeErrorTransform()=0
Once this routine has been called, the error transform is not modified by offsetParams().
ChipVisitFluxMapping(std::shared_ptr< PhotometryMapping > chipMapping, std::shared_ptr< PhotometryMapping > visitMapping)
Relates transform(s) to their position in the fitting matrix and allows interaction with the transfor...
virtual std::size_t getNpar() const =0
Number of total parameters in this mapping.
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 transform 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 transforms, 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
void getMappingIndices(IndexVector &indices) const override
Gets how this set of parameters (of length getNpar()) map into the "grand" fit.
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:41
std::shared_ptr< PhotometryMapping > getVisitMapping() const
A base class for image defects.
virtual void getMappingIndices(IndexVector &indices) const =0
Gets how this set of parameters (of length getNpar()) map into the "grand" fit.
void dump(std::ostream &stream=std::cout) const override
Dump the contents of the transforms, for debugging.
void setIndex(Eigen::Index i)
Set the index of this mapping in the grand fit.
std::shared_ptr< PhotometryTransform > getTransform() const
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:46
std::size_t getNpar() const override
Number of total parameters in this mapping.
T move(T... args)
double transform(MeasuredStar const &measuredStar, double value) const override
Return the on-sky transformed flux for measuredStar on ccdImage.
PhotometryMapping(std::shared_ptr< PhotometryTransform > transform)
Value transform takes ownership of transform, error transform aliases it.
std::shared_ptr< PhotometryTransform > getTransformErrors() const
T size(T... args)
STL class.
Eigen::Index getIndex()
Get the index of this mapping in the grand fit.
ChipVisitPhotometryMapping(std::shared_ptr< PhotometryMapping > chipMapping, std::shared_ptr< PhotometryMapping > visitMapping)
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).
A mapping containing a single photometryTransform.
STL class.
virtual void dump(std::ostream &stream=std::cout) const =0
Dump the contents of the transforms, for debugging.
Implementation of the Photometric Calibration class.
std::size_t getNpar() const override
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)
A two-level photometric transform: one for the ccd and one for the visit.
Eigen::VectorXd getParameters() override