46LOG_LOGGER _log =
LOG_GET(
"lsst.jointcal.CcdImage");
53 out <<
"(visit: " << key.
visit <<
", detector: " << key.
ccd <<
")";
58 auto xKey = catalog.
getSchema().
find<
double>(
"slot_Centroid_x").key;
59 auto yKey = catalog.
getSchema().
find<
double>(
"slot_Centroid_y").key;
60 auto xsKey = catalog.
getSchema().
find<
float>(
"slot_Centroid_xErr").key;
61 auto ysKey = catalog.
getSchema().
find<
float>(
"slot_Centroid_yErr").key;
62 auto mxxKey = catalog.
getSchema().
find<
double>(
"slot_Shape_xx").key;
63 auto myyKey = catalog.
getSchema().
find<
double>(
"slot_Shape_yy").key;
64 auto mxyKey = catalog.
getSchema().
find<
double>(
"slot_Shape_xy").key;
65 auto instFluxKey = catalog.
getSchema().
find<
double>(fluxField +
"_instFlux").key;
66 auto instFluxErrKey = catalog.
getSchema().
find<
double>(fluxField +
"_instFluxErr").key;
70 _wholeCatalog.
clear();
71 for (
auto const &record : catalog) {
72 auto ms = std::make_shared<MeasuredStar>();
73 ms->setId(record.getId());
74 ms->x = record.get(xKey);
75 ms->y = record.get(yKey);
76 ms->vx =
std::pow(record.get(xsKey), 2);
77 ms->vy =
std::pow(record.get(ysKey), 2);
78 auto pointFocal =
transform->applyForward(record.getCentroid());
79 ms->setXFocal(pointFocal.getX());
80 ms->setYFocal(pointFocal.getY());
84 double mxx = record.get(mxxKey);
85 double myy = record.get(myyKey);
86 double mxy = record.get(mxyKey);
87 ms->vxy = mxy * (ms->vx + ms->vy) / (mxx + myy);
88 if (
std::isnan(ms->vxy) || ms->vx < 0 || ms->vy < 0 || (ms->vxy * ms->vxy) > (ms->vx * ms->vy)) {
89 LOGLS_WARN(_log,
"Bad source detected during loadCatalog, "
90 <<
"detector=" << _ccdId <<
", visit=" << _visit
91 <<
" id: " << ms->getId() <<
" with vx,vy: " << ms->vx <<
"," << ms->vy
92 <<
" vxy^2: " << ms->vxy * ms->vxy <<
" vx*vy: " << ms->vx * ms->vy);
95 ms->setInstFluxAndErr(record.get(instFluxKey), record.get(instFluxErrKey));
99 geom::Point<double, 2> point(ms->x, ms->y);
100 auto flux = _photoCalib->instFluxToNanojansky(ms->getInstFlux(), ms->getInstFluxErr(), point);
101 ms->setFlux(flux.value);
102 ms->setFluxErr(flux.error);
103 auto mag = _photoCalib->instFluxToMagnitude(ms->getInstFlux(), ms->getInstFluxErr(), point);
104 ms->getMag() = mag.value;
105 ms->setMagErr(mag.error);
106 ms->setCcdImage(
this);
117 : _ccdId(ccdId), _visit(visit), _photoCalib(
photoCalib), _detector(
detector), _filter(filter) {
118 loadCatalog(catalog, fluxField);
122 _imageFrame =
Frame(lowerLeft, upperRight);
124 _readWcs = std::make_shared<AstrometryTransformSkyWcs>(
wcs);
127 out << visit <<
"_" << ccdId;
130 _boresightRaDec =
visitInfo->getBoresightRaDec();
131 _airMass =
visitInfo->getBoresightAirmass();
134 _hourAngle =
visitInfo->getBoresightHourAngle();
143 _sinEta = _cosEta = _tanZ = 0;
145 double cosz = 1. / _airMass;
146 double sinz =
std::sqrt(1 - cosz * cosz);
155 int measuredStars = 0;
157 for (
auto const &measuredStar : _catalogForFit) {
158 if (measuredStar->isValid()) {
161 if ((measuredStar->getFittedStar() !=
nullptr) &&
162 (measuredStar->getFittedStar()->getRefStar() !=
nullptr)) {
170 _commonTangentPoint = commonTangentPoint;
172 auto const crval = _readWcs->getSkyWcs()->getSkyOrigin();
180 _pixelToTangentPlane =
compose(raDecToTangentPlane, *_readWcs);
181 TanPixelToRaDec CommonTangentPlane2RaDec(identity, commonTangentPoint);
182 _commonTangentPlaneToTangentPlane =
compose(raDecToTangentPlane, CommonTangentPlane2RaDec);
185 TanRaDecToPixel raDecToCommonTangentPlane(identity, commonTangentPoint);
187 _tangentPlaneToCommonTangentPlane =
compose(raDecToCommonTangentPlane, TangentPlaneToRaDec);
191 _pixelToCommonTangentPlane =
compose(raDecToCommonTangentPlane, *_readWcs);
#define LOGLS_WARN(logger, message)
table::Key< int > detector
table::PointKey< double > crval
table::Key< table::Array< std::uint8_t > > wcs
SchemaItem< T > find(std::string const &name) const
constexpr double asRadians() const noexcept
void setCommonTangentPoint(Point const &commonTangentPoint)
Sets the common tangent point and computes necessary transforms.
CcdImage(afw::table::SourceCatalog &record, std::shared_ptr< lsst::afw::geom::SkyWcs > wcs, std::shared_ptr< lsst::afw::image::VisitInfo > visitInfo, lsst::geom::Box2I const &bbox, std::string const &filter, std::shared_ptr< afw::image::PhotoCalib > photoCalib, std::shared_ptr< afw::cameraGeom::Detector > detector, int visit, int ccd, std::string const &fluxField)
std::pair< int, int > countStars() const
Count the number of valid measured and reference stars that fall within this ccdImage.
rectangle with sides parallel to axes.
void setCcdImage(const CcdImage *_ccdImage)
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
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)
Class for a simple mapping implementing a generic AstrometryTransform.
For hashing a ccdImage: the pair of (visit, ccd) IDs should be unique to each ccdImage.