示例#1
0
    def test_wavelet_denoising_dwt(self):

        dwt_config = DwtWaveletConfiguration(wavelet='db8')

        assert dwt_config.m_wavelet == 'db8'

        wavelet_dwt = WaveletTimeDenoisingModule(
            wavelet_configuration=dwt_config,
            name_in='wavelet_dwt',
            image_in_tag='images',
            image_out_tag='wavelet_dwt',
            padding='zero',
            median_filter=True,
            threshold_function='soft')

        self.pipeline.add_module(wavelet_dwt)
        self.pipeline.run_module('wavelet_dwt')

        data = self.pipeline.get_data('wavelet_dwt')
        assert np.allclose(data[0, 10, 10],
                           0.09650639476873678,
                           rtol=limit,
                           atol=0.)
        assert np.allclose(np.mean(data),
                           0.0024998798596330475,
                           rtol=limit,
                           atol=0.)
        assert data.shape == (40, 20, 20)
示例#2
0
    def test_wavelet_denoising_cwt_morlet(self):

        with h5py.File(self.test_dir+'PynPoint_database.hdf5', 'a') as hdf_file:
            hdf_file['config'].attrs['CPU'] = 1

        cwt_config = CwtWaveletConfiguration(wavelet='morlet',
                                             wavelet_order=5,
                                             keep_mean=False,
                                             resolution=0.5)

        assert cwt_config.m_wavelet == 'morlet'
        assert np.allclose(cwt_config.m_wavelet_order, 5, rtol=limit, atol=0.)
        assert not cwt_config.m_keep_mean
        assert np.allclose(cwt_config.m_resolution, 0.5, rtol=limit, atol=0.)

        module = WaveletTimeDenoisingModule(wavelet_configuration=cwt_config,
                                            name_in='wavelet_cwt_morlet',
                                            image_in_tag='images',
                                            image_out_tag='wavelet_cwt_morlet',
                                            padding='mirror',
                                            median_filter=False,
                                            threshold_function='hard')

        self.pipeline.add_module(module)
        self.pipeline.run_module('wavelet_cwt_morlet')

        data = self.pipeline.get_data('wavelet_cwt_morlet')
        assert np.allclose(data[0, 10, 10], 0.09805577173716859, rtol=limit, atol=0.)
        assert np.allclose(np.mean(data), 0.0025019409784314286, rtol=limit, atol=0.)
        assert data.shape == (40, 20, 20)

        data = self.pipeline.get_attribute('wavelet_cwt_morlet', 'NFRAMES', static=False)
        assert np.allclose(data, [10, 10, 10, 10], rtol=limit, atol=0.)
示例#3
0
    def test_wavelet_denoising_cwt_dog(self):

        cwt_config = CwtWaveletConfiguration(wavelet='dog',
                                             wavelet_order=2,
                                             keep_mean=False,
                                             resolution=0.5)

        assert cwt_config.m_wavelet == 'dog'
        assert np.allclose(cwt_config.m_wavelet_order, 2, rtol=limit, atol=0.)
        assert not cwt_config.m_keep_mean
        assert np.allclose(cwt_config.m_resolution, 0.5, rtol=limit, atol=0.)

        wavelet_cwt = WaveletTimeDenoisingModule(
            wavelet_configuration=cwt_config,
            name_in='wavelet_cwt_dog',
            image_in_tag='images',
            image_out_tag='wavelet_cwt_dog',
            padding='zero',
            median_filter=True,
            threshold_function='soft')

        self.pipeline.add_module(wavelet_cwt)
        self.pipeline.run_module('wavelet_cwt_dog')

        data = self.pipeline.get_data('wavelet_cwt_dog')
        assert np.allclose(data[0, 10, 10],
                           0.09805577173716859,
                           rtol=limit,
                           atol=0.)
        assert np.allclose(np.mean(data),
                           0.002502083112599873,
                           rtol=limit,
                           atol=0.)
        assert data.shape == (40, 20, 20)

        with h5py.File(self.test_dir + 'PynPoint_database.hdf5',
                       'a') as hdf_file:
            hdf_file['config'].attrs['CPU'] = 4

        self.pipeline.run_module('wavelet_cwt_dog')

        data_multi = self.pipeline.get_data('wavelet_cwt_dog')
        assert np.allclose(data, data_multi, rtol=limit, atol=0.)
        assert data.shape == data_multi.shape
