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

        combine = CombineTagsModule(image_in_tags=('images', 'extra'),
                                    check_attr=True,
                                    index_init=False,
                                    name_in='combine1',
                                    image_out_tag='combine1')

        self.pipeline.add_module(combine)

        with pytest.warns(UserWarning) as warning:
            self.pipeline.run_module('combine1')

        assert len(warning) == 1
        assert warning[0].message.args[0] == 'The non-static keyword FILES is already used but ' \
                                             'with different values. It is advisable to only ' \
                                             'combine tags that descend from the same data set.'

        data = self.pipeline.get_data('combine1')
        assert np.allclose(data[0, 50, 50],
                           0.09798413502193704,
                           rtol=limit,
                           atol=0.)
        assert np.allclose(np.mean(data),
                           0.00010029494781738068,
                           rtol=limit,
                           atol=0.)
        assert data.shape == (80, 100, 100)

        data = self.pipeline.get_data('header_combine1/INDEX')
        assert data[40] == 0
        assert data.shape == (80, )

        combine = CombineTagsModule(image_in_tags=('images', 'extra'),
                                    check_attr=False,
                                    index_init=True,
                                    name_in='combine2',
                                    image_out_tag='combine2')

        self.pipeline.add_module(combine)
        self.pipeline.run_module('combine2')

        data = self.pipeline.get_data('combine1')
        extra = self.pipeline.get_data('combine2')
        assert np.allclose(data, extra, rtol=limit, atol=0.)

        data = self.pipeline.get_data('header_combine2/INDEX')
        assert data[40] == 40
        assert data.shape == (80, )
Exemplo n.º 2
0
    def test_combine_tags(self) -> None:

        module = CombineTagsModule(image_in_tags=['images', 'extra'],
                                   check_attr=True,
                                   index_init=False,
                                   name_in='combine1',
                                   image_out_tag='combine1')

        self.pipeline.add_module(module)

        with pytest.warns(UserWarning) as warning:
            self.pipeline.run_module('combine1')

        assert len(warning) == 1

        assert warning[0].message.args[0] == 'The non-static keyword FILES is already used but ' \
                                             'with different values. It is advisable to only ' \
                                             'combine tags that descend from the same data set.'

        data = self.pipeline.get_data('combine1')
        assert np.mean(data) == pytest.approx(0.0872254452876469,
                                              rel=self.limit,
                                              abs=0.)
        assert data.shape == (20, 11, 11)

        data = self.pipeline.get_data('header_combine1/INDEX')
        assert data[19] == 9
        assert data.shape == (20, )

        module = CombineTagsModule(image_in_tags=['images', 'extra'],
                                   check_attr=False,
                                   index_init=True,
                                   name_in='combine2',
                                   image_out_tag='combine2')

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

        data = self.pipeline.get_data('combine1')
        extra = self.pipeline.get_data('combine2')
        assert data == pytest.approx(extra, rel=self.limit, abs=0.)

        data = self.pipeline.get_data('header_combine2/INDEX')
        assert data[19] == 19
        assert data.shape == (20, )
