Loading [MathJax]/extensions/tex2jax.js
LSST Applications g0fba68d861+05a5e06e50,g1fd858c14a+904f1f4196,g2c84ff76c0+247cd845a2,g2c9e612ef2+f5117f1d55,g35bb328faa+fcb1d3bbc8,g4af146b050+123c2f4d45,g4d2262a081+a9e7a6e053,g4e0f332c67+c58e4b632d,g53246c7159+fcb1d3bbc8,g5a012ec0e7+ac98094cfc,g60b5630c4e+f5117f1d55,g67b6fd64d1+dd0349c22b,g78460c75b0+2f9a1b4bcd,g786e29fd12+cf7ec2a62a,g7b71ed6315+fcb1d3bbc8,g87b7deb4dc+2a1aa4536a,g8852436030+d21aad2af4,g89139ef638+dd0349c22b,g8d6b6b353c+f5117f1d55,g9125e01d80+fcb1d3bbc8,g989de1cb63+dd0349c22b,g9f33ca652e+0a580a37dd,g9f7030ddb1+ae84e0d5a5,ga2b97cdc51+f5117f1d55,gabe3b4be73+1e0a283bba,gb1101e3267+1d994e7598,gb58c049af0+f03b321e39,gb89ab40317+dd0349c22b,gcca6a94b71+4ed007ada1,gcf25f946ba+d21aad2af4,gd315a588df+9d9c5ccff1,gd6cbbdb0b4+75aa4b1db4,gd9a9a58781+fcb1d3bbc8,gde0f65d7ad+6fce216140,ge278dab8ac+c61fbefdff,ge410e46f29+dd0349c22b,ge82c20c137+e12a08b75a,gf67bdafdda+dd0349c22b,v28.0.2.rc1
LSST Data Management Base Package
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
test_image.cc
Go to the documentation of this file.
1#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
2
3#include "doctest.h"
4
5#include <memory>
6
8#include "lsst/gauss2d/python/image.h"
9
10#include <pybind11/embed.h>
11
12namespace g2d = lsst::gauss2d;
13
17
18// Import numpy, otherwise all Image calls will segfault
19py::scoped_interpreter guard{};
20py::module_ numpy = py::module_::import("numpy");
21
22TEST_CASE("Image") {
23 size_t n_rows = 3, n_cols = 2;
25 Image zeros{n_rows, n_cols};
26 for (size_t row = 0; row < n_rows; ++row) {
27 for (size_t col = 0; col < n_cols; ++col) {
28 image->set_value(row, col, 0);
29 zeros.set_value(row, col, 0);
30 }
31 }
32 CHECK(*image == zeros);
33 CHECK(image->get_coordsys() == g2d::COORDS_DEFAULT);
34 CHECK(&(image->get_coordsys()) == &(g2d::COORDS_DEFAULT));
35 CHECK(image->get_n_cols() == n_cols);
36 CHECK(image->get_n_rows() == n_rows);
37 CHECK(image->size() == n_cols * n_rows);
38
39 image->set_value_unchecked(0, 0, 0);
40 CHECK(image->get_value_unchecked(0, 0) == 0);
41 image->add_value_unchecked(0, 0, 1);
42 CHECK(image->get_value_unchecked(0, 0) == 1);
43 CHECK(*image != zeros);
44 CHECK_THROWS_AS(image->get_value(0, n_cols), std::out_of_range);
45 CHECK_THROWS_AS(image->set_value(n_rows, 0, 1), std::out_of_range);
46 double& value = image->_get_value_unchecked(1, 1);
47 value = -1;
48 CHECK(image->get_value_unchecked(1, 1) == -1);
49}
50
51TEST_CASE("ImageArray") {
52 size_t n_rows = 3, n_cols = 2;
55 ImageArray arr = ImageArray(&data);
56
57 for (ImageArray::const_iterator it = arr.cbegin(); it != arr.cend(); ++it) {
58 CHECK(*it == image);
59 }
60 for (const auto& img : arr) {
61 CHECK(img == image);
62 }
63}
64
65TEST_CASE("Mask") {
66 auto image = Image(2, 2);
67 auto mask = Mask(2, 2);
68 mask.fill(false);
69 CHECK_EQ(mask.get_value_unchecked(0, 0), false);
70 mask._get_value_unchecked(1, 1) = true;
71 CHECK_EQ(mask.get_value_unchecked(1, 1), true);
73}
74
75TEST_CASE("Evaluate") {
78 auto gauss_conv = std::make_shared<g2d::ConvolvedGaussian>(gauss1, gauss2);
80 auto gaussians_conv = std::make_shared<g2d::ConvolvedGaussians>(data);
82 nullptr, 5, 7);
83 CHECK_EQ(output->get_n_rows(), 5);
84}
std::vector< std::shared_ptr< ConvolvedGaussian > > Data
Definition gaussian.h:251
An array of compatible Images.
Definition image.h:268
typename Data::const_iterator const_iterator
Definition image.h:279
Data::const_iterator cbegin() const noexcept
Definition image.h:284
std::vector< std::shared_ptr< Image > > Data
Definition image.h:271
Data::const_iterator cend() const noexcept
Definition image.h:285
A Python image using numpy arrrays for storage.
Definition image.h:72
#define CHECK(...)
Definition doctest.h:2969
#define TEST_CASE(name)
Definition doctest.h:2936
#define CHECK_THROWS_AS(expr,...)
Definition doctest.h:2972
#define CHECK_EQ(...)
Definition doctest.h:3017
T make_shared(T... args)
std::shared_ptr< Data > make_gaussians_pixel(const std::shared_ptr< const ConvolvedGaussians > gaussians, std::shared_ptr< Data > output=nullptr, const unsigned int n_rows=0, const unsigned int n_cols=0, const std::shared_ptr< const CoordinateSystem > coordsys=nullptr, bool to_add=false)
Add gaussians to an image, creating one if needed.
Definition evaluate.h:1233
bool images_compatible(const Image< T1, C1 > &img1, const Image< T2, C2 > &img2, bool compare_coordsys=true, std::string *msg=nullptr)
Return if two images are compatible.
Definition image.h:70
data(channels)
Definition test_model.py:17
g2d::python::Image< double > Image
Definition test_image.cc:14
g2d::ImageArray< double, Image > ImageArray
Definition test_image.cc:15
py::module_ numpy
Definition test_image.cc:20
py::scoped_interpreter guard
Definition test_image.cc:19
g2d::python::Image< bool > Mask
Definition test_image.cc:16