47LOG_LOGGER _log =
LOG_GET(
"lsst.jointcal.CcdImage");
54 out <<
"(visit: " << key.
visit <<
", detector: " << key.
ccd <<
")";
59 auto xKey = catalog.
getSchema().
find<
double>(
"slot_Centroid_x").key;
60 auto yKey = catalog.
getSchema().
find<
double>(
"slot_Centroid_y").key;
61 auto xsKey = catalog.
getSchema().
find<
float>(
"slot_Centroid_xErr").key;
62 auto ysKey = catalog.
getSchema().
find<
float>(
"slot_Centroid_yErr").key;
63 auto mxxKey = catalog.
getSchema().
find<
double>(
"slot_Shape_xx").key;
64 auto myyKey = catalog.
getSchema().
find<
double>(
"slot_Shape_yy").key;
65 auto mxyKey = catalog.
getSchema().
find<
double>(
"slot_Shape_xy").key;
66 auto instFluxKey = catalog.
getSchema().
find<
double>(fluxField +
"_instFlux").key;
67 auto instFluxErrKey = catalog.
getSchema().
find<
double>(fluxField +
"_instFluxErr").key;
71 _wholeCatalog.
clear();
72 for (
auto const &record : catalog) {
74 ms->setId(record.getId());
75 ms->x = record.get(xKey);
76 ms->y = record.get(yKey);
77 ms->vx =
std::pow(record.get(xsKey), 2);
78 ms->vy =
std::pow(record.get(ysKey), 2);
79 auto pointFocal =
transform->applyForward(record.getCentroid());
80 ms->setXFocal(pointFocal.getX());
81 ms->setYFocal(pointFocal.getY());
85 double mxx = record.get(mxxKey);
86 double myy = record.get(myyKey);
87 double mxy = record.get(mxyKey);
88 ms->vxy = mxy * (ms->vx + ms->vy) / (mxx + myy);
89 if (
std::isnan(ms->vxy) || ms->vx < 0 || ms->vy < 0 || (ms->vxy * ms->vxy) > (ms->vx * ms->vy)) {
90 LOGLS_WARN(_log,
"Bad source detected during loadCatalog, "
91 <<
"detector=" << _ccdId <<
", visit=" << _visit
92 <<
" id: " << ms->getId() <<
" with vx,vy: " << ms->vx <<
"," << ms->vy
93 <<
" vxy^2: " << ms->vxy * ms->vxy <<
" vx*vy: " << ms->vx * ms->vy);
96 ms->setInstFluxAndErr(record.get(instFluxKey), record.get(instFluxErrKey));
100 geom::Point<double, 2> point(ms->x, ms->y);
101 auto flux = _photoCalib->instFluxToNanojansky(ms->getInstFlux(), ms->getInstFluxErr(), point);
102 ms->setFlux(flux.value);
103 ms->setFluxErr(flux.error);
104 auto mag = _photoCalib->instFluxToMagnitude(ms->getInstFlux(), ms->getInstFluxErr(), point);
105 ms->getMag() = mag.value;
106 ms->setMagErr(mag.error);
107 ms->setCcdImage(
this);
110 _wholeCatalog.setCcdImage(
this);
118 : _ccdId(ccdId), _visit(visit), _photoCalib(
std::
move(photoCalib)), _detector(
std::
move(detector)), _filter(
std::
move(filter)) {
119 loadCatalog(catalog, fluxField);
123 _imageFrame =
Frame(lowerLeft, upperRight);
128 out << visit <<
"_" << ccdId;
131 _boresightRaDec = visitInfo->getBoresightRaDec();
132 _airMass = visitInfo->getBoresightAirmass();
134 _lstObs = visitInfo->getEra();
135 _hourAngle = visitInfo->getBoresightHourAngle();
144 _sinEta = _cosEta = _tanZ = 0;
146 double cosz = 1. / _airMass;
147 double sinz =
std::sqrt(1 - cosz * cosz);
156 int measuredStars = 0;
158 for (
auto const &measuredStar : _catalogForFit) {
159 if (measuredStar->isValid()) {
162 if ((measuredStar->getFittedStar() !=
nullptr) &&
163 (measuredStar->getFittedStar()->getRefStar() !=
nullptr)) {
171 _commonTangentPoint = commonTangentPoint;
173 auto const crval = _readWcs->getSkyWcs()->getSkyOrigin();
174 jointcal::Point tangentPoint(crval[0].asDegrees(), crval[1].asDegrees());
181 _pixelToTangentPlane =
compose(raDecToTangentPlane, *_readWcs);
182 TanPixelToRaDec CommonTangentPlane2RaDec(identity, commonTangentPoint);
183 _commonTangentPlaneToTangentPlane =
compose(raDecToTangentPlane, CommonTangentPlane2RaDec);
186 TanRaDecToPixel raDecToCommonTangentPlane(identity, commonTangentPoint);
188 _tangentPlaneToCommonTangentPlane =
compose(raDecToCommonTangentPlane, TangentPlaneToRaDec);
192 _pixelToCommonTangentPlane =
compose(raDecToCommonTangentPlane, *_readWcs);
#define LOGLS_WARN(logger, message)
SchemaItem< T > find(std::string const &name) const
constexpr double asRadians() const noexcept
int getMinY() const noexcept
int getMinX() const noexcept
int getMaxX() const noexcept
int getMaxY() const noexcept
void setCommonTangentPoint(Point const &commonTangentPoint)
Sets the common tangent point and computes necessary transforms.
std::pair< int, int > countStars() const
Count the number of valid measured and reference stars that fall within this ccdImage.
CcdImage(afw::table::SourceCatalog &record, const std::shared_ptr< lsst::afw::geom::SkyWcs > &wcs, const std::shared_ptr< lsst::afw::image::VisitInfo > &visitInfo, lsst::geom::Box2I const &bbox, std::string filter, std::shared_ptr< afw::image::PhotoCalib > photoCalib, std::shared_ptr< afw::cameraGeom::Detector > detector, int visit, int ccd, std::string const &fluxField)
rectangle with sides parallel to axes.
The transformation that handles pixels to sideral transformations (Gnomonic, possibly with polynomial...
This one is the Tangent Plane (called gnomonic) projection (from celestial sphere to tangent plane)
CameraSys const FOCAL_PLANE
CameraSysPrefix const PIXELS
SortedCatalogT< SourceRecord > SourceCatalog
std::unique_ptr< AstrometryTransform > compose(AstrometryTransform const &left, AstrometryTransform const &right)
Returns a pointer to a composition of transforms, representing left(right()).
std::ostream & operator<<(std::ostream &stream, AstrometryMapping const &mapping)
For hashing a ccdImage: the pair of (visit, ccd) IDs should be unique to each ccdImage.