def test_scale_images(self): module = ScaleImagesModule(scaling=(2., 2., None), name_in='scale1', image_in_tag='read', image_out_tag='scale1') self.pipeline.add_module(module) self.pipeline.run_module('scale1') module = ScaleImagesModule(scaling=(None, None, 2.), name_in='scale2', image_in_tag='read', image_out_tag='scale2') self.pipeline.add_module(module) self.pipeline.run_module('scale2') data = self.pipeline.get_data('scale1') assert np.allclose(data[0, 100, 100], 0.02356955774929094, rtol=limit, atol=0.) assert np.allclose(np.mean(data), 2.507373695434516e-05, rtol=limit, atol=0.) assert data.shape == (40, 200, 200) data = self.pipeline.get_data('scale2') assert np.allclose(data[0, 50, 50], 0.19596827004387415, rtol=limit, atol=0.) assert np.allclose(np.mean(data), 0.00020058989563476127, rtol=limit, atol=0.) assert data.shape == (40, 100, 100)
def test_scale_images(self) -> None: module = ScaleImagesModule(scaling=(2., 2., None), name_in='scale1', image_in_tag='read', image_out_tag='scale1') self.pipeline.add_module(module) self.pipeline.run_module('scale1') module = ScaleImagesModule(scaling=(None, None, 2.), name_in='scale2', image_in_tag='read', image_out_tag='scale2') self.pipeline.add_module(module) self.pipeline.run_module('scale2') data = self.pipeline.get_data('scale1') assert np.sum(data) == pytest.approx(105.54278879805277, rel=self.limit, abs=0.) assert data.shape == (10, 22, 22) data = self.pipeline.get_data('scale2') assert np.sum(data) == pytest.approx(211.08557759610554, rel=self.limit, abs=0.) assert data.shape == (10, 11, 11)
def test_scale_images(self) -> None: module = ScaleImagesModule(name_in='scale1', image_in_tag='read', image_out_tag='scale1', scaling=(2., 2., None), pixscale=True) self.pipeline.add_module(module) self.pipeline.run_module('scale1') module = ScaleImagesModule(name_in='scale2', image_in_tag='read', image_out_tag='scale2', scaling=(None, None, 2.), pixscale=True) self.pipeline.add_module(module) self.pipeline.run_module('scale2') data = self.pipeline.get_data('scale1') assert np.sum(data) == pytest.approx(105.54278879805277, rel=self.limit, abs=0.) assert data.shape == (10, 22, 22) data = self.pipeline.get_data('scale2') assert np.sum(data) == pytest.approx(211.08557759610554, rel=self.limit, abs=0.) assert data.shape == (10, 11, 11) attr = self.pipeline.get_attribute('read', 'PIXSCALE', static=True) assert attr == pytest.approx(0.027, rel=self.limit, abs=0.) attr = self.pipeline.get_attribute('scale1', 'PIXSCALE', static=True) assert attr == pytest.approx(0.0135, rel=self.limit, abs=0.) attr = self.pipeline.get_attribute('scale2', 'PIXSCALE', static=True) assert attr == pytest.approx(0.027, rel=self.limit, abs=0.)
def test_apply_function_to_images_2d_args(self): self.pipeline.set_attribute("image_2d", "PIXSCALE", 0.1, static=True) scale = ScaleImagesModule(scaling=(1.2, 1.2, 10.), pixscale=True, name_in="scale2", image_in_tag="image_2d", image_out_tag="scale_2d") self.pipeline.add_module(scale) self.pipeline.run_module("scale2") data = self.pipeline.get_data("scale_2d") assert np.allclose(np.mean(data), 8.937141109641279e-05, rtol=limit, atol=0.) assert data.shape == (12, 12) attribute = self.pipeline.get_attribute("scale_2d", "PIXSCALE", static=True) assert np.allclose(attribute, 0.08333333333333334, rtol=limit, atol=0.)
def test_apply_function_to_images_3d_args(self): self.pipeline.set_attribute("config", "MEMORY", 1, static=True) self.pipeline.set_attribute("image_3d", "PIXSCALE", 0.1, static=True) scale = ScaleImagesModule(scaling=(1.2, 1.2, 10.), pixscale=True, name_in="scale1", image_in_tag="image_3d", image_out_tag="scale_3d") self.pipeline.add_module(scale) self.pipeline.run_module("scale1") data = self.pipeline.get_data("scale_3d") assert np.allclose(np.mean(data), 7.042953308754017e-05, rtol=limit, atol=0.) assert data.shape == (4, 12, 12) attribute = self.pipeline.get_attribute("scale_3d", "PIXSCALE", static=True) assert np.allclose(attribute, 0.08333333333333334, rtol=limit, atol=0.)
def test_mcmc_sampling_gaussian(self): self.pipeline.set_attribute('adi', 'PARANG', np.arange(0., 200., 10.), static=False) module = ScaleImagesModule(scaling=(None, None, 100.), pixscale=False, name_in='scale1', image_in_tag='adi', image_out_tag='adi_scale') self.pipeline.add_module(module) self.pipeline.run_module('scale1') data = self.pipeline.get_data('adi_scale') assert np.allclose(data[0, 7, 7], 9.82388817812263, rtol=limit, atol=0.) assert data.shape == (20, 15, 15) module = ScaleImagesModule(scaling=(None, None, 100.), pixscale=False, name_in='scale2', image_in_tag='psf', image_out_tag='psf_scale') self.pipeline.add_module(module) self.pipeline.run_module('scale2') data = self.pipeline.get_data('psf_scale') assert np.allclose(data[0, 7, 7], 9.806026673451198, rtol=limit, atol=0.) assert data.shape == (4, 15, 15) module = DerotateAndStackModule(name_in='take_psf_avg', image_in_tag='psf_scale', image_out_tag='psf_avg', derotate=False, stack='mean') self.pipeline.add_module(module) self.pipeline.run_module('take_psf_avg') data = self.pipeline.get_data('psf_avg') assert data.shape == (1, 15, 15) module = MCMCsamplingModule(param=(0.1485, 0., 0.), bounds=((0.1, 0.25), (-5., 5.), (-0.5, 0.5)), name_in='mcmc', image_in_tag='adi_scale', psf_in_tag='psf_avg', chain_out_tag='mcmc', nwalkers=50, nsteps=150, psf_scaling=-1., pca_number=1, aperture={ 'type': 'circular', 'pos_x': 7.0, 'pos_y': 12.5, 'radius': 0.1 }, mask=None, extra_rot=0., scale=2., sigma=(1e-3, 1e-1, 1e-2), prior='flat', variance='gaussian') self.pipeline.add_module(module) with pytest.warns(FutureWarning) as warning: self.pipeline.run_module('mcmc') assert warning[0].message.args[0] == 'Using a non-tuple sequence for multidimensional ' \ 'indexing is deprecated; use `arr[tuple(seq)]` ' \ 'instead of `arr[seq]`. In the future this will be ' \ 'interpreted as an array index, ' \ '`arr[np.array(seq)]`, which will result either ' \ 'in an error or a different result.' single = self.pipeline.get_data('mcmc') single = single[:, 20:, :].reshape((-1, 3)) assert np.allclose(np.median(single[:, 0]), 0.148, rtol=0., atol=0.01) assert np.allclose(np.median(single[:, 1]), 0., rtol=0., atol=0.2) assert np.allclose(np.median(single[:, 2]), 0., rtol=0., atol=0.1)
def test_mcmc_sampling_poisson(self): self.pipeline.set_attribute("adi", "PARANG", np.arange(0., 200., 10.), static=False) scale = ScaleImagesModule(scaling=(None, None, 100.), pixscale=False, name_in="scale1", image_in_tag="adi", image_out_tag="adi_scale") self.pipeline.add_module(scale) self.pipeline.run_module("scale1") data = self.pipeline.get_data("adi_scale") assert np.allclose(data[0, 7, 7], 9.82388817812263, rtol=limit, atol=0.) assert data.shape == (20, 15, 15) scale = ScaleImagesModule(scaling=(None, None, 100.), pixscale=False, name_in="scale2", image_in_tag="psf", image_out_tag="psf_scale") self.pipeline.add_module(scale) self.pipeline.run_module("scale2") data = self.pipeline.get_data("psf_scale") assert np.allclose(data[0, 7, 7], 9.806026673451198, rtol=limit, atol=0.) assert data.shape == (4, 15, 15) avg_psf = DerotateAndStackModule(name_in="take_psf_avg", image_in_tag="psf_scale", image_out_tag="psf_avg", derotate=False, stack="mean") self.pipeline.add_module(avg_psf) self.pipeline.run_module("take_psf_avg") data = self.pipeline.get_data("psf_avg") assert data.shape == (15, 15) mcmc = MCMCsamplingModule(param=(0.1485, 0., 0.), bounds=((0.1, 0.25), (-5., 5.), (-0.5, 0.5)), name_in="mcmc", image_in_tag="adi_scale", psf_in_tag="psf_avg", chain_out_tag="mcmc", nwalkers=50, nsteps=150, psf_scaling=-1., pca_number=1, aperture=0.1, mask=None, extra_rot=0., scale=2., sigma=(1e-3, 1e-1, 1e-2), prior="flat", variance="poisson") self.pipeline.add_module(mcmc) self.pipeline.run_module("mcmc") single = self.pipeline.get_data("mcmc") single = single[:, 20:, :].reshape((-1, 3)) assert np.allclose(np.median(single[:, 0]), 0.148, rtol=0., atol=0.01) assert np.allclose(np.median(single[:, 1]), 0., rtol=0., atol=0.2) assert np.allclose(np.median(single[:, 2]), 0., rtol=0., atol=0.1)