LSST Applications g063fba187b+cac8b7c890,g0f08755f38+6aee506743,g1653933729+a8ce1bb630,g168dd56ebc+a8ce1bb630,g1a2382251a+b4475c5878,g1dcb35cd9c+8f9bc1652e,g20f6ffc8e0+6aee506743,g217e2c1bcf+73dee94bd0,g28da252d5a+1f19c529b9,g2bbee38e9b+3f2625acfc,g2bc492864f+3f2625acfc,g3156d2b45e+6e55a43351,g32e5bea42b+1bb94961c2,g347aa1857d+3f2625acfc,g35bb328faa+a8ce1bb630,g3a166c0a6a+3f2625acfc,g3e281a1b8c+c5dd892a6c,g3e8969e208+a8ce1bb630,g414038480c+5927e1bc1e,g41af890bb2+8a9e676b2a,g7af13505b9+809c143d88,g80478fca09+6ef8b1810f,g82479be7b0+f568feb641,g858d7b2824+6aee506743,g89c8672015+f4add4ffd5,g9125e01d80+a8ce1bb630,ga5288a1d22+2903d499ea,gb58c049af0+d64f4d3760,gc28159a63d+3f2625acfc,gcab2d0539d+b12535109e,gcf0d15dbbd+46a3f46ba9,gda6a2b7d83+46a3f46ba9,gdaeeff99f8+1711a396fd,ge79ae78c31+3f2625acfc,gef2f8181fd+0a71e47438,gf0baf85859+c1f95f4921,gfa517265be+6aee506743,gfa999e8aa5+17cd334064,w.2024.51
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}