Пример #1
0
def test_refet_daily_values(daily_params):
    """Test daily RefET calculation at a single point and time"""
    # If I don't copy, the pop changes the test values in daily_data()
    inputs = daily_params.copy()
    surface = inputs.pop('surface')
    expected = inputs.pop('expected')
    # print('ETr: {}'.format(expected))

    # ETr/ETo values only have 4 significant figures
    # Small number of days don't match if difference is set < 0.008
    diff = 0.05 if expected >= 10.0 else 0.008

    if surface.lower() == 'etr':
        assert float(Daily(**inputs).etr()) == pytest.approx(expected,
                                                             abs=diff)
    elif surface.lower() == 'eto':
        assert float(Daily(**inputs).eto()) == pytest.approx(expected,
                                                             abs=diff)
Пример #2
0
def test_refet_daily_default_method():
    etr = Daily(tmin=d_args['tmin'],
                tmax=d_args['tmax'],
                ea=d_args['ea'],
                rs=d_args['rs'],
                uz=d_args['uz'],
                zw=s_args['zw'],
                elev=s_args['elev'],
                lat=s_args['lat'],
                doy=d_args['doy']).etr()
    assert float(etr) == pytest.approx(d_args['etr_asce'])
Пример #3
0
def test_refet_daily_eto():
    eto = Daily(tmin=d_args['tmin'],
                tmax=d_args['tmax'],
                ea=d_args['ea'],
                rs=d_args['rs'],
                uz=d_args['uz'],
                zw=s_args['zw'],
                elev=s_args['elev'],
                lat=s_args['lat'],
                doy=d_args['doy'],
                method='refet').eto()
    assert float(eto) == pytest.approx(d_args['eto_refet'])
Пример #4
0
def test_refet_daily_etsz(surface, expected):
    etsz = Daily(tmin=d_args['tmin'],
                 tmax=d_args['tmax'],
                 ea=d_args['ea'],
                 rs=d_args['rs'],
                 uz=d_args['uz'],
                 zw=s_args['zw'],
                 elev=s_args['elev'],
                 lat=s_args['lat'],
                 doy=d_args['doy'],
                 method='refet').etsz(surface)
    assert float(etsz) == pytest.approx(expected)
Пример #5
0
def test_refet_daily_method(method, expected):
    etr = Daily(tmin=d_args['tmin'],
                tmax=d_args['tmax'],
                ea=d_args['ea'],
                rs=d_args['rs'],
                uz=d_args['uz'],
                zw=s_args['zw'],
                elev=s_args['elev'],
                lat=s_args['lat'],
                doy=d_args['doy'],
                method=method).etr()
    assert float(etr) == pytest.approx(expected)
Пример #6
0
def test_refet_daily_rso_type_simple():
    etr = Daily(tmin=d_args['tmin'],
                tmax=d_args['tmax'],
                ea=d_args['ea'],
                rs=d_args['rs'],
                uz=d_args['uz'],
                zw=s_args['zw'],
                elev=s_args['elev'],
                lat=s_args['lat'],
                doy=d_args['doy'],
                method='refet',
                rso_type='simple').etr()
    assert float(etr) == pytest.approx(d_args['etr_rso_simple'])
Пример #7
0
def test_refet_daily_rso_type_exception():
    with pytest.raises(ValueError):
        etr = Daily(tmin=d_args['tmin'],
                    tmax=d_args['tmax'],
                    ea=d_args['ea'],
                    rs=d_args['rs'],
                    uz=d_args['uz'],
                    zw=s_args['zw'],
                    elev=s_args['elev'],
                    lat=s_args['lat'],
                    doy=d_args['doy'],
                    method='refet',
                    rso_type='nonsense').etr()
Пример #8
0
def test_refet_daily_lat_rad():
    etr = Daily(tmin=d_args['tmin'],
                tmax=d_args['tmax'],
                ea=d_args['ea'],
                rs=d_args['rs'],
                uz=d_args['uz'],
                zw=s_args['zw'],
                elev=s_args['elev'],
                lat=s_args['lat'] * math.pi / 180,
                doy=d_args['doy'],
                input_units={
                    'lat': 'rad'
                }).etr()
    assert float(etr) == pytest.approx(d_args['etr_asce'])
Пример #9
0
def test_refet_daily_elev_ft():
    etr = Daily(tmin=d_args['tmin'],
                tmax=d_args['tmax'],
                ea=d_args['ea'],
                rs=d_args['rs'],
                uz=d_args['uz'],
                zw=s_args['zw'],
                elev=s_args['elev'] / 0.3048,
                lat=s_args['lat'],
                doy=d_args['doy'],
                input_units={
                    'elev': 'ft'
                }).etr()
    assert float(etr) == pytest.approx(d_args['etr_asce'])
