def __init__(self, **kwargs): if 'json' in kwargs or 'data' in kwargs: data = {} try: data = json.loads(kwargs['json']) except Exception: try: data = kwargs.get('data') except Exception: pass self.name = data.get('name', None) self.linear_a = data.get('linear_a', None) self.linear_b = data.get('linear_b', None) # duration is in days self.duration = data.get('duration', None) self.diel = [Diel(data=d) for d in data.get('diel')] self.taxis = [Taxis(data=t) for t in data.get('taxis')] self.capability = None if data.get('capability', None) is not None: self.capability = Capability(data=data.get('capability')) self.settlement = None if data.get('settlement', None) is not None: self.settlement = Settlement(data=data.get('settlement'))
def test_specifictime_object_from_dict(self): data = open(os.path.normpath(os.path.join(os.path.dirname(__file__),"./resources/files/diel_behavior_specifictime.json"))).read() d = Diel(data=json.loads(data)) t = datetime.utcnow().replace(tzinfo=pytz.utc) loc = Location4D(time=t, latitude=35, longitude=-76) assert d.pattern == "specifictime" assert d.min_depth == -4.0 assert d.max_depth == -5.0 assert d.get_time(loc4d=loc).year == t.year assert d.get_time(loc4d=loc).month == t.month assert d.get_time(loc4d=loc).day == t.day assert d.get_time(loc4d=loc).hour == 17 assert d.get_time(loc4d=loc).minute == 0 assert d.get_time(loc4d=loc).second == 0 assert d.get_time(loc4d=loc).microsecond == 0
def test_cycle_object_from_dict(self): data = open( os.path.normpath( os.path.join( os.path.dirname(__file__), "./resources/files/diel_behavior_cycle.json"))).read() d = Diel(data=json.loads(data)) assert d.pattern == "cycles" assert d.plus_or_minus == "+" assert d.min_depth == -4.0 assert d.max_depth == -5.0 assert d.time_delta == 4 assert d.cycle == "sunrise"
def test_specifictime_object_from_dict(self): data = open( os.path.normpath( os.path.join( os.path.dirname(__file__), "./resources/files/diel_behavior_specifictime.json")) ).read() d = Diel(data=json.loads(data)) t = datetime.utcnow().replace(tzinfo=pytz.utc) loc = Location4D(time=t, latitude=35, longitude=-76) assert d.pattern == "specifictime" assert d.min_depth == -4.0 assert d.max_depth == -5.0 assert d.get_time(loc4d=loc).year == t.year assert d.get_time(loc4d=loc).month == t.month assert d.get_time(loc4d=loc).day == t.day assert d.get_time(loc4d=loc).hour == 17 assert d.get_time(loc4d=loc).minute == 0 assert d.get_time(loc4d=loc).second == 0 assert d.get_time(loc4d=loc).microsecond == 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)