def update_forecast(self, jdata, latitude, elevation, plant_type, units, force): epoch = int(jdata['time']) dow = time.strftime("%w", time.gmtime(epoch)) LOGGER.info('Day of week = ' + dow) try: self.update_driver('CLIHUM', round(float(jdata['humidity']) * 100, 0), force) self.update_driver('BARPRES', jdata['pressure'], force) self.update_driver('GV0', jdata['temperatureMax'], force) self.update_driver('GV1', jdata['temperatureMin'], force) self.update_driver('GV13', self.icon_2_int(jdata['icon']), force) self.update_driver('GV14', round(float(jdata['cloudCover']) * 100, 0), force) self.update_driver('UV', jdata['uvIndex'], force) self.update_driver('GV18', float(jdata['precipProbability']) * 100, force) self.update_driver('GV19', int(dow), force) self.update_driver('DEWPT', jdata['dewPoint'], force) self.update_driver('GV4', jdata['windSpeed'], force) self.update_driver('GV5', jdata['windGust'], force) self.update_driver('WINDDIR', jdata['windBearing'], force) if 'precipAccumulation' in jdata: self.update_driver('GV7', jdata['precipAccumulation'], force) else: self.update_driver('GV7', 0, force) self.update_driver('GV10', jdata['ozone'], force) self.update_driver('DISTANC', jdata['visibility'], force) self.update_driver('GV9', jdata['moonPhase'], force) except Exception as e: LOGGER.error('Update failed: ' + str(e)) # Calculate ETo # Temp is in degree C and windspeed is in m/s, we may need to # convert these. Tmin = float(jdata['temperatureMin']) Tmax = float(jdata['temperatureMax']) Hmin = Hmax = float(jdata['humidity']) Ws = float(jdata['windSpeed']) J = datetime.datetime.fromtimestamp(jdata['time']).timetuple().tm_yday if units != 'si': LOGGER.info('Conversion of temperature/wind speed required') Tmin = et3.FtoC(Tmin) Tmax = et3.FtoC(Tmax) Ws = et3.mph2ms(Ws) et0 = et3.evapotranspriation(Tmax, Tmin, None, Ws, float(elevation), Hmax, Hmin, latitude, float(plant_type), J) if self.units == 'metric' or self.units == 'si' or self.units.startswith( 'm'): self.update_driver('GV20', round(et0, 2), force) else: self.update_driver('GV20', round(self.mm2inch(et0), 3), force) LOGGER.info("ETo = %f %f" % (et0, self.mm2inch(et0)))
def update_forecast(self, forecast, latitude, elevation, plant_type, units, f): LOGGER.debug(forecast) epoch = int(forecast['dt']) dow = time.strftime("%w", time.localtime(epoch)) LOGGER.info('Day of week = ' + dow) try: humidity = (forecast['Hmin'] + forecast['Hmax']) / 2 self.update_driver('CLIHUM', round(humidity, 0), f) self.update_driver('BARPRES', round(forecast['pressure'], 1), f) self.update_driver('DEWPT', round(forecast['dewpoint'], 1), f) self.update_driver('GV0', round(forecast['temp_max'], 1), f) self.update_driver('GV1', round(forecast['temp_min'], 1), f) self.update_driver('GV2', round(forecast['feelslike'], 1), f) self.update_driver('GV14', round(forecast['clouds'], 0), f) self.update_driver('GV4', round(forecast['speed'], 1), f) self.update_driver('GV19', int(dow), f) self.update_driver('GV13', forecast['weather'], f) self.update_driver('UV', round(forecast['uv'], 1), f) self.update_driver('GV6', round(forecast['rain'], 2), f) self.update_driver('GV7', round(forecast['snow'], 2), f) self.update_driver('GV18', round(forecast['pop'], 0), f) except exception as e: LOGGER.error('Forecast node update failed:') LOGGER.error(str(e)) # Calculate ETo # Temp is in degree C and windspeed is in m/s, we may need to # convert these. J = datetime.datetime.fromtimestamp(epoch).timetuple().tm_yday Tmin = forecast['temp_min'] Tmax = forecast['temp_max'] Ws = forecast['speed'] if units != 'metric': LOGGER.info('Conversion of temperature/wind speed required') Tmin = et3.FtoC(Tmin) Tmax = et3.FtoC(Tmax) Ws = et3.mph2ms(Ws) et0 = et3.evapotranspriation(Tmax, Tmin, None, Ws, float(elevation), forecast['Hmax'], forecast['Hmin'], latitude, float(plant_type), J) if self.units == 'imperial': self.update_driver('GV20', round(self.mm2inch(et0), 3)) else: self.update_driver('GV20', round(et0, 2)) LOGGER.info("ETo = %f %f" % (et0, self.mm2inch(et0)))
def update_forecast(self, forecast, latitude, elevation, plant_type, force): try: (year, month, day) = forecast['observation_time']['value'].split('-') forecast_day = datetime.datetime(int(year), int(month), int(day)) dow = forecast_day.weekday() except Exception as e: LOGGER.error('get day of week: ' + str(e)) dow = 0 (hmin, hmax) = self.get_min_max('humidity', forecast) LOGGER.debug('humidity = ' + str(hmin) + ' / ' + str(hmax)) humidity = (hmin + hmax) / 2 #humidity = (forecast['humidity'][0]['min']['value'] + forecast['humidity'][1]['max']['value']) / 2 try: (tmin, tmax) = self.get_min_max('temp', forecast) self.update_driver('GV0', tmax, force, prec=1) self.update_driver('GV1', tmin, force, prec=1) self.update_driver('CLIHUM', humidity, force, prec=0) # TODO: min/max pressure (vmin, vmax) = self.get_min_max('baro_pressure', forecast) self.update_driver('BARPRES', vmax, force, prec=1) # rate: self.update_driver('GV6', forecast['preciptiation'][0]['max']['value'], force, prec=1) self.update_driver('GV6', forecast['precipitation_accumulation']['value'], force, prec=1) self.update_driver('RAINRT', forecast['precipitation'][0]['max']['value'], force, prec=3) (vmin, vmax) = self.get_min_max('wind_speed', forecast) Ws = (vmin + vmax) / 2 self.update_driver('GV7', vmax, force, prec=1) self.update_driver('GV8', vmin, force, prec=1) self.update_driver('GV19', int(dow), force) self.update_driver('GV18', forecast['precipitation_probability']['value'], force, prec=1) #TODO: add visibility(min/max), moon phase, feelslike(min/max) LOGGER.debug('Forecast coded weather = ' + forecast['weather_code']['value']) self.update_driver( 'GV13', wx.weather_code(forecast['weather_code']['value']), force) except Exception as e: LOGGER.error('Forcast: ' + str(e)) # Calculate ETo # Temp is in degree C and windspeed is in m/s, we may need to # convert these. #J = datetime.datetime.fromtimestamp(epoch).timetuple().tm_yday J = forecast_day.timetuple().tm_yday try: if self.units != 'si': LOGGER.info('Conversion of temperature/wind speed required') tmin = et3.FtoC(tmin) tmax = et3.FtoC(tmax) Ws = et3.mph2ms(Ws) except Exception as e: LOGGER.error('conversion issue: ' + str(e)) et0 = et3.evapotranspriation(tmax, tmin, None, Ws, float(elevation), hmax, hmin, float(latitude), float(plant_type), J) if self.units == 'metric' or self.units == 'si' or self.units.startswith( 'm'): self.update_driver('GV20', round(et0, 2), force) else: self.update_driver('GV20', self.mm2inch(et0), force, prec=3) LOGGER.info("ETo = %f %f" % (et0, self.mm2inch(et0)))
def update_forecast(self, forecast, latitude, elevation, plant_type, tags, force): epoch = int(forecast['timestamp']) dow = time.strftime("%w", time.gmtime(epoch)) LOGGER.info('Day of week = ' + dow) LOGGER.info(tags) humidity = (forecast[tags['humidity_min']] + forecast[tags['humidity_max']]) / 2 try: self.update_driver('CLIHUM', humidity, force, prec=0) self.update_driver('BARPRES', forecast[tags['pressure']], force, prec=1) self.update_driver('GV0', forecast[tags['temp_max']], force, prec=1) self.update_driver('GV1', forecast[tags['temp_min']], force, prec=1) self.update_driver('GV14', forecast['sky'], force, prec=0) self.update_driver('SPEED', forecast[tags['windspeed']], force, prec=1) self.update_driver('GV5', forecast[tags['gustspeed']], force, prec=1) self.update_driver('GV6', forecast[tags['precipitation']], force, prec=1) self.update_driver('GV7', forecast[tags['wind_max']], force, prec=1) self.update_driver('GV8', forecast[tags['wind_min']], force, prec=1) if tags['snowf'] in forecast: if self.units == 'metric': snow = float(forecast[tags['snowf']]) * 10 else: snow = float(forecast[tags['snowf']]) self.update_driver('GV15', snow, force, prec=2) self.update_driver('GV19', int(dow), force) self.update_driver('UV', forecast['uvi'], force, prec=1) self.update_driver('GV18', forecast['pop'], force, prec=1) LOGGER.debug('Forecast coded weather = ' + forecast['weatherPrimaryCoded']) weather = forecast['weatherPrimaryCoded'].split(':')[0] self.update_driver('GV11', wx.coverage_codes(weather), force) weather = forecast['weatherPrimaryCoded'].split(':')[1] self.update_driver('GV12', wx.intensity_codes(weather), force) weather = forecast['weatherPrimaryCoded'].split(':')[2] self.update_driver('GV13', wx.weather_codes(weather), force) except Exception as e: LOGGER.error('Forcast: ' + str(e)) # Calculate ETo # Temp is in degree C and windspeed is in m/s, we may need to # convert these. J = datetime.datetime.fromtimestamp(epoch).timetuple().tm_yday Tmin = forecast[tags['temp_min']] Tmax = forecast[tags['temp_max']] Ws = forecast[tags['windspeed']] if self.units != 'metric': LOGGER.info('Conversion of temperature/wind speed required') Tmin = et3.FtoC(Tmin) Tmax = et3.FtoC(Tmax) Ws = et3.mph2ms(Ws) else: Ws = et3.kph2ms(Ws) et0 = et3.evapotranspriation(Tmax, Tmin, None, Ws, float(elevation), forecast[tags['humidity_max']], forecast[tags['humidity_min']], latitude, float(plant_type), J) if self.units == 'metric' or self.units == 'si' or self.units.startswith( 'm'): self.update_driver('GV20', round(et0, 2), force) else: self.update_driver('GV20', self.mm2inch(et0), force, prec=3) LOGGER.info("ETo = %f %f" % (et0, self.mm2inch(et0)))