7 #include "astshim/ChebyMap.h" 16 LOG_LOGGER _log =
LOG_GET(
"jointcal.ConstrainedPhotometryModel");
30 for (
auto const &
ccdImage : ccdImageList) {
33 auto visitPair = _visitMap.
find(visit);
34 auto chipPair = _chipMap.
find(chip);
37 if (chipPair == _chipMap.
end()) {
39 double radius2 =
std::pow(center.getPoint().getX(), 2) +
std::pow(center.getPoint().getY(), 2);
40 if (radius2 < minRadius2) {
42 constrainedChip = chip;
44 auto photoCalib =
ccdImage->getPhotoCalib();
47 std::make_shared<PhotometryTransfoSpatiallyInvariant>(photoCalib->getCalibrationMean());
52 if (visitPair == _visitMap.
end()) {
53 auto visitTransfo = std::make_shared<PhotometryTransfoChebyshev>(visitDegree, focalPlaneBBox);
60 _chipMap.
at(constrainedChip)->setFixed(
true);
63 _myMap.
reserve(ccdImageList.size());
64 for (
auto const &
ccdImage : ccdImageList) {
71 LOGLS_INFO(_log,
"Got " << _chipMap.
size() <<
" chip mappings and " << _visitMap.
size()
72 <<
" visit mappings; holding chip " << constrainedChip <<
" fixed.");
74 <<
" buckets and a load factor of " << _myMap.
load_factor());
79 unsigned index = firstIndex;
80 for (
auto &i : _chipMap) {
81 auto mapping = i.second.get();
83 if (mapping->isFixed())
continue;
84 mapping->setIndex(index);
85 index += mapping->getNpar();
87 for (
auto &i : _visitMap) {
88 auto mapping = i.second.get();
89 mapping->setIndex(index);
90 index += mapping->getNpar();
96 for (
auto &i : _chipMap) {
97 auto mapping = i.second.get();
99 if (mapping->isFixed())
continue;
100 mapping->offsetParams(delta.segment(mapping->getIndex(), mapping->getNpar()));
102 for (
auto &i : _visitMap) {
103 auto mapping = i.second.get();
104 mapping->offsetParams(delta.segment(mapping->getIndex(), mapping->getNpar()));
109 double instFlux)
const {
110 auto mapping = findMapping(ccdImage);
111 return mapping->transform(measuredStar, instFlux);
116 auto mapping = findMapping(ccdImage);
117 mapping->getMappingIndices(indices);
122 Eigen::VectorXd &derivatives)
const {
123 auto mapping = findMapping(ccdImage);
124 mapping->computeParameterDerivatives(measuredStar, measuredStar.
getInstFlux(), derivatives);
130 auto coeffs = transfo->getCoefficients();
132 ndarray::Array<double, 2, 2> chebyCoeffs = allocate(ndarray::makeVector(transfo->getNpar(), 4));
133 Eigen::VectorXd::Index k = 0;
134 auto degree = transfo->getDegree();
135 for (ndarray::Size j = 0; j <= degree; ++j) {
136 ndarray::Size
const iMax = degree - j;
137 for (ndarray::Size i = 0; i <= iMax; ++i, ++k) {
138 chebyCoeffs[k][0] = coeffs[j][i];
139 chebyCoeffs[k][1] = 1;
140 chebyCoeffs[k][2] = i;
141 chebyCoeffs[k][3] = j;
152 auto ccdBBox = detector->getBBox();
156 assert(mapping !=
nullptr);
161 assert(visitTransfo !=
nullptr);
162 auto focalBBox = visitTransfo->getBBox();
165 auto coeff_f = toChebyMapCoeffs(
166 std::dynamic_pointer_cast<PhotometryTransfoChebyshev>(mapping->
getVisitMapping()->getTransfo()));
179 double mean = mapping->
getChipMapping()->getParameters()[0] * visitTransfo->mean();
180 auto boundedField = std::make_shared<afw::math::TransformBoundedField>(ccdBBox,
transform);
181 return std::make_shared<afw::image::PhotoCalib>(mean, oldPhotoCalib->getCalibrationErr(), boundedField,
186 for (
auto &i : _chipMap) {
187 i.second->dump(stream);
191 for (
auto &i : _visitMap) {
192 i.second->dump(stream);
199 if (i == _myMap.
end())
201 "ConstrainedPhotometryModel cannot find CcdImage " + ccdImage.
getName());
202 return i->second.get();
Transform< Point2Endpoint, GenericEndpoint > TransformPoint2ToGeneric
Relates transfo(s) to their position in the fitting matrix and allows interaction with the transfo(s)...
std::string getName() const
Return the _name that identifies this ccdImage.
CameraSysPrefix const PIXELS
std::shared_ptr< PhotometryMapping > getChipMapping() const
T bucket_count(T... args)
#define LOGLS_INFO(logger, message)
unsigned assignIndices(std::string const &whatToFit, unsigned firstIndex) override
Assign indices to parameters involved in mappings, starting at firstIndex.
std::shared_ptr< PhotometryMapping > getVisitMapping() const
std::shared_ptr< afw::image::PhotoCalib > getPhotoCalib() const
Return the exposure's photometric calibration.
Class for a simple mapping implementing a generic Gtransfo.
double getInstFlux() const
objects measured on actual images.
T dynamic_pointer_cast(T... args)
void computeParameterDerivatives(MeasuredStar const &measuredStar, CcdImage const &ccdImage, Eigen::VectorXd &derivatives) const override
Compute the parametric derivatives of this model.
void dump(std::ostream &stream=std::cout) const override
Dump the contents of the transfos, for debugging.
#define LSST_EXCEPT(type,...)
void offsetParams(Eigen::VectorXd const &delta) override
Offset the parameters by the provided amounts.
double transform(CcdImage const &ccdImage, MeasuredStar const &star, double instFlux) const override
Return the on-sky transformed flux for measuredStar on ccdImage.
#define LOGLS_DEBUG(logger, message)
nth-degree 2d Chebyshev photometry transfo.
std::shared_ptr< afw::image::PhotoCalib > toPhotoCalib(CcdImage const &ccdImage) const override
Return the mapping of ccdImage represented as a PhotoCalib.
CcdImageKey getHashKey() const
std::shared_ptr< afw::cameraGeom::Detector > getDetector() const
Handler of an actual image from a single CCD.
ConstrainedPhotometryModel(CcdImageList const &ccdImageList, afw::geom::Box2D const &focalPlaneBBox, int visitDegree=7)
Construct a constrained photometry model.
A mapping containing a single photometryTransfo.
CameraSys const FOCAL_PLANE
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.