def test_output_port_name(self) -> None: module = FitsReadingModule(name_in='read', image_tag='images', input_dir=self.test_dir + 'images') module.add_output_port('test') with pytest.warns(UserWarning) as warning: module.add_output_port('test') assert len(warning) == 1 assert warning[0].message.args[0] == 'Tag \'test\' of ReadingModule \'read\' is already ' \ 'used.' module = BadPixelSigmaFilterModule(name_in='badpixel', image_in_tag='images', image_out_tag='im_out') module.add_output_port('test') with pytest.warns(UserWarning) as warning: module.add_output_port('test') assert len(warning) == 1 assert warning[0].message.args[0] == 'Tag \'test\' of ProcessingModule \'badpixel\' is ' \ 'already used.'
def test_output_port_name(self): read = FitsReadingModule(name_in="read", input_dir=self.test_dir + "images", image_tag="images") read.add_output_port("test") with pytest.warns(UserWarning) as warning: read.add_output_port("test") assert len(warning) == 1 assert warning[0].message.args[ 0] == "Tag 'test' of ReadingModule 'read' is already used." process = BadPixelSigmaFilterModule(name_in="badpixel", image_in_tag="images") process.add_output_port("test") with pytest.warns(UserWarning) as warning: process.add_output_port("test") assert len(warning) == 1 assert warning[0].message.args[0] == "Tag 'test' of ProcessingModule 'badpixel' is " \ "already used." self.pipeline.m_data_storage.close_connection() process._m_data_base = self.test_dir + "database.hdf5" process.add_output_port("new")
def test_bad_pixel_map_out(self) -> None: module = BadPixelSigmaFilterModule(name_in='sigma2', image_in_tag='images', image_out_tag='sigma2', map_out_tag='bpmap', box=9, sigma=5., iterate=1) self.pipeline.add_module(module) self.pipeline.run_module('sigma2') data = self.pipeline.get_data('sigma2') assert data[0, 0, 0] == pytest.approx(0.00032486907273264834, rel=self.limit, abs=0.) assert data[0, 5, 5] == pytest.approx(9.903775276151606e-06, rel=self.limit, abs=0.) assert np.sum(data) == pytest.approx(0.007314386854009355, rel=self.limit, abs=0.) assert data.shape == (5, 11, 11) data = self.pipeline.get_data('bpmap') assert data[0, 0, 0] == pytest.approx(1., rel=self.limit, abs=0.) assert data[0, 5, 5] == pytest.approx(0., rel=self.limit, abs=0.) assert np.sum(data) == pytest.approx(604., rel=self.limit, abs=0.) assert data.shape == (5, 11, 11)
def test_remove_module(self): pipeline = Pypeline(self.test_dir, self.test_dir, self.test_dir) read = FitsReadingModule(name_in='read') pipeline.add_module(read) process = BadPixelSigmaFilterModule(name_in='badpixel', image_in_tag='im_arr1', image_out_tag='im_out') pipeline.add_module(process) assert pipeline.get_module_names() == ['read', 'badpixel'] assert pipeline.remove_module('read') assert pipeline.get_module_names() == ['badpixel'] assert pipeline.remove_module('badpixel') with pytest.warns(UserWarning) as warning: pipeline.remove_module('test') assert len(warning) == 1 assert warning[0].message.args[0] == 'Module name \'test\' not found in the Pypeline ' \ 'dictionary.' os.remove(self.test_dir + 'PynPoint_database.hdf5')
def test_remove_module(self) -> None: pipeline = Pypeline(self.test_dir, self.test_dir, self.test_dir) module = FitsReadingModule(name_in='read') pipeline.add_module(module) module = BadPixelSigmaFilterModule(name_in='badpixel', image_in_tag='im_arr1', image_out_tag='im_out') pipeline.add_module(module) assert pipeline.get_module_names() == ['read', 'badpixel'] assert pipeline.remove_module('read') assert pipeline.get_module_names() == ['badpixel'] assert pipeline.remove_module('badpixel') with pytest.warns(UserWarning) as warning: pipeline.remove_module('test') assert len(warning) == 1 assert warning[0].message.args[0] == 'Pipeline module \'test\' is not found in the ' \ 'Pypeline dictionary so it could not be removed. ' \ 'The dictionary contains the following modules: [].' \ os.remove(self.test_dir + 'PynPoint_database.hdf5')
def test_output_port_name(self): read = FitsReadingModule(name_in='read', input_dir=self.test_dir + 'images', image_tag='images') read.add_output_port('test') with pytest.warns(UserWarning) as warning: read.add_output_port('test') assert len(warning) == 1 assert warning[0].message.args[0] == 'Tag \'test\' of ReadingModule \'read\' is already ' \ 'used.' process = BadPixelSigmaFilterModule(name_in='badpixel', image_in_tag='images', image_out_tag='im_out') process.add_output_port('test') with pytest.warns(UserWarning) as warning: process.add_output_port('test') assert len(warning) == 1 assert warning[0].message.args[0] == 'Tag \'test\' of ProcessingModule \'badpixel\' is ' \ 'already used.' self.pipeline.m_data_storage.close_connection() process._m_data_base = self.test_dir + 'database.hdf5' process.add_output_port('new')
def test_add_module(self): pipeline = Pypeline(self.test_dir, self.test_dir, self.test_dir) read = FitsReadingModule(name_in='read1', input_dir=None, image_tag='im_arr1') assert pipeline.add_module(read) is None read = FitsReadingModule(name_in='read2', input_dir=self.test_dir, image_tag='im_arr2') assert pipeline.add_module(read) is None with pytest.warns(UserWarning) as warning: pipeline.add_module(read) assert len(warning) == 1 assert warning[0].message.args[0] == 'Pipeline module names need to be unique. ' \ 'Overwriting module \'read2\'.' process = BadPixelSigmaFilterModule(name_in='badpixel', image_in_tag='im_arr1', image_out_tag='im_out') assert pipeline.add_module(process) is None write = FitsWritingModule(name_in='write1', file_name='result.fits', data_tag='im_arr1') assert pipeline.add_module(write) is None write = FitsWritingModule(name_in='write2', file_name='result.fits', data_tag='im_arr1', output_dir=self.test_dir) assert pipeline.add_module(write) is None assert pipeline.run() is None assert pipeline.get_module_names() == ['read1', 'read2', 'badpixel', 'write1', 'write2'] os.remove(self.test_dir+'result.fits') os.remove(self.test_dir+'PynPoint_database.hdf5')
def test_bad_pixel_sigma_filter(self): module = BadPixelSigmaFilterModule(name_in='sigma1', image_in_tag='images', image_out_tag='sigma1', map_out_tag='None', box=9, sigma=5, iterate=1) self.pipeline.add_module(module) self.pipeline.run_module('sigma1') data = self.pipeline.get_data('sigma1') assert np.allclose(data[0, 0, 0], 0.00032486907273264834, rtol=limit, atol=0.) assert np.allclose(data[0, 10, 10], 0.025022559679385093, rtol=limit, atol=0.) assert np.allclose(data[0, 20, 20], 0.024962143884217046, rtol=limit, atol=0.) assert np.allclose(np.mean(data), 6.721637736047109e-07, rtol=limit, atol=0.) assert data.shape == (40, 100, 100)
def test_bad_pixel_map_out(self) -> None: module = BadPixelSigmaFilterModule(name_in='sigma2', image_in_tag='images', image_out_tag='sigma2', map_out_tag='bpmap', box=9, sigma=2., iterate=3) self.pipeline.add_module(module) self.pipeline.run_module('sigma2') data = self.pipeline.get_data('sigma2') assert data[0, 0, 0] == pytest.approx(-2.4570591355257687e-05, rel=self.limit, abs=0.) assert data[0, 5, 5] == pytest.approx(9.903775276151606e-06, rel=self.limit, abs=0.) assert np.sum(data) == pytest.approx(0.011777887008566097, rel=self.limit, abs=0.) assert data.shape == (5, 11, 11) data = self.pipeline.get_data('bpmap') assert data[0, 1, 1] == pytest.approx(1., rel=self.limit, abs=0.) assert data[0, 5, 5] == pytest.approx(0., rel=self.limit, abs=0.) assert np.sum(data) == pytest.approx(519.0, rel=self.limit, abs=0.) assert data.shape == (5, 11, 11)
def test_add_module(self) -> None: pipeline = Pypeline(self.test_dir, self.test_dir, self.test_dir) module = FitsReadingModule(name_in='read1', input_dir=None, image_tag='im_arr1') assert pipeline.add_module(module) is None module = FitsReadingModule(name_in='read2', input_dir=self.test_dir, image_tag='im_arr2') assert pipeline.add_module(module) is None with pytest.warns(UserWarning) as warning: pipeline.add_module(module) assert len(warning) == 1 assert warning[0].message.args[0] == 'Names of pipeline modules that are added to the ' \ 'Pypeline need to be unique. The current pipeline ' \ 'module, \'read2\', does already exist in the ' \ 'Pypeline dictionary so the previous module with ' \ 'the same name will be overwritten.' module = BadPixelSigmaFilterModule(name_in='badpixel', image_in_tag='im_arr1', image_out_tag='im_out') assert pipeline.add_module(module) is None module = FitsWritingModule(name_in='write1', file_name='result.fits', data_tag='im_arr1') assert pipeline.add_module(module) is None module = FitsWritingModule(name_in='write2', file_name='result.fits', data_tag='im_arr1', output_dir=self.test_dir) assert pipeline.add_module(module) is None assert pipeline.run() is None assert pipeline.get_module_names() == [ 'read1', 'read2', 'badpixel', 'write1', 'write2' ] os.remove(self.test_dir + 'result.fits') os.remove(self.test_dir + 'PynPoint_database.hdf5')
def test_output_port_set_connection(self) -> None: self.pipeline.m_data_storage.open_connection() module = BadPixelSigmaFilterModule(name_in='badpixel2', image_in_tag='images', image_out_tag='im_out') self.pipeline.add_module(module) port = module.add_output_port('test1') self.pipeline.m_data_storage.close_connection()
def test_bad_pixel(self): bp_cleaning = BadPixelSigmaFilterModule(name_in="sigma_filtering", image_in_tag="bg_cleaned_arr", image_out_tag="bp_cleaned_arr") self.pipeline.add_module(bp_cleaning) self.pipeline.run_module("sigma_filtering") data = self.pipeline.get_data("bp_cleaned_arr") assert np.allclose(data[0, 61, 39], -0.00013095662386792948, rtol=limit, atol=0.) assert data.shape == (78, 100, 100)
def test_run_module_wrong_tag(self) -> None: pipeline = Pypeline(self.test_dir, self.test_dir, self.test_dir) module = FitsReadingModule(name_in='read') pipeline.add_module(module) module = FitsWritingModule(name_in='write', file_name='result.fits', data_tag='im_list') pipeline.add_module(module) module = BadPixelSigmaFilterModule(name_in='badpixel', image_in_tag='im_list', image_out_tag='im_out') pipeline.add_module(module) with pytest.raises(AttributeError) as error: pipeline.run_module('badpixel') assert str(error.value) == 'Pipeline module \'badpixel\' is looking for data under a ' \ 'tag which does not exist in the database.' with pytest.raises(AttributeError) as error: pipeline.run_module('write') assert str(error.value) == 'Pipeline module \'write\' is looking for data under a tag ' \ 'which does not exist in the database.' with pytest.raises(AttributeError) as error: pipeline.run() assert str(error.value) == 'Pipeline module \'write\' is looking for data under a tag ' \ 'which is not created by a previous module or the data does ' \ 'not exist in the database.' assert pipeline.validate_pipeline_module('test') == (False, 'test') with pytest.raises(TypeError) as error: pipeline._validate('module', 'tag') assert str(error.value) == 'type of argument "module" must be one of (ReadingModule, ' \ 'WritingModule, ProcessingModule); got str instead' os.remove(self.test_dir + 'PynPoint_database.hdf5')
def test_bad_pixel_sigma_filter(self) -> None: module = BadPixelSigmaFilterModule(name_in='sigma1', image_in_tag='images', image_out_tag='sigma1', map_out_tag='None', box=9, sigma=3., iterate=5) self.pipeline.add_module(module) self.pipeline.run_module('sigma1') data = self.pipeline.get_data('sigma1') assert np.sum(data) == pytest.approx(0.006513475520308432, rel=self.limit, abs=0.) assert data.shape == (5, 11, 11)
def test_add_module(self): pipeline = Pypeline(self.test_dir, self.test_dir, self.test_dir) read = FitsReadingModule(name_in="read1", input_dir=None, image_tag="im_arr1") assert pipeline.add_module(read) is None read = FitsReadingModule(name_in="read2", input_dir=self.test_dir, image_tag="im_arr2") assert pipeline.add_module(read) is None with pytest.warns(UserWarning) as warning: pipeline.add_module(read) assert len(warning) == 1 assert warning[0].message.args[0] == "Processing module names need to be unique. " \ "Overwriting module 'read2'." process = BadPixelSigmaFilterModule(name_in="badpixel", image_in_tag="im_arr1") assert pipeline.add_module(process) is None write = FitsWritingModule(name_in="write1", file_name="result.fits", data_tag="im_arr1") assert pipeline.add_module(write) is None write = FitsWritingModule(name_in="write2", file_name="result.fits", data_tag="im_arr1", output_dir=self.test_dir) assert pipeline.add_module(write) is None assert pipeline.run() is None assert pipeline.get_module_names() == [ 'read1', 'read2', 'badpixel', 'write1', 'write2' ] os.remove(self.test_dir + "result.fits") os.remove(self.test_dir + "PynPoint_database.hdf5")
def test_run_module_wrong_tag(self): pipeline = Pypeline(self.test_dir, self.test_dir, self.test_dir) read = FitsReadingModule(name_in='read') pipeline.add_module(read) write = FitsWritingModule(name_in='write', file_name='result.fits', data_tag='im_list') pipeline.add_module(write) process = BadPixelSigmaFilterModule(name_in='badpixel', image_in_tag='im_list', image_out_tag='im_out') pipeline.add_module(process) with pytest.raises(AttributeError) as error: pipeline.run_module('badpixel') assert str(error.value) == 'Pipeline module \'badpixel\' is looking for data under a ' \ 'tag which does not exist in the database.' with pytest.raises(AttributeError) as error: pipeline.run_module('write') assert str(error.value) == 'Pipeline module \'write\' is looking for data under a tag ' \ 'which does not exist in the database.' with pytest.raises(AttributeError) as error: pipeline.run() assert str(error.value) == 'Pipeline module \'write\' is looking for data under a tag ' \ 'which is not created by a previous module or does not exist ' \ 'in the database.' assert pipeline.validate_pipeline_module('test') is None assert pipeline._validate('module', 'tag') == (False, None) os.remove(self.test_dir + 'PynPoint_database.hdf5')
def test_run_module_wrong_tag(self): pipeline = Pypeline(self.test_dir, self.test_dir, self.test_dir) read = FitsReadingModule(name_in="read") pipeline.add_module(read) write = FitsWritingModule(name_in="write", file_name="result.fits", data_tag="im_list") pipeline.add_module(write) process = BadPixelSigmaFilterModule(name_in="badpixel", image_in_tag="im_list") pipeline.add_module(process) with pytest.raises(AttributeError) as error: pipeline.run_module("badpixel") assert str(error.value) == "Pipeline module 'badpixel' is looking for data under a tag " \ "which does not exist in the database." with pytest.raises(AttributeError) as error: pipeline.run_module("write") assert str(error.value) == "Pipeline module 'write' is looking for data under a tag " \ "which does not exist in the database." with pytest.raises(AttributeError) as error: pipeline.run() assert str(error.value) == "Pipeline module 'write' is looking for data under a tag " \ "which is not created by a previous module or does not exist " \ "in the database." assert pipeline.validate_pipeline_module("test") is None assert pipeline._validate("module", "tag") == (False, None) os.remove(self.test_dir + "PynPoint_database.hdf5")
def test_remove_module(self): pipeline = Pypeline(self.test_dir, self.test_dir, self.test_dir) read = FitsReadingModule(name_in="read") pipeline.add_module(read) process = BadPixelSigmaFilterModule(name_in="badpixel") pipeline.add_module(process) assert pipeline.get_module_names() == ["read", "badpixel"] assert pipeline.remove_module("read") assert pipeline.get_module_names() == ["badpixel"] assert pipeline.remove_module("badpixel") with pytest.warns(UserWarning) as warning: pipeline.remove_module("test") assert len(warning) == 1 assert warning[0].message.args[0] == "Module name 'test' not found in the Pypeline " \ "dictionary." os.remove(self.test_dir + "PynPoint_database.hdf5")