From 58db042726243faf140e4d80bd04bff10d11ae2d Mon Sep 17 00:00:00 2001 From: richardarsenault Date: Mon, 24 Feb 2020 09:20:07 -0500 Subject: [PATCH 1/5] initial NRCAN data tests with HMETS --- tests/test_NRCAN_daily.py | 107 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 107 insertions(+) create mode 100644 tests/test_NRCAN_daily.py diff --git a/tests/test_NRCAN_daily.py b/tests/test_NRCAN_daily.py new file mode 100644 index 00000000..0e9fd1d7 --- /dev/null +++ b/tests/test_NRCAN_daily.py @@ -0,0 +1,107 @@ +import pytest +import datetime as dt +import numpy as np +import xarray as xr +import netCDF4 as nc + +from pywps import Service +from pywps.tests import assert_response_success + +from . common import client_for, TESTDATA, CFG_FILE, get_output, urlretrieve +from raven.processes import RavenHMETSProcess +import pdb + +class TestRavenERA5Process: + + def test_simple(self): + client = client_for(Service(processes=[RavenHMETSProcess(), ], cfgfiles=CFG_FILE)) + + startYear=2007 + + 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' + tasmax='https://pavics.ouranos.ca/twitcher/ows/proxy/thredds/dodsC/birdhouse/nrcan/nrcan_canada_daily_v2/tasmax/nrcan_canada_daily_tasmax_' + tasmin = 'https://pavics.ouranos.ca/twitcher/ows/proxy/thredds/dodsC/birdhouse/nrcan/nrcan_canada_daily_v2/tasmin/nrcan_canada_daily_tasmin_' + precip = 'https://pavics.ouranos.ca/twitcher/ows/proxy/thredds/dodsC/birdhouse/nrcan/nrcan_canada_daily_v2/pr/nrcan_canada_daily_pr_' + + # Get information for given catchment, could be passed in parameter to the function + salmon=xr.open_dataset(TESTDATA['raven-hmets-nc-ts']) + salmon_lat = salmon.lat.values[0] + salmon_lon = salmon.lon.values[0] + + # Get first year + firstYear=str(startYear) + tmaxYear=xr.open_dataset(tasmax + firstYear + '.nc').sel(lon=salmon_lon, lat=salmon_lat, method='nearest') + tminYear=xr.open_dataset(tasmin + firstYear + '.nc').sel(lon=salmon_lon, lat=salmon_lat, method='nearest') + prYear=xr.open_dataset(precip + firstYear + '.nc').sel(lon=salmon_lon, lat=salmon_lat, method='nearest') + + # Now extract all years + for i in range(startYear+1,2009): + + tmaxYear=xr.concat([tmaxYear,xr.open_dataset(tasmax + str(i) + '.nc').sel(lon=salmon_lon, lat=salmon_lat, method='nearest')],dim='time') + tminYear=xr.concat([tminYear,xr.open_dataset(tasmin + str(i) + '.nc').sel(lon=salmon_lon, lat=salmon_lat, method='nearest')],dim='time') + prYear=xr.concat([prYear,xr.open_dataset(precip + str(i) + '.nc').sel(lon=salmon_lon, lat=salmon_lat, method='nearest')],dim='time') + + # Now we need to stack years one after the other + + + main=tmaxYear.merge(tminYear,compat='override') + main=main.merge(prYear,compat='override') + main.to_netcdf('/home/ets/TEST_NRCAN.nc') + pdb.set_trace() + D = nc.Dataset('/home/ets/TEST_NRCAN.nc', "a") + D.variables["time"].units = "days since " + str(startYear) + "-01-01 00:00:00" + D.close() + D = nc.Dataset('/home/ets/TEST_NRCAN.nc', "r+") + D.variables["time"] = list(range(0,D.variables["tasmax"].shape[0])) + D.close() + + ''' + need to write netcdf file here, I did it outside Python. Probably possible to pass a netcdf file directly? + ''' + datainputs = "ts=files@xlink:href=file://{ts};" \ + "params={params};" \ + "start_date={start_date};" \ + "end_date={end_date};" \ + "init={init};" \ + "name={name};" \ + "run_name={run_name};" \ + "area={area};" \ + "latitude={latitude};" \ + "longitude={longitude};" \ + "elevation={elevation};" \ + .format(ts='/home/ets/TEST_NRCAN.nc', # This is a file on disk, need to pass 'g' + params=params, + start_date=dt.datetime(2008, 1, 1), + end_date=dt.datetime(2008, 8, 10), + init='155,455', + name='Salmon', + run_name='test-hmets-NRCAN', + area='4250.6', + elevation='843.0', + latitude=salmon_lat, + longitude=salmon_lon, + ) + + resp = client.get( + service='WPS', request='Execute', version='1.0.0', identifier='raven-hmets', + datainputs=datainputs) + pdb.set_trace() + assert_response_success(resp) + out = get_output(resp.xml) + assert 'diagnostics' in out + tmp_file, _ = urlretrieve(out['diagnostics']) + tmp_content = open(tmp_file).readlines() + + # checking correctness of NSE (full period 1954-2011 would be NSE=0.636015 as template in Wiki) + assert 'DIAG_NASH_SUTCLIFFE' in tmp_content[0] + idx_diag = tmp_content[0].split(',').index("DIAG_NASH_SUTCLIFFE") + diag = np.float(tmp_content[1].split(',')[idx_diag]) + np.testing.assert_almost_equal(diag, -7.03141, 4, err_msg='NSE is not matching expected value') + + # checking correctness of RMSE (full period 1954-2011 would be RMSE=28.3759 as template in wiki) + assert 'DIAG_RMSE' in tmp_content[0] + idx_diag = tmp_content[0].split(',').index("DIAG_RMSE") + diag = np.float(tmp_content[1].split(',')[idx_diag]) + + np.testing.assert_almost_equal(diag, 101.745, 4, err_msg='RMSE is not matching expected value') From 55fe54fb4cec4cdde95e7e45f7cabb38703a905b Mon Sep 17 00:00:00 2001 From: richardarsenault Date: Mon, 2 Mar 2020 19:43:51 -0500 Subject: [PATCH 2/5] NRCAN test with assertion error to check --- tests/test_NRCAN_daily.py | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/tests/test_NRCAN_daily.py b/tests/test_NRCAN_daily.py index 0e9fd1d7..40149a1a 100644 --- a/tests/test_NRCAN_daily.py +++ b/tests/test_NRCAN_daily.py @@ -2,8 +2,8 @@ import datetime as dt import numpy as np import xarray as xr +import json import netCDF4 as nc - from pywps import Service from pywps.tests import assert_response_success @@ -41,21 +41,19 @@ def test_simple(self): tmaxYear=xr.concat([tmaxYear,xr.open_dataset(tasmax + str(i) + '.nc').sel(lon=salmon_lon, lat=salmon_lat, method='nearest')],dim='time') tminYear=xr.concat([tminYear,xr.open_dataset(tasmin + str(i) + '.nc').sel(lon=salmon_lon, lat=salmon_lat, method='nearest')],dim='time') prYear=xr.concat([prYear,xr.open_dataset(precip + str(i) + '.nc').sel(lon=salmon_lon, lat=salmon_lat, method='nearest')],dim='time') - + # Now we need to stack years one after the other main=tmaxYear.merge(tminYear,compat='override') main=main.merge(prYear,compat='override') main.to_netcdf('/home/ets/TEST_NRCAN.nc') - pdb.set_trace() D = nc.Dataset('/home/ets/TEST_NRCAN.nc', "a") D.variables["time"].units = "days since " + str(startYear) + "-01-01 00:00:00" D.close() D = nc.Dataset('/home/ets/TEST_NRCAN.nc', "r+") D.variables["time"] = list(range(0,D.variables["tasmax"].shape[0])) - D.close() - + D.close() ''' need to write netcdf file here, I did it outside Python. Probably possible to pass a netcdf file directly? ''' @@ -70,10 +68,14 @@ def test_simple(self): "latitude={latitude};" \ "longitude={longitude};" \ "elevation={elevation};" \ + "rain_snow_fraction={rain_snow_fraction};"\ + "nc_spec={tasmax};"\ + "nc_spec={tasmin};"\ + "nc_spec={pr}"\ .format(ts='/home/ets/TEST_NRCAN.nc', # This is a file on disk, need to pass 'g' params=params, - start_date=dt.datetime(2008, 1, 1), - end_date=dt.datetime(2008, 8, 10), + start_date=dt.datetime(2007, 1, 1), + end_date=dt.datetime(2007, 8, 10), init='155,455', name='Salmon', run_name='test-hmets-NRCAN', @@ -81,18 +83,23 @@ def test_simple(self): elevation='843.0', latitude=salmon_lat, longitude=salmon_lon, + rain_snow_fraction="RAINSNOW_DINGMAN", + tasmax=json.dumps({'tasmax': {'linear_transform': (1.0, -273.15)}}), + tasmin=json.dumps({'tasmin': {'linear_transform': (1.0, -273.15)}}), + pr=json.dumps({'pr': {'linear_transform': (86400.0, 0.0)}}), ) - + resp = client.get( service='WPS', request='Execute', version='1.0.0', identifier='raven-hmets', datainputs=datainputs) - pdb.set_trace() + assert_response_success(resp) out = get_output(resp.xml) assert 'diagnostics' in out tmp_file, _ = urlretrieve(out['diagnostics']) tmp_content = open(tmp_file).readlines() - + + pdb.set_trace() # checking correctness of NSE (full period 1954-2011 would be NSE=0.636015 as template in Wiki) assert 'DIAG_NASH_SUTCLIFFE' in tmp_content[0] idx_diag = tmp_content[0].split(',').index("DIAG_NASH_SUTCLIFFE") From 5d9c9eef5666115558ab4f02dd02e814f173fb52 Mon Sep 17 00:00:00 2001 From: richardarsenault Date: Mon, 2 Mar 2020 20:54:28 -0500 Subject: [PATCH 3/5] Updated tests for NRCAN --- tests/test_NRCAN_daily.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/tests/test_NRCAN_daily.py b/tests/test_NRCAN_daily.py index 40149a1a..5791fad9 100644 --- a/tests/test_NRCAN_daily.py +++ b/tests/test_NRCAN_daily.py @@ -9,7 +9,7 @@ from . common import client_for, TESTDATA, CFG_FILE, get_output, urlretrieve from raven.processes import RavenHMETSProcess -import pdb + class TestRavenERA5Process: @@ -95,11 +95,15 @@ def test_simple(self): assert_response_success(resp) out = get_output(resp.xml) + + """ + # THERE IS NO QOBS HERE SO NO TESTING OF NASH PERFORMANCE + assert 'diagnostics' in out tmp_file, _ = urlretrieve(out['diagnostics']) tmp_content = open(tmp_file).readlines() - pdb.set_trace() + # checking correctness of NSE (full period 1954-2011 would be NSE=0.636015 as template in Wiki) assert 'DIAG_NASH_SUTCLIFFE' in tmp_content[0] idx_diag = tmp_content[0].split(',').index("DIAG_NASH_SUTCLIFFE") @@ -112,3 +116,4 @@ def test_simple(self): diag = np.float(tmp_content[1].split(',')[idx_diag]) np.testing.assert_almost_equal(diag, 101.745, 4, err_msg='RMSE is not matching expected value') + """ \ No newline at end of file From 2bd29f5c4d6760ce5927b9ced326899b286edef8 Mon Sep 17 00:00:00 2001 From: richardarsenault Date: Mon, 2 Mar 2020 21:40:50 -0500 Subject: [PATCH 4/5] Final NRCAN tests done and passing --- tests/test_NRCAN_daily.py | 109 ++++++++++++++++++++++++-------------- 1 file changed, 69 insertions(+), 40 deletions(-) diff --git a/tests/test_NRCAN_daily.py b/tests/test_NRCAN_daily.py index 5791fad9..87cbee1c 100644 --- a/tests/test_NRCAN_daily.py +++ b/tests/test_NRCAN_daily.py @@ -6,57 +6,86 @@ import netCDF4 as nc from pywps import Service from pywps.tests import assert_response_success +import os from . common import client_for, TESTDATA, CFG_FILE, get_output, urlretrieve from raven.processes import RavenHMETSProcess +from raven.models import HMETS + +# THIS SECTION BASICALLY PREPARES A NETCDF FILE TO RUN THE TESTS... +startYear=2007 +path = os.getcwd() +filepath = path + "/NRCAN_ts.nc" +tasmax='https://pavics.ouranos.ca/twitcher/ows/proxy/thredds/dodsC/birdhouse/nrcan/nrcan_canada_daily_v2/tasmax/nrcan_canada_daily_tasmax_' +tasmin = 'https://pavics.ouranos.ca/twitcher/ows/proxy/thredds/dodsC/birdhouse/nrcan/nrcan_canada_daily_v2/tasmin/nrcan_canada_daily_tasmin_' +precip = 'https://pavics.ouranos.ca/twitcher/ows/proxy/thredds/dodsC/birdhouse/nrcan/nrcan_canada_daily_v2/pr/nrcan_canada_daily_pr_' + +# Get information for given catchment, could be passed in parameter to the function +salmon=xr.open_dataset(TESTDATA['raven-hmets-nc-ts']) +salmon_lat = salmon.lat.values[0] +salmon_lon = salmon.lon.values[0] + +# Get first year +firstYear=str(startYear) +tmaxYear=xr.open_dataset(tasmax + firstYear + '.nc').sel(lon=salmon_lon, lat=salmon_lat, method='nearest') +tminYear=xr.open_dataset(tasmin + firstYear + '.nc').sel(lon=salmon_lon, lat=salmon_lat, method='nearest') +prYear=xr.open_dataset(precip + firstYear + '.nc').sel(lon=salmon_lon, lat=salmon_lat, method='nearest') + +# Now extract all years +for i in range(startYear+1,2009): + + tmaxYear=xr.concat([tmaxYear,xr.open_dataset(tasmax + str(i) + '.nc').sel(lon=salmon_lon, lat=salmon_lat, method='nearest')],dim='time') + tminYear=xr.concat([tminYear,xr.open_dataset(tasmin + str(i) + '.nc').sel(lon=salmon_lon, lat=salmon_lat, method='nearest')],dim='time') + prYear=xr.concat([prYear,xr.open_dataset(precip + str(i) + '.nc').sel(lon=salmon_lon, lat=salmon_lat, method='nearest')],dim='time') + +# Merge and fix time units so that RAVEN understands +main=tmaxYear.merge(tminYear,compat='override') +main=main.merge(prYear,compat='override') +main.to_netcdf(filepath) +D = nc.Dataset(filepath, "a") +D.variables["time"].units = "days since " + str(startYear) + "-01-01 00:00:00" +D.close() +D = nc.Dataset(filepath, "r+") +D.variables["time"] = list(range(0,D.variables["tasmax"].shape[0])) +D.close() + + +class TestRavenNRCAN: + 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) + + model = HMETS() + model(ts=filepath, + params=params, + start_date=dt.datetime(2007, 1, 1), + end_date=dt.datetime(2007, 8, 10), + 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)} + ) + + + class TestRavenERA5Process: def test_simple(self): client = client_for(Service(processes=[RavenHMETSProcess(), ], cfgfiles=CFG_FILE)) - startYear=2007 - 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' - tasmax='https://pavics.ouranos.ca/twitcher/ows/proxy/thredds/dodsC/birdhouse/nrcan/nrcan_canada_daily_v2/tasmax/nrcan_canada_daily_tasmax_' - tasmin = 'https://pavics.ouranos.ca/twitcher/ows/proxy/thredds/dodsC/birdhouse/nrcan/nrcan_canada_daily_v2/tasmin/nrcan_canada_daily_tasmin_' - precip = 'https://pavics.ouranos.ca/twitcher/ows/proxy/thredds/dodsC/birdhouse/nrcan/nrcan_canada_daily_v2/pr/nrcan_canada_daily_pr_' - - # Get information for given catchment, could be passed in parameter to the function - salmon=xr.open_dataset(TESTDATA['raven-hmets-nc-ts']) - salmon_lat = salmon.lat.values[0] - salmon_lon = salmon.lon.values[0] - - # Get first year - firstYear=str(startYear) - tmaxYear=xr.open_dataset(tasmax + firstYear + '.nc').sel(lon=salmon_lon, lat=salmon_lat, method='nearest') - tminYear=xr.open_dataset(tasmin + firstYear + '.nc').sel(lon=salmon_lon, lat=salmon_lat, method='nearest') - prYear=xr.open_dataset(precip + firstYear + '.nc').sel(lon=salmon_lon, lat=salmon_lat, method='nearest') - - # Now extract all years - for i in range(startYear+1,2009): - - tmaxYear=xr.concat([tmaxYear,xr.open_dataset(tasmax + str(i) + '.nc').sel(lon=salmon_lon, lat=salmon_lat, method='nearest')],dim='time') - tminYear=xr.concat([tminYear,xr.open_dataset(tasmin + str(i) + '.nc').sel(lon=salmon_lon, lat=salmon_lat, method='nearest')],dim='time') - prYear=xr.concat([prYear,xr.open_dataset(precip + str(i) + '.nc').sel(lon=salmon_lon, lat=salmon_lat, method='nearest')],dim='time') - - # Now we need to stack years one after the other - - main=tmaxYear.merge(tminYear,compat='override') - main=main.merge(prYear,compat='override') - main.to_netcdf('/home/ets/TEST_NRCAN.nc') - D = nc.Dataset('/home/ets/TEST_NRCAN.nc', "a") - D.variables["time"].units = "days since " + str(startYear) + "-01-01 00:00:00" - D.close() - D = nc.Dataset('/home/ets/TEST_NRCAN.nc', "r+") - D.variables["time"] = list(range(0,D.variables["tasmax"].shape[0])) - D.close() - ''' - need to write netcdf file here, I did it outside Python. Probably possible to pass a netcdf file directly? - ''' datainputs = "ts=files@xlink:href=file://{ts};" \ "params={params};" \ "start_date={start_date};" \ @@ -72,7 +101,7 @@ def test_simple(self): "nc_spec={tasmax};"\ "nc_spec={tasmin};"\ "nc_spec={pr}"\ - .format(ts='/home/ets/TEST_NRCAN.nc', # This is a file on disk, need to pass 'g' + .format(ts=filepath, # This is a file on disk, need to pass 'g' params=params, start_date=dt.datetime(2007, 1, 1), end_date=dt.datetime(2007, 8, 10), @@ -96,7 +125,7 @@ def test_simple(self): assert_response_success(resp) out = get_output(resp.xml) - """ + """ # THERE IS NO QOBS HERE SO NO TESTING OF NASH PERFORMANCE assert 'diagnostics' in out From c9403ca249aad7af5f62e08c46ab545337bcedfa Mon Sep 17 00:00:00 2001 From: richardarsenault Date: Thu, 30 Apr 2020 16:54:33 -0400 Subject: [PATCH 5/5] Added tests for NRCAN --- tests/test_NRCAN_daily.py | 94 +++++++++++++-------------------------- 1 file changed, 30 insertions(+), 64 deletions(-) diff --git a/tests/test_NRCAN_daily.py b/tests/test_NRCAN_daily.py index 87cbee1c..ba5e8e8e 100644 --- a/tests/test_NRCAN_daily.py +++ b/tests/test_NRCAN_daily.py @@ -3,53 +3,35 @@ import numpy as np import xarray as xr import json -import netCDF4 as nc +import matplotlib.pyplot as plt from pywps import Service from pywps.tests import assert_response_success -import os +import tempfile from . common import client_for, TESTDATA, CFG_FILE, get_output, urlretrieve from raven.processes import RavenHMETSProcess from raven.models import HMETS +NRCAN_path='https://pavics.ouranos.ca/twitcher/ows/proxy/thredds/dodsC/birdhouse/1-Datasets/gridded_obs/nrcan_v2.ncml' -# THIS SECTION BASICALLY PREPARES A NETCDF FILE TO RUN THE TESTS... -startYear=2007 -path = os.getcwd() -filepath = path + "/NRCAN_ts.nc" -tasmax='https://pavics.ouranos.ca/twitcher/ows/proxy/thredds/dodsC/birdhouse/nrcan/nrcan_canada_daily_v2/tasmax/nrcan_canada_daily_tasmax_' -tasmin = 'https://pavics.ouranos.ca/twitcher/ows/proxy/thredds/dodsC/birdhouse/nrcan/nrcan_canada_daily_v2/tasmin/nrcan_canada_daily_tasmin_' -precip = 'https://pavics.ouranos.ca/twitcher/ows/proxy/thredds/dodsC/birdhouse/nrcan/nrcan_canada_daily_v2/pr/nrcan_canada_daily_pr_' +# Temporary path +filepath = tempfile.mkdtemp() + "/NRCAN_ts.nc" # Get information for given catchment, could be passed in parameter to the function salmon=xr.open_dataset(TESTDATA['raven-hmets-nc-ts']) -salmon_lat = salmon.lat.values[0] -salmon_lon = salmon.lon.values[0] +lat = salmon.lat.values[0] +lon = salmon.lon.values[0] -# Get first year -firstYear=str(startYear) -tmaxYear=xr.open_dataset(tasmax + firstYear + '.nc').sel(lon=salmon_lon, lat=salmon_lat, method='nearest') -tminYear=xr.open_dataset(tasmin + firstYear + '.nc').sel(lon=salmon_lon, lat=salmon_lat, method='nearest') -prYear=xr.open_dataset(precip + firstYear + '.nc').sel(lon=salmon_lon, lat=salmon_lat, method='nearest') +#Start and end dates +start_date=dt.datetime(2006, 1, 1) +end_date=dt.datetime(2007, 12, 31) + +# Get data for the covered period including a 1-degree bounding box for good measure. Eventually we will be +# able to take the catchment polygon as a mask and average points residing inside. -# Now extract all years -for i in range(startYear+1,2009): - - tmaxYear=xr.concat([tmaxYear,xr.open_dataset(tasmax + str(i) + '.nc').sel(lon=salmon_lon, lat=salmon_lat, method='nearest')],dim='time') - tminYear=xr.concat([tminYear,xr.open_dataset(tasmin + str(i) + '.nc').sel(lon=salmon_lon, lat=salmon_lat, method='nearest')],dim='time') - prYear=xr.concat([prYear,xr.open_dataset(precip + str(i) + '.nc').sel(lon=salmon_lon, lat=salmon_lat, method='nearest')],dim='time') - -# Merge and fix time units so that RAVEN understands -main=tmaxYear.merge(tminYear,compat='override') -main=main.merge(prYear,compat='override') -main.to_netcdf(filepath) -D = nc.Dataset(filepath, "a") -D.variables["time"].units = "days since " + str(startYear) + "-01-01 00:00:00" -D.close() -D = nc.Dataset(filepath, "r+") -D.variables["time"] = list(range(0,D.variables["tasmax"].shape[0])) -D.close() +ds=xr.open_dataset(NRCAN_path).sel(lat=slice(lat+1,lat-1), lon=slice(lon-1,lon+1), time=slice(start_date, end_date)).mean(dim={'lat','lon'}, keep_attrs=True) +ds.to_netcdf(filepath) class TestRavenNRCAN: @@ -58,12 +40,12 @@ 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) - + model = HMETS() model(ts=filepath, params=params, - start_date=dt.datetime(2007, 1, 1), - end_date=dt.datetime(2007, 8, 10), + start_date=start_date, + end_date=end_date, name='Salmon', run_name='test-hmets-NRCAN', area=4250.6, @@ -76,16 +58,15 @@ def test_simple(self): pr={'linear_transform': (86400, 0.0)} ) - -class TestRavenERA5Process: +class TestRavenNRCANProcess: def test_simple(self): client = client_for(Service(processes=[RavenHMETSProcess(), ], cfgfiles=CFG_FILE)) 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' - + datainputs = "ts=files@xlink:href=file://{ts};" \ "params={params};" \ "start_date={start_date};" \ @@ -103,15 +84,15 @@ def test_simple(self): "nc_spec={pr}"\ .format(ts=filepath, # This is a file on disk, need to pass 'g' params=params, - start_date=dt.datetime(2007, 1, 1), - end_date=dt.datetime(2007, 8, 10), + start_date=start_date, + end_date=end_date, init='155,455', name='Salmon', run_name='test-hmets-NRCAN', area='4250.6', elevation='843.0', - latitude=salmon_lat, - longitude=salmon_lon, + latitude=lat, + longitude=lon, rain_snow_fraction="RAINSNOW_DINGMAN", tasmax=json.dumps({'tasmax': {'linear_transform': (1.0, -273.15)}}), tasmin=json.dumps({'tasmin': {'linear_transform': (1.0, -273.15)}}), @@ -123,26 +104,11 @@ def test_simple(self): datainputs=datainputs) assert_response_success(resp) - out = get_output(resp.xml) - - """ - # THERE IS NO QOBS HERE SO NO TESTING OF NASH PERFORMANCE - assert 'diagnostics' in out - tmp_file, _ = urlretrieve(out['diagnostics']) - tmp_content = open(tmp_file).readlines() + # For testing purposes + #out = get_output(resp.xml) + #tmp_file, _ = urlretrieve(out['hydrograph']) + #tmp=xr.open_dataset(tmp_file) + #plt.plot(tmp['q_sim']) + #plt.show() - - # checking correctness of NSE (full period 1954-2011 would be NSE=0.636015 as template in Wiki) - assert 'DIAG_NASH_SUTCLIFFE' in tmp_content[0] - idx_diag = tmp_content[0].split(',').index("DIAG_NASH_SUTCLIFFE") - diag = np.float(tmp_content[1].split(',')[idx_diag]) - np.testing.assert_almost_equal(diag, -7.03141, 4, err_msg='NSE is not matching expected value') - - # checking correctness of RMSE (full period 1954-2011 would be RMSE=28.3759 as template in wiki) - assert 'DIAG_RMSE' in tmp_content[0] - idx_diag = tmp_content[0].split(',').index("DIAG_RMSE") - diag = np.float(tmp_content[1].split(',')[idx_diag]) - - np.testing.assert_almost_equal(diag, 101.745, 4, err_msg='RMSE is not matching expected value') - """ \ No newline at end of file