示例#1
0
    def test_cycle(self):

        t = datetime.utcnow().replace(tzinfo=pytz.utc)
        loc = Location4D(time=t, latitude=35, longitude=-76)
        c = SunCycles.cycles(loc=loc)
        sunrise = c[SunCycles.RISING]
        sunset = c[SunCycles.SETTING]

        d = Diel()
        d.min_depth = -4
        d.max_depth = -10
        d.pattern = 'cycles'
        d.cycle = 'sunrise'
        d.plus_or_minus = '+'
        d.time_delta = 4
        assert d.get_time(loc4d=loc) == sunrise + timedelta(hours=4)

        d = Diel()
        d.min_depth = -4
        d.max_depth = -10
        d.pattern = 'cycles'
        d.cycle = 'sunset'
        d.plus_or_minus = '-'
        d.time_delta = 2
        assert d.get_time(loc4d=loc) == sunset - timedelta(hours=2)
示例#2
0
    def test_classmethod_with_lat_lon_time(self):

        d = SunCycles.cycles(lat=self.lat, lon=self.lon, time=self.dt)

        zrise = d[SunCycles.RISING].astimezone(timezone('US/Eastern'))
        assert zrise.year == 2012
        assert zrise.month == 8
        assert zrise.day == 6
        assert zrise.hour == 5
        assert zrise.minute == 46

        zset = d[SunCycles.SETTING].astimezone(timezone('US/Eastern'))
        assert zset.year == 2012
        assert zset.month == 8
        assert zset.day == 6
        assert zset.hour == 19
        assert zset.minute == 57
示例#3
0
    def test_alaskan_waters(self):

        d = SunCycles.cycles(lat=59.671120, lon=-144.849561, time=datetime(2011, 5, 2, tzinfo=pytz.utc))

        zrise = d[SunCycles.RISING].astimezone(timezone('US/Alaska'))
        assert zrise.year == 2011
        assert zrise.month == 5
        assert zrise.day == 2
        assert zrise.hour == 5
        assert zrise.minute == 36

        zset = d[SunCycles.SETTING].astimezone(timezone('US/Alaska'))
        assert zset.year == 2011
        assert zset.month == 5
        assert zset.day == 2
        assert zset.hour == 21
        assert zset.minute == 37
示例#4
0
    def test_classmethod_with_location4d(self):

        loc = Location4D(time=self.dt, latitude=self.lat, longitude=self.lon)
        d = SunCycles.cycles(loc=loc)

        zrise = d[SunCycles.RISING].astimezone(timezone('US/Eastern'))
        assert zrise.year == 2012
        assert zrise.month == 8
        assert zrise.day == 6
        assert zrise.hour == 5
        assert zrise.minute == 46

        zset = d[SunCycles.SETTING].astimezone(timezone('US/Eastern'))
        assert zset.year == 2012
        assert zset.month == 8
        assert zset.day == 6
        assert zset.hour == 19
        assert zset.minute == 57
示例#5
0
文件: diel.py 项目: hetland/paegan
    def get_time(self, loc4d=None):
        """
            Based on a Location4D object and this Diel object, calculate
            the time at which this Diel migration is actually happening
        """
        if loc4d is None:
            raise ValueError("Location4D object can not be None")

        if self.pattern == self.PATTERN_CYCLE:
            c = SunCycles.cycles(loc=loc4d)
            if self.cycle == self.CYCLE_SUNRISE:
                r = c[SunCycles.RISING]
            elif self.cycle == self.CYCLE_SUNSET:
                r = c[SunCycles.SETTING]
            td = timedelta(hours=self.time_delta)
            if self.plus_or_minus == self.HOURS_PLUS:
                r = r + td
            elif self.plus_or_minus == self.HOURS_MINUS:
                r = r - td
            return r
        elif self.pattern == self.PATTERN_SPECIFICTIME:
            return self._time.replace(year=loc4d.time.year, month=loc4d.time.month, day=loc4d.time.day)