Exemplo n.º 3
0
    def run(self) -> None:
        """
        Run method of the module. Cuts out the detector sections at the different dither positions,
        prepares the PCA background subtraction, locates the star in each image, runs the PCA
        background subtraction, combines the output from the different dither positions is written
        to a single database tag.

        Returns
        -------
        NoneType
            None
        """

        @typechecked
        def _admin_start(count: int,
                         n_dither: int,
                         position: Tuple[int, int],
                         star_pos: Union[np.ndarray, np.int64]) -> None:
            if self.m_crop or self.m_prepare or self.m_pca_background:
                print(f'Processing dither position {count+1} out of {n_dither}...')
                print(f'Center position = {position}')

                if self.m_cubes is None and self.m_center is not None:
                    print(f'DITHER_X, DITHER_Y = {tuple(star_pos)}')

        @typechecked
        def _admin_end(count: int) -> None:
            if self.m_combine == 'mean':
                tags.append(f'{self.m_image_in_tag}_dither_mean{count+1}')

            elif self.m_combine == 'pca':
                tags.append(f'{self.m_image_in_tag}_dither_pca_res{count+1}')

        n_dither, star_pos = self._initialize()
        tags = []

        for i, position in enumerate(self.m_center):
            _admin_start(i, n_dither, position, star_pos[i])

            if self.m_crop:
                im_out_tag = f'{self.m_image_in_tag}_dither_crop{i+1}'

                module = CropImagesModule(name_in=f'crop{i}',
                                          image_in_tag=self.m_image_in_tag,
                                          image_out_tag=im_out_tag,
                                          size=self.m_size,
                                          center=(int(math.ceil(position[0])),
                                                  int(math.ceil(position[1]))))

                module.connect_database(self._m_data_base)
                module._m_output_ports[im_out_tag].del_all_data()
                module._m_output_ports[im_out_tag].del_all_attributes()
                module.run()

            if self.m_prepare:
                if self.m_cubes is None:
                    dither_val = (n_dither, self.m_cubes, tuple(star_pos[i]))
                else:
                    dither_val = (n_dither, self.m_cubes, int(star_pos[i]))

                im_in_tag = f'{self.m_image_in_tag}_dither_crop{i+1}'
                star_out_tag = f'{self.m_image_in_tag}_dither_star{i+1}'
                sub_out_tag = f'{self.m_image_in_tag}_dither_mean{i+1}'
                back_out_tag = f'{self.m_image_in_tag}_dither_background{i+1}'

                module = PCABackgroundPreparationModule(name_in=f'prepare{i}',
                                                        image_in_tag=im_in_tag,
                                                        star_out_tag=star_out_tag,
                                                        subtracted_out_tag=sub_out_tag,
                                                        background_out_tag=back_out_tag,
                                                        dither=dither_val,
                                                        combine='mean')

                module.connect_database(self._m_data_base)
                module._m_output_ports[star_out_tag].del_all_data()
                module._m_output_ports[star_out_tag].del_all_attributes()
                module._m_output_ports[sub_out_tag].del_all_data()
                module._m_output_ports[sub_out_tag].del_all_attributes()
                module._m_output_ports[back_out_tag].del_all_data()
                module._m_output_ports[back_out_tag].del_all_attributes()
                module.run()

            if self.m_pca_background:
                star_in_tag = f'{self.m_image_in_tag}_dither_star{i+1}'
                back_in_tag = f'{self.m_image_in_tag}_dither_background{i+1}'
                res_out_tag = f'{self.m_image_in_tag}_dither_pca_res{i+1}'
                fit_out_tag = f'{self.m_image_in_tag}_dither_pca_fit{i+1}'
                mask_out_tag = f'{self.m_image_in_tag}_dither_pca_mask{i+1}'

                module = PCABackgroundSubtractionModule(pca_number=self.m_pca_number,
                                                        mask_star=self.m_mask_star,
                                                        subtract_mean=self.m_subtract_mean,
                                                        subframe=self.m_subframe,
                                                        name_in=f'pca_background{i}',
                                                        star_in_tag=star_in_tag,
                                                        background_in_tag=back_in_tag,
                                                        residuals_out_tag=res_out_tag,
                                                        fit_out_tag=fit_out_tag,
                                                        mask_out_tag=mask_out_tag)

                module.connect_database(self._m_data_base)
                module._m_output_ports[res_out_tag].del_all_data()
                module._m_output_ports[res_out_tag].del_all_attributes()
                module._m_output_ports[fit_out_tag].del_all_data()
                module._m_output_ports[fit_out_tag].del_all_attributes()
                module._m_output_ports[mask_out_tag].del_all_data()
                module._m_output_ports[mask_out_tag].del_all_attributes()
                module.run()

            _admin_end(i)

        if self.m_combine is not None and self.m_image_out_tag is not None:
            module = CombineTagsModule(name_in='combine',
                                       check_attr=True,
                                       index_init=False,
                                       image_in_tags=tags,
                                       image_out_tag=self.m_image_in_tag+'_dither_combine')

            module.connect_database(self._m_data_base)
            module._m_output_ports[self.m_image_in_tag+'_dither_combine'].del_all_data()
            module._m_output_ports[self.m_image_in_tag+'_dither_combine'].del_all_attributes()
            module.run()

            module = SortParangModule(name_in='sort',
                                      image_in_tag=self.m_image_in_tag+'_dither_combine',
                                      image_out_tag=self.m_image_out_tag)

            module.connect_database(self._m_data_base)
            module._m_output_ports[self.m_image_out_tag].del_all_data()
            module._m_output_ports[self.m_image_out_tag].del_all_attributes()
            module.run()
