LSST Applications g0f08755f38+9c285cab97,g1635faa6d4+13f3999e92,g1653933729+a8ce1bb630,g1a0ca8cf93+bf6eb00ceb,g28da252d5a+0829b12dee,g29321ee8c0+5700dc9eac,g2bbee38e9b+9634bc57db,g2bc492864f+9634bc57db,g2cdde0e794+c2c89b37c4,g3156d2b45e+41e33cbcdc,g347aa1857d+9634bc57db,g35bb328faa+a8ce1bb630,g3a166c0a6a+9634bc57db,g3e281a1b8c+9f2c4e2fc3,g414038480c+077ccc18e7,g41af890bb2+fde0dd39b6,g5fbc88fb19+17cd334064,g781aacb6e4+a8ce1bb630,g80478fca09+55a9465950,g82479be7b0+d730eedb7d,g858d7b2824+9c285cab97,g9125e01d80+a8ce1bb630,g9726552aa6+10f999ec6a,ga5288a1d22+2a84bb7594,gacf8899fa4+c69c5206e8,gae0086650b+a8ce1bb630,gb58c049af0+d64f4d3760,gc28159a63d+9634bc57db,gcf0d15dbbd+4b7d09cae4,gda3e153d99+9c285cab97,gda6a2b7d83+4b7d09cae4,gdaeeff99f8+1711a396fd,ge2409df99d+5e831397f4,ge79ae78c31+9634bc57db,gf0baf85859+147a0692ba,gf3967379c6+41c94011de,gf3fb38a9a8+8f07a9901b,gfb92a5be7c+9c285cab97,w.2024.46
LSST Data Management Base Package
Loading...
Searching...
No Matches
Classes | Functions
lsst::gauss2d::python Namespace Reference

Classes

class  Image
 A Python image using numpy arrrays for storage. More...
 

Functions

template<typename T >
std::string replace_type (std::string target, std::string replacement)
 
template<typename Value , typename Index >
std::string replace_images_types (std::string target, std::string str_type, std::string_view separator)
 Replace templated Image and index Image type name with Pythonic names.
 
template<typename T >
void declare_image (py::module &m, std::string str_type)
 
template<typename T >
std::string replace_image_types (std::string target, std::string str_type, std::string_view separator)
 Replace a template Image type name with Pythonic names.
 
template<typename T >
void declare_image_array (py::module &m, std::string str_type)
 
template<typename T >
void declare_evaluator (py::module &m, std::string str_type)
 
template<typename T , class Data , class Indices >
void declare_maker (py::module &m, std::string str_type)
 

Function Documentation

◆ declare_evaluator()

template<typename T >
void lsst::gauss2d::python::declare_evaluator ( py::module & m,
std::string str_type )

Definition at line 237 of file image.h.

237 {
239 std::string pyclass_name = std::string("GaussianEvaluator") + str_type;
240 py::class_<Class, std::shared_ptr<Class>>(m, pyclass_name.c_str())
242 const std::shared_ptr<const Image<T>>, const std::shared_ptr<const Image<T>>,
246 const std::shared_ptr<const Image<T>>,
248 const std::shared_ptr<const Image<T>>, const std::shared_ptr<const Image<T>>>(),
249 "gaussians"_a, "data"_a = nullptr, "sigma_inv"_a = nullptr, "output"_a = nullptr,
250 "residual"_a = nullptr, "grads"_a = nullptr, "grad_param_map"_a = nullptr,
251 "grad_param_factor"_a = nullptr, "extra_param_map"_a = nullptr,
252 "extra_param_factor"_a = nullptr, "background"_a = nullptr)
253 .def("loglike_pixel", &Class::loglike_pixel, "to_add"_a = false)
254 .def_property_readonly("n_cols", &Class::get_n_cols)
255 .def_property_readonly("n_rows", &Class::get_n_rows)
256 .def_property_readonly("size", &Class::get_size)
257 .def("__len__", &Class::get_size)
258 .def("__repr__",
259 [str_type](const Class &self) {
260 std::string repr = self.repr(true, self.PY_NAMESPACE_SEPARATOR);
261 repr = replace_images_types<T, lsst::gauss2d::idx_type>(repr, str_type,
262 self.PY_NAMESPACE_SEPARATOR);
263 return repr;
264 })
265 .def("__str__", [str_type](const Class &self) {
266 std::string str = self.str();
267 str = replace_images_types<T, lsst::gauss2d::idx_type>(str, str_type,
268 self.CC_NAMESPACE_SEPARATOR);
269 return str;
270 });
271}
int m
Definition SpanSet.cc:48
T c_str(T... args)
A class that evaluates 2D Gaussians and renders them in images.
Definition evaluate.h:668
An array of compatible Images.
Definition image.h:268
A Python image using numpy arrrays for storage.
Definition image.h:72

◆ declare_image()

template<typename T >
void lsst::gauss2d::python::declare_image ( py::module & m,
std::string str_type )

Definition at line 157 of file image.h.

