def process_temporal_data(lat, lon, root): times = [ datetime.fromtimestamp(int(t)) for t in nc.getvar(root, 'time') ] indexes = range(len(times)) for i in indexes: show("\rTemporal data: preprocessing image %d / %d " % (i, len(indexes)-1)) dt = times[i] # Calculate some geometry parameters # Parameters that need the datetime: gamma, tst_hour, slots, linketurbidity gamma = geo.getdailyangle(geo.getjulianday(dt),geo.gettotaldays(dt)) tst_hour = geo.gettsthour(geo.getdecimalhour(dt), GREENWICH_LON, lon, geo.gettimeequation(gamma)) declination = geo.getdeclination(gamma) slots = geo.getslots(dt,IMAGE_PER_HOUR) omega = geo.gethourlyangle(tst_hour, lat/abs(lat)) solarangle = geo.getzenithangle(declination,lat,omega) solarelevation = geo.getelevation(solarangle) excentricity = geo.getexcentricity(gamma) save_temporal_data(root,i,gamma,tst_hour,declination,solarangle,solarelevation,excentricity,slots) say("Projecting Linke's turbidity index... ") linke.cut_projected(root) say("Calculating the satellital zenith angle... ") satellitalzenithangle = geo.getsatellitalzenithangle(lat, lon, SAT_LON) dem.cut_projected(root) v_satellitalzenithangle = nc.getvar(root,'satellitalzenithangle', 'f4', ('northing','easting',),4) v_satellitalzenithangle[:] = satellitalzenithangle nc.sync(root)
def process_temporal_data(lat, lon, root): times = [ datetime.utcfromtimestamp(int(t)) for t in nc.getvar(root, 'data_time')[:] ] indexes = range(len(times)) gamma = nc.clonevar(root,'data_time', 'gamma') nc.sync(root) tst_hour = nc.clonevar(root,'data', 'tst_hour') declination = nc.clonevar(root, 'gamma', 'declination') solarangle = nc.clonevar(root, 'data', 'solarangle') solarelevation = nc.clonevar(root, 'solarangle', 'solarelevation') excentricity = nc.clonevar(root, 'gamma', 'excentricity') slots = nc.getvar(root,'slots', 'u1', ('timing',)) nc.sync(root) for i in indexes: show("\rTemporal data: preprocessing image %d / %d " % (i, len(indexes)-1)) dt = times[i] # Calculate some geometry parameters # Parameters that need the datetime: gamma, tst_hour, slots, linketurbidity gamma[i] = geo.getdailyangle(geo.getjulianday(dt),geo.gettotaldays(dt)) tst_hour[i,:] = geo.gettsthour(geo.getdecimalhour(dt), GREENWICH_LON, lon, geo.gettimeequation(gamma[i])) declination[i] = geo.getdeclination(gamma[i]) slots[i] = geo.getslots(dt,IMAGE_PER_HOUR) omega = geo.gethourlyangle(tst_hour[i], lat/abs(lat)) solarangle[i] = geo.getzenithangle(declination[i],lat,omega) solarelevation[i] = geo.getelevation(solarangle[i]) excentricity[i] = geo.getexcentricity(gamma[i]) nc.sync(root) say("Projecting Linke's turbidity index... ") linke.cut_projected(root) say("Calculating the satellital zenith angle... ") satellitalzenithangle = geo.getsatellitalzenithangle(lat, lon, SAT_LON) dem.cut_projected(root) v_satellitalzenithangle = nc.clonevar(root,'lat', 'satellitalzenithangle') v_satellitalzenithangle[:] = satellitalzenithangle nc.sync(root) v_satellitalzenithangle = None
def rows2slots(rows, image_per_hour): resumed_slots = [] old_slot = geo.getslots(rows[0][0],image_per_hour) seconds_in_slot = (rows[1][0] - rows[0][0]).total_seconds() mvolt = 0 rows_by_slot = 0 dt = rows[0][0] for r in rows: slot = geo.getslots(dt,image_per_hour) if not old_slot is slot: resumed_slots.append([slot, [dt, mvolt_to_watt((mvolt/rows_by_slot)/seconds_in_slot), rows_by_slot]]) old_slot, rows_by_slot, mvolt = slot, 0, 0 mvolt += r[1] rows_by_slot += 1 dt = r[0] if not old_slot is slot: resumed_slots.append([slot, [dt, mvolt_to_watt((mvolt/rows_by_slot)/seconds_in_slot), rows_by_slot]]) old_slot, rows_by_slot, mvolt = slot, 0, 0 return resumed_slots
def rows2slots(rows, image_per_hour): resumed_slots = [] old_slot = geo.getslots(rows[0][0],image_per_hour) seconds_in_slot = (rows[1][0] - rows[0][0]).total_seconds() MJ = 0 rows_by_slot = 0 dt = rows[0][0] for r in rows: slot = geo.getslots(dt,image_per_hour) if not old_slot is slot: resumed_slots.append([slot, [dt, ((MJ/rows_by_slot)/seconds_in_slot)*1E6, rows_by_slot]]) old_slot, rows_by_slot, MJ = slot, 0, 0 MJ += r[1] rows_by_slot += 1 dt = r[0] if not old_slot is slot: resumed_slots.append([slot, [dt, ((MJ/rows_by_slot)/seconds_in_slot)*1E6, rows_by_slot]]) old_slot, rows_by_slot, MJ = slot, 0, 0 return resumed_slots
def should_be_cloned(self, material_status): if not hasattr(material_status.material,'datetime'): return False dt = material_status.material.datetime() if self.yearly: return self.contains(dt.year) if self.monthly: return self.contains(dt.month) if self.weekly: return self.contains(dt.isocalendar()[1]) if self.week_day: return self.contains(dt.weekday()) if self.daily: return self.contains(dt.timetuple().tm_yday) if self.hourly: return self.contains(dt.hour) if self.slotly: return self.contains(getslots(dt.hour,self.slots_by_day/24))