Esempio n. 1
0
    def test_derotate_and_stack(self):

        derotate = DerotateAndStackModule(name_in="derotate1",
                                          image_in_tag="images",
                                          image_out_tag="derotate1",
                                          derotate=True,
                                          stack="mean",
                                          extra_rot=10.)

        self.pipeline.add_module(derotate)
        self.pipeline.run_module("derotate1")

        data = self.pipeline.get_data("derotate1")
        assert np.allclose(data[50, 50], 0.09689679769268554, rtol=limit, atol=0.)
        assert np.allclose(np.mean(data), 0.00010021671152246617, rtol=limit, atol=0.)
        assert data.shape == (100, 100)

        derotate = DerotateAndStackModule(name_in="derotate2",
                                          image_in_tag="images",
                                          image_out_tag="derotate2",
                                          derotate=False,
                                          stack="median",
                                          extra_rot=0.)

        self.pipeline.add_module(derotate)
        self.pipeline.run_module("derotate2")

        data = self.pipeline.get_data("derotate2")
        assert np.allclose(data[50, 50], 0.09809001768003645, rtol=limit, atol=0.)
        assert np.allclose(np.mean(data), 0.00010033064394962, rtol=limit, atol=0.)
        assert data.shape == (100, 100)
Esempio n. 2
0
    def test_derotate_and_stack(self) -> None:

        module = DerotateAndStackModule(name_in='derotate1',
                                        image_in_tag='images',
                                        image_out_tag='derotate1',
                                        derotate=True,
                                        stack='mean',
                                        extra_rot=10.)

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

        data = self.pipeline.get_data('derotate1')
        assert np.allclose(data[0, 50, 50],
                           0.09689679769268554,
                           rtol=limit,
                           atol=0.)
        assert np.allclose(np.mean(data),
                           0.00010021671152246617,
                           rtol=limit,
                           atol=0.)
        assert data.shape == (1, 100, 100)

        module = DerotateAndStackModule(name_in='derotate2',
                                        image_in_tag='images',
                                        image_out_tag='derotate2',
                                        derotate=False,
                                        stack='median',
                                        extra_rot=0.)

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

        data = self.pipeline.get_data('derotate2')
        assert np.allclose(data[0, 50, 50],
                           0.09809001768003645,
                           rtol=limit,
                           atol=0.)
        assert np.allclose(np.mean(data),
                           0.00010033064394962,
                           rtol=limit,
                           atol=0.)
        assert data.shape == (1, 100, 100)
Esempio n. 3
0
    def test_mcmc_sampling(self):

        self.pipeline.set_attribute('adi',
                                    'PARANG',
                                    np.arange(0., 200., 10.),
                                    static=False)

        module = DerotateAndStackModule(name_in='stack',
                                        image_in_tag='psf',
                                        image_out_tag='psf_stack',
                                        derotate=False,
                                        stack='mean')

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

        data = self.pipeline.get_data('psf_stack')
        assert data.shape == (1, 15, 15)

        module = MCMCsamplingModule(name_in='mcmc',
                                    image_in_tag='adi',
                                    psf_in_tag='psf_stack',
                                    chain_out_tag='mcmc',
                                    param=(0.15, 0., 1.),
                                    bounds=((0.1, 0.2), (-2., 2.), (-1., 2.)),
                                    nwalkers=50,
                                    nsteps=150,
                                    psf_scaling=-1.,
                                    pca_number=1,
                                    aperture=(7, 13, 0.1),
                                    mask=None,
                                    extra_rot=0.,
                                    merit='gaussian',
                                    residuals='median',
                                    scale=2.,
                                    sigma=(1e-3, 1e-1, 1e-2))

        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.'

        data = self.pipeline.get_data('mcmc')
        data = data[:, 50:, :].reshape((-1, 3))
        assert np.allclose(np.median(data[:, 0]), 0.15, rtol=0., atol=0.1)
        assert np.allclose(np.median(data[:, 1]), 0., rtol=0., atol=1.0)
        assert np.allclose(np.median(data[:, 2]), 0.0, rtol=0., atol=1.)
