LSSTApplications  19.0.0-14-gb0260a2+72efe9b372,20.0.0+7927753e06,20.0.0+8829bf0056,20.0.0+995114c5d2,20.0.0+b6f4b2abd1,20.0.0+bddc4f4cbe,20.0.0-1-g253301a+8829bf0056,20.0.0-1-g2b7511a+0d71a2d77f,20.0.0-1-g5b95a8c+7461dd0434,20.0.0-12-g321c96ea+23efe4bbff,20.0.0-16-gfab17e72e+fdf35455f6,20.0.0-2-g0070d88+ba3ffc8f0b,20.0.0-2-g4dae9ad+ee58a624b3,20.0.0-2-g61b8584+5d3db074ba,20.0.0-2-gb780d76+d529cf1a41,20.0.0-2-ged6426c+226a441f5f,20.0.0-2-gf072044+8829bf0056,20.0.0-2-gf1f7952+ee58a624b3,20.0.0-20-geae50cf+e37fec0aee,20.0.0-25-g3dcad98+544a109665,20.0.0-25-g5eafb0f+ee58a624b3,20.0.0-27-g64178ef+f1f297b00a,20.0.0-3-g4cc78c6+e0676b0dc8,20.0.0-3-g8f21e14+4fd2c12c9a,20.0.0-3-gbd60e8c+187b78b4b8,20.0.0-3-gbecbe05+48431fa087,20.0.0-38-ge4adf513+a12e1f8e37,20.0.0-4-g97dc21a+544a109665,20.0.0-4-gb4befbc+087873070b,20.0.0-4-gf910f65+5d3db074ba,20.0.0-5-gdfe0fee+199202a608,20.0.0-5-gfbfe500+d529cf1a41,20.0.0-6-g64f541c+d529cf1a41,20.0.0-6-g9a5b7a1+a1cd37312e,20.0.0-68-ga3f3dda+5fca18c6a4,20.0.0-9-g4aef684+e18322736b,w.2020.45
LSSTDataManagementBasePackage
Public Member Functions | Protected Types | Protected Member Functions | Protected Attributes | List of all members
lsst::jointcal::ConstrainedFluxModel Class Reference

#include <ConstrainedPhotometryModel.h>

Inheritance diagram for lsst::jointcal::ConstrainedFluxModel:
lsst::jointcal::ConstrainedPhotometryModel lsst::jointcal::PhotometryModel

Public Member Functions

 ConstrainedFluxModel (CcdImageList const &ccdImageList, geom::Box2D const &focalPlaneBBox, int visitOrder=7, double errorPedestal=0)
 
void offsetFittedStar (FittedStar &fittedStar, double delta) const override
 Offset the appropriate flux or magnitude (by -delta). More...
 
double computeResidual (CcdImage const &ccdImage, MeasuredStar const &measuredStar) const override
 Compute the residual between the model applied to a star and its associated fittedStar. More...
 
double computeRefResidual (FittedStar const &fittedStar, RefStar const &refStar) const override
 Return the fittedStar - refStar residual appropriate for this model (e.g. flux - flux or mag - mag). More...
 
double getRefError (RefStar const &refStar) const override
 Return the refStar error appropriate for this model (e.g. fluxErr or magErr). More...
 
double transform (CcdImage const &ccdImage, MeasuredStar const &measuredStar) const override
 Return the on-sky transformed flux for measuredStar on ccdImage. More...
 
double transformError (CcdImage const &ccdImage, MeasuredStar const &measuredStar) const override
 Return the on-sky transformed flux uncertainty for measuredStar on ccdImage. More...
 
std::shared_ptr< afw::image::PhotoCalibtoPhotoCalib (CcdImage const &ccdImage) const override
 Return the mapping of ccdImage represented as a PhotoCalib. More...
 
void print (std::ostream &out) const override
 Print a string representation of the contents of this mapping, for debugging. More...
 
Eigen::Index assignIndices (std::string const &whatToFit, Eigen::Index firstIndex) override
 Assign indices in the full matrix to the parameters being fit in the mappings, starting at firstIndex. More...
 
void offsetParams (Eigen::VectorXd const &delta) override
 Offset the parameters by the provided amounts (by -delta). More...
 
void freezeErrorTransform () override
 Once this routine has been called, the error transform is not modified by offsetParams(). More...
 
void getMappingIndices (CcdImage const &ccdImage, IndexVector &indices) const override
 Get how this set of parameters (of length Npar()) map into the "grand" fit. More...
 
std::size_t getTotalParameters () const override
 Return the total number of parameters in this model. More...
 
void computeParameterDerivatives (MeasuredStar const &measuredStar, CcdImage const &ccdImage, Eigen::VectorXd &derivatives) const override
 Compute the parametric derivatives of this model. More...
 
std::size_t getNpar (CcdImage const &ccdImage) const
 Return the number of parameters in the mapping of CcdImage. More...
 
