Exemplo n.º 1
0
    def generate_target(self, fb_observation, tag='generate'):
        '''Takes an observation array given by the feature based scheduler and generate an appropriate OpSim target.

        :param fb_observation: numpy.array
        :return: Target
        '''

        # self.log.debug('%s: %s' % (tag, fb_observation))
        self.targetid += 1
        filtername = fb_observation['filter']
        propid = fb_observation['survey_id']

        target = Target()
        target.targetid = self.targetid
        target.fieldid = fb_observation['field_id']
        target.filter = str(filtername)
        target.num_exp = fb_observation['nexp']
        target.exp_times = [
            fb_observation['exptime'] / fb_observation['nexp']
        ] * fb_observation['nexp']
        target.ra_rad = fb_observation['RA']
        target.dec_rad = fb_observation['dec']
        target.ang_rad = fb_observation['rotSkyPos']
        target.propid = propid
        target.goal = 100
        target.visits = 0
        target.progress = 0.0
        target.groupid = 1
        target.groupix = 0
        target.propid_list = [propid]
        target.need_list = [target.need]
        target.bonus_list = [target.bonus]
        target.value_list = [target.value]
        target.propboost_list = [target.propboost]
        target.sequenceid_list = [target.sequenceid]
        target.subsequencename_list = [target.subsequencename]
        target.groupid_list = [target.groupid]
        target.groupix_list = [target.groupix]
        target.is_deep_drilling_list = [target.is_deep_drilling]
        target.is_dd_firstvisit_list = [target.is_dd_firstvisit]
        target.remaining_dd_visits_list = [target.remaining_dd_visits]
        target.dd_exposures_list = [target.dd_exposures]
        target.dd_filterchanges_list = [target.dd_filterchanges]
        target.dd_exptime_list = [target.dd_exptime]

        return target
    def start_night(self, timestamp, filters_mounted_tonight_list, night):

        Proposal.start_night(self, timestamp, filters_mounted_tonight_list,
                             night)
        self.fieldsvisitedtonight = {}
        self.tonight_filters_list = []
        self.tonight_targets = 0
        self.tonight_targets_dict = {}
        for filter in filters_mounted_tonight_list:
            self.tonight_filters_list.append(filter)
        self.build_tonight_fields_list(timestamp, night)
        self.tonight_fields = len(self.tonight_fields_list)

        # compute at start night
        for field in self.tonight_fields_list:
            fieldid = field.fieldid

            # add new fields to fields dictionary
            if fieldid not in self.survey_fields_dict:
                self.survey_fields_dict[fieldid] = field.get_copy()
                self.survey_fields += 1

            # add new fields to targets dictionary
            if fieldid not in self.survey_targets_dict:
                self.survey_targets_dict[fieldid] = {}

            self.tonight_targets_dict[fieldid] = {}
            for filter in filters_mounted_tonight_list:
                if filter in self.params.filter_list:
                    if self.params.filter_goal_dict[filter] > 0:
                        if filter not in self.survey_targets_dict[fieldid]:
                            target = Target()
                            target.fieldid = fieldid
                            target.filter = filter
                            target.num_exp = self.params.filter_num_exp_dict[
                                filter]
                            target.exp_times = self.params.filter_exp_times_dict[
                                filter]
                            target.ra_rad = field.ra_rad
                            target.dec_rad = field.dec_rad
                            target.propid = self.propid
                            target.goal = self.params.filter_goal_dict[filter]
                            target.visits = 0
                            target.progress = 0.0
                            target.groupid = 1
                            target.groupix = 1
                            self.survey_targets_dict[fieldid][filter] = target

                            self.survey_targets += 1
                            self.survey_targets_goal += target.goal
                            self.survey_filters_goal_dict[
                                filter] += target.goal
                        target = self.survey_targets_dict[fieldid][filter]
                        if target.progress < 1.0:
                            self.tonight_targets_dict[fieldid][filter] = target
                            self.tonight_targets += 1

        for filter in self.params.filter_list:
            if self.survey_filters_goal_dict[filter] > 0:
                self.survey_filters_progress_dict[filter] = \
                    float(self.survey_filters_visits_dict[filter]) / self.survey_filters_goal_dict[filter]
            else:
                self.survey_filters_progress_dict[filter] = 0.0

        if self.survey_targets_goal > 0:
            self.survey_targets_progress = float(
                self.survey_targets_visits) / self.survey_targets_goal
        else:
            self.survey_targets_progress = 0.0

        self.log.debug("start_night tonight fields=%i targets=%i" %
                       (self.tonight_fields, self.tonight_targets))

        self.last_observation = None
        self.last_observation_was_for_this_proposal = False