24#include "pybind11/pybind11.h"
26#include "pybind11/eigen.h"
32#include "pybind11/stl.h"
33#include "ndarray/pybind11.h"
42using namespace py::literals;
49void declareSkyWcs(lsst::cpputils::python::WrapperCollection &wrappers) {
50 wrappers.
wrap([](
auto &mod) {
53 mod.def(
"makeFlippedWcs",
makeFlippedWcs,
"wcs"_a,
"flipLR"_a,
"flipTB"_a,
"center"_a);
54 mod.def(
"makeModifiedWcs",
makeModifiedWcs,
"pixelTransform"_a,
"wcs"_a,
"modifyActualPixels"_a);
57 Eigen::Matrix2d
const &, std::string
const &))
makeSkyWcs,
58 "crpix"_a,
"crval"_a,
"cdMatrix"_a,
"projection"_a =
"TAN");
59 mod.def(
"makeSkyWcs", (std::shared_ptr<SkyWcs>(*)(daf::base::PropertySet &,
bool))
makeSkyWcs,
60 "metadata"_a,
"strip"_a =
false);
63 lsst::geom::SpherePoint
const &, std::string
const &))
makeSkyWcs,
64 "pixelsToFieldAngle"_a,
"orientation"_a,
"flipX"_a,
"boresight"_a,
"projection"_a =
"TAN");
65 mod.def(
"makeTanSipWcs",
67 Eigen::Matrix2d
const &, Eigen::MatrixXd
const &,
69 "crpix"_a,
"crval"_a,
"cdMatrix"_a,
"sipA"_a,
"sipB"_a);
70 mod.def(
"makeTanSipWcs",
72 Eigen::Matrix2d
const &, Eigen::MatrixXd
const &,
73 Eigen::MatrixXd
const &, Eigen::MatrixXd
const &,
75 "crpix"_a,
"crval"_a,
"cdMatrix"_a,
"sipA"_a,
"sipB"_a,
"sipAp"_a,
"sipBp"_a);
83 py::class_<
SkyWcs, std::shared_ptr<SkyWcs>, typehandling::Storable>(wrappers.
module,
"SkyWcs"),
84 [](
auto &mod,
auto &cls) {
85 cls.def(py::init<daf::base::PropertySet &, bool>(),
"metadata"_a,
"strip"_a = false);
86 cls.def(py::init<ast::FrameDict const &>(),
"frameDict"_a);
88 cls.def(
"__eq__", &SkyWcs::operator==, py::is_operator());
89 cls.def(
"__ne__", &SkyWcs::operator!=, py::is_operator());
91 table::io::python::addPersistableMethods<SkyWcs>(cls);
93 cls.def(
"copyAtShiftedPixelOrigin", &SkyWcs::copyAtShiftedPixelOrigin,
"shift"_a);
94 cls.def(
"getFitsMetadata", &SkyWcs::getFitsMetadata,
"precise"_a = false);
95 cls.def(
"getPixelScale",
96 (lsst::geom::Angle(SkyWcs::*)(lsst::geom::Point2D const &) const) &
97 SkyWcs::getPixelScale,
99 cls.def(
"getPixelScale", (lsst::geom::Angle(SkyWcs::*)() const) & SkyWcs::getPixelScale);
100 cls.def(
"getPixelOrigin", &SkyWcs::getPixelOrigin);
101 cls.def(
"getSkyOrigin", &SkyWcs::getSkyOrigin);
102 cls.def(
"getCdMatrix",
103 (Eigen::Matrix2d(SkyWcs::*)(lsst::geom::Point2D const &) const) & SkyWcs::getCdMatrix,
105 cls.def(
"getCdMatrix", (Eigen::Matrix2d(SkyWcs::*)() const) & SkyWcs::getCdMatrix);
106 cls.def(
"getTanWcs", &SkyWcs::getTanWcs,
"pixel"_a);
107 cls.def(
"getFrameDict", [](SkyWcs const &self) { return self.getFrameDict()->copy(); });
112 cls.def(
"linearizePixelToSky",
113 (lsst::geom::AffineTransform(
SkyWcs::*)(lsst::geom::SpherePoint
const &,
114 lsst::geom::AngleUnit
const &)
const) &
116 "coord"_a,
"skyUnit"_a);
117 cls.def(
"linearizePixelToSky",
119 lsst::geom::AngleUnit
const &)
const) &
121 "coord"_a,
"skyUnit"_a);
122 cls.def(
"linearizeSkyToPixel",
123 (lsst::geom::AffineTransform(
SkyWcs::*)(lsst::geom::SpherePoint
const &,
124 lsst::geom::AngleUnit
const &)
const) &
126 "coord"_a,
"skyUnit"_a);
127 cls.def(
"linearizeSkyToPixel",
129 lsst::geom::AngleUnit
const &)
const) &
131 "coord"_a,
"skyUnit"_a);
132 cls.def(
"pixelToSky",
136 cls.def(
"pixelToSky",
139 cls.def(
"pixelToSky",
140 (std::vector<lsst::geom::SpherePoint>(
SkyWcs::*)(
141 std::vector<lsst::geom::Point2D>
const &)
const) &
144 cls.def(
"skyToPixel",
148 cls.def(
"skyToPixel",
149 (std::vector<lsst::geom::Point2D>(
SkyWcs::*)(
150 std::vector<lsst::geom::SpherePoint>
const &)
const) &
169 declareSkyWcs(wrappers);
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)
lsst::geom::AffineTransform linearizeSkyToPixel(lsst::geom::SpherePoint const &coord, lsst::geom::AngleUnit const &skyUnit) const
Return the local linear approximation to skyToPixel at a point given in sky coordinates.
bool isFlipped() const
Does the WCS follow the convention of North=Up, East=Left?
std::string writeString() const
Serialize this SkyWcs to a string, using the same format as writeStream.
lsst::geom::AffineTransform linearizePixelToSky(lsst::geom::SpherePoint const &coord, lsst::geom::AngleUnit const &skyUnit) const
Return the local linear approximation to pixelToSky at a point given in sky coordinates.
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)
bool isFits() const
Return true getFitsMetadata(true) will succeed, false if not.
static std::shared_ptr< SkyWcs > readString(std::string &str)
Deserialize a SkyWcs from a string, using the same format as readStream.
A helper class for subdividing pybind11 module across multiple translation units (i....
void addSignatureDependency(std::string const &name)
Indicate an external module that provides a type used in function/method signatures.
void wrap(WrapperCallback function)
Add a set of wrappers without defining a class.
void addInheritanceDependency(std::string const &name)
Indicate an external module that provides a base class for a subsequent addType call.
PyType wrapType(PyType cls, ClassWrapperCallback function, bool setModuleName=true)
Add a type (class or enum) wrapper, deferring method and other attribute definitions until finish() i...
pybind11::module module
The module object passed to the PYBIND11_MODULE block that contains this WrapperCollection.
std::shared_ptr< SkyWcs > makeSkyWcs(daf::base::PropertySet &metadata, bool strip=false)
Construct a SkyWcs from FITS keywords.
std::shared_ptr< TransformPoint2ToPoint2 > getPixelToIntermediateWorldCoords(SkyWcs const &wcs, bool simplify=true)
Return a transform from pixel coordinates to intermediate world coordinates.
void wrapSkyWcs(lsst::cpputils::python::WrapperCollection &)
std::shared_ptr< SkyWcs > makeTanSipWcs(lsst::geom::Point2D const &crpix, lsst::geom::SpherePoint const &crval, Eigen::Matrix2d const &cdMatrix, Eigen::MatrixXd const &sipA, Eigen::MatrixXd const &sipB)
Construct a TAN-SIP SkyWcs with forward SIP distortion terms and an iterative inverse.
Eigen::Matrix2d makeCdMatrix(lsst::geom::Angle const &scale, lsst::geom::Angle const &orientation=0 *lsst::geom::degrees, bool flipX=false)
Make a WCS CD matrix.
std::shared_ptr< TransformPoint2ToSpherePoint > getIntermediateWorldCoordsToSky(SkyWcs const &wcs, bool simplify=true)
Return a transform from intermediate world coordinates to sky.
std::shared_ptr< SkyWcs > makeModifiedWcs(TransformPoint2ToPoint2 const &pixelTransform, SkyWcs const &wcs, bool modifyActualPixels)
Create a new SkyWcs whose pixels are transformed by pixelTransform, as described below.
Transform< Point2Endpoint, Point2Endpoint > TransformPoint2ToPoint2
std::shared_ptr< TransformPoint2ToPoint2 > makeWcsPairTransform(SkyWcs const &src, SkyWcs const &dst)
A Transform obtained by putting two SkyWcs objects "back to back".
std::shared_ptr< SkyWcs > makeFlippedWcs(SkyWcs const &wcs, bool flipLR, bool flipTB, lsst::geom::Point2D const ¢er)
Return a copy of a FITS-WCS with pixel positions flipped around a specified center.
void addOutputOp(PyClass &cls, std::string const &method)
Add __str__ or __repr__ method implemented by operator<<.
AngleUnit constexpr degrees
constant with units of degrees
Point< double, 2 > Point2D