SourceXtractorPlusPlus 1.0.3
SourceXtractor++, the next generation SExtractor
Loading...
Searching...
No Matches
PythonModule.cpp
Go to the documentation of this file.
1
17/*
18 * @file PythonModule.cpp
19 * @author Nikolaos Apostolakos <nikoapos@gmail.com>
20 */
21
22#include <boost/python/class.hpp>
23#include <boost/python/enum.hpp>
24#include <boost/python/module.hpp>
25#include <boost/python/suite/indexing/vector_indexing_suite.hpp>
26#include <boost/python/suite/indexing/map_indexing_suite.hpp>
27
34
35namespace bp = boost::python;
36
37namespace SourceXtractor {
38
39BOOST_PYTHON_MODULE(_SourceXtractorPy) {
40
41 bp::class_<PyOutputWrapper, boost::noncopyable>("OutputWrapper",
42 "A file-like object used to wrap stdout and stderr", bp::no_init)
43 .def_readonly("closed", &PyOutputWrapper::closed)
44 .def("close", &PyOutputWrapper::close)
45 .def("fileno", &PyOutputWrapper::fileno)
46 .def("flush", &PyOutputWrapper::flush)
47 .def("isatty", &PyOutputWrapper::isatty)
48 .def("readable", &PyOutputWrapper::readable)
49 .def("read", &PyOutputWrapper::read)
50 .def("readline", &PyOutputWrapper::readline)
51 .def("readlines", &PyOutputWrapper::readlines)
52 .def("seek", &PyOutputWrapper::seek)
53 .def("seekable", &PyOutputWrapper::seekable)
54 .def("tell", &PyOutputWrapper::tell)
55 .def("truncate", &PyOutputWrapper::truncate)
56 .def("writable", &PyOutputWrapper::writable)
57 .def("write", &PyOutputWrapper::write)
58 .def("writelines", &PyOutputWrapper::writelines);
59
60 bp::class_<PyMeasurementImage>("MeasurementImage",
61 "C++ part of the MeasurementImage", bp::init<std::string, std::string, std::string>())
62 .def_readonly("id", &PyMeasurementImage::id)
63 .def_readonly("file", &PyMeasurementImage::file)
64 .def_readwrite("gain", &PyMeasurementImage::gain)
65 .def_readwrite("saturation", &PyMeasurementImage::saturation)
66 .def_readwrite("flux_scale", &PyMeasurementImage::flux_scale)
67 .def_readonly("psf_file", &PyMeasurementImage::psf_file)
68 .def_readonly("weight_file", &PyMeasurementImage::weight_file)
69 .def_readwrite("weight_type", &PyMeasurementImage::weight_type)
70 .def_readwrite("weight_absolute", &PyMeasurementImage::weight_absolute)
71 .def_readwrite("weight_scaling", &PyMeasurementImage::weight_scaling)
72 .def_readwrite("has_weight_threshold", &PyMeasurementImage::has_weight_threshold)
73 .def_readwrite("weight_threshold", &PyMeasurementImage::weight_threshold)
74 .def_readwrite("is_background_constant", &PyMeasurementImage::is_background_constant)
75 .def_readwrite("constant_background_value", &PyMeasurementImage::constant_background_value)
76 .def_readwrite("image_hdu", &PyMeasurementImage::image_hdu)
77 .def_readwrite("psf_hdu", &PyMeasurementImage::psf_hdu)
78 .def_readwrite("weight_hdu", &PyMeasurementImage::weight_hdu)
79 .def_readwrite("is_data_cube", &PyMeasurementImage::is_data_cube)
80 .def_readwrite("image_layer", &PyMeasurementImage::image_layer)
81 .def_readwrite("weight_layer", &PyMeasurementImage::weight_layer)
82 .def_readwrite("psf_renormalize", &PyMeasurementImage::psf_renormalize);
83 ;
84
85 bp::class_<PyId>("Id", bp::init<>())
86 .def_readonly("id", &PyId::id);
87
88 bp::class_<PyAperture, bp::bases<PyId>>("Aperture",
89 "Set of aperture photometries", bp::init<bp::list>())
90 .def_readonly("apertures", &PyAperture::apertures, "List of aperture diameters, in pixels")
91 .def("__str__", &PyAperture::toString)
92 .def("__repr__", &PyAperture::toString);
93
94 bp::class_<CoordinateSystem, boost::noncopyable>("CoordinateSystem",
95 "Implements transformation of coordinates between image and world coordinates", bp::no_init)
96 .def("image_to_world", &CoordinateSystem::imageToWorld)
97 .def("world_to_image", &CoordinateSystem::worldToImage);
98 bp::register_ptr_to_python<std::shared_ptr<CoordinateSystem>>();
99
100 bp::class_<WorldCoordinate>("WorldCoordinate", "World coordinates")
101 .def(bp::init<double, double>())
102 .def_readwrite("alpha", &WorldCoordinate::m_alpha)
103 .def_readwrite("delta", &WorldCoordinate::m_delta);
104
105 bp::class_<ImageCoordinate>("ImageCoordinate", "Image coordinates, in pixels")
106 .def(bp::init<double, double>())
107 .def_readwrite("x", &ImageCoordinate::m_x)
108 .def_readwrite("y", &ImageCoordinate::m_y);
109
110 bp::enum_<Flags>("Flags", "Source flags")
111 .value("NONE", Flags::NONE)
112 .value("BIASED", Flags::BIASED)
113 .value("SATURATED", Flags::SATURATED)
114 .value("BOUNDARY", Flags::BOUNDARY)
115 .value("NEIGHBORS", Flags::NEIGHBORS)
116 .value("OUTSIDE", Flags::OUTSIDE)
117 .value("PARTIAL_FIT", Flags::PARTIAL_FIT)
118 .value("INSUFFICIENT_DATA", Flags::INSUFFICIENT_DATA)
119 .value("ERROR", Flags::ERROR);
120
121 bp::class_<std::vector<int> >("_IntVector")
122 .def(bp::vector_indexing_suite<std::vector<int> >());
123
124 bp::class_<std::vector<unsigned int> >("_UIntVector")
125 .def(bp::vector_indexing_suite<std::vector<unsigned int> >());
126
127 bp::class_<std::map<std::string, std::string>>("_StringStringMap")
128 .def(bp::map_indexing_suite<std::map<std::string, std::string>>());
129
130 bp::class_<PyFitsFile>("FitsFile", "A FITS file opened by SourceXtractor++", bp::init<const std::string&>())
131 .def_readonly("filename", &PyFitsFile::getFilename)
132 .def_readonly("image_hdus", &PyFitsFile::getImageHdus)
133 .def("get_headers", &PyFitsFile::getHeaders, "get headers for hdu")
134 .def("get_dimensions", &PyFitsFile::getDimensions, "get dimensions for hdu");
135
136}
137
138} // namespace SourceXtractor
virtual WorldCoordinate imageToWorld(ImageCoordinate image_coordinate) const =0
virtual ImageCoordinate worldToImage(WorldCoordinate world_coordinate) const =0
std::vector< float > apertures
Definition PyAperture.h:36
std::string toString() const
std::map< std::string, std::string > getHeaders(int hdu) const
std::vector< int > getDimensions(int hdu) const
std::string getFilename() const
Definition PyFitsFile.h:36
std::vector< int > getImageHdus() const
const int id
Definition PyId.h:35
boost::python::list readlines(int)
void writelines(const boost::python::list &)
int write(const boost::python::object &)
@ NEIGHBORS
The object has neighbors, bright and close enough.
Definition SourceFlags.h:43
@ SATURATED
At least one pixel of the object is saturated.
Definition SourceFlags.h:41
@ OUTSIDE
The object is completely outside of the measurement frame.
Definition SourceFlags.h:44
@ BOUNDARY
The object is truncated (too close to an image boundary).
Definition SourceFlags.h:42
@ NONE
No flag is set.
Definition SourceFlags.h:38
@ ERROR
Error flag: something bad happened during the measurement, model fitting, etc.
Definition SourceFlags.h:47
@ BIASED
The object has bad pixels.
Definition SourceFlags.h:39
@ INSUFFICIENT_DATA
There are not enough good pixels to fit the parameters.
Definition SourceFlags.h:46
@ PARTIAL_FIT
Some/all of the model parameters could not be fitted.
Definition SourceFlags.h:45
BOOST_PYTHON_MODULE(_SourceXtractorPy)