Ejemplo n.º 1
0
    def save(self):

        if self.exit:
            self.after(self.check_visibility)
        else:
            plc.save_dict(self.all_frames, self.log.all_frames)
            self.after(self.check_visibility)
Ejemplo n.º 2
0
    def find_all_stars(self):

        if self.exit:
            self.after(self.align)

        fits = plc.open_fits(
            os.path.join(self.log.reduction_directory, self.science_files[0]))
        metadata = self.all_frames[self.science_files[0]]

        self.progress_figure.load_fits(fits[1], self.science_files[0])

        stars, psf = plc.find_all_stars(fits[1].data,
                                        mean=metadata[self.log.mean_key],
                                        std=metadata[self.log.std_key],
                                        std_limit=3,
                                        burn_limit=self.burn_limit,
                                        star_std=metadata[self.log.psf_key],
                                        progressbar=self.progress_all_stars,
                                        progress_window=self,
                                        verbose=True)

        if self.exit:
            self.after(self.choose_calibartion_stars)

        stars = np.array(stars)

        self.log.save_local_log()

        all_stars_dict = {'all_stars': stars}
        plc.save_dict(all_stars_dict, 'all_stars.pickle')

        self.progress_all_stars.set('Choosing calibrating stars...')

        self.after(self.choose_calibartion_stars)
Ejemplo n.º 3
0
    def save(self):

        if self.exit:
            self.def_close()
        else:
            plc.save_dict(self.all_frames, self.log.all_frames)
            self.log.set_param('reduction_complete', True)
            self.log.set_param('reduction_version', self.log.version)
            self.log.save_local_log()
            self.log.set_param('proceed', True)
            self.def_close()
Ejemplo n.º 4
0
    def save(self):

        self.log.set_param('sky_threshold', self.sky_threshold.get())
        self.log.set_param('psf_threshold', self.psf_threshold.get())

        for science_file in range(len(self.science_files)):
            self.all_frames[self.science_files[science_file]][
                self.log.skip_key] = self.skip_array[science_file]

        plc.save_dict(self.all_frames, self.log.all_frames)

        self.log.save_local_log()
Ejemplo n.º 5
0
    def find_all_stars():

        stars, psf = plc.find_all_stars(fits[1].data,
                                        mean=fits[1].header[mean_key],
                                        std=fits[1].header[std_key],
                                        std_limit=3,
                                        burn_limit=burn_limit,
                                        star_std=star_std,
                                        order_by_flux=False,
                                        progress_pack=(progress_bar,
                                                       percent_label))

        stars = np.array(stars)

        log.write_local_log('alignment', int(max(1, round(max(psf[0],
                                                              psf[1])))),
                            'star_std')
        log.write_local_log('alignment', float(max(psf[0], psf[1])),
                            'star_psf')
        log.write_local_log('alignment', float(psf[0]), 'star_psf_x')
        log.write_local_log('alignment', float(psf[1]), 'star_psf_y')

        all_stars_dict = {'all_stars': stars}
        plc.save_dict(all_stars_dict, 'all_stars.pickle')
