LSST Applications g1653933729+a8ce1bb630,g1a997c3884+a8ce1bb630,g28da252d5a+d15de4ab0d,g2bbee38e9b+97aa061eef,g2bc492864f+97aa061eef,g2cdde0e794+3ad5f2bb52,g3156d2b45e+07302053f8,g347aa1857d+97aa061eef,g35bb328faa+a8ce1bb630,g3a166c0a6a+97aa061eef,g3e281a1b8c+693a468c5f,g4005a62e65+17cd334064,g414038480c+56e3b84a79,g41af890bb2+1c23cd8dc6,g4e1a3235cc+346d8468f1,g6249c6f860+0f10df03c7,g80478fca09+469ce5f220,g82479be7b0+90e3dadc5b,g858d7b2824+e7f795e3fb,g9125e01d80+a8ce1bb630,g923454667a+e7f795e3fb,ga5288a1d22+d13454dda5,gae0086650b+a8ce1bb630,gb58c049af0+d64f4d3760,gc28159a63d+97aa061eef,gcf0d15dbbd+874ca8ec09,gd6b7c0dfd1+d9d51876e5,gda3e153d99+e7f795e3fb,gda6a2b7d83+874ca8ec09,gdaeeff99f8+1711a396fd,gdd5a9049c5+40baf9de4f,ge2409df99d+634e70b004,ge33fd446bb+e7f795e3fb,ge79ae78c31+97aa061eef,gf0baf85859+5daf287408,gf5289d68f6+f8c5105d69,gfa443fc69c+1babd4a8ba,gfda6b12a05+3bcad770a9,w.2024.41
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}