From 6c621bcffc27b3623fd8d301a4833257077b43ea Mon Sep 17 00:00:00 2001 From: John Parejko Date: Fri, 27 Oct 2023 02:08:00 -0700 Subject: [PATCH 1/3] clang-format pass --- src/table/wcsUtils.cc | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/src/table/wcsUtils.cc b/src/table/wcsUtils.cc index 4426a93a0..57558a583 100644 --- a/src/table/wcsUtils.cc +++ b/src/table/wcsUtils.cc @@ -91,35 +91,32 @@ void updateRefCentroids(geom::SkyWcs const &wcs, ReferenceCollection &refList) { } } -Eigen::Matrix2f calculateCoordCovariance(geom::SkyWcs const& wcs, lsst::geom::Point2D center, Eigen::Matrix2f err) { +Eigen::Matrix2f calculateCoordCovariance(geom::SkyWcs const &wcs, lsst::geom::Point2D center, + Eigen::Matrix2f err) { // Get the derivative of the pixel-to-sky transformation, then use it to // propagate the centroid uncertainty to coordinate uncertainty. Note that // the calculation is done in arcseconds, then converted to radians in // order to achieve higher precision. double scale = 1.0 / 3600.0; - Eigen::Matrix2d cdMatrix { {scale, 0}, {0, scale}}; + Eigen::Matrix2d cdMatrix{{scale, 0}, {0, scale}}; lsst::geom::SpherePoint skyCenter = wcs.pixelToSky(center); - auto localGnomonicWcs = geom::makeSkyWcs(center, skyCenter, cdMatrix); - auto measurementToLocalGnomonic = wcs.getTransform()->then( - *localGnomonicWcs->getTransform()->inverted() - ); - + auto measurementToLocalGnomonic = wcs.getTransform()->then(*localGnomonicWcs->getTransform()->inverted()); + Eigen::Matrix2d localMatrix = measurementToLocalGnomonic->getJacobian(center); - Eigen::Matrix2f d = localMatrix.cast < float > () * scale * (lsst::geom::PI / 180.0); + Eigen::Matrix2f d = localMatrix.cast() * scale * (lsst::geom::PI / 180.0); Eigen::Matrix2f skyCov = d * err * d.transpose(); // Multiply by declination correction matrix in order to get sigma(RA) * cos(Dec) for the uncertainty // in RA, and cov(RA, Dec) * cos(Dec) for the RA/Dec covariance: float cosDec = std::cos(skyCenter.getDec().asRadians()); - Eigen::Matrix2f decCorr{ {cosDec, 0}, {0, 1.0}}; + Eigen::Matrix2f decCorr{{cosDec, 0}, {0, 1.0}}; Eigen::Matrix2f skyCovCorr = decCorr * skyCov * decCorr; return skyCovCorr; } - template void updateSourceCoords(geom::SkyWcs const &wcs, SourceCollection &sourceList, bool include_covariance) { if (sourceList.empty()) { @@ -164,8 +161,7 @@ template void updateRefCentroids(geom::SkyWcs const &, SimpleCatalog &); template void updateSourceCoords(geom::SkyWcs const &, std::vector> &, bool include_covariance); -template void updateSourceCoords(geom::SkyWcs const &, SourceCatalog &, - bool include_covariance); +template void updateSourceCoords(geom::SkyWcs const &, SourceCatalog &, bool include_covariance); /// @endcond } // namespace table From 59d70a06e4ccb922ab1527550417790ee924e8be Mon Sep 17 00:00:00 2001 From: John Parejko Date: Fri, 27 Oct 2023 02:14:39 -0700 Subject: [PATCH 2/3] Make constants const and static --- src/table/wcsUtils.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/table/wcsUtils.cc b/src/table/wcsUtils.cc index 57558a583..c46fc6119 100644 --- a/src/table/wcsUtils.cc +++ b/src/table/wcsUtils.cc @@ -97,8 +97,8 @@ Eigen::Matrix2f calculateCoordCovariance(geom::SkyWcs const &wcs, lsst::geom::Po // propagate the centroid uncertainty to coordinate uncertainty. Note that // the calculation is done in arcseconds, then converted to radians in // order to achieve higher precision. - double scale = 1.0 / 3600.0; - Eigen::Matrix2d cdMatrix{{scale, 0}, {0, scale}}; + const static double scale = 1.0 / 3600.0; + const static Eigen::Matrix2d cdMatrix{{scale, 0}, {0, scale}}; lsst::geom::SpherePoint skyCenter = wcs.pixelToSky(center); auto localGnomonicWcs = geom::makeSkyWcs(center, skyCenter, cdMatrix); From 2e4cf33d5940394d03cfbf7e0263679b07b10c67 Mon Sep 17 00:00:00 2001 From: John Parejko Date: Fri, 27 Oct 2023 02:15:00 -0700 Subject: [PATCH 3/3] Properly handle non-finite position If either position is NaN, the `makeSkyWcs` call further down will fail because `skyCenter` is also NaN. --- src/table/wcsUtils.cc | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/table/wcsUtils.cc b/src/table/wcsUtils.cc index c46fc6119..d1ce67580 100644 --- a/src/table/wcsUtils.cc +++ b/src/table/wcsUtils.cc @@ -22,6 +22,7 @@ * see . */ +#include #include #include @@ -93,6 +94,9 @@ void updateRefCentroids(geom::SkyWcs const &wcs, ReferenceCollection &refList) { Eigen::Matrix2f calculateCoordCovariance(geom::SkyWcs const &wcs, lsst::geom::Point2D center, Eigen::Matrix2f err) { + if (!std::isfinite(center.getX()) || !std::isfinite(center.getY())) { + return Eigen::Matrix2f::Constant(NAN); + } // Get the derivative of the pixel-to-sky transformation, then use it to // propagate the centroid uncertainty to coordinate uncertainty. Note that // the calculation is done in arcseconds, then converted to radians in