Ejemplo n.º 6
0
    def check_visibility():

        star_std = log.read_local_log('alignment', 'star_std')
        all_stars_dict = plc.open_dict('all_stars.pickle')
        stars = np.array(all_stars_dict['all_stars'])

        polar_coords = []
        fits = pf.open(science[0])
        for star in all_stars_dict['all_stars']:
            polar_coords.append(
                plc.cartesian_to_polar(star[0], star[1],
                                       fits[1].header[align_x0_key],
                                       fits[1].header[align_y0_key]))
        fits.close()

        in_fov = np.ones(len(polar_coords))

        percent = 0
        lt0 = time.time()
        for counter, science_file in enumerate(science):

            if show_progress.exit:
                return None

            in_fov_single = []
            fits = pf.open(science_file)
            if fits[1].header[align_x0_key]:
                ref_x_position = fits[1].header[align_x0_key]
                ref_y_position = fits[1].header[align_y0_key]
                ref_u_position = fits[1].header[align_u0_key]

                for star in polar_coords:

                    cartesian_x = ref_x_position + star[0] * np.cos(
                        ref_u_position + star[1])
                    cartesian_y = ref_y_position + star[0] * np.sin(
                        ref_u_position + star[1])

                    if (cartesian_x > 3 * star_std and
                            cartesian_x < len(fits[1].data[0]) - 3 * star_std
                            and cartesian_y > 3 * star_std and
                            cartesian_y < len(fits[1].data) - 3 * star_std):

                        in_fov_single.append(1)
                    else:
                        in_fov_single.append(0)

                in_fov *= in_fov_single

            fits.close()

            # counter
            new_percent = round(100 * (counter + 1) / float(len(science)), 1)
            if new_percent != percent:
                lt1 = time.time()
                rm_time = (100 - new_percent) * (lt1 - lt0) / new_percent
                hours = rm_time / 3600.0
                minutes = (hours - int(hours)) * 60
                seconds = (minutes - int(minutes)) * 60

                progress_bar_3['value'] = new_percent
                percent_label_3.configure(
                    text='{0} % ({1}h {2}m {3}s left)'.format(
                        new_percent, int(hours), int(minutes), int(seconds)))

                percent = new_percent

                show_progress.update()

        all_stars_dict['in_fov'] = np.array(in_fov)

        visible_fov_x_min = np.min(stars[np.where(in_fov), 0]) - 3 * star_std
        visible_fov_x_max = np.max(stars[np.where(in_fov), 0]) + 3 * star_std
        visible_fov_y_min = np.min(stars[np.where(in_fov), 1]) - 3 * star_std
        visible_fov_y_max = np.max(stars[np.where(in_fov), 1]) + 3 * star_std

        log.write_local_log('alignment', float(visible_fov_x_min), 'min_x')
        log.write_local_log('alignment', float(visible_fov_y_min), 'min_y')
        log.write_local_log('alignment', float(visible_fov_x_max), 'max_x')
        log.write_local_log('alignment', float(visible_fov_y_max), 'max_y')

        plc.save_dict(all_stars_dict, 'all_stars.pickle')
Ejemplo n.º 7
0
    def check_visibility(self):

        if self.exit:
            self.def_close()

        else:

            all_stars_dict = plc.open_dict('all_stars.pickle')
            stars = np.array(all_stars_dict['all_stars'])
            fits = plc.open_fits(
                os.path.join(self.log.reduction_directory,
                             self.science_files[0]))

            polar_coords = []
            for star in all_stars_dict['all_stars']:
                polar_coords.append(
                    plc.cartesian_to_polar(
                        star[0], star[1], self.all_frames[
                            self.science_files[0]][self.log.align_x0_key],
                        self.all_frames[self.science_files[0]][
                            self.log.align_y0_key]))

            in_fov = np.ones(len(polar_coords))

            for science_file in self.science_files:

                metadata = self.all_frames[science_file]

                if self.exit:
                    self.def_close()

                ref_x_position = metadata[self.log.align_x0_key]
                ref_y_position = metadata[self.log.align_y0_key]
                ref_u_position = metadata[self.log.align_u0_key]
                star_std = metadata[self.log.psf_key]

                if ref_x_position:

                    in_fov_single = []

                    for star in polar_coords:

                        cartesian_x = ref_x_position + star[0] * np.cos(
                            ref_u_position + star[1])
                        cartesian_y = ref_y_position + star[0] * np.sin(
                            ref_u_position + star[1])

                        if (3 * star_std < cartesian_x <
                                len(fits[1].data[0]) - 3 * star_std
                                and 3 * star_std < cartesian_y <
                                len(fits[1].data) - 3 * star_std):

                            in_fov_single.append(1)
                        else:
                            in_fov_single.append(0)

                    in_fov *= in_fov_single

            all_stars_dict['in_fov'] = np.array(in_fov)

            visible_fov_x_min = np.min(stars[np.where(in_fov),
                                             0]) - 3 * star_std
            visible_fov_x_max = np.max(stars[np.where(in_fov),
                                             0]) + 3 * star_std
            visible_fov_y_min = np.min(stars[np.where(in_fov),
                                             1]) - 3 * star_std
            visible_fov_y_max = np.max(stars[np.where(in_fov),
                                             1]) + 3 * star_std

            self.log.set_param('min_x', float(visible_fov_x_min))
            self.log.set_param('min_y', float(visible_fov_y_min))
            self.log.set_param('max_x', float(visible_fov_x_max))
            self.log.set_param('max_y', float(visible_fov_y_max))

            plc.save_dict(all_stars_dict, 'all_stars.pickle')

            self.log.set_param('alignment_complete', True)
            self.log.set_param('alignment_version', self.log.version)
            self.log.save_local_log()
            self.log.set_param('proceed', True)

            self.def_close()
