def test_create_instance_using_existing_database(self): np.random.seed(1) images = np.random.normal(loc=0, scale=2e-4, size=(10, 100, 100)) h5f = h5py.File(self.test_data, "w") dset = h5f.create_dataset("images", data=images) dset.attrs['PIXSCALE'] = 0.01 h5f.close() pipeline = Pypeline(self.test_dir, self.test_dir, self.test_dir) data = pipeline.get_data("images") assert np.allclose(data[0, 0, 0], 0.00032486907273264834, rtol=limit, atol=0.) assert np.allclose(np.mean(data), 1.0506056979365338e-06, rtol=limit, atol=0.) assert pipeline.get_attribute("images", "PIXSCALE") == 0.01 os.remove(self.test_data)
class TestEndToEnd(object): def setup(self): self.test_dir = os.path.dirname(__file__) + "/" self.pipeline = Pypeline(self.test_dir, self.test_dir, self.test_dir) def test_read(self): read_fits = FitsReadingModule(name_in="read_fits", image_tag="im", overwrite=True) self.pipeline.add_module(read_fits) self.pipeline.run_module("read_fits") data = self.pipeline.get_data("im") assert np.allclose(data[0, 0, 0], 0.00032486907273264834, rtol=limit, atol=0.) assert np.allclose(np.mean(data), 9.4518306864680034e-05, rtol=limit, atol=0.) assert data.shape == (82, 102, 100) def test_remove_last(self): remove_last = RemoveLastFrameModule(name_in="remove_last", image_in_tag="im", image_out_tag="im_last") self.pipeline.add_module(remove_last) self.pipeline.run_module("remove_last") data = self.pipeline.get_data("im_last") assert np.allclose(data[0, 0, 0], 0.00032486907273264834, rtol=limit, atol=0.) assert np.allclose(np.mean(data), 9.9365399524407205e-05, rtol=limit, atol=0.) assert data.shape == (78, 102, 100) def test_parang(self): angle = AngleInterpolationModule(name_in="angle", data_tag="im_last") self.pipeline.add_module(angle) self.pipeline.run_module("angle") files = self.pipeline.get_attribute("im_last", "FILES", static=False) parang = self.pipeline.get_attribute("im_last", "PARANG", static=False) assert files[0] == self.test_dir + 'adi01.fits' assert parang[1] == 1.1904761904761905 def test_cut_lines(self): cut_lines = RemoveLinesModule(lines=(0, 0, 0, 2), name_in="cut_lines", image_in_tag="im_last", image_out_tag="im_cut") self.pipeline.add_module(cut_lines) self.pipeline.run_module("cut_lines") data = self.pipeline.get_data("im_cut") assert np.allclose(data[0, 0, 0], 0.00032486907273264834, rtol=limit, atol=0.) assert np.allclose(np.mean(data), 0.00010141595132969683, rtol=limit, atol=0.) assert data.shape == (78, 100, 100) def test_background(self): background = MeanBackgroundSubtractionModule(shift=None, cubes=1, name_in="background", image_in_tag="im_cut", image_out_tag="im_bg") self.pipeline.add_module(background) self.pipeline.run_module("background") data = self.pipeline.get_data("im_bg") assert np.allclose(data[0, 0, 0], 0.00037132392435389595, rtol=limit, atol=0.) assert np.allclose(np.mean(data), 2.3675404363850964e-07, rtol=limit, atol=0.) assert data.shape == (78, 100, 100) def test_bad_pixel(self): bad_pixel = BadPixelSigmaFilterModule(name_in="bad_pixel", image_in_tag="im_bg", image_out_tag="im_bp", box=9, sigma=8, iterate=3) self.pipeline.add_module(bad_pixel) self.pipeline.run_module("bad_pixel") data = self.pipeline.get_data("im_bp") assert np.allclose(data[0, 0, 0], 0.00037132392435389595, rtol=limit, atol=0.) assert np.allclose(np.mean(data), 2.3675404363850964e-07, rtol=limit, atol=0.) assert data.shape == (78, 100, 100) def test_star(self): star = StarExtractionModule(name_in="star", image_in_tag="im_bp", image_out_tag="im_star", image_size=1.08, fwhm_star=0.0108) self.pipeline.add_module(star) self.pipeline.run_module("star") data = self.pipeline.get_data("im_star") assert np.allclose(data[0, 0, 0], 0.00018025424208141221, rtol=limit, atol=0.) assert np.allclose(np.mean(data), 0.00063151691905138636, rtol=limit, atol=0.) assert data.shape == (78, 40, 40) def test_center(self): center = StarAlignmentModule(name_in="center", image_in_tag="im_star", ref_image_in_tag=None, image_out_tag="im_center", interpolation="spline", accuracy=10, resize=5) self.pipeline.add_module(center) self.pipeline.run_module("center") data = self.pipeline.get_data("im_center") assert np.allclose(data[1, 0, 0], 1.2113798549047296e-06, rtol=limit, atol=0.) assert np.allclose(data[16, 0, 0], 1.0022456564129139e-05, rtol=limit, atol=0.) assert np.allclose(data[50, 0, 0], 1.7024977291686637e-06, rtol=limit, atol=0.) assert np.allclose(data[67, 0, 0], 7.8143774182171561e-07, rtol=limit, atol=0.) assert np.allclose(np.mean(data), 2.5260676762055473e-05, rtol=limit, atol=0.) assert data.shape == (78, 200, 200) def test_remove_frames(self): remove_frames = RemoveFramesModule(frames=(0, 15, 49, 66), name_in="remove_frames", image_in_tag="im_center", selected_out_tag="im_remove", removed_out_tag=None) self.pipeline.add_module(remove_frames) self.pipeline.run_module("remove_frames") data = self.pipeline.get_data("im_remove") assert np.allclose(data[0, 0, 0], 1.2113798549047296e-06, rtol=limit, atol=0.) assert np.allclose(data[14, 0, 0], 1.0022456564129139e-05, rtol=limit, atol=0.) assert np.allclose(data[47, 0, 0], 1.7024977291686637e-06, rtol=limit, atol=0.) assert np.allclose(data[63, 0, 0], 7.8143774182171561e-07, rtol=limit, atol=0.) assert np.allclose(np.mean(data), 2.5255308248050269e-05, rtol=limit, atol=0.) assert data.shape == (74, 200, 200) def test_subset(self): subset = StackAndSubsetModule(name_in="subset", image_in_tag="im_remove", image_out_tag="im_subset", random=37, stacking=2) self.pipeline.add_module(subset) self.pipeline.run_module("subset") data = self.pipeline.get_data("im_subset") assert np.allclose(data[0, 0, 0], -1.9081971570461925e-06, rtol=limit, atol=0.) assert np.allclose(np.mean(data), 2.5255308248050275e-05, rtol=limit, atol=0.) assert data.shape == (37, 200, 200) def test_pca(self): pca = PSFSubtractionModule(name_in="pca", pca_number=2, images_in_tag="im_subset", reference_in_tag="im_subset", res_arr_out_tag="res_arr", res_arr_rot_out_tag="res_rot", res_mean_tag="res_mean", res_median_tag="res_median", res_var_tag="res_var", res_rot_mean_clip_tag="res_rot_mean_clip", extra_rot=0.0, cent_size=0.1) self.pipeline.add_module(pca) self.pipeline.run_module("pca") data = self.pipeline.get_data("res_mean") assert np.allclose(data[154, 99], 0.0004308570688425797, rtol=limit, atol=0.) assert np.allclose(np.mean(data), 9.372451154992271e-08, rtol=limit, atol=0.) assert data.shape == (200, 200)