LSST Applications g044012fb7c+6976b5ec80,g04a91732dc+88a5fc122b,g07dc498a13+7e3c5f68a2,g114c6a66ad+09472d7a76,g1409bbee79+7e3c5f68a2,g1a7e361dbc+7e3c5f68a2,g1fd858c14a+3a43eabc0e,g35bb328faa+fcb1d3bbc8,g3bd4b5ce2c+2647bb081c,g4e0f332c67+5d362be553,g53246c7159+fcb1d3bbc8,g5477a8d5ce+b19c77c7ae,g58d0cdf3ff+4a2e102ff8,g60b5630c4e+09472d7a76,g623d845a50+09472d7a76,g6f0c2978f1+fcf1c0bcd6,g71fabbc107+09472d7a76,g75b6c65c88+d0b1dc44cc,g78460c75b0+2f9a1b4bcd,g786e29fd12+cf7ec2a62a,g7b71ed6315+fcb1d3bbc8,g8852436030+349c7e81d4,g89139ef638+7e3c5f68a2,g9125e01d80+fcb1d3bbc8,g95236ca021+f7a31438ed,g989de1cb63+7e3c5f68a2,g9f33ca652e+f17d666fbc,gaaedd4e678+7e3c5f68a2,gabe3b4be73+1e0a283bba,gb1101e3267+f870f33517,gb58c049af0+f03b321e39,gc99c83e5f0+76d20ab76d,gcf25f946ba+349c7e81d4,gd0fa69b896+f3a65fa83c,gd6cbbdb0b4+c8606af20c,gde0f65d7ad+5bd27d919f,ge278dab8ac+932305ba37,gfba249425e+fcb1d3bbc8,w.2025.07
LSST Data Management Base Package
Loading...
Searching...
No Matches
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