PhotometryMappingBase const & getMapping (CcdImage const &ccdImage) const
 Get the mapping associated with ccdImage. More...
 
bool validate (CcdImageList const &ccdImageList, int ndof) const
 Return true if this is a "reasonable" model. More...
 
bool checkPositiveOnBBox (CcdImage const &ccdImage) const
 Check that the model is positive on the ccdImage bbox. More...
 
double getErrorPedestal ()
 
double tweakFluxError (jointcal::MeasuredStar const &measuredStar) const
 Add a fraction of the instrumental flux to the instrumental flux error, in quadrature. More...
 
double tweakMagnitudeError (jointcal::MeasuredStar const &measuredStar) const
 Add a small magnitude offset to the "instrumental magnitude" error, in quadrature. More...
 

Protected Types

typedef std::unordered_map< CcdImageKey, std::unique_ptr< ChipVisitPhotometryMapping > > MapType
 
typedef std::map< VisitIdType, std::shared_ptr< PhotometryMapping > > VisitMapType
 
typedef std::map< CcdIdType, std::shared_ptr< PhotometryMapping > > ChipMapType
 

Protected Member Functions

double initialChipCalibration (std::shared_ptr< afw::image::PhotoCalib const > photoCalib) override
 Return the initial calibration to use from this photoCalib. More...
 
PhotometryMappingBasefindMapping (CcdImage const &ccdImage) const override
 Return a pointer to the mapping associated with this ccdImage. More...
 
template<class ChipTransform , class VisitTransform , class ChipVisitMapping >
void initialize (CcdImageList const &ccdImageList, geom::Box2D const &focalPlaneBBox, int visitOrder)
 Initialize the chip, visit, and chipVisit mappings by creating appropriate transforms and mappings. More...
 
PrepPhotoCalib prepPhotoCalib (CcdImage const &ccdImage) const
 Helper for preparing toPhotoCalib() More...
 

Protected Attributes

MapType _chipVisitMap
 
VisitMapType _visitMap
 
ChipMapType _chipMap
 
LOG_LOGGER _log
 lsst.logging instance, to be created by a subclass so that messages have consistent name. More...
 
double errorPedestal
 

Detailed Description

Definition at line 137 of file ConstrainedPhotometryModel.h.

Member Typedef Documentation

◆ ChipMapType

Definition at line 108 of file ConstrainedPhotometryModel.h.

◆ MapType

Definition at line 101 of file ConstrainedPhotometryModel.h.

◆ VisitMapType

Definition at line 105 of file ConstrainedPhotometryModel.h.

Constructor & Destructor Documentation

◆ ConstrainedFluxModel()

lsst::jointcal::ConstrainedFluxModel::ConstrainedFluxModel ( CcdImageList const &  ccdImageList,
geom::Box2D const &  focalPlaneBBox,
int  visitOrder = 7,
double  errorPedestal = 0 
)
inlineexplicit

Definition at line 139 of file ConstrainedPhotometryModel.h.

141  : ConstrainedPhotometryModel(ccdImageList, focalPlaneBBox,
142  LOG_GET("jointcal.ConstrainedFluxModel"), visitOrder,
143  errorPedestal) {
144  initialize<FluxTransformSpatiallyInvariant, FluxTransformChebyshev, ChipVisitFluxMapping>(
145  ccdImageList, focalPlaneBBox, visitOrder);
146  }

Member Function Documentation

◆ assignIndices()

Eigen::Index lsst::jointcal::ConstrainedPhotometryModel::assignIndices ( std::string const &  whatToFit,
Eigen::Index  firstIndex 
)
overridevirtualinherited

Assign indices in the full matrix to the parameters being fit in the mappings, starting at firstIndex.

Parameters
[in]whatToFitString containing parameters to fit.
[in]firstIndexIndex to start assigning at.
Returns
The highest assigned index.

Implements lsst::jointcal::PhotometryModel.

Definition at line 45 of file ConstrainedPhotometryModel.cc.

46  {
47  Eigen::Index index = firstIndex;
48  if (whatToFit.find("Model") == std::string::npos) {
49  LOGLS_WARN(_log, "assignIndices was called and Model is *not* in whatToFit");
50  return index;
51  }
52 
53  // If we got here, "Model" is definitely in whatToFit.
54  _fittingChips = (whatToFit.find("ModelChip") != std::string::npos);
55  _fittingVisits = (whatToFit.find("ModelVisit") != std::string::npos);
56  // If nothing more than "Model" is specified, it means fit everything.
57  if ((!_fittingChips) && (!_fittingVisits)) {
58  _fittingChips = _fittingVisits = true;
59  }
60 
61  if (_fittingChips) {
62  for (auto &idMapping : _chipMap) {
63  auto mapping = idMapping.second.get();
64  // Don't assign indices for fixed parameters.
65  if (mapping->isFixed()) continue;
66  mapping->setIndex(index);
67  index += mapping->getNpar();
68  }
69  }
70  if (_fittingVisits) {
71  for (auto &idMapping : _visitMap) {
72  auto mapping = idMapping.second.get();
73  mapping->setIndex(index);
74  index += mapping->getNpar();
75  }
76  }
77  for (auto &idMapping : _chipVisitMap) {
78  idMapping.second->setWhatToFit(_fittingChips, _fittingVisits);
79  }
80  return index;
81 }

