lsst.jointcal  16.0-20-g17d57d5+3
PhotometryMapping.cc
Go to the documentation of this file.
1 #include <cmath>
2 
3 #include "lsst/log/Log.h"
4 
7 
8 namespace {
9 LOG_LOGGER _log = LOG_GET("jointcal.PhotometryMapping");
10 }
11 
12 namespace lsst {
13 namespace jointcal {
14 
16  if (indices.size() < getNpar()) indices.resize(getNpar());
17  // If we're fitting the chip mapping, fill those indices.
18  if (_nParChip > 0) {
19  _chipMapping->getMappingIndices(indices);
20  }
21  // If we're fitting the visit mapping, fill those indices.
22  if (_nParVisit > 0) {
23  // TODO DM-12169: there is probably a better way to feed a subpart of a std::vector
24  // (maybe a view or iterators?)
25  std::vector<unsigned> tempIndices(_visitMapping->getNpar());
26  _visitMapping->getMappingIndices(tempIndices);
27  // We have to insert the visit indices starting after the chip indices.
28  for (unsigned k = 0; k < _visitMapping->getNpar(); ++k) {
29  indices.at(k + _nParChip) = tempIndices.at(k);
30  }
31  }
32 }
33 
34 void ChipVisitPhotometryMapping::setWhatToFit(bool const fittingChips, bool const fittingVisits) {
35  if (fittingChips) {
36  _nParChip = _chipMapping->getNpar();
37  } else {
38  _nParChip = 0;
39  }
40  if (fittingVisits) {
41  _nParVisit = _visitMapping->getNpar();
42  } else {
43  _nParVisit = 0;
44  }
45 }
46 
47 // ChipVisitFluxMapping methods
48 
49 double ChipVisitFluxMapping::transformError(MeasuredStar const &measuredStar, double instFlux,
50  double instFluxErr) const {
51  // The transformed error is s_m = dM(f,x,y)/df + s_f.
52  double tempFlux =
53  _chipMapping->getTransfoErrors()->transform(measuredStar.x, measuredStar.y, instFluxErr);
54  return _visitMapping->getTransfoErrors()->transform(measuredStar.getXFocal(), measuredStar.getYFocal(),
55  tempFlux);
56 }
57 
58 void ChipVisitFluxMapping::computeParameterDerivatives(MeasuredStar const &measuredStar, double instFlux,
59  Eigen::Ref<Eigen::VectorXd> derivatives) const {
60  // TODO DM-12161: possible optimization is to merge transform and computeDerivatives,
61  // and/or save these intermediate calculations when transforming flux to use in derivatives.
62  // Like what AstrometryMappings do with `computeTransformAndDerivatives` vs. `transformPosAndErrors`.
63 
64  double chipScale = _chipMapping->getTransfo()->transform(measuredStar.x, measuredStar.y, 1);
65  double visitScale =
66  _visitMapping->getTransfo()->transform(measuredStar.getXFocal(), measuredStar.getYFocal(), 1);
67 
68  // NOTE: chipBlock is the product of the chip derivatives and the visit transforms, and vice versa.
69  // NOTE: See DMTN-036 for the math behind this.
70  if (getNParChip() > 0 && !_chipMapping->isFixed()) {
71  // The chip derivatives start at 0, independent of the full-fit indices.
72  Eigen::Ref<Eigen::VectorXd> chipBlock = derivatives.segment(0, getNParChip());
73  _chipMapping->getTransfo()->computeParameterDerivatives(measuredStar.x, measuredStar.y, instFlux,
74  chipBlock);
75  chipBlock *= visitScale;
76  }
77  if (getNParVisit() > 0) {
78  // The visit derivatives start at the last chip derivative, independent of the full-fit indices.
79  Eigen::Ref<Eigen::VectorXd> visitBlock = derivatives.segment(getNParChip(), getNParVisit());
80  _visitMapping->getTransfo()->computeParameterDerivatives(
81  measuredStar.getXFocal(), measuredStar.getYFocal(), instFlux, visitBlock);
82  visitBlock *= chipScale;
83  }
84 }
85 
86 // ChipVisitMagnitudeMapping methods
87 
88 double ChipVisitMagnitudeMapping::transformError(MeasuredStar const &measuredStar, double instFlux,
89  double instFluxErr) const {
90  // The transformed error is s_mout = 2.5/ln(10) * instFluxErr / instFlux
91  // because the other components of the mapping (f0, the polynomials) disappear in the partial derivative.
92  return 2.5 / std::log(10.0) * instFluxErr / instFlux;
93 }
94 
95 void ChipVisitMagnitudeMapping::computeParameterDerivatives(MeasuredStar const &measuredStar, double instFlux,
96  Eigen::Ref<Eigen::VectorXd> derivatives) const {
97  // TODO DM-12161: possible optimization is to merge transform and computeDerivatives,
98  // and/or save these intermediate calculations when transforming flux to use in derivatives.
99  // Like what AstrometryMappings do with `computeTransformAndDerivatives` vs. `transformPosAndErrors`.
100 
101  // NOTE: See DMTN-036 for the math behind this.
102  if (getNParChip() > 0 && !_chipMapping->isFixed()) {
103  // The chip derivatives start at 0, independent of the full-fit indices.
104  Eigen::Ref<Eigen::VectorXd> chipBlock = derivatives.segment(0, getNParChip());
105  _chipMapping->getTransfo()->computeParameterDerivatives(measuredStar.x, measuredStar.y, instFlux,
106  chipBlock);
107  }
108  if (getNParVisit() > 0) {
109  // The visit derivatives start at the last chip derivative, independent of the full-fit indices.
110  Eigen::Ref<Eigen::VectorXd> visitBlock = derivatives.segment(getNParChip(), getNParVisit());
111  _visitMapping->getTransfo()->computeParameterDerivatives(
112  measuredStar.getXFocal(), measuredStar.getYFocal(), instFlux, visitBlock);
113  }
114 }
115 
116 } // namespace jointcal
117 } // namespace lsst
double transformError(MeasuredStar const &measuredStar, double value, double valueErr) const override
Return the on-sky transformed flux uncertainty for measuredStar on ccdImage.
std::shared_ptr< PhotometryMapping > _visitMapping
void getMappingIndices(std::vector< unsigned > &indices) const override
Gets how this set of parameters (of length getNpar()) map into the "grand" fit.
void setWhatToFit(bool const fittingChips, bool const fittingVisits)
Set whether to fit chips or visits.
T log(T... args)
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.
std::shared_ptr< PhotometryMapping > _chipMapping
T resize(T... args)
double x
coordinate
Definition: Point.h:18
T at(T... args)
Class for a simple mapping implementing a generic Gtransfo.
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:19
T size(T... args)
unsigned getNpar() const override
Number of total parameters in this mapping.
#define LOG_GET(logger)