outvarname = options.outvarname # varlist = ['hurs', 'psl', 'rls', 'rss', 'sfcWind', 'tasmax', 'tasmin', 'tas'] # pd = dict([[v, # "/Users/nelereyniers/data/toydata/toydata_3x3/{}_rcp85_land-rcm_uk_12km_01_day_19801201-20801130.nc".format(v)] # for v in varlist]) # outvarname = 'evpot-fao' # outpath = "/Users/nelereyniers/data/toydata/toydata_3x3/{}_rcp85_land-rcm_uk_12km_01_day_19801201-20801130.nc".format(outvarname) # --------------------------------------------------------------------- pd = dict([[v, input_path_format.format(var=v)] for v in varlist]) outpath = output_path_format.format(outvarname) ds_ukcp18 = prepare_input_from_ukcp18(pd, concat_dim=False) kwargs_ukcp18 = get_ukcp18_kwargs() et_ukcp18 = ETo_xr() et_ukcp18.param_est_xr(ds_ukcp18, **kwargs_ukcp18) et_ukcp18_fao = et_ukcp18.eto_fao_xr(remove_extreme_values=False, round_decimals=2) attributes = { 'creation_script': sys.argv[0] + " (github user mullenkamp and N. Reyniers)", 'creation_time': datetime.now().strftime("%d-%m-%Y %H:%M"), 'standard_name': 'water_potential_evaporation_amount', 'long_name': 'FAO reference crop evaporation amount', 'units': 'kg m-2', 'label_units': 'kg m-2', 'plot_label': 'FAO56-Penman-Monteith ETo (kg m-2)', 'description': 'FAO56-Penman-Monteith reference crop potential evaporation (kg m-2)', 'units_equivalent': 'mm', 'PE_calculation_method': 'FAO56 Penman-Monteith (Allen et al., 1998)', 'references': 'Allen, R. G., Pereira, L. S., Raes, D., & Smith, M. (1998). Crop evapotranspiration-Guidelines \
This computes FAO56 PM well-watered grass PE. """ from eto import ETo_xr, datasets from eto.util_xr import get_ukcp18_kwargs, prepare_input_from_ukcp18 import pandas as pd import numpy as np # test on generic dataset. # this dataset contains: # R_sm # T_max # T_min # e_a # along with date. et1 = ETo_xr() ex1_path = datasets.get_path('example_daily') dftemp = pd.read_csv(ex1_path, parse_dates=True, infer_datetime_format=True, index_col='date') ds = dftemp.to_xarray().assign_coords({ 'projection_x_coordinate': 20000, 'projection_y_coordinate': 50000 }).expand_dims(['projection_x_coordinate', 'projection_y_coordinate']) z_msl = 500 # known Elevation of the met station above mean sea level (m) (only needed if P is not in df). lat = -43.6 # knwon The latitude of the met station (dec deg) (only needed if R_s or R_n are not in df). lon = 172 # known The longitude of the met station (dec deg) (only needed if calculating ETo hourly) TZ_lon = 173 # known The longitude of the center of the time zone (dec deg) (only needed if calculating ETo hourly). # z_u = 2: The height of the wind speed measurement (m). Default is 2 m.
def test_eto_fao_daily(): et1 = ETo_xr(ds, 'D', z_msl, lat, lon, TZ_lon) eto1 = et1.eto_fao_xr(remove_extreme_values=False, round_decimals=2).sum() res1 = tsresults['ETo_FAO_mm'].sum() assert eto1 == res1
### Tests tsdata = pd.read_csv(example1, parse_dates=True, infer_datetime_format=True, index_col='date') tsresults = pd.read_csv(results1, parse_dates=True, infer_datetime_format=True, index_col='date') ds = tsdata.to_xarray().assign_coords({ 'projection_x_coordinate': 20000, 'projection_y_coordinate': 50000 }).expand_dims(['projection_x_coordinate', 'projection_y_coordinate']) self = ETo_xr(ds, 'D', z_msl, lat, lon, TZ_lon) # eto1 = et1.eto_fao().sum() # res1 = tsresults['ETo_FAO_mm'].sum() print("self:\n", self) remove_extreme_values = False round_decimals = 2 max_ETo = 15 min_ETo = 0 interp = False maxgap = 15 # def eto_fao(self, max_ETo=15, min_ETo=0, interp=False, maxgap=15, remove_extreme_values=True, round_decimals=2): """ Function to estimate reference ET (ETo) from the `FAO 56 paper <http://www.fao.org/docrep/X0490E/X0490E00.htm>`_ [1]_ using a minimum of T_min and T_max for daily estimates and T_mean and RH_mean for hourly, but optionally utilising the maximum number of available met parameters. The function prioritizes the estimation of specific parameters based on the available input data.
'projection_y_coordinate': 50000 }).expand_dims(['projection_x_coordinate', 'projection_y_coordinate']) def test_eto_fao_daily(): et1 = ETo_xr(ds, 'D', z_msl, lat, lon, TZ_lon) eto1 = et1.eto_fao_xr(remove_extreme_values=False, round_decimals=2).sum() res1 = tsresults['ETo_FAO_mm'].sum() assert eto1 == res1 et1 = ETo_xr(ds, 'D', z_msl, lat, lon, TZ_lon, remove_extreme_values=False, round_decimals=2) # # TODO # def test_eto_har_daily(): # pass # eto2 = et1.eto_hargreaves_xr().sum() # res1 = tsresults['ETo_Har_mm'].sum() # # assert eto2 == res1 # # TODO # def test_eto_fao_hourly(): # pass