Пример #1
0
def get_data_from_WU():

    ###array to store the reports
    wu_weather_reports = []

    ##  today and last 6 days definition
    day1 = now - datetime.timedelta(days=6)
    day2 = now - datetime.timedelta(days=5)
    day3 = now - datetime.timedelta(days=4)
    day4 = now - datetime.timedelta(days=3)
    day5 = now - datetime.timedelta(days=2)
    day6 = now - datetime.timedelta(days=1)
    day7 = now

    #### convert dates to WU required format
    days = {
    'day1': day1.strftime('%Y%m%d'),
    'day2': day2.strftime('%Y%m%d'),
    'day3': day3.strftime('%Y%m%d'),
    'day4': day4.strftime('%Y%m%d'),
    'day5': day5.strftime('%Y%m%d'),
    'day6': day6.strftime('%Y%m%d'),
    'day7': day7.strftime('%Y%m%d')

    }

    ### make API wather hisotry call for each day
    for day in days:
        url = 'http://api.wunderground.com/api/7c2ab99a0ccee978/history_{0}/q/95316.json'.format(days[day])
        headers = {'content-type': 'application/JSON; charset=utf8'} 
        response = requests.get(url, headers=headers)

        data = json.loads(response.text)

        #ETo calculation for the day using FAO-56 Penman-Monteith method
        lat = pyeto.deg2rad(37.585652)
        altitude = 38

        julian_day = datetime.datetime.strptime(days.get(day), '%Y%m%d').timetuple().tm_yday
        sol_dec = pyeto.sol_dec(julian_day)
        sha = pyeto.sunset_hour_angle(lat, sol_dec)
        ird = pyeto.inv_rel_dist_earth_sun(julian_day)

        ### net radiation calculator
        net_rad = pyeto.et_rad(lat, sol_dec, sha, ird) 

        temp_c = float(data["history"]["observations"][1]["tempm"])
        temp_k = float(data["history"]["observations"][1]["tempi"])
        humidity = float(data["history"]["observations"][1]["hum"])
        dew_point = float(data["history"]["observations"][1]["dewptm"])
        ws = float(data["history"]["observations"][1]["wspdm"])

        #actual and saturated vapour pressure in kPH
        svp = pyeto.svp_from_t(temp_c)
        avp = pyeto.avp_from_tdew(dew_point)
        delta_svp = pyeto.delta_svp(temp_c)

        atm_pressure = pyeto.atm_pressure(altitude)
        psy = pyeto.psy_const(atm_pressure)

        #### the ETo plugin retun results in mm, it was converted to inched
        ETo_in_mm = pyeto.fao56_penman_monteith(net_rad, temp_k, ws, svp, avp, delta_svp, psy, shf=0.0)
        ETo = ETo_in_mm * 0.039370

        ## insert eto value to day weather report
        data["history"]["observations"][1].update({"ETo": "{0:.2f}".format(ETo)})

        ###add report to report collector array
        wu_weather_reports.append(data["history"]["observations"][1])

    #return all reports
    return wu_weather_reports
tmin = 37
tmax = 53
coastal = True
altitude = 147
rh_min = 13
rh_max = 88
ws = 1.3

tmean = pyeto.daily_mean_t(tmin, tmax)
atmos_pres = pyeto.atm_pressure(altitude)
psy = pyeto.psy_const(atmos_pres)

# Humidity
svp_tmin = pyeto.svp_from_t(tmin)
svp_tmax = pyeto.svp_from_t(tmax)
delta_svp = pyeto.delta_svp(tmean)
svp = pyeto.mean_svp(tmin, tmax)
avp = pyeto.avp_from_rhmin_rhmax(svp_tmin, svp_tmax, rh_min, rh_max)

# Radiation
sol_dec = pyeto.sol_dec(day_of_year)
sha = pyeto.sunset_hour_angle(latitude, sol_dec)
ird = pyeto.inv_rel_dist_earth_sun(day_of_year)
et_rad = pyeto.et_rad(latitude, sol_dec, sha, ird)
cs_rad = pyeto.cs_rad(altitude, et_rad)
sol_rad = pyeto.sol_rad_from_t(et_rad, cs_rad, tmin, tmax, coastal)
ni_sw_rad = pyeto.net_in_sol_rad(sol_rad)
no_lw_rad = pyeto.net_out_lw_rad(pyeto.celsius2kelvin(tmin), pyeto.celsius2kelvin(tmax), sol_rad, cs_rad, avp)
net_rad = pyeto.net_rad(ni_sw_rad, no_lw_rad)

eto = pyeto.fao56_penman_monteith(net_rad, pyeto.celsius2kelvin(tmean), ws, svp, avp, delta_svp, psy)
Пример #3
0
 def test_delta_svp(self):
     # Test based on example 17, p.111 of FAO paper
     dh = pyeto.delta_svp(30.2)
     self.assertAlmostEqual(dh, 0.246, 3)