Ejemplo n.º 8
0
    def update_window(self):

        self.data_target_button.activate()

        if self.log.get_param('data_target_complete'):

            self.data_target_complete.set('Data:     {0}\nTarget:    {1} '.format(
                self.log.get_param('directory_short'), self.log.get_param('target_name')))

            self.reduction_button.activate()
            trash = 0

            if not os.path.isfile(self.log.all_frames):
                self.log.set_param('reduction_complete', False)
            else:
                all_frames = plc.open_dict(self.log.all_frames)
                for i in all_frames:
                    if not os.path.isfile(os.path.join(self.log.reduction_directory, i)):
                        self.log.set_param('reduction_complete', False)
                        break
                    if all_frames[i][self.log.skip_key]:
                        trash += 1

            if self.log.get_param('reduction_complete'):
                self.reduction_complete.set('Completed under v{0}'.format(self.log.get_param('reduction_version')))
                self.inspection_button.activate()
                self.inspection_complete.set('Files discarded: {0}'.format(trash))
                self.alignment_button.activate()

                all_frames = plc.open_dict(self.log.all_frames)
                for i in all_frames:
                    if not all_frames[i][self.log.skip_key] and not all_frames[i][self.log.align_x0_key]:
                        self.log.set_param('alignment_complete', False)
                plc.save_dict(all_frames, self.log.all_frames)

                if not os.path.isfile(self.log.all_stars):
                    self.log.set_param('alignment_complete', False)

                if self.log.get_param('alignment_complete'):

                    self.alignment_complete.set('Completed under v{0}'.format(self.log.get_param('alignment_version')))
                    self.photometry_button.activate()

                    if len(glob.glob('{0}*'.format(self.log.photometry_directory_base))) == 0:
                        self.log.set_param('photometry_complete', False)

                    if self.log.get_param('photometry_complete'):
                        self.photometry_complete.set('Completed under v{0}'.format(self.log.get_param('photometry_version')))
                        self.fitting_button.activate()

                        if self.log.get_param('fitting_complete'):
                            self.fitting_complete.set('Completed under v{0}'.format(self.log.get_param('fitting_version')))

                    else:
                        self.photometry_complete.set('You need to complete this step to proceed')
                        self.fitting_button.disable()
                        self.fitting_complete.set('')


                else:
                    self.alignment_complete.set('You need to complete this step to proceed')
                    self.photometry_button.disable()
                    self.photometry_complete.set('')
                    self.fitting_button.disable()
                    self.fitting_complete.set('')

            else:
                self.reduction_complete.set('You need to complete this step to proceed')
                self.inspection_button.disable()
                self.inspection_complete.set('')
                self.alignment_button.disable()
                self.alignment_complete.set('')
                self.photometry_button.disable()
                self.photometry_complete.set('')
                self.fitting_button.disable()
                self.fitting_complete.set('')

        else:
            self.data_target_complete.set('You need to complete this step to proceed.')
            self.reduction_button.disable()
            self.reduction_complete.set('')
            self.inspection_button.disable()
            self.inspection_complete.set('')
            self.alignment_button.disable()
            self.alignment_complete.set('')
            self.photometry_button.disable()
            self.photometry_complete.set('')
            self.fitting_button.disable()
            self.fitting_complete.set('')