LSSTApplications  16.0-10-g0ee56ad+5,16.0-11-ga33d1f2+5,16.0-12-g3ef5c14+3,16.0-12-g71e5ef5+18,16.0-12-gbdf3636+3,16.0-13-g118c103+3,16.0-13-g8f68b0a+3,16.0-15-gbf5c1cb+4,16.0-16-gfd17674+3,16.0-17-g7c01f5c+3,16.0-18-g0a50484+1,16.0-20-ga20f992+8,16.0-21-g0e05fd4+6,16.0-21-g15e2d33+4,16.0-22-g62d8060+4,16.0-22-g847a80f+4,16.0-25-gf00d9b8+1,16.0-28-g3990c221+4,16.0-3-gf928089+3,16.0-32-g88a4f23+5,16.0-34-gd7987ad+3,16.0-37-gc7333cb+2,16.0-4-g10fc685+2,16.0-4-g18f3627+26,16.0-4-g5f3a788+26,16.0-5-gaf5c3d7+4,16.0-5-gcc1f4bb+1,16.0-6-g3b92700+4,16.0-6-g4412fcd+3,16.0-6-g7235603+4,16.0-69-g2562ce1b+2,16.0-8-g14ebd58+4,16.0-8-g2df868b+1,16.0-8-g4cec79c+6,16.0-8-gadf6c7a+1,16.0-8-gfc7ad86,16.0-82-g59ec2a54a+1,16.0-9-g5400cdc+2,16.0-9-ge6233d7+5,master-g2880f2d8cf+3,v17.0.rc1
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 unsigned 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(std::vector<unsigned> &indices) const = 0;
110 
112  virtual void dump(std::ostream &stream = std::cout) const = 0;
113 
115  unsigned getIndex() { return index; }
116 
118  void setIndex(unsigned i) { index = i; }
119 
120 protected:
121  // Start index of this mapping in the "grand" fit
122  unsigned 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  unsigned 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(std::vector<unsigned> &indices) const override {
187  if (indices.size() < getNpar()) indices.resize(getNpar());
188  for (unsigned 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  unsigned 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(std::vector<unsigned> &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  unsigned getNParChip() const { return _nParChip; }
272  unsigned 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.
276  unsigned _nParChip, _nParVisit;
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...
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
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
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.
A base class for image defects.
void dump(std::ostream &stream=std::cout) const override
Dump the contents of the transforms, for debugging.
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
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)
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 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).
unsigned getIndex()
Get the index of this mapping in the grand fit.
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.
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().
ChipVisitMagnitudeMapping(std::shared_ptr< PhotometryMapping > chipMapping, std::shared_ptr< PhotometryMapping > visitMapping)
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