示例#4
0
    def test_wavelet_denoising_dwt(self) -> None:

        dwt_config = DwtWaveletConfiguration(wavelet='db8')

        assert dwt_config.m_wavelet == 'db8'

        module = WaveletTimeDenoisingModule(wavelet_configuration=dwt_config,
                                            name_in='wavelet_dwt',
                                            image_in_tag='images',
                                            image_out_tag='wavelet_dwt',
                                            padding='zero',
                                            median_filter=True,
                                            threshold_function='soft')

        self.pipeline.add_module(module)
        self.pipeline.run_module('wavelet_dwt')

        data = self.pipeline.get_data('wavelet_dwt')
        assert np.sum(data) == pytest.approx(105.54278879805277,
                                             rel=self.limit,
                                             abs=0.)
        assert data.shape == (10, 11, 11)
示例#5
0
    def test_wavelet_denoising_cwt_dog(self) -> None:

        cwt_config = CwtWaveletConfiguration(wavelet='dog',
                                             wavelet_order=2,
                                             keep_mean=False,
                                             resolution=0.5)

        assert cwt_config.m_wavelet == 'dog'
        assert cwt_config.m_wavelet_order == 2
        assert not cwt_config.m_keep_mean
        assert cwt_config.m_resolution == 0.5

        module = WaveletTimeDenoisingModule(wavelet_configuration=cwt_config,
                                            name_in='wavelet_cwt_dog',
                                            image_in_tag='images',
                                            image_out_tag='wavelet_cwt_dog',
                                            padding='zero',
                                            median_filter=True,
                                            threshold_function='soft')

        self.pipeline.add_module(module)
        self.pipeline.run_module('wavelet_cwt_dog')

        data = self.pipeline.get_data('wavelet_cwt_dog')
        assert np.sum(data) == pytest.approx(105.1035789572968,
                                             rel=self.limit,
                                             abs=0.)
        assert data.shape == (10, 11, 11)

        with h5py.File(self.test_dir + 'PynPoint_database.hdf5',
                       'a') as hdf_file:
            hdf_file['config'].attrs['CPU'] = 4

        self.pipeline.run_module('wavelet_cwt_dog')

        data_multi = self.pipeline.get_data('wavelet_cwt_dog')
        assert data == pytest.approx(data_multi, rel=self.limit, abs=0.)
        assert data.shape == data_multi.shape
示例#6
0
    def test_wavelet_denoising_cwt_morlet(self) -> None:

        with h5py.File(self.test_dir + 'PynPoint_database.hdf5',
                       'a') as hdf_file:
            hdf_file['config'].attrs['CPU'] = 1

        cwt_config = CwtWaveletConfiguration(wavelet='morlet',
                                             wavelet_order=5,
                                             keep_mean=False,
                                             resolution=0.5)

        assert cwt_config.m_wavelet == 'morlet'
        assert cwt_config.m_wavelet_order == 5
        assert not cwt_config.m_keep_mean
        assert cwt_config.m_resolution == 0.5

        module = WaveletTimeDenoisingModule(wavelet_configuration=cwt_config,
                                            name_in='wavelet_cwt_morlet',
                                            image_in_tag='images',
                                            image_out_tag='wavelet_cwt_morlet',
                                            padding='mirror',
                                            median_filter=False,
                                            threshold_function='hard')

        self.pipeline.add_module(module)
        self.pipeline.run_module('wavelet_cwt_morlet')

        data = self.pipeline.get_data('wavelet_cwt_morlet')
        assert np.sum(data) == pytest.approx(104.86262840716438,
                                             rel=self.limit,
                                             abs=0.)
        assert data.shape == (10, 11, 11)

        data = self.pipeline.get_attribute('wavelet_cwt_morlet',
                                           'NFRAMES',
                                           static=False)
        assert data[0] == data[1] == 5