◆ checkPositiveOnBBox()

bool lsst::jointcal::PhotometryModel::checkPositiveOnBBox ( CcdImage const &  ccdImage) const
inherited

Check that the model is positive on the ccdImage bbox.

Parameters
ccdImageThe ccdImage to test.
Returns
True if the image is positive on a sampling of points of the ccdImage bbox.

Definition at line 49 of file PhotometryModel.cc.

49  {
50  bool check = true;
51  auto bbox = ccdImage.getImageFrame();
52  for (auto const &x : {bbox.xMin, bbox.getCenter().x, bbox.xMax})
53  for (auto const &y : {bbox.yMin, bbox.getCenter().y, bbox.yMax}) {
54  // flux, fluxErr, instFlux, instFluxErr all 1
56  star.setInstFluxAndErr(1, 1);
57  double result = transform(ccdImage, star);
58  // Don't short circuit so that we log every place the model is negative.
59  if (result < 0) {
60  LOGLS_WARN(_log, "CcdImage " << ccdImage.getName() << " is negative at (" << x << "," << y
61  << "): " << result);
62  check = false;
63  }
64  }
65  return check;
66 }

◆ computeParameterDerivatives()

void lsst::jointcal::ConstrainedPhotometryModel::computeParameterDerivatives ( MeasuredStar const &  measuredStar,
CcdImage const &  ccdImage,
Eigen::VectorXd &  derivatives 
) const
overridevirtualinherited

Compute the parametric derivatives of this model.

Parameters
[in]measuredStarThe measured star with the position and flux to compute at.
[in]ccdImageThe ccdImage containing the measured star, to find the correct mapping.
[out]derivativesThe computed derivatives. Must be pre-allocated to the correct size.

Implements lsst::jointcal::PhotometryModel.

Definition at line 125 of file ConstrainedPhotometryModel.cc.

127  {
128  auto mapping = findMapping(ccdImage);
129  mapping->computeParameterDerivatives(measuredStar, measuredStar.getInstFlux(), derivatives);
130 }

◆ computeRefResidual()

double lsst::jointcal::ConstrainedFluxModel::computeRefResidual ( FittedStar const &  fittedStar,
RefStar const &  refStar 
) const
inlineoverridevirtual

Return the fittedStar - refStar residual appropriate for this model (e.g. flux - flux or mag - mag).

Implements lsst::jointcal::PhotometryModel.

Definition at line 157 of file ConstrainedPhotometryModel.h.

157  {
158  return fittedStar.getFlux() - refStar.getFlux();
159  };

◆ computeResidual()

double lsst::jointcal::ConstrainedFluxModel::computeResidual ( CcdImage const &  ccdImage,
MeasuredStar const &  measuredStar 
) const
overridevirtual

Compute the residual between the model applied to a star and its associated fittedStar.

\[ residual = Model(measuredStar) - fittedStar \]

Parameters
ccdImageThe ccdImage where measuredStar resides.
measuredStarThe measured star position to compute the residual of.
Returns
The residual.

Implements lsst::jointcal::PhotometryModel.

Definition at line 267 of file ConstrainedPhotometryModel.cc.

268  {
269  return transform(ccdImage, measuredStar) - measuredStar.getFittedStar()->getFlux();
270 }

◆ findMapping()

PhotometryMappingBase * lsst::jointcal::ConstrainedPhotometryModel::findMapping ( CcdImage const &  ccdImage) const
overrideprotectedvirtualinherited

Return a pointer to the mapping associated with this ccdImage.

Implements lsst::jointcal::PhotometryModel.

Definition at line 168 of file ConstrainedPhotometryModel.cc.

168  {
169  auto idMapping = _chipVisitMap.find(ccdImage.getHashKey());
170  if (idMapping == _chipVisitMap.end())
171  throw LSST_EXCEPT(pex::exceptions::InvalidParameterError,
172  "ConstrainedPhotometryModel cannot find CcdImage " + ccdImage.getName());
173  return idMapping->second.get();
174 }

◆ freezeErrorTransform()

void lsst::jointcal::ConstrainedPhotometryModel::freezeErrorTransform ( )
overridevirtualinherited

Once this routine has been called, the error transform is not modified by offsetParams().

The routine can be called when the mappings are roughly in place. After the call, the transformations used to propagate errors are no longer affected when updating the mappings. This allows an exactly linear fit, which can be necessary for some model+data combinations.

Implements lsst::jointcal::PhotometryModel.

Definition at line 100 of file ConstrainedPhotometryModel.cc.

