Coverage for tests/test_wavelet.py: 29%
38 statements
« prev ^ index » next coverage.py v7.4.4, created at 2024-04-19 10:38 +0000
« prev ^ index » next coverage.py v7.4.4, created at 2024-04-19 10:38 +0000
1# This file is part of lsst.scarlet.lite.
2#
3# Developed for the LSST Data Management System.
4# This product includes software developed by the LSST Project
5# (https://www.lsst.org).
6# See the COPYRIGHT file at the top-level directory of this distribution
7# for details of code ownership.
8#
9# This program is free software: you can redistribute it and/or modify
10# it under the terms of the GNU General Public License as published by
11# the Free Software Foundation, either version 3 of the License, or
12# (at your option) any later version.
13#
14# This program is distributed in the hope that it will be useful,
15# but WITHOUT ANY WARRANTY; without even the implied warranty of
16# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17# GNU General Public License for more details.
18#
19# You should have received a copy of the GNU General Public License
20# along with this program. If not, see <https://www.gnu.org/licenses/>.
22import os
24import numpy as np
25from lsst.scarlet.lite.wavelet import (
26 apply_wavelet_denoising,
27 get_multiresolution_support,
28 multiband_starlet_reconstruction,
29 multiband_starlet_transform,
30 starlet_reconstruction,
31 starlet_transform,
32)
33from numpy.testing import assert_almost_equal
34from utils import ScarletTestCase
37class TestWavelet(ScarletTestCase):
38 def setUp(self) -> None:
39 filename = os.path.join(__file__, "..", "..", "data", "hsc_cosmos_35.npz")
40 filename = os.path.abspath(filename)
41 self.data = np.load(filename)
43 def tearDown(self) -> None:
44 del self.data
46 def test_transform_inverse(self):
47 image = np.sum(self.data["images"], axis=0)
48 starlets = starlet_transform(image, scales=3)
49 self.assertEqual(starlets.dtype, np.float32)
51 # Test number of levels
52 self.assertTupleEqual(starlets.shape, (4, 58, 48))
54 # Test inverse
55 inverse = starlet_reconstruction(starlets)
56 assert_almost_equal(inverse, image, decimal=5)
57 self.assertEqual(inverse.dtype, np.float32)
59 # Test using gen1 starlets
60 starlets = starlet_transform(image, scales=3, generation=1)
62 # Test number of levels
63 self.assertTupleEqual(starlets.shape, (4, 58, 48))
65 # Test inverse
66 inverse = starlet_reconstruction(starlets, generation=1)
67 assert_almost_equal(inverse, image, decimal=5)
69 def test_multiband_transform(self):
70 image = self.data["images"]
71 starlets = multiband_starlet_transform(image, scales=3)
72 self.assertEqual(starlets.dtype, np.float32)
74 # Test number of levels
75 self.assertTupleEqual(starlets.shape, (4, 5, 58, 48))
77 # Test inverse
78 inverse = multiband_starlet_reconstruction(starlets)
79 assert_almost_equal(inverse, image, decimal=5)
80 self.assertEqual(inverse.dtype, np.float32)
82 def test_extras(self):
83 # This is code that is not used in production,
84 # but that might be used in the future,
85 # so we test to prevent bitrot
86 image = np.sum(self.data["images"].astype(float), axis=0)
87 starlets = starlet_transform(image, scales=3)
89 # Execute to ensure that the code runs
90 get_multiresolution_support(image, starlets, 0.1)
91 get_multiresolution_support(image, starlets, 0.1, image_type="space")
92 apply_wavelet_denoising(image)