-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add model testing w/ Docker container
- Loading branch information
1 parent
828b69b
commit 8bae092
Showing
6 changed files
with
118 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
WorkDir=tests/test_data/directories/ | ||
SoilPropertyPath=tests/test_data/directories/model_parameters/soil_property/ | ||
ForcingPath=tests/test_data/directories/forcing/plumber2_data/ | ||
Location=XX-Xxx | ||
directional=tests/test_data/directories/model_parameters/vegetation_property/directional/ | ||
fluspect_parameters=tests/test_data/directories/model_parameters/vegetation_property/fluspect_parameters/ | ||
leafangles=tests/test_data/directories/model_parameters/vegetation_property/leafangles/ | ||
radiationdata=tests/test_data/directories/model_parameters/vegetation_property/radiationdata/ | ||
soil_spectrum=tests/test_data/directories/model_parameters/vegetation_property/soil_spectrum/ | ||
input_data=tests/test_data/directories/model_parameters/vegetation_property/dummy_data.xlsx | ||
InitialConditionPath=tests/test_data/directories/model_parameters/soil_initialcondition/ | ||
StartTime=1996-01-01T00:00 | ||
EndTime=1996-01-01T02:00 | ||
InputPath= | ||
OutputPath= | ||
DockerImage=ghcr.io/ecoextreml/stemmus_scope:1.5.0 |
3 changes: 3 additions & 0 deletions
3
tests/test_data/directories/model_parameters/vegetation_property/.gitignore
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
fluspect_parameters/Optipar2017_ProspectD.mat | ||
radiationdata/FLEX-S3_std.atm | ||
soil_spectrum/soilnew.txt |
Binary file added
BIN
+20.2 KB
tests/test_data/directories/model_parameters/vegetation_property/input_data.xlsx
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
from pathlib import Path | ||
from PyStemmusScope.bmi.implementation import StemmusScopeBmi | ||
from PyStemmusScope import config_io, forcing_io, soil_io | ||
from distutils.dir_util import copy_tree | ||
import requests | ||
|
||
from . import data_folder | ||
import pytest | ||
|
||
|
||
SCOPE_INPUTDATA_v2_1 = "https://github.com/Christiaanvandertol/SCOPE/raw/2.1/input/" | ||
SCOPE_INPUTDATA_v1_7 = "https://github.com/Christiaanvandertol/SCOPE/raw/1.73/data/input/" | ||
|
||
|
||
cfg_file = data_folder / "config_file_docker.txt" | ||
vegetation_property_dir = data_folder / "directories" / "model_parameters" / "vegetation_property" | ||
|
||
|
||
def write_config_file(cfg: dict, file: Path) -> None: | ||
with file.open("w") as f: | ||
for key, val in cfg.items(): | ||
f.write(f"{key}={val}\n") | ||
|
||
|
||
@pytest.fixture(scope="session") | ||
def prep_input_data(): | ||
optipar_path = vegetation_property_dir / "fluspect_parameters" / "Optipar2017_ProspectD.mat" | ||
if not optipar_path.exists(): | ||
r = requests.get( # Older version due to v2 compatibility issues | ||
SCOPE_INPUTDATA_v1_7 + "fluspect_parameters/Optipar2017_ProspectD.mat" | ||
) | ||
assert r.status_code == 200 | ||
optipar_path.open("wb").write(r.content) | ||
|
||
flex_s3_path = vegetation_property_dir / "radiationdata" / "FLEX-S3_std.atm" | ||
if not flex_s3_path.exists(): | ||
r = requests.get( | ||
SCOPE_INPUTDATA_v2_1 + "radiationdata/FLEX-S3_std.atm" | ||
) | ||
assert r.status_code == 200 | ||
flex_s3_path.open("wb").write(r.content) | ||
|
||
soil_path = vegetation_property_dir / "soil_spectrum" / "soilnew.txt" | ||
if not soil_path.exists(): | ||
r = requests.get( | ||
SCOPE_INPUTDATA_v2_1 + "soil_spectra/soilnew.txt" | ||
) | ||
assert r.status_code == 200 | ||
soil_path.open("wb").write(r.content) | ||
|
||
|
||
@pytest.fixture(scope="session") | ||
def prepare_data_config(tmpdir_factory, prep_input_data) -> Path: | ||
tempdir = Path(tmpdir_factory.mktemp("tempdir")) | ||
output_dir = tempdir / "output_dir" | ||
input_dir = tempdir / "input_dir" | ||
output_dir.mkdir() | ||
input_dir.mkdir() | ||
config = config_io.read_config(cfg_file) | ||
config["OutputPath"] = str(output_dir) + "/" | ||
config["InputPath"] = str(input_dir) + "/" | ||
|
||
forcing_io.prepare_forcing(config) | ||
soil_io.prepare_soil_data(config) | ||
soil_io.prepare_soil_init(config) | ||
|
||
copy_tree(src=str(vegetation_property_dir), dst=str(input_dir)) | ||
|
||
config_dir = tempdir / "config.txt" | ||
write_config_file(config, config_dir) | ||
|
||
return config_dir | ||
|
||
|
||
def test_initialize(prepare_data_config): | ||
model = StemmusScopeBmi() | ||
model.initialize(str(prepare_data_config)) | ||
model.update() | ||
model.finalize() |