45 unsigned index = firstIndex;
46 if (whatToFit.
find(
"Model") == std::string::npos) {
47 LOGLS_WARN(
_log,
"assignIndices was called and Model is *not* in whatToFit");
52 _fittingChips = (whatToFit.
find(
"ModelChip") != std::string::npos);
53 _fittingVisits = (whatToFit.
find(
"ModelVisit") != std::string::npos);
55 if ((!_fittingChips) && (!_fittingVisits)) {
56 _fittingChips = _fittingVisits =
true;
61 auto mapping = idMapping.second.get();
63 if (mapping->isFixed())
continue;
64 mapping->setIndex(index);
65 index += mapping->getNpar();
70 auto mapping = idMapping.second.get();
71 mapping->setIndex(index);
72 index += mapping->getNpar();
76 idMapping.second->setWhatToFit(_fittingChips, _fittingVisits);
84 auto mapping = idMapping.second.get();
86 if (mapping->isFixed())
continue;
87 mapping->offsetParams(delta.segment(mapping->getIndex(), mapping->getNpar()));
92 auto mapping = idMapping.second.get();
93 mapping->offsetParams(delta.segment(mapping->getIndex(), mapping->getNpar()));
100 idMapping.second.get()->freezeErrorTransform();
103 idMapping.second.get()->freezeErrorTransform();
110 mapping->getMappingIndices(indices);
116 total += idMapping.second->getNpar();
119 total += idMapping.second->getNpar();
126 Eigen::VectorXd &derivatives)
const {
128 mapping->computeParameterDerivatives(measuredStar, measuredStar.
getInstFlux(), derivatives);
134 auto coeffs = transform->getCoefficients();
136 ndarray::Array<double, 2, 2> chebyCoeffs = allocate(ndarray::makeVector(transform->getNpar(), 4));
137 Eigen::VectorXd::Index k = 0;
138 auto order = transform->getOrder();
139 for (ndarray::Size j = 0; j <= order; ++j) {
140 ndarray::Size
const iMax = order - j;
141 for (ndarray::Size i = 0; i <= iMax; ++i, ++k) {
142 chebyCoeffs[k][0] = coeffs[j][i];
143 chebyCoeffs[k][1] = 1;
144 chebyCoeffs[k][2] = i;
145 chebyCoeffs[k][3] = j;
154 idMapping.second->dump(stream);
159 idMapping.second->dump(stream);
168 "ConstrainedPhotometryModel cannot find CcdImage " + ccdImage.
getName());
169 return idMapping->second.get();
172 template <
class ChipTransform,
class VisitTransform,
class ChipVisitMapping>
174 afw::geom::Box2D
const &focalPlaneBBox,
int visitOrder) {
180 for (
auto const &
ccdImage : ccdImageList) {
190 if (radius2 < minRadius2) {
191 minRadius2 = radius2;
192 constrainedChip = chip;
194 auto photoCalib =
ccdImage->getPhotoCalib();
201 auto visitTransform = std::make_unique<VisitTransform>(visitOrder, focalPlaneBBox);
210 for (
auto const &
ccdImage : ccdImageList) {
217 <<
" visit mappings; holding chip " << constrainedChip <<
" fixed (" 233 return mapping->transform(measuredStar, measuredStar.
getInstFlux());
240 return mapping->transformError(measuredStar, measuredStar.
getInstFlux(), tempErr);
250 assert(mapping !=
nullptr);
255 assert(visitTransform !=
nullptr);
256 auto focalBBox = visitTransform->getBBox();
259 auto coeff_f = toChebyMapCoeffs(std::dynamic_pointer_cast<PhotometryTransformChebyshev>(
272 auto transform = pixToFocal->then(chebyTransform)->then(zoomTransform);
276 auto boundedField = std::make_shared<afw::math::TransformBoundedField>(ccdBBox, *
transform);
277 return std::make_shared<afw::image::PhotoCalib>(oldPhotoCalib->getCalibrationMean(),
278 oldPhotoCalib->getCalibrationErr(), boundedField,
false);
291 return mapping->transform(measuredStar, measuredStar.
getInstMag());
298 return mapping->transformError(measuredStar, measuredStar.
getInstFlux(), tempErr);
309 assert(mapping !=
nullptr);
314 assert(visitTransform !=
nullptr);
315 auto focalBBox = visitTransform->getBBox();
318 auto coeff_f = toChebyMapCoeffs(std::dynamic_pointer_cast<PhotometryTransformChebyshev>(
326 using namespace std::string_literals;
328 ast::MathMap(1, 1, {
"y=pow(10.0,x/-2.5)"s}, {
"x=-2.5*log10(y)"s}));
336 auto transform = pixToFocal->then(chebyTransform)->then(logTransform)->then(zoomTransform);
340 auto boundedField = std::make_shared<afw::math::TransformBoundedField>(ccdBBox, *
transform);
341 return std::make_shared<afw::image::PhotoCalib>(oldPhotoCalib->getCalibrationMean(),
342 oldPhotoCalib->getCalibrationErr(), boundedField,
false);
348 afw::geom::Box2D
const &, int);
351 CcdImageList
const &, afw::geom::Box2D
const &, int);
Photometric offset independent of position, defined as -2.5 * log(flux / fluxMag0).
Relates transform(s) to their position in the fitting matrix and allows interaction with the transfor...
double transformError(CcdImage const &ccdImage, MeasuredStar const &measuredStar) const override
Return the on-sky transformed flux uncertainty for measuredStar on ccdImage.
std::string getName() const
Return the _name that identifies this ccdImage.
CameraSysPrefix const PIXELS
std::shared_ptr< PhotometryMapping > getChipMapping() const
table::Key< int > detector
double getInstMag() const
T bucket_count(T... args)
nth-order 2d Chebyshev photometry transform, times the input flux.
Photometric offset independent of position, defined as (fluxMag0)^-1.
table::Key< double > calibrationMean
#define LOGLS_INFO(logger, message)
unsigned assignIndices(std::string const &whatToFit, unsigned firstIndex) override
Assign indices in the full matrix to the parameters being fit in the mappings, starting at firstIndex...
std::shared_ptr< PhotometryMapping > getVisitMapping() const
std::shared_ptr< afw::image::PhotoCalib > toPhotoCalib(CcdImage const &ccdImage) const override
Return the mapping of ccdImage represented as a PhotoCalib.
int getTotalParameters() const override
Return the total number of parameters in this model.
double computeResidual(CcdImage const &ccdImage, MeasuredStar const &measuredStar) const override
Compute the residual between the model applied to a star and its associated fittedStar.
std::shared_ptr< afw::image::PhotoCalib > getPhotoCalib() const
Return the exposure's photometric calibration.
Class for a simple mapping implementing a generic AstrometryTransform.
double getInstFlux() const
PhotometryMappingBase * findMapping(CcdImage const &ccdImage) const override
Return a pointer to the mapping associated with this ccdImage.
objects measured on actual images.
T dynamic_pointer_cast(T... args)
void initialize(CcdImageList const &ccdImageList, afw::geom::Box2D const &focalPlaneBBox, int visitOrder)
Initialize the chip, visit, and chipVisit mappings by creating appropriate transfos and mappings...
void computeParameterDerivatives(MeasuredStar const &measuredStar, CcdImage const &ccdImage, Eigen::VectorXd &derivatives) const override
Compute the parametric derivatives of this model.
double transform(CcdImage const &ccdImage, MeasuredStar const &measuredStar) const override
Return the on-sky transformed flux for measuredStar on ccdImage.
void dump(std::ostream &stream=std::cout) const override
Dump the contents of the transfos, for debugging.
#define LSST_EXCEPT(type,...)
double tweakFluxError(jointcal::MeasuredStar const &measuredStar) const
Add a fraction of the instrumental flux to the instrumental flux error, in quadrature.
LOG_LOGGER _log
lsst.logging instance, to be created by a subclass so that messages have consistent name...
void offsetParams(Eigen::VectorXd const &delta) override
Offset the parameters by the provided amounts (by -delta).
#define LOGLS_DEBUG(logger, message)
double computeResidual(CcdImage const &ccdImage, MeasuredStar const &measuredStar) const override
Compute the residual between the model applied to a star and its associated fittedStar.
CcdImageKey getHashKey() const
virtual double initialChipCalibration(std::shared_ptr< afw::image::PhotoCalib const > photoCalib)=0
Return the initial calibration to use from this photoCalib.
std::shared_ptr< afw::cameraGeom::Detector > getDetector() const
Handler of an actual image from a single CCD.
std::shared_ptr< afw::image::PhotoCalib > toPhotoCalib(CcdImage const &ccdImage) const override
Return the mapping of ccdImage represented as a PhotoCalib.
double transform(CcdImage const &ccdImage, MeasuredStar const &measuredStar) const override
Return the on-sky transformed flux for measuredStar on ccdImage.
nth-order 2d Chebyshev photometry transform, plus the input flux.
std::shared_ptr< FittedStar > getFittedStar() const
CameraSys const FOCAL_PLANE
void freezeErrorTransform() override
Once this routine has been called, the error transform is not modified by offsetParams().
virtual double transform(CcdImage const &ccdImage, MeasuredStar const &measuredStar) const =0
Return the on-sky transformed flux for measuredStar on ccdImage.
void getMappingIndices(CcdImage const &ccdImage, std::vector< unsigned > &indices) const override
Get how this set of parameters (of length Npar()) map into the "grand" fit.
A two-level photometric transform: one for the ccd and one for the visit.
#define LOGLS_WARN(logger, message)
double transformError(CcdImage const &ccdImage, MeasuredStar const &measuredStar) const override
Return the on-sky transformed flux uncertainty for measuredStar on ccdImage.