100  {
101  for (auto &idMapping : _chipMap) {
102  idMapping.second.get()->freezeErrorTransform();
103  }
104  for (auto &idMapping : _visitMap) {
105  idMapping.second.get()->freezeErrorTransform();
106  }
107 }

◆ getErrorPedestal()

double lsst::jointcal::PhotometryModel::getErrorPedestal ( )
inlineinherited

Definition at line 196 of file PhotometryModel.h.

196 { return errorPedestal; }

◆ getMapping()

PhotometryMappingBase const& lsst::jointcal::PhotometryModel::getMapping ( CcdImage const &  ccdImage) const
inlineinherited

Get the mapping associated with ccdImage.

Definition at line 156 of file PhotometryModel.h.

156  {
157  return *(findMapping(ccdImage));
158  }

◆ getMappingIndices()

void lsst::jointcal::ConstrainedPhotometryModel::getMappingIndices ( CcdImage const &  ccdImage,
IndexVector indices 
) const
overridevirtualinherited

Get how this set of parameters (of length Npar()) map into the "grand" fit.

Parameters
[in]ccdImageThe ccdImage to look up.
[out]indicesThe indices of the mapping associated with ccdImage.

Implements lsst::jointcal::PhotometryModel.

Definition at line 109 of file ConstrainedPhotometryModel.cc.

109  {
110  auto mapping = findMapping(ccdImage);
111  mapping->getMappingIndices(indices);
112 }

◆ getNpar()

std::size_t lsst::jointcal::PhotometryModel::getNpar ( CcdImage const &  ccdImage) const
inlineinherited

Return the number of parameters in the mapping of CcdImage.

Definition at line 153 of file PhotometryModel.h.

153 { return findMapping(ccdImage)->getNpar(); }

◆ getRefError()

double lsst::jointcal::ConstrainedFluxModel::getRefError ( RefStar const &  refStar) const
inlineoverridevirtual

Return the refStar error appropriate for this model (e.g. fluxErr or magErr).

Implements lsst::jointcal::PhotometryModel.

Definition at line 162 of file ConstrainedPhotometryModel.h.

162 { return refStar.getFluxErr(); }

◆ getTotalParameters()

std::size_t lsst::jointcal::ConstrainedPhotometryModel::getTotalParameters ( ) const
overridevirtualinherited

Return the total number of parameters in this model.

Implements lsst::jointcal::PhotometryModel.

Definition at line 114 of file ConstrainedPhotometryModel.cc.

114  {
115  std::size_t total = 0;
116  for (auto &idMapping : _chipMap) {
117  total += idMapping.second->getNpar();
118  }
119  for (auto &idMapping : _visitMap) {
120  total += idMapping.second->getNpar();
121  }
122  return total;
123 }

◆ initialChipCalibration()

double lsst::jointcal::ConstrainedFluxModel::initialChipCalibration ( std::shared_ptr< afw::image::PhotoCalib const >  photoCalib)
inlineoverrideprotectedvirtual

Return the initial calibration to use from this photoCalib.

Implements lsst::jointcal::ConstrainedPhotometryModel.

Definition at line 178 of file ConstrainedPhotometryModel.h.

178  {
179  return photoCalib->getCalibrationMean();
180  }

◆ initialize()

template<class ChipTransform , class VisitTransform , class ChipVisitMapping >
template void lsst::jointcal::ConstrainedPhotometryModel::initialize< MagnitudeTransformSpatiallyInvariant, MagnitudeTransformChebyshev, ChipVisitMagnitudeMapping > ( CcdImageList const &  ccdImageList,
geom::Box2D const &  focalPlaneBBox,
int  visitOrder 
)
protectedinherited

Initialize the chip, visit, and chipVisit mappings by creating appropriate transforms and mappings.

Definition at line 177 of file ConstrainedPhotometryModel.cc.

