def test_simple(self): ts = get_local_testdata("era5/tas_pr_20180101-20180108.nc") model = HMETS() model( ts=ts, params=params, start_date=dt.datetime(2018, 1, 1), end_date=dt.datetime(2018, 1, 3), run_name="test-hmets-era5", area=4250.6, elevation=843.0, latitude=54.4848, longitude=-123.3659, rain_snow_fraction="RAINSNOW_DINGMAN", tas={ "scale": 1.0, "offset": -273.15, "time_shift": -0.25 }, pr={ "scale": 24000.0, "offset": 0.0, "time_shift": -0.25 }, )
def test_simple(self): params = ( 9.5019, 0.2774, 6.3942, 0.6884, 1.2875, 5.4134, 2.3641, 0.0973, 0.0464, 0.1998, 0.0222, -1.0919, 2.6851, 0.3740, 1.0000, 0.4739, 0.0114, 0.0243, 0.0069, 310.7211, 916.1947, ) ts = get_local_testdata("nrcan/NRCAN_2006-2007_subset.nc") start_date = dt.datetime(2006, 1, 1) end_date = dt.datetime(2007, 12, 31) model = HMETS() model( ts=ts, params=params, start_date=start_date, end_date=end_date, name="Salmon", run_name="test-hmets-NRCAN", area=4250.6, elevation=843.0, latitude=54.4848, longitude=-123.3659, rain_snow_fraction="RAINSNOW_DINGMAN", tasmax={"linear_transform": (1.0, -273.15)}, tasmin={"linear_transform": (1.0, -273.15)}, pr={"linear_transform": (86400, 0.0)}, )
def test_simple(self): model = HMETS() params = ( 9.5019, 0.2774, 6.3942, 0.6884, 1.2875, 5.4134, 2.3641, 0.0973, 0.0464, 0.1998, 0.0222, -1.0919, 2.6851, 0.3740, 1.0000, 0.4739, 0.0114, 0.0243, 0.0069, 310.7211, 916.1947, ) model( TS, start_date=dt.datetime(2000, 1, 1), end_date=dt.datetime(2002, 1, 1), area=4250.6, elevation=843.0, latitude=54.4848, longitude=-123.3659, params=params, suppress_output=True, ) d = model.diagnostics np.testing.assert_almost_equal(d["DIAG_NASH_SUTCLIFFE"], -3.0132, 4)
def test_simple(self): model = HMETS_OST() model.configure( get_local_testdata("ostrich-gr4j-cemaneige/OstRandomNumbers.txt")) # Parameter bounds low = ( 0.3, 0.01, 0.5, 0.15, 0.0, 0.0, -2.0, 0.01, 0.0, 0.01, 0.005, -5.0, 0.0, 0.0, 0.0, 0.0, 0.00001, 0.0, 0.00001, 0.0, 0.0, ) high = ( 20.0, 5.0, 13.0, 1.5, 20.0, 20.0, 3.0, 0.2, 0.1, 0.3, 0.1, 2.0, 5.0, 1.0, 3.0, 1.0, 0.02, 0.1, 0.01, 0.5, 2.0, ) model( TS, start_date=dt.datetime(1954, 1, 1), duration=208, area=4250.6, elevation=843.0, latitude=54.4848, longitude=-123.3659, lowerBounds=low, upperBounds=high, algorithm="DDS", random_seed=0, max_iterations=10, ) d = model.diagnostics np.testing.assert_almost_equal(d["DIAG_NASH_SUTCLIFFE"], -1.43474, 4) opt_para = model.optimized_parameters opt_func = model.obj_func # # Random number seed: 123 # # Budget: 50 # # Algorithm: DDS # # :StartDate 1954-01-01 00:00:00 # # :Duration 20819 # np.testing.assert_almost_equal( opt_para, [0.3243268,3.034247,407.2890,2.722774,12.18124,0.9468769], 4, # err_msg='calibrated parameter set is not matching expected value') # np.testing.assert_almost_equal( opt_func, -0.5779910, 4, # err_msg='calibrated NSE is not matching expected value') # # Random number seed: 123 # # Budget: 10 # This is the setup used for testing: # Algorithm: DDS # shorter sim-period and lower budget # :StartDate 1954-01-01 00:00:00 # First tested that example below matches # :Duration 208 # expected_value = [ 1.777842e01, 3.317211e00, 5.727342e00, 1.419491e00, 1.382141e01, 1.637954e01, 7.166296e-01, 1.389346e-01, 2.620464e-02, 2.245525e-01, 2.839426e-02, -2.003810e00, 9.479623e-01, 4.803857e-01, 2.524914e00, 4.117232e-01, 1.950058e-02, 4.494123e-02, 1.405815e-03, 2.815803e-02, 1.007823e00, ] np.testing.assert_almost_equal( opt_para, expected_value, 4, err_msg="calibrated parameter set is not matching expected value", ) np.testing.assert_almost_equal( opt_func, 1.43474, 4, err_msg="calibrated NSE is not matching expected value", ) # # Random number seed: 123 # # # Budget: 50 # This is the setup in the Wiki: # # Algorithm: DDS # https://github.com/Ouranosinc/raven/wiki/ # # :StartDate 1954-01-01 00:00:00 # Technical-Notes#example-setups-for-hmets # # :Duration 20819 # # np.testing.assert_almost_equal(opt_para, [5.008045E+00, 7.960246E-02, 4.332698E+00, 4.978125E-01, # 1.997029E+00, 6.269773E-01, 1.516961E+00, 8.180383E-02, # 6.730663E-02, 2.137822E-02, 2.097163E-02, 1.773348E+00, # 3.036039E-01, 1.928524E-02, 1.758471E+00, 8.942299E-01, # 8.741980E-03, 5.036474E-02, 9.465804E-03, 1.851839E-01, # 1.653934E-01, 2.624006E+00, 8.868485E-02, 9.259195E+01, # 8.269670E+01], 4, # err_msg='calibrated parameter set is not matching expected value') # np.testing.assert_almost_equal(opt_func, -6.350490E-01, 4, # err_msg='calibrated NSE is not matching expected value') hmets = HMETS() hmets( TS, start_date=dt.datetime(1954, 1, 1), duration=208, area=4250.6, elevation=843.0, latitude=54.4848, longitude=-123.3659, params=model.calibrated_params, ) np.testing.assert_almost_equal( hmets.diagnostics["DIAG_NASH_SUTCLIFFE"], d["DIAG_NASH_SUTCLIFFE"], 4)
from . import wpsio as wio # Defaults for this process params_defaults = HMETS.params( GAMMA_SHAPE=9.5019, GAMMA_SCALE=0.2774, GAMMA_SHAPE2=6.3942, GAMMA_SCALE2=0.6884, MIN_MELT_FACTOR=1.2875, MAX_MELT_FACTOR=5.4134, DD_MELT_TEMP=2.3641, DD_AGGRADATION=0.0973, SNOW_SWI_MIN=0.0464, SNOW_SWI_MAX=0.1998, SWI_REDUCT_COEFF=0.0222, DD_REFREEZE_TEMP=-1.0919, REFREEZE_FACTOR=2.6851, REFREEZE_EXP=0.3740, PET_CORRECTION=1.0000, HMETS_RUNOFF_COEFF=0.4739, PERC_COEFF=0.0114, BASEFLOW_COEFF_1=0.0243, BASEFLOW_COEFF_2=0.0069, TOPSOIL=310.7211, PHREATIC=916.1947, ) params = LiteralInput( "params", "Comma separated list of model parameters",