LSST Applications  21.0.0-172-gfb10e10a+18fedfabac,22.0.0+297cba6710,22.0.0+80564b0ff1,22.0.0+8d77f4f51a,22.0.0+a28f4c53b1,22.0.0+dcf3732eb2,22.0.1-1-g7d6de66+2a20fdde0d,22.0.1-1-g8e32f31+297cba6710,22.0.1-1-geca5380+7fa3b7d9b6,22.0.1-12-g44dc1dc+2a20fdde0d,22.0.1-15-g6a90155+515f58c32b,22.0.1-16-g9282f48+790f5f2caa,22.0.1-2-g92698f7+dcf3732eb2,22.0.1-2-ga9b0f51+7fa3b7d9b6,22.0.1-2-gd1925c9+bf4f0e694f,22.0.1-24-g1ad7a390+a9625a72a8,22.0.1-25-g5bf6245+3ad8ecd50b,22.0.1-25-gb120d7b+8b5510f75f,22.0.1-27-g97737f7+2a20fdde0d,22.0.1-32-gf62ce7b1+aa4237961e,22.0.1-4-g0b3f228+2a20fdde0d,22.0.1-4-g243d05b+871c1b8305,22.0.1-4-g3a563be+32dcf1063f,22.0.1-4-g44f2e3d+9e4ab0f4fa,22.0.1-42-gca6935d93+ba5e5ca3eb,22.0.1-5-g15c806e+85460ae5f3,22.0.1-5-g58711c4+611d128589,22.0.1-5-g75bb458+99c117b92f,22.0.1-6-g1c63a23+7fa3b7d9b6,22.0.1-6-g50866e6+84ff5a128b,22.0.1-6-g8d3140d+720564cf76,22.0.1-6-gd805d02+cc5644f571,22.0.1-8-ge5750ce+85460ae5f3,master-g6e05de7fdc+babf819c66,master-g99da0e417a+8d77f4f51a,w.2021.48
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)