Exemplo n.º 4
0
    def run(self):
        """
        Run method of the module. Cuts out the detector sections at the different dither positions,
        prepares the PCA background subtraction, locates the star in each image, runs the PCA
        background subtraction, combines the output from the different dither positions is written
        to a single database tag.

        :return: None
        """
        def _admin_start(count, n_dither, position, star_pos):
            if self.m_crop or self.m_prepare or self.m_pca_background:
                print("Processing dither position " + str(count + 1) +
                      " out of " + str(n_dither) + "...")
                print("Center position =", position)

                if self.m_cubes is None and self.m_center is not None:
                    print("DITHER_X, DITHER_Y =", tuple(star_pos))

        def _admin_end(count, n_dither):
            if self.m_combine == "mean":
                tags.append(self.m_image_in_tag + "_dither_mean" +
                            str(count + 1))

            elif self.m_combine == "pca":
                tags.append(self.m_image_in_tag + "_dither_pca_res" +
                            str(count + 1))

            if self.m_crop or self.m_prepare or self.m_pca_background:
                print("Processing dither position "+str(count+1)+ \
                      " out of "+str(n_dither)+"... [DONE]")

        n_dither, star_pos = self._initialize()
        tags = []

        for i, position in enumerate(self.m_center):
            _admin_start(i, n_dither, position, star_pos[i])

            if self.m_crop:
                module = CropImagesModule(size=self.m_size,
                                          center=(int(math.ceil(position[0])),
                                                  int(math.ceil(position[1]))),
                                          name_in="crop"+str(i),
                                          image_in_tag=self.m_image_in_tag,
                                          image_out_tag=self.m_image_in_tag+ \
                                                        "_dither_crop"+str(i+1))

                module.connect_database(self._m_data_base)
                module.run()

            if self.m_prepare:
                module = PCABackgroundPreparationModule(dither=(n_dither,
                                                                self.m_cubes,
                                                                star_pos[i]),
                                                        name_in="prepare"+str(i),
                                                        image_in_tag=self.m_image_in_tag+ \
                                                                     "_dither_crop"+str(i+1),
                                                        star_out_tag=self.m_image_in_tag+ \
                                                                     "_dither_star"+str(i+1),
                                                        mean_out_tag=self.m_image_in_tag+ \
                                                                     "_dither_mean"+str(i+1),
                                                        background_out_tag=self.m_image_in_tag+ \
                                                                           "_dither_background"+ \
                                                                           str(i+1))

                module.connect_database(self._m_data_base)
                module.run()

            if self.m_pca_background:
                module = PCABackgroundSubtractionModule(pca_number=self.m_pca_number,
                                                        mask_star=self.m_mask_star,
                                                        mask_planet=self.m_mask_planet,
                                                        subtract_mean=self.m_subtract_mean,
                                                        subframe=self.m_subframe,
                                                        name_in="pca_background"+str(i),
                                                        star_in_tag=self.m_image_in_tag+ \
                                                                    "_dither_star"+str(i+1),
                                                        background_in_tag=self.m_image_in_tag+ \
                                                                          "_dither_background"+ \
                                                                          str(i+1),
                                                        residuals_out_tag=self.m_image_in_tag+ \
                                                                          "_dither_pca_res"+ \
                                                                          str(i+1),
                                                        fit_out_tag=self.m_image_in_tag+ \
                                                                    "_dither_pca_fit"+str(i+1),
                                                        mask_out_tag=self.m_image_in_tag+ \
                                                                     "_dither_pca_mask"+str(i+1))

                module.connect_database(self._m_data_base)
                module.run()

            _admin_end(i, n_dither)

        if self.m_combine is not None and self.m_image_out_tag is not None:
            module = CombineTagsModule(name_in="combine",
                                       check_attr=True,
                                       index_init=False,
                                       image_in_tags=tags,
                                       image_out_tag=self.m_image_in_tag +
                                       "_dither_combine")

            module.connect_database(self._m_data_base)
            module.run()

            module = SortParangModule(name_in="sort",
                                      image_in_tag=self.m_image_in_tag +
                                      "_dither_combine",
                                      image_out_tag=self.m_image_out_tag)

            module.connect_database(self._m_data_base)
            module.run()
