1+ import platform
12from distutils .dir_util import copy_tree
23from pathlib import Path
34import docker
45import docker .errors
6+ import numpy as np
57import pytest
68import requests
79from PyStemmusScope import config_io
810from PyStemmusScope import forcing_io
911from PyStemmusScope import soil_io
10- from PyStemmusScope .bmi .implementation import StemmusScopeBmi
1112from PyStemmusScope .bmi .docker_utils import pull_image
13+ from PyStemmusScope .bmi .implementation import StemmusScopeBmi
1214from . import data_folder
13- import platform
1415
1516
1617SCOPE_INPUTDATA_v2_1 = "https://github.com/Christiaanvandertol/SCOPE/raw/2.1/input/"
2223def docker_available ():
2324 try :
2425 docker .APIClient ()
25-
26+
2627 # Github Actions windows runners couldn't pull the image:
2728 if platform .system () == "Windows" :
2829 pull_image ("ghcr.io/ecoextreml/stemmus_scope:1.5.0" )
@@ -34,7 +35,7 @@ def docker_available():
3435 if "404 Client Error" in str (err ): # Can't find image
3536 return False
3637 else :
37- raise err # Unknown error.
38+ raise err # Unknown error.
3839
3940
4041cfg_file = data_folder / "config_file_docker.txt"
@@ -100,6 +101,46 @@ def prepare_data_config(tmpdir_factory, prep_input_data) -> Path:
100101@pytest .mark .skipif (not docker_available (), reason = "Docker not available" )
101102def test_initialize (prepare_data_config ):
102103 model = StemmusScopeBmi ()
104+
105+ assert model .get_component_name () == "STEMMUS_SCOPE"
106+ with pytest .raises (ValueError , match = "STEMMUS_SCOPE process is not running" ):
107+ model .update ()
108+
103109 model .initialize (str (prepare_data_config ))
110+
111+ assert isinstance (model .get_input_item_count (), int )
112+ assert isinstance (model .get_output_item_count (), int )
113+ assert "soil_temperature" in model .get_input_var_names ()
114+ assert "respiration" in model .get_output_var_names ()
115+
116+ assert model .get_var_grid ("respiration" ) == 0
117+ assert model .get_var_grid ("soil_temperature" ) == 1
118+
119+ assert model .get_var_type ("soil_temperature" ) == "float64"
120+
121+ # model.get_grid_size needs to have .update() run.
122+ model .update ()
123+
124+ dest = np .zeros (model .get_grid_size (0 ))
125+ np .testing .assert_almost_equal (model .get_grid_x (0 , x = dest ), np .array ([- 107.80752563 ]))
126+ np .testing .assert_almost_equal (model .get_grid_y (0 , y = dest ), np .array ([37.93380356 ]))
127+
128+ with pytest .raises (ValueError , match = "has no dimension `z`" ):
129+ model .get_grid_z (0 , z = dest )
130+
104131 model .update ()
132+
133+ dest = np .zeros (1 )
134+ model .get_value ("respiration" , dest )
135+ assert dest [0 ] != 0.
136+
137+ dest = np .zeros (1 )
138+ model .set_value_at_indices (
139+ "soil_temperature" ,
140+ inds = np .array ([0 ]),
141+ src = np .array ([0. ]),
142+ )
143+ model .get_value_at_indices ("soil_temperature" , dest , inds = np .array ([0 ]))
144+ assert dest [0 ] == 0.
145+
105146 model .finalize ()
0 commit comments