Ejemplo n.º 1
0
    def _get_ra_target_intervals(self, target, up, airmass, effective_horizon):
        star = Star(self.site['latitude'], target, effective_horizon)

        if up:
            day_interval_func = self._find_when_target_is_up
        else:
            day_interval_func = self._find_when_target_is_down

        # Find rise/set/transit for each day
        intervals = []
        current_date = self.start_date
        while current_date < self.end_date + ONE_DAY:
            one_day_intervals = day_interval_func(target, current_date, star,
                                                  airmass)

            # Add today's intervals to the accumulating list of intervals
            intervals.extend(one_day_intervals)

            # Move on to tomorrow
            current_date += ONE_DAY

        # Collapse adjacent intervals into continuous larger intervals
        intervals = coalesce_adjacent_intervals(intervals)
        intervals = intersect_intervals(intervals,
                                        [(self.start_date, self.end_date)])

        return intervals
Ejemplo n.º 2
0
    def get_ha_intervals(self, target):
        """Returns the hour angle intervals for the given target.

        Returns the hour anle intervals for the given target and given site and date range set in this visibility object.
        The hour angle intervals are uninterupted chunks of time that the target is within the hour angle limits of the
        telescope.

        Args:
            target (dict): A dictionary of target details in the rise-set library format
        Returns:
            list: A list of tuples of start/end datetime pairs that make up the intervals over which this target is within HA limits.
        """
        SIDEREAL_SOLAR_DAY_RATIO = 1.002737909350
        SIDEREAL_SOLAR_DAY = datetime.timedelta(
            seconds=(ONE_DAY.total_seconds() / SIDEREAL_SOLAR_DAY_RATIO))

        earliest_date = self.start_date - SIDEREAL_SOLAR_DAY

        tdb = date_to_tdb(earliest_date)
        mjd = gregorian_to_ut_mjd(earliest_date)
        gmst = ut_mjd_to_gmst(mjd)

        # Need the apparent ra/dec for getting correct ha limits on high dec targets
        apparent_ra, apparent_dec = mean_to_apparent(target, tdb)

        # Flip the neg/pos ha limits if site is in the southern hemisphere
        ha_neg = self.ha_limit_neg
        ha_pos = self.ha_limit_pos
        if self.site['latitude'].in_degrees() < 0:
            ha_neg = -self.ha_limit_pos
            ha_pos = -self.ha_limit_neg

        # the rise time
        hour_rise = ha_neg + apparent_ra.in_hours() - \
            self.site['longitude'].in_hours() - gmst.in_hours()
        hour_rise /= SIDEREAL_SOLAR_DAY_RATIO

        # the set time
        hour_set  = ha_pos + apparent_ra.in_hours() - \
            self.site['longitude'].in_hours() - gmst.in_hours()
        hour_set /= SIDEREAL_SOLAR_DAY_RATIO

        current_rise = earliest_date + datetime.timedelta(hours=hour_rise)
        current_set = earliest_date + datetime.timedelta(hours=hour_set)

        # Find hour angle limits for each day
        intervals = []
        while current_set < (self.end_date + SIDEREAL_SOLAR_DAY):
            intervals.append((current_rise, current_set))
            current_rise += SIDEREAL_SOLAR_DAY
            current_set += SIDEREAL_SOLAR_DAY

        # do not exceed start/end dates
        intervals = coalesce_adjacent_intervals(intervals)
        intervals = intersect_intervals(intervals,
                                        [(self.start_date, self.end_date)])

        return intervals
Ejemplo n.º 3
0
    def test_intersect_case09(self):
        # case 9      |......|
        #                    |......|
        expected = []

        int1 = [(datetime.datetime(2013, 6, 15, 12, 0, 0),
                 datetime.datetime(2013, 6, 15, 15, 0, 0))]
        int2 = [(datetime.datetime(2013, 6, 15, 15, 0, 0),
                 datetime.datetime(2013, 6, 15, 18, 0, 0))]
        received = intersect_intervals(int1, int2)

        assert_equal(received, expected)
Ejemplo n.º 4
0
    def test_intersect_case12(self):
        # case 12     |......|
        #           |...| |....|
        expected = [(datetime.datetime(2013, 6, 15, 12, 0, 0),
                     datetime.datetime(2013, 6, 15, 13, 0, 0)),
                    (datetime.datetime(2013, 6, 15, 14, 0, 0),
                     datetime.datetime(2013, 6, 15, 15, 0, 0))]

        int1 = [(datetime.datetime(2013, 6, 15, 12, 0, 0),
                 datetime.datetime(2013, 6, 15, 15, 0, 0))]
        int2 = [(datetime.datetime(2013, 6, 15, 11, 0, 0),
                 datetime.datetime(2013, 6, 15, 13, 0, 0)),
                (datetime.datetime(2013, 6, 15, 14, 0, 0),
                 datetime.datetime(2013, 6, 15, 16, 0, 0))]

        received = intersect_intervals(int1, int2)

        assert_equal(received, expected)