178  {
179  // keep track of which chip we want to constrain (the one closest to the middle of the focal plane)
180  double minRadius2 = std::numeric_limits<double>::infinity();
181  CcdIdType constrainedChip = -1;
182 
183  // First initialize all visit and ccd transforms, before we make the ccdImage mappings.
184  for (auto const &ccdImage : ccdImageList) {
185  auto visit = ccdImage->getVisit();
186  auto chip = ccdImage->getCcdId();
187  auto visitPair = _visitMap.find(visit);
188  auto chipPair = _chipMap.find(chip);
189 
190  // If the chip is not in the map, add it, otherwise continue.
191  if (chipPair == _chipMap.end()) {
192  auto center = ccdImage->getDetector()->getCenter(afw::cameraGeom::FOCAL_PLANE);
193  double radius2 = std::pow(center.getX(), 2) + std::pow(center.getY(), 2);
194  if (radius2 < minRadius2) {
195  minRadius2 = radius2;
196  constrainedChip = chip;
197  }
198  auto photoCalib = ccdImage->getPhotoCalib();
199  // Use the single-frame processing calibration from the PhotoCalib as the default.
200  auto chipTransform = std::make_unique<ChipTransform>(initialChipCalibration(photoCalib));
201  _chipMap[chip] = std::make_shared<PhotometryMapping>(std::move(chipTransform));
202  }
203  // If the visit is not in the map, add it, otherwise continue.
204  if (visitPair == _visitMap.end()) {
205  auto visitTransform = std::make_unique<VisitTransform>(visitOrder, focalPlaneBBox);
206  _visitMap[visit] = std::make_shared<PhotometryMapping>(std::move(visitTransform));
207  }
208  }
209 
210  // Fix one chip mapping, to remove the degeneracy from the system.
211  _chipMap.at(constrainedChip)->setFixed(true);
212 
213  // Now create the ccdImage mappings, which are combinations of the chip/visit mappings above.
214  for (auto const &ccdImage : ccdImageList) {
215  auto visit = ccdImage->getVisit();
216  auto chip = ccdImage->getCcdId();
217  _chipVisitMap.emplace(ccdImage->getHashKey(),
218  std::make_unique<ChipVisitMapping>(_chipMap[chip], _visitMap[visit]));
219  }
220  LOGLS_INFO(_log, "Got " << _chipMap.size() << " chip mappings and " << _visitMap.size()
221  << " visit mappings; holding chip " << constrainedChip << " fixed ("
222  << getTotalParameters() << " total parameters).");
223  LOGLS_DEBUG(_log, "CcdImage map has " << _chipVisitMap.size() << " mappings, with "
224  << _chipVisitMap.bucket_count() << " buckets and a load factor of "
226 }

◆ offsetFittedStar()

void lsst::jointcal::ConstrainedFluxModel::offsetFittedStar ( FittedStar fittedStar,
double  delta 
) const
inlineoverridevirtual

Offset the appropriate flux or magnitude (by -delta).

Parameters
fittedStarThe star to update.
deltaThe amount to update by.

Implements lsst::jointcal::PhotometryModel.

Definition at line 149 of file ConstrainedPhotometryModel.h.

149  {
150  fittedStar.getFlux() -= delta;
151  }

◆ offsetParams()

void lsst::jointcal::ConstrainedPhotometryModel::offsetParams ( Eigen::VectorXd const &  delta)
overridevirtualinherited

Offset the parameters by the provided amounts (by -delta).

The shifts are applied according to the indices given in assignIndices.

Parameters
[in]deltavector of offsets to apply

Implements lsst::jointcal::PhotometryModel.

Definition at line 83 of file ConstrainedPhotometryModel.cc.

83  {
84  if (_fittingChips) {
85  for (auto &idMapping : _chipMap) {
86  auto mapping = idMapping.second.get();
87  // Don't offset indices for fixed parameters.
88  if (mapping->isFixed()) continue;
89  mapping->offsetParams(delta.segment(mapping->getIndex(), mapping->getNpar()));
90  }
91  }
92  if (_fittingVisits) {
93  for (auto &idMapping : _visitMap) {
94  auto mapping = idMapping.second.get();
95  mapping->offsetParams(delta.segment(mapping->getIndex(), mapping->getNpar()));
96  }
97  }
98 }

◆ prepPhotoCalib()

ConstrainedPhotometryModel::PrepPhotoCalib lsst::jointcal::ConstrainedPhotometryModel::prepPhotoCalib ( CcdImage const &  ccdImage) const
protectedinherited

Helper for preparing toPhotoCalib()

Definition at line 228 of file ConstrainedPhotometryModel.cc.

229  {
230  auto detector = ccdImage.getDetector();
231  auto ccdBBox = detector->getBBox();
232  ChipVisitPhotometryMapping *mapping = dynamic_cast<ChipVisitPhotometryMapping *>(findMapping(ccdImage));
233 
234  // There should be no way in which we can get to this point and not have a ChipVisitMapping,
235  // so blow up if we don't.
236  assert(mapping != nullptr);
237  // We know it's a Chebyshev transform because we created it as such, so blow up if it's not.
238  auto visitPhotometryTransform = std::dynamic_pointer_cast<PhotometryTransformChebyshev>(
239  mapping->getVisitMapping()->getTransform());
240  assert(visitPhotometryTransform != nullptr);
241  auto focalBBox = visitPhotometryTransform->getBBox();
242 
243  // Unravel our chebyshev coefficients to build an astshim::ChebyMap.
244  auto coeff_f = toChebyMapCoeffs(std::dynamic_pointer_cast<PhotometryTransformChebyshev>(
245  mapping->getVisitMapping()->getTransform()));
246  // Bounds are the bbox
247  std::vector<double> lowerBound = {focalBBox.getMinX(), focalBBox.getMinY()};
248  std::vector<double> upperBound = {focalBBox.getMaxX(), focalBBox.getMaxY()};
249  afw::geom::TransformPoint2ToGeneric visitTransform(ast::ChebyMap(coeff_f, 1, lowerBound, upperBound));
250 
251  double chipConstant = mapping->getChipMapping()->getParameters()[0];
252 
253  // Compute a box that covers the area of the ccd in focal plane coordinates.
254  // This is the box over which we want to compute the mean of the visit transform.
255  auto pixToFocal = detector->getTransform(afw::cameraGeom::PIXELS, afw::cameraGeom::FOCAL_PLANE);
256  geom::Box2D ccdBBoxInFocal;
257  for (auto const &point : pixToFocal->applyForward(geom::Box2D(ccdBBox).getCorners())) {
258  ccdBBoxInFocal.include(point);
259  }
260  double visitMean = visitPhotometryTransform->mean(ccdBBoxInFocal);
261 
262  return {chipConstant, visitTransform, pixToFocal, visitMean};
263 }

◆ print()

void lsst::jointcal::ConstrainedFluxModel::print ( std::ostream out) const
overridevirtual

Print a string representation of the contents of this mapping, for debugging.

This string representation can be very verbose, as it contains all of the parameters of all of the transforms in this model.

Reimplemented from lsst::jointcal::ConstrainedPhotometryModel.

Definition at line 303 of file ConstrainedPhotometryModel.cc.

303  {
304  out << "ConstrainedFluxModel:" << std::endl;
306 }

◆ toPhotoCalib()

std::shared_ptr< afw::image::PhotoCalib > lsst::jointcal::ConstrainedFluxModel::toPhotoCalib ( CcdImage const &  ccdImage) const
overridevirtual

Return the mapping of ccdImage represented as a PhotoCalib.

Implements lsst::jointcal::PhotometryModel.

Definition at line 284 of file ConstrainedPhotometryModel.cc.

284  {
285  auto ccdBBox = ccdImage.getDetector()->getBBox();
286  auto prep = prepPhotoCalib(ccdImage);
287 
288  // The chip part is easy: zoom map with the single value as the "zoom" factor
289  afw::geom::Transform<afw::geom::GenericEndpoint, afw::geom::GenericEndpoint> zoomTransform(
290  ast::ZoomMap(1, prep.chipConstant));
291 
292  // Now stitch them all together.
293  auto transform = prep.pixToFocal->then(prep.visitTransform)->then(zoomTransform);
294 
295  // NOTE: TransformBoundedField does not implement mean(), so we have to compute it here.
296  double mean = prep.chipConstant * prep.visitMean;
297 
298  auto boundedField = std::make_shared<afw::math::TransformBoundedField>(ccdBBox, *transform);
299  return std::make_shared<afw::image::PhotoCalib>(mean, ccdImage.getPhotoCalib()->getCalibrationErr(),
300  boundedField, false);
301 }

◆ transform()

double lsst::jointcal::ConstrainedFluxModel::transform ( CcdImage const &  ccdImage,
MeasuredStar const &  measuredStar 
) const
overridevirtual

Return the on-sky transformed flux for measuredStar on ccdImage.

Parameters
[in]ccdImageThe ccdImage where measuredStar resides.
measuredStarThe measured star position to transform.
Returns
The on-sky flux transformed from instFlux at measuredStar's position.

Implements lsst::jointcal::PhotometryModel.

Definition at line 272 of file ConstrainedPhotometryModel.cc.

272  {
273  auto mapping = findMapping(ccdImage);
274  return mapping->transform(measuredStar, measuredStar.getInstFlux());
275 }

◆ transformError()

double lsst::jointcal::ConstrainedFluxModel::transformError ( CcdImage const &  ccdImage,
MeasuredStar const &  measuredStar 
) const
overridevirtual

Return the on-sky transformed flux uncertainty for measuredStar on ccdImage.

Identical to transform() until freezeErrorTransform() is called.

Parameters
[in]ccdImageThe ccdImage where measuredStar resides.
measuredStarThe measured star position to transform.
Returns
The on-sky flux transformed from instFlux at measuredStar's position.

Implements lsst::jointcal::PhotometryModel.

Definition at line 277 of file ConstrainedPhotometryModel.cc.

278  {
279  auto mapping = findMapping(ccdImage);
280  double tempErr = tweakFluxError(measuredStar);
281  return mapping->transformError(measuredStar, measuredStar.getInstFlux(), tempErr);
282 }

◆ tweakFluxError()

double lsst::jointcal::PhotometryModel::tweakFluxError ( jointcal::MeasuredStar const &  measuredStar) const
inlineinherited

Add a fraction of the instrumental flux to the instrumental flux error, in quadrature.

Definition at line 199 of file PhotometryModel.h.

199  {
200  if (errorPedestal == 0) {
201  return measuredStar.getInstFluxErr();
202  } else {
203  return std::hypot(measuredStar.getInstFluxErr(), measuredStar.getInstFlux() * errorPedestal);
204  }
205  }

◆ tweakMagnitudeError()

double lsst::jointcal::PhotometryModel::tweakMagnitudeError ( jointcal::MeasuredStar const &  measuredStar) const
inlineinherited

Add a small magnitude offset to the "instrumental magnitude" error, in quadrature.

Definition at line 208 of file PhotometryModel.h.

208  {
209  if (errorPedestal == 0) {
210  return measuredStar.getInstMagErr();
211  } else {
212  return std::hypot(measuredStar.getInstMagErr(), errorPedestal);
213  }
214  }

◆ validate()

bool lsst::jointcal::PhotometryModel::validate ( CcdImageList const &  ccdImageList,
int  ndof 
) const
inherited

Return true if this is a "reasonable" model.

A valid photometry model is positive within each sensor's bounding box.

Parameters
ccdImageListThe ccdImages to test the model validity on.
ndofThe number of degrees of freedom in the fit, e.g. from Fitterbase.computeChi2().
Returns
True if the model is valid on all ccdImages.

Definition at line 33 of file PhotometryModel.cc.

33  {
34  bool check = true;
35  for (auto const &ccdImage : ccdImageList) {
36  // Don't short circuit so that we log every place the model is negative.
37  check &= checkPositiveOnBBox(*ccdImage);
38  }
39  if (ndof < 0) {
40  check &= false;
41  LOGLS_ERROR(_log, "This model only has "
42  << ndof << " degrees of freedom, with " << getTotalParameters()
43  << " total parameters. Reduce the model complexity (e.g. polynomial order)"
44  " to better match the number of measured sources.");
45  }
46  return check;
47 }

Member Data Documentation

◆ _chipMap

ChipMapType lsst::jointcal::ConstrainedPhotometryModel::_chipMap
protectedinherited

Definition at line 109 of file ConstrainedPhotometryModel.h.

◆ _chipVisitMap

MapType lsst::jointcal::ConstrainedPhotometryModel::_chipVisitMap
protectedinherited

Definition at line 102 of file ConstrainedPhotometryModel.h.

◆ _log

LOG_LOGGER lsst::jointcal::PhotometryModel::_log
protectedinherited

lsst.logging instance, to be created by a subclass so that messages have consistent name.

Definition at line 221 of file PhotometryModel.h.

◆ _visitMap

VisitMapType lsst::jointcal::ConstrainedPhotometryModel::_visitMap
protectedinherited

Definition at line 106 of file ConstrainedPhotometryModel.h.

◆ errorPedestal

double lsst::jointcal::PhotometryModel::errorPedestal
protectedinherited

Definition at line 224 of file PhotometryModel.h.


The documentation for this class was generated from the following files:
y
int y
Definition: SpanSet.cc:49
lsst::jointcal::MeasuredStar
objects measured on actual images.
Definition: MeasuredStar.h:46
lsst::jointcal::PhotometryModel::transform
virtual double transform(CcdImage const &ccdImage, MeasuredStar const &measuredStar) const =0
Return the on-sky transformed flux for measuredStar on ccdImage.
std::move
T move(T... args)
lsst::jointcal::CcdIdType
int CcdIdType
Definition: CcdImage.h:49
std::vector< double >
std::unordered_map::find
T find(T... args)
std::map::size
T size(T... args)
std::unordered_map::emplace
T emplace(T... args)
LOG_GET
#define LOG_GET(logger)
Definition: Log.h:75
lsst::afw::geom::TransformPoint2ToGeneric
Transform< Point2Endpoint, GenericEndpoint > TransformPoint2ToGeneric
Definition: Transform.h:301
LOGLS_INFO
#define LOGLS_INFO(logger, message)
Definition: Log.h:628
ast::ZoomMap
A Mapping which "zooms" a set of points about the origin by multiplying all coordinate values by the ...
Definition: ZoomMap.h:45
LOGLS_ERROR
#define LOGLS_ERROR(logger, message)
Definition: Log.h:668
lsst::jointcal::ConstrainedPhotometryModel::ConstrainedPhotometryModel
ConstrainedPhotometryModel(CcdImageList const &ccdImageList, geom::Box2D const &focalPlaneBBox, LOG_LOGGER log, int visitOrder=7, double errorPedestal=0)
Construct a constrained photometry model.
Definition: ConstrainedPhotometryModel.h:60
lsst::jointcal::PhotometryModel::getTotalParameters
virtual std::size_t getTotalParameters() const =0
Return the total number of parameters in this model.
lsst::geom::Box2D::getCorners
std::vector< Point2D > getCorners() const
Get the corner points.
Definition: Box.cc:496
lsst::jointcal::PhotometryMappingBase::getNpar
virtual std::size_t getNpar() const =0
Number of total parameters in this mapping.
LOGLS_WARN
#define LOGLS_WARN(logger, message)
Definition: Log.h:648
lsst::jointcal::PhotometryModel::tweakFluxError
double tweakFluxError(jointcal::MeasuredStar const &measuredStar) const
Add a fraction of the instrumental flux to the instrumental flux error, in quadrature.
Definition: PhotometryModel.h:199
std::hypot
T hypot(T... args)
lsst::jointcal::PhotometryModel::checkPositiveOnBBox
bool checkPositiveOnBBox(CcdImage const &ccdImage) const
Check that the model is positive on the ccdImage bbox.
Definition: PhotometryModel.cc:49
std::map::at
T at(T... args)
std::numeric_limits::infinity
T infinity(T... args)
x
double x
Definition: ChebyshevBoundedField.cc:277
lsst::jointcal::ConstrainedPhotometryModel::initialChipCalibration
virtual double initialChipCalibration(std::shared_ptr< afw::image::PhotoCalib const > photoCalib)=0
Return the initial calibration to use from this photoCalib.
lsst::jointcal::ConstrainedPhotometryModel::_visitMap
VisitMapType _visitMap
Definition: ConstrainedPhotometryModel.h:106
lsst::jointcal::PhotometryModel::findMapping
virtual PhotometryMappingBase * findMapping(CcdImage const &ccdImage) const =0
Return a pointer to the mapping associated with this ccdImage.
result
py::object result
Definition: _schema.cc:429
LSST_EXCEPT
#define LSST_EXCEPT(type,...)
Create an exception with a given type.
Definition: Exception.h:48
LOGLS_DEBUG
#define LOGLS_DEBUG(logger, message)
Definition: Log.h:608
ast::ChebyMap
A ChebyMap is a form of Mapping which performs a Chebyshev polynomial transformation.
Definition: ChebyMap.h:97
photoCalib
Key< int > photoCalib
Definition: Exposure.cc:67
lsst::afw::cameraGeom::FOCAL_PLANE
CameraSys const FOCAL_PLANE
Focal plane coordinates: Position on a 2-d planar approximation to the focal plane (x,...
Definition: CameraSys.cc:30
std::endl
T endl(T... args)
std::unordered_map::load_factor
T load_factor(T... args)
lsst::jointcal::PhotometryModel::_log
LOG_LOGGER _log
lsst.logging instance, to be created by a subclass so that messages have consistent name.
Definition: PhotometryModel.h:221
lsst::jointcal::ConstrainedFluxModel::transform
double transform(CcdImage const &ccdImage, MeasuredStar const &measuredStar) const override
Return the on-sky transformed flux for measuredStar on ccdImage.
Definition: ConstrainedPhotometryModel.cc:272
std::unordered_map::bucket_count
T bucket_count(T... args)
detector
table::Key< int > detector
Definition: DetectorCollection.cc:172
lsst::jointcal::ConstrainedPhotometryModel::print
void print(std::ostream &out) const override
Print a string representation of the contents of this mapping, for debugging.
Definition: ConstrainedPhotometryModel.cc:154
lsst::geom::Box2D::include
void include(Point2D const &point) noexcept
Expand this to ensure that this->contains(point).
Definition: Box.cc:380
lsst::jointcal::ConstrainedPhotometryModel::prepPhotoCalib
PrepPhotoCalib prepPhotoCalib(CcdImage const &ccdImage) const
Helper for preparing toPhotoCalib()
Definition: ConstrainedPhotometryModel.cc:228
std::size_t
std::unordered_map::end
T end(T... args)
lsst::jointcal::BaseStar
The base class for handling stars. Used by all matching routines.
Definition: BaseStar.h:50
lsst::jointcal::PhotometryModel::errorPedestal
double errorPedestal
Definition: PhotometryModel.h:224
lsst::geom::Box2D
A floating-point coordinate rectangle geometry.
Definition: Box.h:413
lsst.pipe.tasks.assembleCoadd.visit
visit
Definition: assembleCoadd.py:343
lsst::jointcal::ConstrainedPhotometryModel::_chipMap
ChipMapType _chipMap
Definition: ConstrainedPhotometryModel.h:109
lsst::jointcal::ConstrainedPhotometryModel::findMapping
PhotometryMappingBase * findMapping(CcdImage const &ccdImage) const override
Return a pointer to the mapping associated with this ccdImage.
Definition: ConstrainedPhotometryModel.cc:168
lsst::afw::cameraGeom::PIXELS
CameraSysPrefix const PIXELS
Pixel coordinates: Nominal position on the entry surface of a given detector (x, y unbinned pixels).
Definition: CameraSys.cc:34
lsst::jointcal::ConstrainedPhotometryModel::_chipVisitMap
MapType _chipVisitMap
Definition: ConstrainedPhotometryModel.h:102
bbox
AmpInfoBoxKey bbox
Definition: Amplifier.cc:117
lsst::jointcal::ConstrainedPhotometryModel::getTotalParameters
std::size_t getTotalParameters() const override
Return the total number of parameters in this model.
Definition: ConstrainedPhotometryModel.cc:114
std::pow
T pow(T... args)