Exemplo n.º 1
0
    def test_mcmc_sampling_wrong_prior(self):

        module = MCMCsamplingModule(param=(0.1485, 0., 0.),
                                    bounds=((0.1, 0.25), (-5., 5.), (-0.5,
                                                                     0.5)),
                                    name_in='mcmc_wrong_prior',
                                    image_in_tag='adi_scale',
                                    psf_in_tag='psf_avg',
                                    chain_out_tag='mcmc_prior',
                                    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='test',
                                    variance='gaussian')

        self.pipeline.add_module(module)

        with pytest.raises(ValueError) as error:
            self.pipeline.run_module('mcmc_wrong_prior')

        assert str(error.value) == 'Prior type not recognized.'
Exemplo n.º 2
0
    def test_mcmc_sampling_gaussian(self):

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

        mcmc = MCMCsamplingModule(param=(0.1485, 0., 0.),
                                  bounds=((0.1, 0.25), (-5., 5.), (-0.5, 0.5)),
                                  name_in="mcmc_gaussian",
                                  image_in_tag="adi_scale",
                                  psf_in_tag="psf_avg",
                                  chain_out_tag="mcmc_gaussian",
                                  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="gaussian")

        self.pipeline.add_module(mcmc)
        self.pipeline.run_module("mcmc_gaussian")

        single = self.pipeline.get_data("mcmc_gaussian")
        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)
Exemplo 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.)
Exemplo 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)
Exemplo n.º 5
0
    def test_mcmc_sampling_poisson(self):

        module = MCMCsamplingModule(param=(0.1485, 0., 0.),
                                    bounds=((0.1, 0.25), (-5., 5.), (-0.5,
                                                                     0.5)),
                                    name_in='mcmc_prior',
                                    image_in_tag='adi_scale',
                                    psf_in_tag='psf_avg',
                                    chain_out_tag='mcmc_prior',
                                    nwalkers=50,
                                    nsteps=150,
                                    psf_scaling=-1.,
                                    pca_number=1,
                                    aperture={
                                        'type': 'elliptical',
                                        'pos_x': 7.0,
                                        'pos_y': 12.5,
                                        'semimajor': 0.1,
                                        'semiminor': 0.1,
                                        'angle': 0.0
                                    },
                                    mask=None,
                                    extra_rot=0.,
                                    scale=2.,
                                    sigma=(1e-3, 1e-1, 1e-2),
                                    prior='aperture',
                                    variance='poisson')

        self.pipeline.add_module(module)

        with pytest.warns(FutureWarning) as warning:
            self.pipeline.run_module('mcmc_prior')

        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_prior')
        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)
Exemplo n.º 6
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')
Exemplo n.º 7
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)
Exemplo n.º 8
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)