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)
Example #2
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)
    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
    def test_change_in_day_baltimore(self):

        d = SunCycles.cycles(lat=39.2833, lon=-76.6167, time=datetime(2013, 4, 15, 21, 00, tzinfo=timezone('US/Eastern')))

        zrise = d[SunCycles.RISING].astimezone(timezone('US/Eastern'))
        assert zrise.year == 2013
        assert zrise.month == 4
        assert zrise.day == 15
        assert zrise.hour == 6
        assert zrise.minute == 29

        zset = d[SunCycles.SETTING].astimezone(timezone('US/Eastern'))
        assert zset.year == 2013
        assert zset.month == 4
        assert zset.day == 15
        assert zset.hour == 19
        assert zset.minute == 43
    def test_alaskan_waters_anchorage(self):

        d = SunCycles.cycles(lat=61.183333, lon=-149.883333, time=datetime(2013, 4, 15, tzinfo=timezone('US/Eastern')))

        zrise = d[SunCycles.RISING].astimezone(timezone('US/Alaska'))
        assert zrise.year == 2013
        assert zrise.month == 4
        assert zrise.day == 15
        assert zrise.hour == 6
        assert zrise.minute == 38

        zset = d[SunCycles.SETTING].astimezone(timezone('US/Alaska'))
        assert zset.year == 2013
        assert zset.month == 4
        assert zset.day == 15
        assert zset.hour == 21
        assert zset.minute == 21
    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
    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
    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
    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
    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
Example #11
0
    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)
    def test_alaskan_waters_anchorage(self):

        d = SunCycles.cycles(lat=61.183333,
                             lon=-149.883333,
                             time=datetime(2013,
                                           4,
                                           15,
                                           tzinfo=timezone('US/Eastern')))

        zrise = d[SunCycles.RISING].astimezone(timezone('US/Alaska'))
        assert zrise.year == 2013
        assert zrise.month == 4
        assert zrise.day == 15
        assert zrise.hour == 6
        assert zrise.minute == 38

        zset = d[SunCycles.SETTING].astimezone(timezone('US/Alaska'))
        assert zset.year == 2013
        assert zset.month == 4
        assert zset.day == 15
        assert zset.hour == 21
        assert zset.minute == 21
    def test_change_in_day_baltimore(self):

        d = SunCycles.cycles(lat=39.2833,
                             lon=-76.6167,
                             time=datetime(2013,
                                           4,
                                           15,
                                           21,
                                           00,
                                           tzinfo=timezone('US/Eastern')))

        zrise = d[SunCycles.RISING].astimezone(timezone('US/Eastern'))
        assert zrise.year == 2013
        assert zrise.month == 4
        assert zrise.day == 15
        assert zrise.hour == 6
        assert zrise.minute == 29

        zset = d[SunCycles.SETTING].astimezone(timezone('US/Eastern'))
        assert zset.year == 2013
        assert zset.month == 4
        assert zset.day == 15
        assert zset.hour == 19
        assert zset.minute == 43
Example #14
0
    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)