-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Yang
committed
Jul 6, 2023
1 parent
970bcb8
commit b887efc
Showing
3 changed files
with
73 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
"""Unit test for regridding.""" | ||
|
||
from pathlib import Path | ||
import numpy as np | ||
import pytest | ||
from zampy.datasets import EthCanopyHeight | ||
from zampy.datasets import converter | ||
from zampy.datasets.eth_canopy_height import parse_tiff_file | ||
|
||
|
||
path_dummy_data = Path(__file__).resolve().parent / "test_data" / "eth-canopy-height" | ||
|
||
# ruff: noqa: B018 (protected-access) | ||
|
||
|
||
def test_check_convention_not_support(): | ||
convention = "fake_convention" | ||
with pytest.raises(ValueError, match="not supported"): | ||
converter.check_convention(convention) | ||
|
||
|
||
def test_check_convention_not_exist(): | ||
convention = Path("fake_path") | ||
with pytest.raises(FileNotFoundError, match="could not be found"): | ||
converter.check_convention(convention) | ||
|
||
|
||
def test_convert(): | ||
ds = parse_tiff_file( | ||
path_dummy_data / "ETH_GlobalCanopyHeight_10m_2020_N51E003_Map.tif", | ||
) | ||
ds_convert = converter.convert( | ||
data=ds, dataset=EthCanopyHeight(), convention="ALMA" | ||
) | ||
|
||
assert list(ds_convert.data_vars)[0] == "Hveg" | ||
|
||
|
||
def test_convert_var(): | ||
ds = parse_tiff_file( | ||
path_dummy_data / "ETH_GlobalCanopyHeight_10m_2020_N51E003_Map.tif", | ||
) | ||
ds_convert = converter._convert_var(ds, "height_of_vegetation", "decimeter") | ||
|
||
assert np.allclose( | ||
ds_convert["height_of_vegetation"].values, | ||
ds["height_of_vegetation"].values * 10.0, | ||
equal_nan=True, | ||
) |
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