예제 #1
0
def test_rso_daily(ra=d_args['ra'],
                   ea=d_args['ea'],
                   pair=s_args['pair'],
                   doy=d_args['doy'],
                   lat=s_args['lat'],
                   rso=d_args['rso']):
    assert float(calcs._rso_daily(ra, ea, pair, doy,
                                  lat)) == pytest.approx(rso)
예제 #2
0
def calc_rso_and_refet(lat, elev, wind_anemom, doy, month, tmax, tmin, ea, uz,
                       rs):
    """
        Calculates all of the following variables using the refet package (https://github.com/DRI-WSWUP/RefET):
            rso : clear sky solar radiation
            monthly_rs : : monthly averaged solar radiation (12 values total) values across all of record
            eto : grass reference evapotranspiration in units mm/day
            etr : alfalfa reference evapotranspiration in units mm/day
            monthly_eto : monthly averaged grass reference ET (12 values total) values across all of record
            monthly_etr : monthly averaged alfalfa reference ET (12 values total) values across all of record

        Parameters:
            lat : station latitude in decimal degrees
            elev: station elevation in meters
            wind_anemom : height of windspeed anemometer in meters
            doy : 1D numpy array of day of year in record
            month : 1D numpy array of current month in record
            tmax : 1D numpy array of maximum temperature values
            tmin : 1D numpy array of minimum temperature values
            ea : 1D numpy array of vapor pressure in kPa
            uz : 1D numpy array of average windspeed values
            rs : 1D numpy array of solar radiation values

        Returns:
            Returns all variables listed above as 1D numpy arrays
    """

    data_size = month.shape[0]  # Size of data set
    ra = np.empty(
        data_size)  # Extraterrestrial solar radiation, MJ/m2, ASCE eq. 21
    rso = np.empty(data_size)  # Clear sky solar radiation, MJ/m2, ASCE eq. 16
    eto = np.empty(data_size)
    etr = np.empty(data_size)
    monthly_rs = np.empty(12)
    monthly_eto = np.empty(12)
    monthly_etr = np.empty(12)

    pressure = 101.3 * ((
        (293 -
         (0.0065 * elev)) / 293)**5.26)  # units kPa, EQ 3 in ASCE RefET manual
    # refet package expects rs in MJ/m2 and latitude in radians
    refet_input_rs = np.array(rs * 0.0864)  # convert W/m2 to  MJ/m2
    refet_input_lat = lat * (np.pi / 180.0)  # convert latitude into radians

    # Calculate daily values
    for i in range(data_size):
        ra[i] = _ra_daily(lat=refet_input_lat, doy=doy[i], method='asce')
        rso[i] = _rso_daily(ra=ra[i],
                            ea=ea[i],
                            pair=pressure,
                            doy=doy[i],
                            lat=refet_input_lat)

        # Calculating ETo in mm using refET package
        eto[i] = Daily(tmin=tmin[i],
                       tmax=tmax[i],
                       ea=ea[i],
                       rs=refet_input_rs[i],
                       uz=uz[i],
                       zw=wind_anemom,
                       elev=elev,
                       lat=lat,
                       doy=doy[i],
                       method='asce').eto()

        # Calculating ETr in mm using refET package
        etr[i] = Daily(tmin=tmin[i],
                       tmax=tmax[i],
                       ea=ea[i],
                       rs=refet_input_rs[i],
                       uz=uz[i],
                       zw=wind_anemom,
                       elev=elev,
                       lat=lat,
                       doy=doy[i],
                       method='asce').etr()

    # Calculate mean monthly values
    j = 1
    for k in range(12):
        temp_indexes = [ex for ex, ind in enumerate(month) if ind == j]
        temp_indexes = np.array(temp_indexes, dtype=int)

        monthly_rs[k] = np.nanmean(rs[temp_indexes])
        monthly_eto[k] = np.nanmean(eto[temp_indexes])
        monthly_etr[k] = np.nanmean(etr[temp_indexes])

        j += 1

    rso *= 11.574  # Convert rso from MJ/m2 to w/m2
    return rso, monthly_rs, eto, etr, monthly_eto, monthly_etr
예제 #3
0
def test_rso_daily_ra_zero(ea=d_args['ea'], pair=s_args['pair']):
    # Rso can go to zero for winter DOY and/or high latitudes when Ra is zero
    rso = calcs._rso_daily(calcs._ra_daily(80 * math.pi / 180, 1), ea, pair, 1,
                           80 * math.pi / 180)
    assert float(rso) == 0