23 #include "pybind11/pybind11.h"
27 #include "numpy/arrayobject.h"
28 #include "ndarray/pybind11.h"
30 #include "lsst/daf/base/Citizen.h"
31 #include "lsst/daf/base/PropertySet.h"
41 namespace py = pybind11;
42 using namespace py::literals;
50 using PyWcs = py::class_<Wcs, std::shared_ptr<Wcs>, daf::base::Citizen, table::io::Persistable,
51 table::io::PersistableFacade<Wcs>>;
53 using PyXYTransformFromWcsPair =
54 py::class_<XYTransformFromWcsPair, std::shared_ptr<XYTransformFromWcsPair>, geom::XYTransform>;
57 void declareWcs(py::module &mod) {
58 table::io::python::declarePersistableFacade<Wcs>(mod,
"Wcs");
61 PyWcs
cls(mod,
"Wcs");
65 std::string
const &, std::string
const &,
double, std::string
const &,
66 std::string
const &, std::string
const &>(),
67 "crval"_a,
"crpix"_a,
"CD"_a,
"ctype1"_a =
"RA---TAN",
"ctype2"_a =
"DEC--TAN",
68 "equinox"_a = 2000,
"raDecSys"_a =
"ICRS",
"cunits1"_a =
"deg",
"cunits2"_a =
"deg");
71 cls.def(
"__eq__", [](Wcs
const &
self, Wcs
const &other) {
return self == other; }, py::is_operator());
72 cls.def(
"__ne__", [](Wcs
const &
self, Wcs
const &other) {
return self != other; }, py::is_operator());
76 cls.def(
"getSkyOrigin", &Wcs::getSkyOrigin);
77 cls.def(
"getPixelOrigin", &Wcs::getPixelOrigin);
78 cls.def(
"getCDMatrix", &Wcs::getCDMatrix);
81 cls.def(
"getFitsMetadata", &Wcs::getFitsMetadata);
82 cls.def(
"isFlipped", &Wcs::isFlipped);
83 cls.def(
"pixArea", &Wcs::pixArea);
84 cls.def(
"pixelScale", &Wcs::pixelScale);
85 cls.def(
"pixelToSky", (std::shared_ptr<coord::Coord> (Wcs::*)(
double,
double)
const) & Wcs::pixelToSky);
87 (std::shared_ptr<coord::Coord> (Wcs::*)(
geom::Point2D const &)
const) & Wcs::pixelToSky);
92 cls.def(
"skyToIntermediateWorldCoord", &Wcs::skyToIntermediateWorldCoord);
93 cls.def(
"hasDistortion", &Wcs::hasDistortion);
94 cls.def(
"getCoordSystem", &Wcs::getCoordSystem);
95 cls.def(
"getEquinox", &Wcs::getEquinox);
96 cls.def(
"isSameSkySystem", &Wcs::isSameSkySystem);
97 cls.def(
"getLinearTransform", &Wcs::getLinearTransform);
98 cls.def(
"linearizePixelToSky",
99 (geom::AffineTransform (Wcs::*)(
coord::Coord const &, geom::AngleUnit)
const) &
100 Wcs::linearizePixelToSky,
102 cls.def(
"linearizePixelToSky",
103 (geom::AffineTransform (Wcs::*)(
geom::Point2D const &, geom::AngleUnit)
const) &
104 Wcs::linearizePixelToSky,
106 cls.def(
"linearizeSkyToPixel",
107 (geom::AffineTransform (Wcs::*)(
coord::Coord const &, geom::AngleUnit)
const) &
108 Wcs::linearizeSkyToPixel,
110 cls.def(
"linearizeSkyToPixel",
111 (geom::AffineTransform (Wcs::*)(
geom::Point2D const &, geom::AngleUnit)
const) &
112 Wcs::linearizeSkyToPixel,
114 cls.def(
"shiftReferencePixel", (
void (Wcs::*)(
double,
double)) & Wcs::shiftReferencePixel);
115 cls.def(
"shiftReferencePixel", (
void (Wcs::*)(
geom::Extent2D const &)) & Wcs::shiftReferencePixel);
116 cls.def(
"isPersistable", &Wcs::isPersistable);
120 void declareXYTransformFromWcsPair(py::module &mod) {
121 PyXYTransformFromWcsPair
cls(mod,
"XYTransformFromWcsPair");
122 cls.def(py::init<std::shared_ptr<Wcs const>, std::shared_ptr<Wcs const>>(),
"dst"_a,
"src"_a);
129 py::module mod(
"wcs");
131 py::module::import(
"lsst.afw.geom");
133 if (_import_array() < 0) {
134 PyErr_SetString(PyExc_ImportError,
"numpy.core.multiarray failed to import");
139 (std::shared_ptr<Wcs>(*)(std::shared_ptr<daf::base::PropertySet>
const &,
bool)) &
makeWcs,
140 "fitsMetadata"_a,
"stripMetadata"_a =
false);
142 double,
double,
double,
double)) &
147 declareXYTransformFromWcsPair(mod);
lsst::afw::geom::Angle Angle
lsst::afw::coord::Coord Coord
Extent< double, 2 > Extent2D
std::shared_ptr< ImageT > flipImage(ImageT const &inImage, bool flipLR, bool flipTB)
Flip an image left–right and/or top–bottom.
AngleUnit constexpr degrees
constant with units of degrees
PYBIND11_PLUGIN(_cameraPoint)
Point< double, 2 > Point2D
std::shared_ptr< ImageT > rotateImageBy90(ImageT const &image, int nQuarter)
Rotate an image by an integral number of quarter turns.
This is the base class for spherical coordinates.
std::shared_ptr< Wcs > makeWcs(std::shared_ptr< lsst::daf::base::PropertySet > const &fitsMetadata, bool stripMetadata=false)
Create a Wcs object from a fits header.