Skip to content

Commit

Permalink
fix some test data loading
Browse files Browse the repository at this point in the history
  • Loading branch information
Zeitsperre committed Jan 12, 2024
1 parent 66c5e52 commit 854414b
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 22 deletions.
105 changes: 83 additions & 22 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import re
from shutil import copyfile

import netCDF4 as nc4
from click.testing import CliRunner
Expand All @@ -13,6 +14,16 @@ def test_generate_grid_weights_with_nc_input_and_2d_coords(
):
runner = CliRunner()
output_path = tmp_path / "bla.rvt"

copyfile(
get_local_testdata("raven-routing-sample/VIC_streaminputs.nc"),
tmp_path / "VIC_streaminputs.nc",
)
copyfile(
get_local_testdata("raven-routing-sample/finalcat_hru_info.zip"),
tmp_path / "finalcat_hru_info.zip",
)

params = [
"-c",
"HRU_ID",
Expand All @@ -21,8 +32,8 @@ def test_generate_grid_weights_with_nc_input_and_2d_coords(
"lat",
"-o",
output_path,
get_local_testdata("raven-routing-sample/VIC_streaminputs.nc"),
get_local_testdata("raven-routing-sample/finalcat_hru_info.zip"),
tmp_path / "VIC_streaminputs.nc",
tmp_path / "finalcat_hru_info.zip",
]
params = list(map(str, params))

Expand All @@ -48,13 +59,19 @@ def test_generate_grid_weights_with_multiple_subids(
# needs a "routing-file-path" with multiple gauges
runner = CliRunner()
output_path = tmp_path / "bla.rvt"

copyfile(
get_local_testdata("raven-routing-sample/VIC_streaminputs.nc"),
tmp_path / "VIC_streaminputs.nc",
)
copyfile(
get_local_testdata("raven-routing-sample/finalcat_hru_info.zip"),
tmp_path / "finalcat_hru_info.zip",
)

params = [
get_local_testdata(
"raven-routing-sample/VIC_streaminputs.nc",
),
get_local_testdata(
"raven-routing-sample/finalcat_hru_info.zip",
),
tmp_path / "VIC_streaminputs.nc",
tmp_path / "finalcat_hru_info.zip",
"-c",
"HRU_ID",
"-v",
Expand Down Expand Up @@ -89,13 +106,19 @@ def test_generate_grid_weights_with_nc_input_and_1d_coords(
):
runner = CliRunner()
output_path = tmp_path / "bla.rvt"

copyfile(
get_local_testdata("raven-routing-sample/era5-test-dataset-crop.nc"),
tmp_path / "era5-test-dataset-crop.nc",
)
copyfile(
get_local_testdata("raven-routing-sample/finalcat_hru_info.zip"),
tmp_path / "finalcat_hru_info.zip",
)

params = [
get_local_testdata(
"raven-routing-sample/era5-test-dataset-crop.nc",
),
get_local_testdata(
"raven-routing-sample/finalcat_hru_info.zip",
),
tmp_path / "era5-test-dataset-crop.nc",
tmp_path / "finalcat_hru_info.zip",
"--var-names",
"longitude",
"latitude",
Expand Down Expand Up @@ -124,13 +147,23 @@ def test_generate_grid_weights_with_nc_input_and_1d_coords(
def test_generate_grid_weights_with_shp_input(self, tmp_path, get_local_testdata):
runner = CliRunner()
output_path = tmp_path / "bla.rvt"

copyfile(
get_local_testdata("raven-routing-sample/OTT_sub.zip"),
tmp_path / "OTT_sub.zip",
)
copyfile(
get_local_testdata("raven-routing-sample/finalcat_hru_info.zip"),
tmp_path / "finalcat_hru_info.zip",
)

params = [
"-c",
"HRU_ID",
"-o",
output_path,
get_local_testdata("raven-routing-sample/OTT_sub.zip"),
get_local_testdata("raven-routing-sample/finalcat_hru_info.zip"),
tmp_path / "OTT_sub.zip",
tmp_path / "finalcat_hru_info.zip",
]
params = map(str, params)

Expand All @@ -154,17 +187,25 @@ def test_generate_grid_weights_with_weight_rescaling(
):
runner = CliRunner()
output_path = tmp_path / "bla.rvt"

copyfile(
get_local_testdata("raven-routing-sample/OTT_sub.zip"),
tmp_path / "OTT_sub.zip",
)
copyfile(
get_local_testdata("raven-routing-sample/finalcat_hru_info.zip"),
tmp_path / "finalcat_hru_info.zip",
)

params = [
"--area-error-threshold",
"0.42",
"-c",
"HRU_ID",
"-o",
output_path,
get_local_testdata("raven-routing-sample/OTT_sub.zip"),
get_local_testdata(
"raven-routing-sample/finalcat_hru_info.zip",
),
tmp_path / "OTT_sub.zip",
tmp_path / "finalcat_hru_info.zip",
]
params = map(str, params)

Expand All @@ -189,13 +230,23 @@ def test_aggregate_forcings_to_hrus(self, tmp_path, get_local_testdata):
runner = CliRunner()
output_nc_file_path = tmp_path / "aggreg.nc"
output_weight_file_path = tmp_path / "weight_aggreg.rvt"
params = [

copyfile(
get_local_testdata(
"raven-routing-sample/VIC_streaminputs.nc",
),
tmp_path / "VIC_streaminputs.nc",
)
copyfile(
get_local_testdata(
"raven-routing-sample/VIC_streaminputs_weights.rvt",
),
tmp_path / "VIC_streaminputs_weights.rvt",
)

params = [
tmp_path / "VIC_streaminputs.nc",
tmp_path / "VIC_streaminputs_weights.rvt",
"-v",
"Streaminputs",
"--output-nc-file",
Expand Down Expand Up @@ -243,9 +294,19 @@ def test_aggregate_forcings_to_hrus_with_nodata(self, tmp_path, get_local_testda
runner = CliRunner()
output_nc_file_path = tmp_path / "aggreg.nc"
output_weight_file_path = tmp_path / "weight_aggreg.rvt"
params = [

copyfile(
get_local_testdata("raven-routing-sample/VIC_test_nodata.nc"),
tmp_path / "VIC_test_nodata.nc",
)
copyfile(
get_local_testdata("raven-routing-sample/VIC_test_nodata_weights.rvt"),
tmp_path / "VIC_test_nodata_weights.rvt",
)

params = [
tmp_path / "VIC_test_nodata.nc",
tmp_path / "VIC_test_nodata_weights.rvt",
"-v",
"et",
"--dim-names",
Expand Down
1 change: 1 addition & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ passenv =
COVERALLS_*
GDAL_VERSION
GITHUB_*
LD_LIBRARY_PATH
LD_PRELOAD
RAVENPY_*
extras =
Expand Down

0 comments on commit 854414b

Please sign in to comment.