Skip to content

Commit a1063cb

Browse files
Make landcover output dynamic (#84)
* Make landcover data time-dependent * Update tests * Add changelog entry, apply formatter. * Update changelog for release
1 parent 8eb8c73 commit a1063cb

File tree

4 files changed

+49
-28
lines changed

4 files changed

+49
-28
lines changed

PyStemmusScope/forcing_io.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,9 @@ def read_forcing_data_plumber2(forcing_file: Path, start_time: str, end_time: st
9696
data["latitude"] = ds_forcing["latitude"].values
9797
data["longitude"] = ds_forcing["longitude"].values
9898
data["elevation"] = ds_forcing["elevation"].values
99-
data["IGBP_veg_long"] = ds_forcing["IGBP_veg_long"].values
99+
data["IGBP_veg_long"] = np.repeat(
100+
ds_forcing["IGBP_veg_long"].values, ds_forcing.time.size
101+
).T
100102
data["reference_height"] = ds_forcing["reference_height"].values
101103
data["canopy_height"] = ds_forcing["canopy_height"].values
102104

@@ -209,8 +211,6 @@ def prepare_global_variables(data: dict, input_path: Path):
209211
function `read_forcing_data`.
210212
input_path: Path to which the file should be written to.
211213
"""
212-
total_duration = data["total_timesteps"]
213-
214214
matfile_vars = [
215215
"latitude",
216216
"longitude",
@@ -223,7 +223,7 @@ def prepare_global_variables(data: dict, input_path: Path):
223223
]
224224
matfiledata = {key: data[key] for key in matfile_vars}
225225

226-
matfiledata["Dur_tot"] = float(total_duration) # Matlab expects a 'double'
226+
matfiledata["Dur_tot"] = float(data["total_timesteps"]) # Matlab expects a 'double'
227227

228228
hdf5storage.savemat(
229229
input_path / "forcing_globals.mat", matfiledata, appendmat=False

PyStemmusScope/global_data/global_data_selection.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,7 @@ def collect_datasets(
106106
time_range,
107107
timestep,
108108
)
109-
# TODO see issue github.com/EcoExtreML/STEMMUS_SCOPE/issues/137
110-
# for now, we only use the first value of the time series
111-
data["IGBP_veg_long"] = landcover_data["IGBP_veg_long"][0]
112-
data["LCCS_landcover"] = landcover_data["LCCS_landcover"][0]
109+
data["IGBP_veg_long"] = landcover_data["IGBP_veg_long"]
110+
data["LCCS_landcover"] = landcover_data["LCCS_landcover"]
113111

114112
return data

docs/CHANGELOG.md

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,24 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
66

77
## [Unreleased]
88

9-
## [0.2.1] - 2023-04-03
9+
### Added:
10+
11+
### Removed:
12+
13+
### Changed:
14+
15+
16+
## [0.3.0] - 2023-06-21
1017
<!-- markdown-link-check-disable-next-line -->
18+
This version is only compatible with [STEMMUS_SCOPE 1.3.0](https://github.com/EcoExtreML/STEMMUS_SCOPE/releases/tag/1.2.0).
19+
20+
### Changed:
21+
- The landcover type outputs in `forcing_globals.mat` (e.g. `IGBP_veg_long`) are now time dependent, instead of a single constant value ([#84](https://github.com/EcoExtreML/STEMMUS_SCOPE_Processing/pull/84)).
22+
23+
### Fixed:
24+
- The regional landcover classes from the IGBP classification system are now supported as well ([#80](https://github.com/EcoExtreML/STEMMUS_SCOPE_Processing/pull/80)).
25+
26+
## [0.2.1] - 2023-04-03
1127
This version is only compatible with [STEMMUS_SCOPE 1.2.0](https://github.com/EcoExtreML/STEMMUS_SCOPE/releases/tag/1.2.0).
1228

1329
### Added:
@@ -22,7 +38,6 @@ This version is only compatible with [STEMMUS_SCOPE 1.2.0](https://github.com/Ec
2238
- The output netcdf file is again compatible to the model evaluation website ([#76](https://github.com/EcoExtreML/STEMMUS_SCOPE_Processing/pull/76)).
2339

2440
## [0.2.0] - 2023-02-21
25-
<!-- markdown-link-check-disable-next-line -->
2641
This version is only compatible with [STEMMUS_SCOPE 1.2.0](https://github.com/EcoExtreML/STEMMUS_SCOPE/releases/tag/1.2.0).
2742

2843
### Added:
@@ -40,11 +55,9 @@ This version is only compatible with [STEMMUS_SCOPE 1.2.0](https://github.com/Ec
4055
## [0.1.0] - 2022-11-24
4156
The first release of PyStemmusScope. Compatible with STEMMUS_SCOPE 1.1.11.
4257

43-
### Added
44-
45-
### Removed
46-
47-
### Changed
48-
49-
<!-- [Unreleased]: https://github.com/EcoExtreML/STEMMUS_SCOPE_Processing/compare/v1.0.0...HEAD
50-
[0.0.1]: https://github.com/EcoExtreML/STEMMUS_SCOPE_Processing/releases/tag/v0.0.1 -->
58+
[Unreleased]: https://github.com/EcoExtreML/STEMMUS_SCOPE_Processing/compare/v0.3.0...HEAD
59+
[0.1.0]: https://github.com/EcoExtreML/STEMMUS_SCOPE_Processing/releases/tag/v0.1.0
60+
[0.1.1]: https://github.com/EcoExtreML/STEMMUS_SCOPE_Processing/releases/tag/v0.1.1
61+
[0.2.0]: https://github.com/EcoExtreML/STEMMUS_SCOPE_Processing/releases/tag/v0.2.0
62+
[0.2.1]: https://github.com/EcoExtreML/STEMMUS_SCOPE_Processing/releases/tag/v0.2.1
63+
[0.3.0]: https://github.com/EcoExtreML/STEMMUS_SCOPE_Processing/releases/tag/v0.3.0

tests/test_global_data_selection.py

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def get_forcing_data():
4343
)
4444

4545

46-
expected_keys_values = [
46+
expected_keys_values_float = [
4747
("wind_speed", (1**2 + 2**2) ** 0.5),
4848
("t_air_celcius", 10),
4949
("precip_conv", 3 / 10),
@@ -60,22 +60,32 @@ def get_forcing_data():
6060
("canopy_height", 1.0),
6161
("reference_height", 10.0),
6262
("doy_float", 0.0),
63+
]
64+
65+
66+
@pytest.mark.parametrize("key, val", expected_keys_values_float)
67+
def test_extract_forcing_data_floats(get_forcing_data, key, val):
68+
data = get_forcing_data
69+
assert key in data.keys()
70+
71+
np.testing.assert_almost_equal(
72+
np.array([val]),
73+
data[key][0] if hasattr(data[key], "__iter__") else data[key],
74+
)
75+
76+
77+
expected_keys_values_str = [
6378
("IGBP_veg_long", "Evergreen Needleleaf Forests"),
6479
("LCCS_landcover", "tree_needleleaved_evergreen_closed_to_open"),
6580
]
6681

6782

68-
@pytest.mark.parametrize("key, val", expected_keys_values)
69-
def test_extract_forcing_data(get_forcing_data, key, val):
83+
@pytest.mark.parametrize("key, val", expected_keys_values_str)
84+
def test_extract_forcing_data_str(get_forcing_data, key, val):
7085
data = get_forcing_data
7186
assert key in data.keys()
72-
if isinstance(val, str):
73-
assert data[key] == val
74-
else:
75-
np.testing.assert_almost_equal(
76-
np.array([val]),
77-
data[key][0] if hasattr(data[key], "__iter__") else data[key],
78-
)
87+
88+
assert np.array([val]) == data[key][0]
7989

8090

8191
class TestEra5:

0 commit comments

Comments
 (0)