6 #include "lsst/afw/cameraGeom/CameraSys.h" 7 #include "lsst/pex/exceptions.h" 8 #include "lsst/afw/image/Image.h" 9 #include "lsst/afw/image/PhotoCalib.h" 10 #include "lsst/afw/geom/Angle.h" 11 #include "lsst/afw/geom/Point.h" 13 #include "lsst/log/Log.h" 21 namespace afwImg = lsst::afw::image;
24 LOG_LOGGER _log = LOG_GET(
"jointcal.CcdImage");
30 void CcdImage::LoadCatalog(afw::table::SourceCatalog
const &catalog, std::string
const &fluxField) {
31 auto xKey = catalog.getSchema().find<
double>(
"slot_Centroid_x").key;
32 auto yKey = catalog.getSchema().find<
double>(
"slot_Centroid_y").key;
33 auto xsKey = catalog.getSchema().find<
float>(
"slot_Centroid_xSigma").key;
34 auto ysKey = catalog.getSchema().find<
float>(
"slot_Centroid_ySigma").key;
35 auto mxxKey = catalog.getSchema().find<
double>(
"slot_Shape_xx").key;
36 auto myyKey = catalog.getSchema().find<
double>(
"slot_Shape_yy").key;
37 auto mxyKey = catalog.getSchema().find<
double>(
"slot_Shape_xy").key;
38 auto fluxKey = catalog.getSchema().find<
double>(fluxField +
"_flux").key;
39 auto fluxErrKey = catalog.getSchema().find<
double>(fluxField +
"_fluxSigma").key;
41 auto transform = _detector->getTransform(afw::cameraGeom::PIXELS,
42 afw::cameraGeom::FOCAL_PLANE);
44 _wholeCatalog.clear();
45 for (
auto const &record : catalog) {
46 auto ms = std::make_shared<MeasuredStar>();
47 ms->x = record.get(xKey);
48 ms->y = record.get(yKey);
49 ms->vx = std::pow(record.get(xsKey), 2);
50 ms->vy = std::pow(record.get(ysKey), 2);
51 auto pointFocal = transform->applyForward(record.getCentroid());
52 ms->setXFocal(pointFocal.getX());
53 ms->setYFocal(pointFocal.getY());
57 double mxx = record.get(mxxKey);
58 double myy = record.get(myyKey);
59 double mxy = record.get(mxyKey);
60 ms->vxy = mxy * (ms->vx + ms->vy) / (mxx + myy);
61 if (ms->vx < 0 || ms->vy < 0 || (ms->vxy * ms->vxy) > (ms->vx * ms->vy)) {
62 LOGLS_WARN(_log,
"Bad source detected in LoadCatalog : " << ms->vx <<
" " << ms->vy <<
" " 63 << ms->vxy * ms->vxy <<
" " 67 ms->setId(record.getId());
68 ms->setInstFlux(record.get(fluxKey));
69 ms->setInstFluxErr(record.get(fluxErrKey));
72 afw::geom::Point<double, 2> point(ms->x, ms->y);
73 auto flux = _photoCalib->instFluxToMaggies(ms->getInstFlux(), ms->getInstFluxErr(), point);
74 ms->setFlux(flux.value);
75 ms->setFluxErr(flux.err);
76 ms->mag = _photoCalib->instFluxToMagnitude(ms->getInstFlux(), point);
77 ms->setCcdImage(
this);
78 _wholeCatalog.push_back(std::move(ms));
80 _wholeCatalog.setCcdImage(
this);
83 CcdImage::CcdImage(afw::table::SourceCatalog &catalog, std::shared_ptr<lsst::afw::image::TanWcs> wcs,
84 std::shared_ptr<lsst::afw::image::VisitInfo> visitInfo, afw::geom::Box2I
const &bbox,
85 std::string
const &filter, std::shared_ptr<afw::image::PhotoCalib> photoCalib,
86 std::shared_ptr<afw::cameraGeom::Detector> detector,
int visit,
int ccdId,
87 std::string
const &fluxField)
88 : _ccdId(ccdId), _visit(visit), _photoCalib(photoCalib), _detector(detector), _filter(filter) {
89 LoadCatalog(catalog, fluxField);
91 Point lowerLeft(bbox.getMinX(), bbox.getMinY());
92 Point upperRight(bbox.getMaxX(), bbox.getMaxY());
93 _imageFrame =
Frame(lowerLeft, upperRight);
96 _inverseReadWcs = _readWcs->inverseTransfo(0.01, _imageFrame);
98 std::stringstream out;
99 out << visit <<
"_" << ccdId;
102 _boresightRaDec = visitInfo->getBoresightRaDec();
103 _airMass = visitInfo->getBoresightAirmass();
104 _mjd = visitInfo->getDate().get(lsst::daf::base::DateTime::MJD);
105 double latitude = visitInfo->getObservatory().getLatitude();
106 _lstObs = visitInfo->getEra();
107 _hourAngle = visitInfo->getBoresightHourAngle();
111 if (std::isnan(_hourAngle) ==
true) {
116 _sineta = _coseta = _tgz = 0;
118 double cosz = 1. / _airMass;
119 double sinz = sqrt(1 - cosz * cosz);
121 _sineta = cos(latitude) * sin(_hourAngle) / sinz;
122 _coseta = sqrt(1 - _sineta * _sineta);
123 if (_boresightRaDec.getDec() > latitude) _coseta = -_coseta;
128 _commonTangentPoint = commonTangentPoint;
Implements the (forward) SIP distorsion scheme.
implements the linear transformations (6 real coefficients).
std::unique_ptr< Gtransfo > gtransfoCompose(const Gtransfo *left, const Gtransfo *right)
Returns a pointer to a composition.
the transformation that handles pix to sideral transfos (Gnomonic, possibly with polynomial distortio...
rectangle with sides parallel to axes.
Class for a simple mapping implementing a generic Gtransfo.
This one is the Tangent Plane (called gnomonic) projection (from celestial sphere to tangent plane) ...
Point getTangentPoint() const
The tangent point (in degrees)
TanSipPix2RaDec convertTanWcs(const std::shared_ptr< lsst::afw::image::TanWcs > wcs)
Transform an afw TanWcs into a Gtransfo.
void setCommonTangentPoint(Point const &commonTangentPoint)
Sets the common tangent point and computes necessary transforms.