示例#7
0
    def test_wavelet_denoising_cwt_morlet(self):

        database = h5py.File(self.test_dir + 'PynPoint_database.hdf5', 'a')
        database['config'].attrs['CPU'] = 1

        cwt_config = CwtWaveletConfiguration(wavelet="morlet",
                                             wavelet_order=5,
                                             keep_mean=False,
                                             resolution=0.5)

        assert cwt_config.m_wavelet == "morlet"
        assert np.allclose(cwt_config.m_wavelet_order, 5, rtol=limit, atol=0.)
        assert not cwt_config.m_keep_mean
        assert np.allclose(cwt_config.m_resolution, 0.5, rtol=limit, atol=0.)

        wavelet_cwt = WaveletTimeDenoisingModule(
            wavelet_configuration=cwt_config,
            name_in="wavelet_cwt_morlet",
            image_in_tag="images",
            image_out_tag="wavelet_cwt_morlet",
            padding="mirror",
            median_filter=False,
            threshold_function="hard")

        self.pipeline.add_module(wavelet_cwt)
        self.pipeline.run_module("wavelet_cwt_morlet")

        data = self.pipeline.get_data("wavelet_cwt_morlet")
        assert np.allclose(data[0, 10, 10],
                           0.09805577173716859,
                           rtol=limit,
                           atol=0.)
        assert np.allclose(np.mean(data),
                           0.0025019409784314286,
                           rtol=limit,
                           atol=0.)
        assert data.shape == (40, 20, 20)
示例#8
0
    def test_wavelet_denoising_odd_size(self):

        module = AddLinesModule(name_in='add',
                                image_in_tag='images',
                                image_out_tag='images_odd',
                                lines=(1, 0, 1, 0))

        self.pipeline.add_module(module)
        self.pipeline.run_module('add')

        data = self.pipeline.get_data('images_odd')
        assert np.allclose(data[0, 10, 10], 0.05294085050174391, rtol=limit, atol=0.)
        assert np.allclose(np.mean(data), 0.002269413609192613, rtol=limit, atol=0.)
        assert data.shape == (40, 21, 21)

        cwt_config = CwtWaveletConfiguration(wavelet='dog',
                                             wavelet_order=2,
                                             keep_mean=False,
                                             resolution=0.5)

        assert cwt_config.m_wavelet == 'dog'
        assert np.allclose(cwt_config.m_wavelet_order, 2, rtol=limit, atol=0.)
        assert not cwt_config.m_keep_mean
        assert np.allclose(cwt_config.m_resolution, 0.5, rtol=limit, atol=0.)

        module = WaveletTimeDenoisingModule(wavelet_configuration=cwt_config,
                                            name_in='wavelet_odd_1',
                                            image_in_tag='images_odd',
                                            image_out_tag='wavelet_odd_1',
                                            padding='zero',
                                            median_filter=True,
                                            threshold_function='soft')

        self.pipeline.add_module(module)
        self.pipeline.run_module('wavelet_odd_1')

        data = self.pipeline.get_data('wavelet_odd_1')
        assert np.allclose(data[0, 10, 10], 0.0529782051386938, rtol=limit, atol=0.)
        assert np.allclose(np.mean(data), 0.0022694631406801565, rtol=limit, atol=0.)
        assert data.shape == (40, 21, 21)

        module = WaveletTimeDenoisingModule(wavelet_configuration=cwt_config,
                                            name_in='wavelet_odd_2',
                                            image_in_tag='images_odd',
                                            image_out_tag='wavelet_odd_2',
                                            padding='mirror',
                                            median_filter=True,
                                            threshold_function='soft')

        self.pipeline.add_module(module)
        self.pipeline.run_module('wavelet_odd_2')

        data = self.pipeline.get_data('wavelet_odd_2')
        assert np.allclose(data[0, 10, 10], 0.05297146283932275, rtol=limit, atol=0.)
        assert np.allclose(np.mean(data), 0.0022694809842930034, rtol=limit, atol=0.)
        assert data.shape == (40, 21, 21)

        data = self.pipeline.get_attribute('images', 'NFRAMES', static=False)
        assert np.allclose(data, [10, 10, 10, 10], rtol=limit, atol=0.)

        data = self.pipeline.get_attribute('wavelet_odd_1', 'NFRAMES', static=False)
        assert np.allclose(data, [10, 10, 10, 10], rtol=limit, atol=0.)

        data = self.pipeline.get_attribute('wavelet_odd_2', 'NFRAMES', static=False)
        assert np.allclose(data, [10, 10, 10, 10], rtol=limit, atol=0.)