Пример #10
0
def test_refet_daily_rs_langleys():
    etr = Daily(tmin=d_args['tmin'],
                tmax=d_args['tmax'],
                ea=d_args['ea'],
                rs=d_args['rs'] / 0.041868,
                uz=d_args['uz'],
                zw=s_args['zw'],
                elev=s_args['elev'],
                lat=s_args['lat'],
                doy=d_args['doy'],
                input_units={
                    'rs': 'Langleys'
                }).etr()
    assert float(etr) == pytest.approx(d_args['etr_asce'])
Пример #11
0
def test_refet_daily_tmin_f():
    etr = Daily(tmin=d_args['tmin'] * (9.0 / 5) + 32,
                tmax=d_args['tmax'],
                ea=d_args['ea'],
                rs=d_args['rs'],
                uz=d_args['uz'],
                zw=s_args['zw'],
                elev=s_args['elev'],
                lat=s_args['lat'],
                doy=d_args['doy'],
                input_units={
                    'tmin': 'F'
                }).etr()
    assert float(etr) == pytest.approx(d_args['etr_asce'])
Пример #12
0
def test_refet_daily_tmax_k():
    print(d_args['tmin'])
    etr = Daily(tmin=d_args['tmin'],
                tmax=d_args['tmax'] + 273.15,
                ea=d_args['ea'],
                rs=d_args['rs'],
                uz=d_args['uz'],
                zw=s_args['zw'],
                elev=s_args['elev'],
                lat=s_args['lat'],
                doy=d_args['doy'],
                input_units={
                    'tmax': 'K'
                }).etr()
    assert float(etr) == pytest.approx(d_args['etr_asce'])
Пример #13
0
 def mesonet_etr(self, lat=46.3, elevation=1000):
     t_dew = dewpoint_temp(self.table['Vapor Pressure'].resample('D').mean().values)
     ea = calcs._sat_vapor_pressure(t_dew)
     tmax_series = self.table['Air Temperature']
     tmax = tmax_series.resample('D').max().values
     tmin = self.table['Air Temperature'].resample('D').min().values
     daily = tmax_series.resample('D').mean()
     doy = daily.index.strftime('%j').astype(int).values
     rs = self.table['Solar Radiation'].resample('D').mean().values * 0.0864
     uz = self.table['Wind Speed'].resample('D').mean().values
     zw = 2.4
     etr = Daily(tmin=tmin, tmax=tmax, ea=ea, rs=rs, uz=uz, zw=zw, elev=elevation,
                 lat=lat, doy=doy).etr()
     df = DataFrame(data=[doy, rs, etr, uz, ea, t_dew, tmax, tmin]).transpose()
     df.columns = ['DOY', 'SR', 'ETR', 'UZ', 'EA', 'TDew', 'TMax', 'TMin']
     df.index = date_range(self.table.index.min(), self.table.index.max(), freq='D')
     return df
Пример #14
0
    def get_agrimet_etr(self, yr, first=False):

        agrimet = Agrimet(station=self.station, start_date=START.format(yr),
                          end_date=END.format(yr), interval='daily')

        formed = agrimet.fetch_met_data()
        if isnull(formed['ETRS']).values.sum() == formed['ETRS'].shape[0]:
            agri_etr = formed['ETRS'].groupby(lambda x: x.month).sum().values
        else:
            agri_etr = formed['ETRS'].groupby(lambda x: x.month).sum().values

        if first:
            self.elev = get_elevation(agrimet.station_coords[0], agrimet.station_coords[1])
            print('Station {}'.format(self.station))

        if formed['YM'].values.mean() != nan:
            t_dew = formed['YM'].values
            ea = calcs._sat_vapor_pressure(t_dew)[0]
            tmin, tmax = formed['MN'].values, formed['MX'].values

            try:
                doy = formed.index.strftime('%j').astype(int).values
            except AttributeError:
                doy = formed.index.strftime('%j').astype(int)

            doy = doy.reshape((len(doy), 1))[0]
            lat = agrimet.station_coords[0]
            rs = formed['SR'].values
            uz = formed['UA'].values
            zw = 2.0
            formed['calc_etr'] = Daily(tmin=tmin, tmax=tmax, ea=ea, rs=rs, uz=uz, zw=zw, elev=self.elev,
                                       lat=lat, doy=doy).etr()
            calc_etr = formed['calc_etr'].groupby(lambda x: x.month).sum().values

        else:
            calc_etr = empty(agri_etr.shape)
            calc_etr[:] = 0.0

        return agri_etr, calc_etr
Пример #15
0
def test_refet_daily_input_positions():
    etr = Daily(d_args['tmin'], d_args['tmax'], d_args['ea'], d_args['rs'],
                d_args['uz'], s_args['zw'], s_args['elev'], s_args['lat'],
                d_args['doy'], 'asce').etr()
    assert float(etr) == pytest.approx(d_args['etr_asce'])