def test_overwrite(self): ts = TESTDATA['raven-gr4j-cemaneige-nc-ts'] model = GR4JCN() 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=(0.529, -3.396, 407.29, 1.072, 16.9, 0.947) ) qsim1 = model.q_sim.copy(deep=True) m1 = qsim1.mean() model(ts, params=(0.5289, -3.397, 407.3, 1.071, 16.89, .948), overwrite=True) qsim2 = model.q_sim.copy(deep=True) m2 = qsim2.mean() assert m1 != m2 np.testing.assert_almost_equal(m1, m2, 1) d = model.diagnostics np.testing.assert_almost_equal(d['DIAG_NASH_SUTCLIFFE'], -0.0269642, 2)
def test_simple(self): ts = TESTDATA['raven-gr4j-cemaneige-nc-ts'] model = GR4JCN(tempfile.mkdtemp()) model.rvi.start_date = dt.datetime(2000, 1, 1) model.rvi.end_date = dt.datetime(2002, 1, 1) model.rvi.run_name = 'test' model.rvh.name = 'Salmon' model.rvh.area = '4250.6' model.rvh.elevation = '843.0' model.rvh.latitude = 54.4848 model.rvh.longitude = -123.3659 model.rvp.params = model.params(0.529, -3.396, 407.29, 1.072, 16.9, 0.947) model([ts, ]) d = model.diagnostics # yields NSE=0.???? for full period 1954-2010 np.testing.assert_almost_equal(d['DIAG_NASH_SUTCLIFFE'], -0.0371048, 2) hds = model.q_sim assert hds.attrs['long_name'] == 'Simulated outflows' # Check attributes assert model.hydrograph.attrs['model_id'] == 'gr4jcn'
def test_simple(self): ts = TESTDATA['ostrich-gr4j-cemaneige-nc-ts'] model = GR4JCN_OST() params = (0.529, -3.396, 407.29, 1.072, 16.9, 0.053) low = (0.01, -15.0, 10.0, 0.0, 1.0, 0.0) high = (2.5, 10.0, 700.0, 7.0, 30.0, 1.0) model(ts, start_date=dt.datetime(1954, 1, 1), duration=208, area=4250.6, elevation=843.0, latitude=54.4848, longitude=-123.3659, params=params, lowerBounds=low, upperBounds=high, algorithm='DDS', random_seed=0, max_iterations=10, ) d = model.diagnostics np.testing.assert_almost_equal(d['DIAG_NASH_SUTCLIFFE'], 0.486033, 4) # Random number seed: 123 # Budget: 10 # Algorithm: DDS # :StartDate 1954-01-01 00:00:00 # :Duration 208 opt_para = model.calibrated_params opt_func = model.obj_func np.testing.assert_almost_equal(opt_para, [2.423961, 3.758972, 204.3856, 5.866946, 16.60408, 0.3728098], 4, err_msg='calibrated parameter set is not matching expected value') np.testing.assert_almost_equal(opt_func, -0.486033, 4, err_msg='calibrated NSE is not matching expected value') # # 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') gr4j = GR4JCN() gr4j(ts, start_date=dt.datetime(1954, 1, 1), duration=208, area=4250.6, elevation=843.0, latitude=54.4848, longitude=-123.3659, params=opt_para, ) np.testing.assert_almost_equal(gr4j.diagnostics['DIAG_NASH_SUTCLIFFE'], d['DIAG_NASH_SUTCLIFFE'])
def test_assign(self): model = GR4JCN() model.assign('run_name', 'test') assert model.rvi.run_name == 'test' model.assign('params', np.array([0.529, -3.396, 407.29, 1.072, 16.9, 0.947])) assert model.rvp.params.GR4J_X1 == 0.529 model.assign('params', [0.529, -3.396, 407.29, 1.072, 16.9, 0.947]) assert model.rvp.params.GR4J_X1 == 0.529 model.assign('params', (0.529, -3.396, 407.29, 1.072, 16.9, 0.947)) assert model.rvp.params.GR4J_X1 == 0.529
def test_run(self): ts = TESTDATA['raven-gr4j-cemaneige-nc-ts'] model = GR4JCN() 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=(0.529, -3.396, 407.29, 1.072, 16.9, 0.947) ) d = model.diagnostics np.testing.assert_almost_equal(d['DIAG_NASH_SUTCLIFFE'], -0.0371048, 2)
def test_parallel_params(self): ts = TESTDATA['raven-gr4j-cemaneige-nc-ts'] model = GR4JCN() 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=[(0.529, -3.396, 407.29, 1.072, 16.9, 0.947), (0.528, -3.4, 407.3, 1.07, 17, .95)] ) assert len(model.diagnostics) == 2 assert model.hydrograph.dims['params'] == 2
def test_parallel_basins(self, input2d): ts = input2d model = GR4JCN() 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=[0.529, -3.396, 407.29, 1.072, 16.9, 0.947], nc_index=[0, 0], name=['basin1', 'basin2'], ) assert len(model.diagnostics) == 2 assert len(model.hydrograph.nbasins) == 2 np.testing.assert_array_equal(model.hydrograph.basin_name[:], ['basin1', 'basin2'])
from pywps import LiteralInput LOGGER = logging.getLogger("PYWPS") """ Notes ----- The configuration files for RAVEN's GR4J-Cemaneige model and in models/raven-gr4j-cemaneige. All parameters that could potentially be user-defined are tagged using {}. These tags need to be replaced by actual values before the model is launched. """ params_defaults = GR4JCN.params(GR4J_X1=0.529, GR4J_X2=-3.396, GR4J_X3=407.29, GR4J_X4=1.072, CEMANEIGE_X1=16.9, CEMANEIGE_X2=0.947) params = LiteralInput('params', 'Comma separated list of model parameters', abstract='Parameters: ' + ', '.join(params_defaults._fields), data_type='string', default=', '.join(str(p) for p in list(params_defaults)), min_occurs=0, max_occurs=config.max_parallel_processes) class RavenGR4JCemaNeigeProcess(RavenProcess): """ RAVEN emulator for the GR4J-Cemaneige model.
def test_rvobjs(self): model = GR4JCN(tempfile.mkdtemp()) a = model.rvobjs assert a
def test_tags(self): model = GR4JCN(tempfile.mkdtemp()) tags = model.tags assert 'run_name' in tags
def test_version(self): model = Raven() assert model.version == '2.9' model = GR4JCN() assert model.version == '2.9'