SourceXtractorPlusPlus  0.16
Please provide a description of the project.
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 
35 namespace bp = boost::python;
36 
37 namespace SourceXtractor {
38 
39 BOOST_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 
80  bp::class_<PyId>("Id", bp::init<>())
81  .def_readonly("id", &PyId::id);
82 
83  bp::class_<PyAperture, bp::bases<PyId>>("Aperture",
84  "Set of aperture photometries", bp::init<bp::list>())
85  .def_readonly("apertures", &PyAperture::apertures, "List of aperture diameters, in pixels")
86  .def("__str__", &PyAperture::toString)
87  .def("__repr__", &PyAperture::toString);
88 
89  bp::class_<CoordinateSystem, boost::noncopyable>("CoordinateSystem",
90  "Implements transformation of coordinates between image and world coordinates", bp::no_init)
91  .def("image_to_world", &CoordinateSystem::imageToWorld)
92  .def("world_to_image", &CoordinateSystem::worldToImage);
93  bp::register_ptr_to_python<std::shared_ptr<CoordinateSystem>>();
94 
95  bp::class_<WorldCoordinate>("WorldCoordinate", "World coordinates")
96  .def(bp::init<double, double>())
97  .def_readwrite("alpha", &WorldCoordinate::m_alpha)
98  .def_readwrite("delta", &WorldCoordinate::m_delta);
99 
100  bp::class_<ImageCoordinate>("ImageCoordinate", "Image coordinates, in pixels")
101  .def(bp::init<double, double>())
102  .def_readwrite("x", &ImageCoordinate::m_x)
103  .def_readwrite("y", &ImageCoordinate::m_y);
104 
105  bp::enum_<Flags>("Flags", "Source flags")
106  .value("NONE", Flags::NONE)
107  .value("BIASED", Flags::BIASED)
108  .value("SATURATED", Flags::SATURATED)
109  .value("BOUNDARY", Flags::BOUNDARY)
110  .value("NEIGHBORS", Flags::NEIGHBORS)
111  .value("OUTSIDE", Flags::OUTSIDE)
112  .value("PARTIAL_FIT", Flags::PARTIAL_FIT)
113  .value("INSUFFICIENT_DATA", Flags::INSUFFICIENT_DATA)
114  .value("ERROR", Flags::ERROR);
115 
116  bp::class_<std::vector<int> >("_IntVector")
117  .def(bp::vector_indexing_suite<std::vector<int> >());
118 
119  bp::class_<std::vector<unsigned int> >("_UIntVector")
120  .def(bp::vector_indexing_suite<std::vector<unsigned int> >());
121 
122  bp::class_<std::map<std::string, std::string>>("_StringStringMap")
123  .def(bp::map_indexing_suite<std::map<std::string, std::string>>());
124 
125  bp::class_<PyFitsFile>("FitsFile", "A FITS file opened by SourceXtractor++", bp::init<const std::string&>())
126  .def_readonly("filename", &PyFitsFile::getFilename)
127  .def_readonly("image_hdus", &PyFitsFile::getImageHdus)
128  .def("get_headers", &PyFitsFile::getHeaders, "get headers for hdu");
129 }
130 
131 } // 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
Definition: PyAperture.cpp:32
std::map< std::string, std::string > getHeaders(int hdu) const
Definition: PyFitsFile.cpp:38
std::string getFilename() const
Definition: PyFitsFile.h:36
std::vector< int > getImageHdus() const
Definition: PyFitsFile.cpp:28
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.
@ SATURATED
At least one pixel of the object is saturated.
@ OUTSIDE
The object is completely outside of the measurement frame.
@ BOUNDARY
The object is truncated (too close to an image boundary)
@ NONE
No flag is set.
@ ERROR
Error flag: something bad happened during the measurement, model fitting, etc.
@ BIASED
The object has bad pixels.
@ INSUFFICIENT_DATA
There are not enough good pixels to fit the parameters.
@ PARTIAL_FIT
Some/all of the model parameters could not be fitted.
BOOST_PYTHON_MODULE(_SourceXtractorPy)