LSST Applications  21.0.0-147-g0e635eb1+1acddb5be5,22.0.0+052faf71bd,22.0.0+1ea9a8b2b2,22.0.0+6312710a6c,22.0.0+729191ecac,22.0.0+7589c3a021,22.0.0+9f079a9461,22.0.1-1-g7d6de66+b8044ec9de,22.0.1-1-g87000a6+536b1ee016,22.0.1-1-g8e32f31+6312710a6c,22.0.1-10-gd060f87+016f7cdc03,22.0.1-12-g9c3108e+df145f6f68,22.0.1-16-g314fa6d+c825727ab8,22.0.1-19-g93a5c75+d23f2fb6d8,22.0.1-19-gb93eaa13+aab3ef7709,22.0.1-2-g8ef0a89+b8044ec9de,22.0.1-2-g92698f7+9f079a9461,22.0.1-2-ga9b0f51+052faf71bd,22.0.1-2-gac51dbf+052faf71bd,22.0.1-2-gb66926d+6312710a6c,22.0.1-2-gcb770ba+09e3807989,22.0.1-20-g32debb5+b8044ec9de,22.0.1-23-gc2439a9a+fb0756638e,22.0.1-3-g496fd5d+09117f784f,22.0.1-3-g59f966b+1e6ba2c031,22.0.1-3-g849a1b8+f8b568069f,22.0.1-3-gaaec9c0+c5c846a8b1,22.0.1-32-g5ddfab5d3+60ce4897b0,22.0.1-4-g037fbe1+64e601228d,22.0.1-4-g8623105+b8044ec9de,22.0.1-5-g096abc9+d18c45d440,22.0.1-5-g15c806e+57f5c03693,22.0.1-7-gba73697+57f5c03693,master-g6e05de7fdc+c1283a92b8,master-g72cdda8301+729191ecac,w.2021.39
LSST Data Management Base Package
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 
117  virtual void print(std::ostream &out) const = 0;
118 
120  Eigen::Index getIndex() { return index; }
121 
123  void setIndex(Eigen::Index i) { index = i; }
124 
125 protected:
126  // Start index of this mapping in the "grand" fit
127  Eigen::Index index;
128  // Should this mapping be varied during fitting?
129  bool fixed;
130 };
131 
136 public:
143  : PhotometryMappingBase(), _transform(std::move(transform)), _transformErrors(_transform) {}
144 
146  std::size_t getNpar() const override {
147  if (fixed) {
148  return 0;
149  } else {
150  return _transform->getNpar();
151  }
152  }
153 
155  double transform(MeasuredStar const &measuredStar, double value) const override {
156  return _transform->transform(measuredStar.x, measuredStar.y, value);
157  }
158 
160  double transformError(MeasuredStar const &measuredStar, double value, double valueErr) const override {
161  return _transformErrors->transformError(measuredStar.x, measuredStar.y, value, valueErr);
162  }
163 
165  void freezeErrorTransform() override {
166  _transformErrors = std::shared_ptr<PhotometryTransform>(_transform->clone());
167  }
168 
170  void computeParameterDerivatives(MeasuredStar const &measuredStar, double value,
171  Eigen::Ref<Eigen::VectorXd> derivatives) const override {
172  if (fixed) {
173  return;
174  } else {
175  _transform->computeParameterDerivatives(measuredStar.x, measuredStar.y, value, derivatives);
176  }
177  }
178 
185  void offsetParams(Eigen::VectorXd const &delta) { _transform->offsetParams(delta); }
186 
188  Eigen::VectorXd getParameters() override { return _transform->getParameters(); }
189 
191  void getMappingIndices(IndexVector &indices) const override {
192  if (indices.size() < getNpar()) indices.resize(getNpar());
193  for (std::size_t k = 0; k < getNpar(); ++k) {
194  indices[k] = index + k;
195  }
196  }
197 
199  void print(std::ostream &out) const override {
200  out << "index: " << index << " fixed: " << fixed << " ";
201  _transform->print(out);
202  }
203 
204  std::shared_ptr<PhotometryTransform> getTransform() const { return _transform; }
205 
206  std::shared_ptr<PhotometryTransform> getTransformErrors() const { return _transformErrors; }
207 
208 private:
209  // the actual transformation to be fit
211  // the transformation used for errors
212  std::shared_ptr<PhotometryTransform> _transformErrors;
213 };
214 
219 public:
223  _nParChip(0),
224  _nParVisit(0),
225  _chipMapping(std::move(chipMapping)),
226  _visitMapping(std::move(visitMapping)) {}
227 
229  std::size_t getNpar() const override { return _nParChip + _nParVisit; }
230 
232  double transform(MeasuredStar const &measuredStar, double value) const override {
233  double temp = _chipMapping->getTransform()->transform(measuredStar.x, measuredStar.y, value);
234  return _visitMapping->getTransform()->transform(measuredStar.getXFocal(), measuredStar.getYFocal(),
235  temp);
236  }
237 
239  void freezeErrorTransform() override {
240  _chipMapping->freezeErrorTransform();
241  _visitMapping->freezeErrorTransform();
242  }
243 
245  Eigen::VectorXd getParameters() override {
246  Eigen::VectorXd joined(getNpar());
247  joined << _chipMapping->getParameters(), _visitMapping->getParameters();
248  return joined;
249  }
250 
252  void getMappingIndices(IndexVector &indices) const override;
253 
263  void setWhatToFit(bool const fittingChips, bool const fittingVisits);
264 
266  void print(std::ostream &out) const override {
267  out << "index: " << index << std::endl;
268  out << "chip mapping: ";
269  _chipMapping->print(out);
270  out << std::endl << "visit mapping: ";
271  _visitMapping->print(out);
272  }
273 
276 
277  std::size_t getNParChip() const { return _nParChip; }
278  std::size_t getNParVisit() const { return _nParVisit; }
279 
280 protected:
281  // These are either transform.getNpar() or 0, depending on whether we are fitting that component or not.
283 
284  // the actual transformation to be fit
287 };
288 
290 public:
293  : ChipVisitPhotometryMapping(chipMapping, visitMapping) {}
294 
296  double transformError(MeasuredStar const &measuredStar, double value, double valueErr) const override;
297 
299  void computeParameterDerivatives(MeasuredStar const &measuredStar, double value,
300  Eigen::Ref<Eigen::VectorXd> derivatives) const override;
301 };
302 
304 public:
307  : ChipVisitPhotometryMapping(chipMapping, visitMapping) {}
308 
315  double transformError(MeasuredStar const &measuredStar, double value, double valueErr) const override;
316 
318  void computeParameterDerivatives(MeasuredStar const &measuredStar, double value,
319  Eigen::Ref<Eigen::VectorXd> derivatives) const override;
320 };
321 
322 } // namespace jointcal
323 } // namespace lsst
324 
325 #endif // LSST_JOINTCAL_PHOTOMETRY_MAPPING_H
Implementation of the Photometric Calibration class.
void computeParameterDerivatives(MeasuredStar const &measuredStar, double value, Eigen::Ref< Eigen::VectorXd > derivatives) const override
Compute the derivatives with respect to the parameters (i.e.
double transformError(MeasuredStar const &measuredStar, double value, double valueErr) const override
Return the on-sky transformed flux uncertainty for measuredStar on ccdImage.
ChipVisitFluxMapping(std::shared_ptr< PhotometryMapping > chipMapping, std::shared_ptr< PhotometryMapping > visitMapping)
ChipVisitMagnitudeMapping(std::shared_ptr< PhotometryMapping > chipMapping, std::shared_ptr< PhotometryMapping > visitMapping)
void computeParameterDerivatives(MeasuredStar const &measuredStar, double value, Eigen::Ref< Eigen::VectorXd > derivatives) const override
Compute the derivatives with respect to the parameters (i.e.
double transformError(MeasuredStar const &measuredStar, double value, double valueErr) const override
Return the on-sky transformed flux uncertainty for measuredStar on ccdImage.
A two-level photometric transform: one for the ccd and one for the visit.
double transform(MeasuredStar const &measuredStar, double value) const override
Return the on-sky transformed flux for measuredStar on ccdImage.
std::shared_ptr< PhotometryMapping > _visitMapping
std::shared_ptr< PhotometryMapping > getChipMapping() const
void print(std::ostream &out) const override
Print a string representation of the contents of this mapping, for debugging.
std::shared_ptr< PhotometryMapping > _chipMapping
void freezeErrorTransform() override
Once this routine has been called, the error transform is not modified by offsetParams().
std::shared_ptr< PhotometryMapping > getVisitMapping() const
std::size_t getNpar() const override
Number of total parameters in this mapping.
void getMappingIndices(IndexVector &indices) const override
Gets how this set of parameters (of length getNpar()) map into the "grand" fit.
ChipVisitPhotometryMapping(std::shared_ptr< PhotometryMapping > chipMapping, std::shared_ptr< PhotometryMapping > visitMapping)
void setWhatToFit(bool const fittingChips, bool const fittingVisits)
Set whether to fit chips or visits.
Sources measured on images.
Definition: MeasuredStar.h:51
Relates transform(s) to their position in the fitting matrix and allows interaction with the transfor...
PhotometryMappingBase & operator=(PhotometryMappingBase &&)=delete
PhotometryMappingBase(PhotometryMappingBase const &)=delete
No copy or move: there is only ever one instance of a given mapping (i.e. per ccd+visit)
virtual Eigen::VectorXd getParameters()=0
virtual std::size_t getNpar() const =0
Number of total parameters in this mapping.
void setFixed(bool _fixed)
Make this mapping's parameters fixed (i.e. not varied during fitting).
Eigen::Index getIndex()
Get the index of this mapping in the grand fit.
virtual void print(std::ostream &out) const =0
Print a string representation of the contents of this mapping, for debugging.
PhotometryMappingBase & operator=(PhotometryMappingBase const &)=delete
void setIndex(Eigen::Index i)
Set the index of this mapping in the grand fit.
PhotometryMappingBase(PhotometryMappingBase &&)=delete
virtual void getMappingIndices(IndexVector &indices) const =0
Gets how this set of parameters (of length getNpar()) map into the "grand" fit.
virtual double transformError(MeasuredStar const &measuredStar, double value, double valueErr) const =0
Return the on-sky transformed flux uncertainty for measuredStar on ccdImage.
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.
virtual void freezeErrorTransform()=0
Once this routine has been called, the error transform is not modified by offsetParams().
virtual double transform(MeasuredStar const &measuredStar, double value) const =0
Return the on-sky transformed flux for measuredStar on ccdImage.
A mapping containing a single photometryTransform.
std::shared_ptr< PhotometryTransform > getTransform() const
void getMappingIndices(IndexVector &indices) const override
Gets how this set of parameters (of length getNpar()) map into the "grand" fit.
void computeParameterDerivatives(MeasuredStar const &measuredStar, double value, Eigen::Ref< Eigen::VectorXd > derivatives) const override
Compute the derivatives with respect to the parameters (i.e.
void freezeErrorTransform() override
Once this routine has been called, the error transform is not modified by offsetParams().
Eigen::VectorXd getParameters() override
std::shared_ptr< PhotometryTransform > getTransformErrors() const
PhotometryMapping(std::shared_ptr< PhotometryTransform > transform)
Value transform takes ownership of transform, error transform aliases it.
double transformError(MeasuredStar const &measuredStar, double value, double valueErr) const override
Return the on-sky transformed flux uncertainty for measuredStar on ccdImage.
void print(std::ostream &out) const override
Print a string representation of the contents of this mapping, for debugging.
double transform(MeasuredStar const &measuredStar, double value) const override
Return the on-sky transformed flux for measuredStar on ccdImage.
void offsetParams(Eigen::VectorXd const &delta)
Offset the transform parameters by delta.
std::size_t getNpar() const override
Number of total parameters in this mapping.
double x
coordinate
Definition: Point.h:42
T endl(T... args)
T move(T... args)
A base class for image defects.
STL namespace.
T resize(T... args)
T size(T... args)