lsst.jointcal g456338a673+73083f2050
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
35#include "lsst/jointcal/Point.h"
37
38namespace lsst {
39namespace jointcal {
40
45public:
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
125protected:
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
136public:
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
205
206 std::shared_ptr<PhotometryTransform> getTransformErrors() const { return _transformErrors; }
207
208private:
209 // the actual transformation to be fit
211 // the transformation used for errors
213};
214
219public:
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
279
280protected:
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
290public:
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
304public:
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
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 > getChipMapping() const
std::shared_ptr< PhotometryMapping > _visitMapping
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::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.
std::shared_ptr< PhotometryMapping > getVisitMapping() const
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)
PhotometryMappingBase & operator=(PhotometryMappingBase const &)=delete
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.
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.
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
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.
std::shared_ptr< PhotometryTransform > getTransform() const
double transform(MeasuredStar const &measuredStar, double value) const override
Return the on-sky transformed flux for measuredStar on ccdImage.
std::shared_ptr< PhotometryTransform > getTransformErrors() const
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)
Class for a simple mapping implementing a generic AstrometryTransform.
STL namespace.
T resize(T... args)
T size(T... args)