157 {
158 using Class = Image<T>;
159 std::string pyclass_name = std::string("Image") + str_type;
160 py::class_<Class, std::shared_ptr<Class>>(m, pyclass_name.c_str())
161 .def(py::init<size_t, size_t, const T *,
163 "n_rows"_a, "n_cols"_a, "value_init"_a = Class::_value_default_ptr(),
164 "coordsys"_a = gauss2d::COORDS_DEFAULT)
165 .def(py::init<py::array_t<T>, const std::shared_ptr<const lsst::gauss2d::CoordinateSystem>>(),
166 "data"_a, "coordsys"_a = gauss2d::COORDS_DEFAULT)
167 .def_property_readonly("coordsys", &Class::get_coordsys_ptr_const)
168 .def_property_readonly("data", &Class::get_data)
169 .def_property_readonly("n_rows", &Class::get_n_rows)
170 .def_property_readonly("n_cols", &Class::get_n_cols)
171 .def("fill", &Class::fill)
172 .def("get_value", &Class::get_value, "row"_a, "col"_a)
173 .def("set_value", &Class::set_value, "row"_a, "col"_a, "value"_a)
174 .def("get_value_unchecked", &Class::get_value_unchecked, "row"_a, "col"_a)
175 .def("set_value_unchecked", &Class::set_value_unchecked, "row"_a, "col"_a, "value"_a)
176 .def_property_readonly("size", &Class::size)
177 .def_property_readonly("shape", &Class::shape)
178 .def(py::self == py::self)
179 .def(py::self != py::self)
180 .def(py::self += T())
181 .def(py::self *= T())
182 .def("__repr__",
183 [str_type](const Class &self) {
184 std::string repr = self.repr(true, self.PY_NAMESPACE_SEPARATOR);
185 return replace_type<T>(repr, str_type);
186 })
187 .def("__str__", [str_type](const Class &self) {
188 std::string str = self.str();
189 return replace_type<T>(str, str_type);
190 });
191}

◆ declare_image_array()

template<typename T >
void lsst::gauss2d::python::declare_image_array ( py::module & m,
std::string str_type )

Definition at line 214 of file image.h.

214 {
216 std::string pyclass_name = std::string("ImageArray") + str_type;
217 py::class_<Class, std::shared_ptr<Class>>(m, pyclass_name.c_str())
218 .def(py::init<const typename Class::Data *>(), "data"_a)
219 .def("at", &Class::at, py::return_value_policy::reference)
220 .def_property_readonly("size", &Class::size)
221 .def("__getitem__", &Class::at, py::return_value_policy::reference)
222 .def("__len__", &Class::size)
223 .def("__repr__",
224 [str_type](const Class &self) {
225 std::string repr = self.repr(true, self.PY_NAMESPACE_SEPARATOR);
226 repr = replace_image_types<T>(repr, str_type, self.PY_NAMESPACE_SEPARATOR);
227 return repr;
228 })
229 .def("__str__", [str_type](const Class &self) {
230 std::string str = self.str();
231 str = replace_image_types<T>(str, str_type, self.CC_NAMESPACE_SEPARATOR);
232 return str;
233 });
234}

◆ declare_maker()

template<typename T , class Data , class Indices >
void lsst::gauss2d::python::declare_maker ( py::module & m,
std::string str_type )

Definition at line 274 of file image.h.

274 {
275 m.def(("make_gaussians_pixel_" + str_type).c_str(), lsst::gauss2d::make_gaussians_pixel<T, Data, Indices>,
276 "Evaluate a 2D Gaussian at the centers of pixels on a rectangular grid using the standard bivariate"
277 "Gaussian PDF.",
278 "gaussians"_a, "output"_a = nullptr, "n_rows"_a = 0, "n_cols"_a = 0, "coordsys"_a = nullptr,
279 "to_add"_a = false);
280}

◆ replace_image_types()

template<typename T >
std::string lsst::gauss2d::python::replace_image_types ( std::string target,
std::string str_type,
std::string_view separator )

Replace a template Image type name with Pythonic names.

Template Parameters
TThe data type of the Image class string to replace.
Parameters
targetThe string to replace type names in.
str_typeThe replacement string for T.
separatorThe namespace separator to replace.
Returns
A replacement string without templated types.

Definition at line 203 of file image.h.

203 {
204 std::string token1 = std::string("<") + type_name_str<T>() + ", ";
205 target = replace_all_none(target, token1);
206 std::string token2 = type_name_str<Image<T>>(false, separator) + std::string(" >");
207 target = replace_all(target, token2, str_type);
208 // str appears to return e.g. Image<double> for some reason
209 target = replace_type<T>(target, str_type);
210 return target;
211}
Key< Flag > const & target
std::string replace_all_none(std::string target, T token)
Replace a token inside a target string with nothing.
std::string replace_all(std::string target, T token, R replacement)
Replace a token inside a target string with another string.

◆ replace_images_types()

template<typename Value , typename Index >
std::string lsst::gauss2d::python::replace_images_types ( std::string target,
std::string str_type,
std::string_view separator )

Replace templated Image and index Image type name with Pythonic names.

Template Parameters
ValueThe data type of the Image (data) class string to replace.
IndexThe data type of the Image (index) class string to replace.
Parameters
targetThe string to replace type names in.
str_typeThe replacement string for T.
separatorThe namespace separator to replace.
Returns
A replacement string without templated types.

Definition at line 144 of file image.h.

144 {
145 std::string token1 = std::string("<") + type_name_str<Value>() + ", ";
146 target = replace_all_none(target, token1);
147 std::string token2 = type_name_str<Image<Value>>(false, separator) + std::string(", ");
148 target = replace_all_none(target, token2);
149 std::string token3 = type_name_str<Image<Index>>(false, separator) + std::string(" >");
150 target = replace_all(target, token3, str_type);
151 // str appears to return e.g. Image<double> for some reason
152 target = replace_type<Value>(target, str_type);
153 return target;
154}

◆ replace_type()

template<typename T >
std::string lsst::gauss2d::python::replace_type ( std::string target,
std::string replacement )

Definition at line 50 of file image.h.

50 {
51 std::string token = "<" + gauss2d::type_name_str<T>() + ">";
52 return replace_all(target, token, replacement);
53}