47 Eigen::Index firstIndex
49 Eigen::Index index = firstIndex;
50 if (whatToFit.
find(
"Model") == std::string::npos) {
51 LOGLS_WARN(
_log,
"assignIndices was called and Model is *not* in whatToFit");
56 _fittingChips = (whatToFit.
find(
"ModelChip") != std::string::npos);
57 _fittingVisits = (whatToFit.
find(
"ModelVisit") != std::string::npos);
59 if ((!_fittingChips) && (!_fittingVisits)) {
60 _fittingChips = _fittingVisits =
true;
65 auto mapping = idMapping.second.get();
67 if (
mapping->isFixed())
continue;
74 auto mapping = idMapping.second.get();
80 idMapping.second->setWhatToFit(_fittingChips, _fittingVisits);
88 auto mapping = idMapping.second.get();
90 if (
mapping->isFixed())
continue;
96 auto mapping = idMapping.second.get();
104 idMapping.second.get()->freezeErrorTransform();
107 idMapping.second.get()->freezeErrorTransform();
114 mapping->getMappingIndices(indices);
120 total += idMapping.second->getNpar();
123 total += idMapping.second->getNpar();
130 Eigen::VectorXd &derivatives)
const {
132 mapping->computeParameterDerivatives(measuredStar, measuredStar.
getInstFlux(), derivatives);
138 auto coeffs = transform->getCoefficients();
140 ndarray::Array<double, 2, 2> chebyCoeffs = allocate(ndarray::makeVector(transform->getNpar(),
142 Eigen::VectorXd::Index k = 0;
143 auto order = transform->getOrder();
144 for (ndarray::Size j = 0; j <= order; ++j) {
145 ndarray::Size
const iMax = order - j;
146 for (ndarray::Size i = 0; i <= iMax; ++i, ++k) {
147 chebyCoeffs[k][0] = coeffs[j][i];
148 chebyCoeffs[k][1] = 1;
149 chebyCoeffs[k][2] = i;
150 chebyCoeffs[k][3] = j;
159 idMapping.second->dump(stream);
164 idMapping.second->dump(stream);
173 "ConstrainedPhotometryModel cannot find CcdImage " + ccdImage.
getName());
174 return idMapping->second.get();
177 template <
class ChipTransform,
class VisitTransform,
class ChipVisitMapping>
179 geom::Box2D const &focalPlaneBBox,
int visitOrder) {
185 for (
auto const &
ccdImage : ccdImageList) {
195 if (radius2 < minRadius2) {
196 minRadius2 = radius2;
197 constrainedChip = chip;
206 auto visitTransform = std::make_unique<VisitTransform>(visitOrder, focalPlaneBBox);
215 for (
auto const &
ccdImage : ccdImageList) {
222 <<
" visit mappings; holding chip " << constrainedChip <<
" fixed (" 237 assert(mapping !=
nullptr);
241 assert(visitPhotometryTransform !=
nullptr);
242 auto focalBBox = visitPhotometryTransform->getBBox();
245 auto coeff_f = toChebyMapCoeffs(std::dynamic_pointer_cast<PhotometryTransformChebyshev>(
252 double chipConstant = mapping->
getChipMapping()->getParameters()[0];
261 double visitMean = visitPhotometryTransform->mean(ccdBBoxInFocal);
263 return {chipConstant, visitTransform, pixToFocal, visitMean};
294 auto transform = prep.pixToFocal->then(prep.visitTransform)->then(zoomTransform);
297 double mean = prep.chipConstant * prep.visitMean;
300 return std::make_shared<afw::image::PhotoCalib>(mean, ccdImage.
getPhotoCalib()->getCalibrationErr(),
331 ast::MathMap(1, 1, {
"y=pow(10.0,x/-2.5)"s}, {
"x=-2.5*log10(y)"s}));
339 auto transform = prep.pixToFocal->then(prep.visitTransform)->then(logTransform)->then(zoomTransform);
342 double mean = chipCalibration *
std::pow(10, prep.visitMean / -2.5);
345 return std::make_shared<afw::image::PhotoCalib>(mean, ccdImage.
getPhotoCalib()->getCalibrationErr(),
355 CcdImageList
const &, geom::Box2D
const &, int);
#define LOGLS_WARN(logger, message)
Log a warn-level message using an iostream-based interface.
std::vector< Point2D > getCorners() const
Get the corner points.
A floating-point coordinate rectangle geometry.
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.
void include(Point2D const &point) noexcept
Expand this to ensure that this->contains(point).
CameraSysPrefix const PIXELS
Pixel coordinates: Nominal position on the entry surface of a given detector (x, y unbinned pixels)...
std::shared_ptr< PhotometryMapping > getChipMapping() const
double getInstMag() const
T bucket_count(T... args)
std::size_t getTotalParameters() const override
Return the total number of parameters in this model.
LSST DM logging module built on log4cxx.
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.
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.
#define LOGLS_DEBUG(logger, message)
Log a debug-level message using an iostream-based interface.
A base class for image defects.
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.
table::Key< int > detector
T dynamic_pointer_cast(T... args)
void initialize(CcdImageList const &ccdImageList, geom::Box2D const &focalPlaneBBox, int visitOrder)
Initialize the chip, visit, and chipVisit mappings by creating appropriate transforms and mappings...
void computeParameterDerivatives(MeasuredStar const &measuredStar, CcdImage const &ccdImage, Eigen::VectorXd &derivatives) const override
Compute the parametric derivatives of this model.
To hold the return of prepPhotoCalib.
#define LOGLS_INFO(logger, message)
Log a info-level message using an iostream-based interface.
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 transforms, for debugging.
#define LSST_EXCEPT(type,...)
Create an exception with a given 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...
A MathMap is a Mapping which allows you to specify a set of forward and/or inverse transformation fun...
void offsetParams(Eigen::VectorXd const &delta) override
Offset the parameters by the provided amounts (by -delta).
A ChebyMap is a form of Mapping which performs a Chebyshev polynomial transformation.
Reports invalid arguments.
PrepPhotoCalib prepPhotoCalib(CcdImage const &ccdImage) const
Helper for preparing toPhotoCalib()
double computeResidual(CcdImage const &ccdImage, MeasuredStar const &measuredStar) const override
Compute the residual between the model applied to a star and its associated fittedStar.
A Mapping which "zooms" a set of points about the origin by multiplying all coordinate values by the ...
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.
std::shared_ptr< FittedStar > getFittedStar() const
CameraSys const FOCAL_PLANE
Focal plane coordinates: Position on a 2-d planar approximation to the focal plane (x...
double ABMagnitudeToNanojansky(double magnitude)
Convert an AB magnitude to a flux in nanojansky.
Implementation of the Photometric Calibration class.
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, IndexVector &indices) const override
Get how this set of parameters (of length Npar()) map into the "grand" fit.
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...
A two-level photometric transform: one for the ccd and one for the visit.
double transformError(CcdImage const &ccdImage, MeasuredStar const &measuredStar) const override
Return the on-sky transformed flux uncertainty for measuredStar on ccdImage.