示例#9
0
    def test_wavelet_denoising_even_size(self) -> None:

        module = AddLinesModule(name_in='add',
                                image_in_tag='images',
                                image_out_tag='images_even',
                                lines=(1, 0, 1, 0))

        self.pipeline.add_module(module)
        self.pipeline.run_module('add')

        data = self.pipeline.get_data('images_even')
        assert np.sum(data) == pytest.approx(105.54278879805275,
                                             rel=self.limit,
                                             abs=0.)
        assert data.shape == (10, 12, 12)

        cwt_config = CwtWaveletConfiguration(wavelet='dog',
                                             wavelet_order=2,
                                             keep_mean=False,
                                             resolution=0.5)

        assert cwt_config.m_wavelet == 'dog'
        assert cwt_config.m_wavelet_order == 2
        assert not cwt_config.m_keep_mean
        assert cwt_config.m_resolution == 0.5

        module = WaveletTimeDenoisingModule(wavelet_configuration=cwt_config,
                                            name_in='wavelet_even_1',
                                            image_in_tag='images_even',
                                            image_out_tag='wavelet_even_1',
                                            padding='zero',
                                            median_filter=True,
                                            threshold_function='soft')

        self.pipeline.add_module(module)
        self.pipeline.run_module('wavelet_even_1')

        data = self.pipeline.get_data('wavelet_even_1')
        assert np.sum(data) == pytest.approx(105.1035789572968,
                                             rel=self.limit,
                                             abs=0.)
        assert data.shape == (10, 12, 12)

        module = WaveletTimeDenoisingModule(wavelet_configuration=cwt_config,
                                            name_in='wavelet_even_2',
                                            image_in_tag='images_even',
                                            image_out_tag='wavelet_even_2',
                                            padding='mirror',
                                            median_filter=True,
                                            threshold_function='soft')

        self.pipeline.add_module(module)
        self.pipeline.run_module('wavelet_even_2')

        data = self.pipeline.get_data('wavelet_even_2')
        assert np.sum(data) == pytest.approx(105.06809820408587,
                                             rel=self.limit,
                                             abs=0.)
        assert data.shape == (10, 12, 12)

        data = self.pipeline.get_attribute('images', 'NFRAMES', static=False)
        assert data == pytest.approx([5, 5], rel=self.limit, abs=0.)

        data = self.pipeline.get_attribute('wavelet_even_1',
                                           'NFRAMES',
                                           static=False)
        assert data == pytest.approx([5, 5], rel=self.limit, abs=0.)

        data = self.pipeline.get_attribute('wavelet_even_2',
                                           'NFRAMES',
                                           static=False)
        assert data == pytest.approx([5, 5], rel=self.limit, abs=0.)