44Schema getSchema(std::shared_ptr<const BaseRecord>
const record) {
return record->getSchema(); }
47template <
typename Key>
49 return record.get(key);
53template <
typename Key>
54inline typename Key::Value getValue(std::shared_ptr<const BaseRecord>
const record,
Key const &key) {
55 return record->
get(key);
59template <
typename Key>
61 record.set(key, value);
65template <
typename Key>
66inline void setValue(std::shared_ptr<SimpleRecord> record,
Key const &key,
typename Key::Value const &value) {
67 record->set(key, value);
72template <
typename ReferenceCollection>
74 if (refList.empty()) {
77 auto const schema = getSchema(refList[0]);
78 CoordKey const coordKey(schema[
"coord"]);
79 Point2DKey const centroidKey(schema[
"centroid"]);
80 Key<Flag> const hasCentroidKey(schema[
"hasCentroid"]);
82 skyList.
reserve(refList.size());
83 for (
auto const &record : refList) {
87 auto pixelPos = pixelList.
cbegin();
88 for (
auto &refObj : refList) {
89 setValue(refObj, centroidKey, *pixelPos);
90 setValue(refObj, hasCentroidKey,
true);
97 Eigen::Matrix<t, 2, 2> err,
double factor) {
99 return Eigen::Matrix<t, 2, 2>::Constant(NAN);
105 const static double scale = 1.0 / 3600.0;
106 const static Eigen::Matrix2d cdMatrix{{scale, 0}, {0, scale}};
110 auto measurementToLocalGnomonic = wcs.
getTransform()->then(*localGnomonicWcs->getTransform()->inverted());
112 Eigen::Matrix2d localMatrix = measurementToLocalGnomonic->getJacobian(center);
113 Eigen::Matrix<t, 2, 2> d = localMatrix.cast<t>() * scale * factor;
115 Eigen::Matrix<t, 2, 2> skyCov = d * err * d.transpose();
122template <
typename SourceCollection>
124 if (sourceList.empty()) {
127 auto const schema = getSchema(sourceList[0]);
128 Point2DKey const centroidKey(schema[
"slot_Centroid"]);
130 CoordKey const coordKey(schema[
"coord"]);
132 pixelList.
reserve(sourceList.size());
134 skyErrList.
reserve(sourceList.size());
136 for (
auto const &source : sourceList) {
139 if (include_covariance) {
140 auto err = getValue(source, centroidErrKey);
147 auto skyCoord = skyList.
cbegin();
148 auto skyErr = skyErrList.
cbegin();
149 for (
auto &source : sourceList) {
150 setValue(source, coordKey, *skyCoord);
151 if (include_covariance) {
153 setValue(source, coordErrKey, *skyErr);
161 geom::SkyWcs const& wcs,
double x,
double y,
double xErr,
double yErr,
double xy_covariance) {
167 err(0, 0) = xErr * xErr;
168 err(1, 1) = yErr * yErr;
169 err(0, 1) = xy_covariance;
170 err(1, 0) = xy_covariance;
174 return {{radec.getRa().asDegrees(), radec.getDec().asDegrees()},
175 {sqrt(result(0, 0)), sqrt(result(1, 1)), result(0, 1)}};
183 bool include_covariance);
187 Eigen::Matrix2f err,
double factor);
189 Eigen::Matrix2d err,
double factor);
A 2-dimensional celestial WCS that transform pixels to ICRS RA/Dec, using the LSST standard for pixel...
lsst::geom::SpherePoint pixelToSky(lsst::geom::Point2D const &pixel) const
Compute sky position(s) from pixel position(s)
std::shared_ptr< const TransformPoint2ToSpherePoint > getTransform() const
Get a TransformPoint2ToSpherePoint that transforms pixels to sky in the forward direction and sky to ...
lsst::geom::Point2D skyToPixel(lsst::geom::SpherePoint const &sky) const
Compute pixel position(s) from sky position(s)
Base class for all records.
A FunctorKey used to get or set celestial coordinates from a pair of lsst::geom::Angle keys.
CovarianceMatrixKey< float, 2 > ErrorKey
static ErrorKey getErrorKey(Schema const &schema)
A class used as a handle to a particular field in a table.
Defines the fields and offsets for a table.
Record class that must contain a unique ID field and a celestial coordinate field.
T emplace_back(T... args)
std::shared_ptr< SkyWcs > makeSkyWcs(daf::base::PropertySet &metadata, bool strip=false)
Construct a SkyWcs from FITS keywords.
SortedCatalogT< SimpleRecord > SimpleCatalog
Eigen::Matrix< t, 2, 2 > calculateCoordCovariance(geom::SkyWcs const &wcs, lsst::geom::Point2D center, Eigen::Matrix< t, 2, 2 > err, double factor=lsst::geom::PI/180.0)
Calculate covariance for sky coordinates given a pixel centroid and errors.
void updateRefCentroids(geom::SkyWcs const &wcs, ReferenceCollection &refList)
Update centroids in a collection of reference objects.
void updateSourceCoords(geom::SkyWcs const &wcs, SourceCollection &sourceList, bool include_covariance=true)
Update sky coordinates in a collection of source objects.
SortedCatalogT< SourceRecord > SourceCatalog
std::pair< std::tuple< double, double >, std::tuple< double, double, double > > convertCentroid(geom::SkyWcs const &wcs, double x, double y, double xErr, double yErr, double xy_covariance=0)
Convert an x/y centroid with errors into RA/dec.
PointKey< double > Point2DKey
Point< double, 2 > Point2D
T Value
the type returned by BaseRecord::get