Skip to content

Commit

Permalink
Make landcover output dynamic (#84)
Browse files Browse the repository at this point in the history
* Make landcover data time-dependent

* Update tests

* Add changelog entry, apply formatter.

* Update changelog for release
  • Loading branch information
BSchilperoort authored Jun 21, 2023
1 parent 8eb8c73 commit a1063cb
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 28 deletions.
8 changes: 4 additions & 4 deletions PyStemmusScope/forcing_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,9 @@ def read_forcing_data_plumber2(forcing_file: Path, start_time: str, end_time: st
data["latitude"] = ds_forcing["latitude"].values
data["longitude"] = ds_forcing["longitude"].values
data["elevation"] = ds_forcing["elevation"].values
data["IGBP_veg_long"] = ds_forcing["IGBP_veg_long"].values
data["IGBP_veg_long"] = np.repeat(
ds_forcing["IGBP_veg_long"].values, ds_forcing.time.size
).T
data["reference_height"] = ds_forcing["reference_height"].values
data["canopy_height"] = ds_forcing["canopy_height"].values

Expand Down Expand Up @@ -209,8 +211,6 @@ def prepare_global_variables(data: dict, input_path: Path):
function `read_forcing_data`.
input_path: Path to which the file should be written to.
"""
total_duration = data["total_timesteps"]

matfile_vars = [
"latitude",
"longitude",
Expand All @@ -223,7 +223,7 @@ def prepare_global_variables(data: dict, input_path: Path):
]
matfiledata = {key: data[key] for key in matfile_vars}

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

hdf5storage.savemat(
input_path / "forcing_globals.mat", matfiledata, appendmat=False
Expand Down
6 changes: 2 additions & 4 deletions PyStemmusScope/global_data/global_data_selection.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,7 @@ def collect_datasets(
time_range,
timestep,
)
# TODO see issue github.com/EcoExtreML/STEMMUS_SCOPE/issues/137
# for now, we only use the first value of the time series
data["IGBP_veg_long"] = landcover_data["IGBP_veg_long"][0]
data["LCCS_landcover"] = landcover_data["LCCS_landcover"][0]
data["IGBP_veg_long"] = landcover_data["IGBP_veg_long"]
data["LCCS_landcover"] = landcover_data["LCCS_landcover"]

return data
33 changes: 23 additions & 10 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,24 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [0.2.1] - 2023-04-03
### Added:

### Removed:

### Changed:


## [0.3.0] - 2023-06-21
<!-- markdown-link-check-disable-next-line -->
This version is only compatible with [STEMMUS_SCOPE 1.3.0](https://github.com/EcoExtreML/STEMMUS_SCOPE/releases/tag/1.2.0).

### Changed:
- 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)).

### Fixed:
- The regional landcover classes from the IGBP classification system are now supported as well ([#80](https://github.com/EcoExtreML/STEMMUS_SCOPE_Processing/pull/80)).

## [0.2.1] - 2023-04-03
This version is only compatible with [STEMMUS_SCOPE 1.2.0](https://github.com/EcoExtreML/STEMMUS_SCOPE/releases/tag/1.2.0).

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

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

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

### Added

### Removed

### Changed

<!-- [Unreleased]: https://github.com/EcoExtreML/STEMMUS_SCOPE_Processing/compare/v1.0.0...HEAD
[0.0.1]: https://github.com/EcoExtreML/STEMMUS_SCOPE_Processing/releases/tag/v0.0.1 -->
[Unreleased]: https://github.com/EcoExtreML/STEMMUS_SCOPE_Processing/compare/v0.3.0...HEAD
[0.1.0]: https://github.com/EcoExtreML/STEMMUS_SCOPE_Processing/releases/tag/v0.1.0
[0.1.1]: https://github.com/EcoExtreML/STEMMUS_SCOPE_Processing/releases/tag/v0.1.1
[0.2.0]: https://github.com/EcoExtreML/STEMMUS_SCOPE_Processing/releases/tag/v0.2.0
[0.2.1]: https://github.com/EcoExtreML/STEMMUS_SCOPE_Processing/releases/tag/v0.2.1
[0.3.0]: https://github.com/EcoExtreML/STEMMUS_SCOPE_Processing/releases/tag/v0.3.0
30 changes: 20 additions & 10 deletions tests/test_global_data_selection.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def get_forcing_data():
)


expected_keys_values = [
expected_keys_values_float = [
("wind_speed", (1**2 + 2**2) ** 0.5),
("t_air_celcius", 10),
("precip_conv", 3 / 10),
Expand All @@ -60,22 +60,32 @@ def get_forcing_data():
("canopy_height", 1.0),
("reference_height", 10.0),
("doy_float", 0.0),
]


@pytest.mark.parametrize("key, val", expected_keys_values_float)
def test_extract_forcing_data_floats(get_forcing_data, key, val):
data = get_forcing_data
assert key in data.keys()

np.testing.assert_almost_equal(
np.array([val]),
data[key][0] if hasattr(data[key], "__iter__") else data[key],
)


expected_keys_values_str = [
("IGBP_veg_long", "Evergreen Needleleaf Forests"),
("LCCS_landcover", "tree_needleleaved_evergreen_closed_to_open"),
]


@pytest.mark.parametrize("key, val", expected_keys_values)
def test_extract_forcing_data(get_forcing_data, key, val):
@pytest.mark.parametrize("key, val", expected_keys_values_str)
def test_extract_forcing_data_str(get_forcing_data, key, val):
data = get_forcing_data
assert key in data.keys()
if isinstance(val, str):
assert data[key] == val
else:
np.testing.assert_almost_equal(
np.array([val]),
data[key][0] if hasattr(data[key], "__iter__") else data[key],
)

assert np.array([val]) == data[key][0]


class TestEra5:
Expand Down

0 comments on commit a1063cb

Please sign in to comment.