def test_run_module_wrong_tag(self) -> None: 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 the data does ' \ 'not exist in the database.' assert pipeline.validate_pipeline_module('test') is None 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_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") 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")
def test_bad_pixel_map_out(self): module = BadPixelSigmaFilterModule(name_in='sigma2', image_in_tag='images', image_out_tag='sigma2', map_out_tag='bpmap', box=9, sigma=5, iterate=0) self.pipeline.add_module(module) self.pipeline.run_module('sigma2') data = self.pipeline.get_data('sigma2') 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) data = self.pipeline.get_data('bpmap') assert np.allclose(data[0, 0, 0], 1.0, rtol=limit, atol=0.) assert np.allclose(np.sum(data), 399994.0, rtol=limit, atol=0.) assert data.shape == (40, 100, 100)