Esempio n. 4
0
    def test_mcmc_sampling(self) -> None:

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

        self.pipeline.set_attribute('adi',
                                    'PARANG',
                                    np.arange(0., 200., 10.),
                                    static=False)

        module = DerotateAndStackModule(name_in='stack',
                                        image_in_tag='psf',
                                        image_out_tag='psf_stack',
                                        derotate=False,
                                        stack='mean')

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

        data = self.pipeline.get_data('psf_stack')
        assert data.shape == (1, 15, 15)

        module = MCMCsamplingModule(name_in='mcmc',
                                    image_in_tag='adi',
                                    psf_in_tag='psf_stack',
                                    chain_out_tag='mcmc',
                                    param=(0.15, 0., 1.),
                                    bounds=((0.1, 0.2), (-2., 2.), (-1., 2.)),
                                    nwalkers=50,
                                    nsteps=150,
                                    psf_scaling=-1.,
                                    pca_number=1,
                                    aperture=(7, 13, 0.1),
                                    mask=None,
                                    extra_rot=0.,
                                    merit='gaussian',
                                    residuals='median',
                                    scale=2.,
                                    sigma=(1e-3, 1e-1, 1e-2))

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

        data = self.pipeline.get_data('mcmc')
        data = data[50:, :, :].reshape((-1, 3))
        assert np.allclose(np.median(data[:, 0]), 0.15, rtol=0., atol=0.1)
        assert np.allclose(np.median(data[:, 1]), 0., rtol=0., atol=1.0)
        assert np.allclose(np.median(data[:, 2]), 0.0, rtol=0., atol=1.)

        attr = self.pipeline.get_attribute('mcmc', 'ACCEPTANCE', static=True)
        assert np.allclose(attr, 0.3, rtol=0., atol=0.3)
Esempio n. 5
0
    def test_mcmc_sampling(self) -> None:

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

        module = DerotateAndStackModule(name_in='stack',
                                        image_in_tag='psf',
                                        image_out_tag='psf_stack',
                                        derotate=False,
                                        stack='mean')

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

        data = self.pipeline.get_data('psf_stack')
        assert np.sum(data) == pytest.approx(10.843655133957288,
                                             rel=self.limit,
                                             abs=0.)
        assert data.shape == (1, 21, 21)

        module = MCMCsamplingModule(name_in='mcmc',
                                    image_in_tag='adi',
                                    psf_in_tag='psf_stack',
                                    chain_out_tag='mcmc',
                                    param=(0.15, 0., 1.),
                                    bounds=((0.1, 0.2), (-2., 2.), (-1., 2.)),
                                    nwalkers=6,
                                    nsteps=5,
                                    psf_scaling=-1.,
                                    pca_number=1,
                                    aperture=(10, 16, 0.06),
                                    mask=None,
                                    extra_rot=0.,
                                    merit='gaussian',
                                    residuals='median',
                                    sigma=(1e-3, 1e-1, 1e-2))

        self.pipeline.add_module(module)

        # with pytest.warns(RuntimeWarning) as warning:
        self.pipeline.run_module('mcmc')
Esempio n. 6
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)
Esempio n. 7
0
    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)
    def test_derotate_and_stack(self) -> None:

        module = DerotateAndStackModule(name_in='derotate1',
                                        image_in_tag='images',
                                        image_out_tag='derotate1',
                                        derotate=True,
                                        stack='mean',
                                        extra_rot=10.)

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

        data = self.pipeline.get_data('derotate1')
        assert np.mean(data) == pytest.approx(0.08709860116308817, rel=self.limit, abs=0.)
        assert data.shape == (1, 11, 11)

        module = DerotateAndStackModule(name_in='derotate2',
                                        image_in_tag='images',
                                        image_out_tag='derotate2',
                                        derotate=False,
                                        stack='median',
                                        extra_rot=0.)

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

        data = self.pipeline.get_data('derotate2')
        assert np.mean(data) == pytest.approx(0.0861160094566323, rel=self.limit, abs=0.)
        assert data.shape == (1, 11, 11)

        data = self.pipeline.get_data('derotate2')
        assert np.mean(data) == pytest.approx(0.0861160094566323, rel=self.limit, abs=0.)
        assert data.shape == (1, 11, 11)

        module = DerotateAndStackModule(name_in='derotate_ifs1',
                                        image_in_tag='images_ifs',
                                        image_out_tag='derotate_ifs1',
                                        derotate=True,
                                        stack='mean',
                                        extra_rot=0.,
                                        dimension='time')

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

        data = self.pipeline.get_data('derotate_ifs1')
        assert np.mean(data) == pytest.approx(0.1884438996655355, rel=self.limit, abs=0.)
        assert data.shape == (3, 1, 21, 21)

        module = DerotateAndStackModule(name_in='derotate_ifs2',
                                        image_in_tag='images_ifs',
                                        image_out_tag='derotate_ifs2',
                                        derotate=False,
                                        stack='median',
                                        extra_rot=0.,
                                        dimension='wavelength')

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

        data = self.pipeline.get_data('derotate_ifs2')
        assert np.mean(data) == pytest.approx(0.055939644983170146, rel=self.limit, abs=0.)
        assert data.shape == (1, 10, 21, 21)

        module = DerotateAndStackModule(name_in='derotate_ifs3',
                                        image_in_tag='images_ifs',
                                        image_out_tag='derotate_ifs3',
                                        derotate=True,
                                        stack=None,
                                        extra_rot=0.,
                                        dimension='wavelength')

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

        data = self.pipeline.get_data('derotate_ifs3')
        assert np.mean(data) == pytest.approx(0.05653316989966066, rel=self.limit, abs=0.)
        assert data.shape == (3, 10, 21, 21)