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()) {
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);
115 double instFluxErr)
const {
116 auto mapping = findMapping(ccdImage);
117 return mapping->transformError(measuredStar, instFluxErr);
121 for (
auto &i : _chipMap) {
122 i.second.get()->freezeErrorTransform();
124 for (
auto &i : _visitMap) {
125 i.second.get()->freezeErrorTransform();
131 auto mapping = findMapping(ccdImage);
132 mapping->getMappingIndices(indices);
137 Eigen::VectorXd &derivatives)
const {
138 auto mapping = findMapping(ccdImage);
139 mapping->computeParameterDerivatives(measuredStar, measuredStar.
getInstFlux(), derivatives);
145 auto coeffs = transfo->getCoefficients();
147 ndarray::Array<double, 2, 2> chebyCoeffs = allocate(ndarray::makeVector(transfo->getNpar(), 4));
148 Eigen::VectorXd::Index k = 0;
149 auto degree = transfo->getDegree();
150 for (ndarray::Size j = 0; j <= degree; ++j) {
151 ndarray::Size
const iMax = degree - j;
152 for (ndarray::Size i = 0; i <= iMax; ++i, ++k) {
153 chebyCoeffs[k][0] = coeffs[j][i];
154 chebyCoeffs[k][1] = 1;
155 chebyCoeffs[k][2] = i;
156 chebyCoeffs[k][3] = j;
167 auto ccdBBox = detector->getBBox();
171 assert(mapping !=
nullptr);
176 assert(visitTransfo !=
nullptr);
177 auto focalBBox = visitTransfo->getBBox();
180 auto coeff_f = toChebyMapCoeffs(
181 std::dynamic_pointer_cast<PhotometryTransfoChebyshev>(mapping->
getVisitMapping()->getTransfo()));
194 double mean = mapping->
getChipMapping()->getParameters()[0] * visitTransfo->mean();
195 auto boundedField = std::make_shared<afw::math::TransformBoundedField>(ccdBBox,
transform);
196 return std::make_shared<afw::image::PhotoCalib>(mean, oldPhotoCalib->getCalibrationErr(), boundedField,
201 for (
auto &i : _chipMap) {
202 i.second->dump(stream);
206 for (
auto &i : _visitMap) {
207 i.second->dump(stream);
214 if (i == _myMap.
end())
216 "ConstrainedPhotometryModel cannot find CcdImage " + ccdImage.
getName());
217 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)
double transform(CcdImage const &ccdImage, MeasuredStar const &measuredStar, double instFlux) const override
Return the on-sky transformed flux for measuredStar on ccdImage.
#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.
#define LOGLS_DEBUG(logger, message)
double transformError(CcdImage const &ccdImage, MeasuredStar const &measuredStar, double instFluxErr) const override
Return the on-sky transformed flux uncertainty for measuredStar on ccdImage.
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 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.