Beispiel #1
0
    def test_angle_sort_ifs(self) -> None:

        index = self.pipeline.get_data('header_read_ifs/INDEX')
        self.pipeline.set_attribute('read_ifs', 'INDEX', index[::-1], static=False)

        module = SortParangModule(name_in='sort2',
                                  image_in_tag='read_ifs',
                                  image_out_tag='read_ifs_sorted')

        self.pipeline.add_module(module)
        self.pipeline.run_module('sort2')
        self.pipeline.set_attribute('read_ifs', 'INDEX', index, static=False)

        parang = self.pipeline.get_data('header_read_ifs/PARANG')[::-1]
        parang_sort = self.pipeline.get_data('header_read_ifs_sorted/PARANG')
        assert np.sum(parang) == pytest.approx(np.sum(parang_sort), rel=self.limit, abs=0.)

        data = self.pipeline.get_data('read_ifs_sorted')
        assert np.sum(data[0, 0]) == pytest.approx(21.185139976163477, rel=self.limit, abs=0.)
Beispiel #2
0
    def test_angle_sort(self) -> None:

        index = self.pipeline.get_data('header_read/INDEX')
        self.pipeline.set_attribute('read', 'INDEX', index[::-1], static=False)

        module = SortParangModule(name_in='sort1',
                                  image_in_tag='read',
                                  image_out_tag='read_sorted')

        self.pipeline.add_module(module)
        self.pipeline.run_module('sort1')
        self.pipeline.set_attribute('read', 'INDEX', index, static=False)

        parang = self.pipeline.get_data('header_read/PARANG')[::-1]
        parang_sort = self.pipeline.get_data('header_read_sorted/PARANG')
        assert np.sum(parang) == pytest.approx(np.sum(parang_sort), rel=self.limit, abs=0.)

        parang_set = [0., 1., 2., 3., 4., 5., 6., 7., 8., 9.]
        self.pipeline.set_attribute('read_ifs', 'PARANG', parang_set, static=False)

        data = self.pipeline.get_data('read_sorted')
        assert np.sum(data[0]) == pytest.approx(9.71156815235485, rel=self.limit, abs=0.)
Beispiel #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()
Beispiel #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()
Beispiel #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()