16 LOG_LOGGER _log =
LOG_GET(
"jointcal.ConstrainedPhotometryModel");
23 afw::geom::Box2D
const &focalPlaneBBox,
30 for (
auto const &
ccdImage : ccdImageList) {
33 auto visitPair = _visitMap.
find(visit);
34 auto chipPair = _chipMap.
find(chip);
37 if (chipPair == _chipMap.
end()) {
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>(visitOrder, 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 (" 75 <<
" buckets and a load factor of " << _myMap.
load_factor());
80 unsigned index = firstIndex;
81 for (
auto &i : _chipMap) {
82 auto mapping = i.second.get();
84 if (mapping->isFixed())
continue;
85 mapping->setIndex(index);
86 index += mapping->getNpar();
88 for (
auto &i : _visitMap) {
89 auto mapping = i.second.get();
90 mapping->setIndex(index);
91 index += mapping->getNpar();
97 for (
auto &i : _chipMap) {
98 auto mapping = i.second.get();
100 if (mapping->isFixed())
continue;
101 mapping->offsetParams(delta.segment(mapping->getIndex(), mapping->getNpar()));
103 for (
auto &i : _visitMap) {
104 auto mapping = i.second.get();
105 mapping->offsetParams(delta.segment(mapping->getIndex(), mapping->getNpar()));
110 double instFlux)
const {
111 auto mapping = findMapping(ccdImage);
112 return mapping->transform(measuredStar, instFlux);
116 double instFluxErr)
const {
117 auto mapping = findMapping(ccdImage);
118 return mapping->transformError(measuredStar, instFluxErr);
122 for (
auto &i : _chipMap) {
123 i.second.get()->freezeErrorTransform();
125 for (
auto &i : _visitMap) {
126 i.second.get()->freezeErrorTransform();
132 auto mapping = findMapping(ccdImage);
133 mapping->getMappingIndices(indices);
138 for (
auto &i : _chipMap) {
139 total += i.second->getNpar();
141 for (
auto &i : _visitMap) {
142 total += i.second->getNpar();
149 Eigen::VectorXd &derivatives)
const {
150 auto mapping = findMapping(ccdImage);
151 mapping->computeParameterDerivatives(measuredStar, measuredStar.
getInstFlux(), derivatives);
157 auto coeffs = transfo->getCoefficients();
159 ndarray::Array<double, 2, 2> chebyCoeffs = allocate(ndarray::makeVector(transfo->getNpar(), 4));
160 Eigen::VectorXd::Index k = 0;
161 auto order = transfo->getOrder();
162 for (ndarray::Size j = 0; j <= order; ++j) {
163 ndarray::Size
const iMax = order - j;
164 for (ndarray::Size i = 0; i <= iMax; ++i, ++k) {
165 chebyCoeffs[k][0] = coeffs[j][i];
166 chebyCoeffs[k][1] = 1;
167 chebyCoeffs[k][2] = i;
168 chebyCoeffs[k][3] = j;
179 auto ccdBBox = detector->getBBox();
183 assert(mapping !=
nullptr);
188 assert(visitTransfo !=
nullptr);
189 auto focalBBox = visitTransfo->getBBox();
192 auto coeff_f = toChebyMapCoeffs(
193 std::dynamic_pointer_cast<PhotometryTransfoChebyshev>(mapping->
getVisitMapping()->getTransfo()));
205 auto transform = pixToFocal->then(chebyTransform)->then(zoomTransform);
207 double mean = mapping->
getChipMapping()->getParameters()[0] * visitTransfo->mean();
208 auto boundedField = std::make_shared<afw::math::TransformBoundedField>(ccdBBox, *
transform);
209 return std::make_shared<afw::image::PhotoCalib>(mean, oldPhotoCalib->getCalibrationErr(), boundedField,
214 for (
auto &i : _chipMap) {
215 i.second->dump(stream);
219 for (
auto &i : _visitMap) {
220 i.second->dump(stream);
227 if (i == _myMap.
end())
229 "ConstrainedPhotometryModel cannot find CcdImage " + ccdImage.
getName());
230 return i->second.get();
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)
ConstrainedPhotometryModel(CcdImageList const &ccdImageList, afw::geom::Box2D const &focalPlaneBBox, int visitOrder=7)
Construct a constrained photometry model.
double transform(CcdImage const &ccdImage, MeasuredStar const &measuredStar, double instFlux) const override
Return the on-sky transformed flux for measuredStar on ccdImage.
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
int getTotalParameters() const override
Return the total number of parameters in this model.
std::shared_ptr< afw::image::PhotoCalib > getPhotoCalib() const
Return the exposure's photometric calibration.
#define LOGLS_DEBUG(logger, message)
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.
#define LOGLS_INFO(logger, message)
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 transformError(CcdImage const &ccdImage, MeasuredStar const &measuredStar, double instFluxErr) const override
Return the on-sky transformed flux uncertainty for measuredStar on ccdImage.
nth-order 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.
A mapping containing a single photometryTransfo.
CameraSys const FOCAL_PLANE
void freezeErrorTransform() override
Once this routine has been called, the error transform is not modified by offsetParams().
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.