Exemplo n.º 5
0
    def run(self) -> None:
        """
        Run method of the module. Cuts out the detector sections at the different dither positions,
        prepares the PCA background subtraction, locates the star in each image, runs the PCA
        background subtraction, combines the output from the different dither positions is written
        to a single database tag.

        Returns
        -------
        NoneType
            None
        """
        def _admin_start(count, n_dither, position, star_pos):
            if self.m_crop or self.m_prepare or self.m_pca_background:
                print('Processing dither position ' + str(count + 1) +
                      ' out of ' + str(n_dither) + '...')
                print('Center position =', position)

                if self.m_cubes is None and self.m_center is not None:
                    print('DITHER_X, DITHER_Y =', tuple(star_pos))

        def _admin_end(count, n_dither):
            if self.m_combine == 'mean':
                tags.append(self.m_image_in_tag + '_dither_mean' +
                            str(count + 1))

            elif self.m_combine == 'pca':
                tags.append(self.m_image_in_tag + '_dither_pca_res' +
                            str(count + 1))

        n_dither, star_pos = self._initialize()
        tags = []

        for i, position in enumerate(self.m_center):
            _admin_start(i, n_dither, position, star_pos[i])

            if self.m_crop:
                module = CropImagesModule(name_in='crop' + str(i),
                                          image_in_tag=self.m_image_in_tag,
                                          image_out_tag=self.m_image_in_tag +
                                          '_dither_crop' + str(i + 1),
                                          size=self.m_size,
                                          center=(int(math.ceil(position[0])),
                                                  int(math.ceil(position[1]))))

                module.connect_database(self._m_data_base)
                module.run()

            if self.m_prepare:
                if self.m_cubes is None:
                    dither_val = (n_dither, self.m_cubes, tuple(star_pos[i]))
                else:
                    dither_val = (n_dither, self.m_cubes, int(star_pos[i]))

                module = PCABackgroundPreparationModule(
                    name_in='prepare' + str(i),
                    image_in_tag=self.m_image_in_tag + '_dither_crop' +
                    str(i + 1),
                    star_out_tag=self.m_image_in_tag + '_dither_star' +
                    str(i + 1),
                    subtracted_out_tag=self.m_image_in_tag + '_dither_mean' +
                    str(i + 1),
                    background_out_tag=self.m_image_in_tag +
                    '_dither_background' + str(i + 1),
                    dither=dither_val,
                    combine='mean')

                module.connect_database(self._m_data_base)
                module.run()

            if self.m_pca_background:
                module = PCABackgroundSubtractionModule(
                    pca_number=self.m_pca_number,
                    mask_star=self.m_mask_star,
                    subtract_mean=self.m_subtract_mean,
                    subframe=self.m_subframe,
                    name_in='pca_background' + str(i),
                    star_in_tag=self.m_image_in_tag + '_dither_star' +
                    str(i + 1),
                    background_in_tag=self.m_image_in_tag +
                    '_dither_background' + str(i + 1),
                    residuals_out_tag=self.m_image_in_tag + '_dither_pca_res' +
                    str(i + 1),
                    fit_out_tag=self.m_image_in_tag + '_dither_pca_fit' +
                    str(i + 1),
                    mask_out_tag=self.m_image_in_tag + '_dither_pca_mask' +
                    str(i + 1))

                module.connect_database(self._m_data_base)
                module.run()

            _admin_end(i, n_dither)

        if self.m_combine is not None and self.m_image_out_tag is not None:
            module = CombineTagsModule(name_in='combine',
                                       check_attr=True,
                                       index_init=False,
                                       image_in_tags=tags,
                                       image_out_tag=self.m_image_in_tag +
                                       '_dither_combine')

            module.connect_database(self._m_data_base)
            module.run()

            module = SortParangModule(name_in='sort',
                                      image_in_tag=self.m_image_in_tag +
                                      '_dither_combine',
                                      image_out_tag=self.m_image_out_tag)

            module.connect_database(self._m_data_base)
            module.run()