Skip to content

Commit

Permalink
Finalize catching warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
rhugonnet committed Mar 17, 2024
1 parent 60fae87 commit d8e139d
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
2 changes: 1 addition & 1 deletion tests/test_dem.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ def test_to_vcrs__grids(self, grid_shifts: dict[str, Any]) -> None:

# Using an arbitrary elevation of 100 m (no influence on the transformation)
dem = DEM.from_array(
data=np.array([[100]]),
data=np.array([[100, 100]]),
transform=rio.transform.from_bounds(
grid_shifts["lon"], grid_shifts["lat"], grid_shifts["lon"] + 0.01, grid_shifts["lat"] + 0.01, 0.01, 0.01
),
Expand Down
2 changes: 2 additions & 0 deletions tests/test_spatialstats.py
Original file line number Diff line number Diff line change
Expand Up @@ -853,6 +853,8 @@ def test_check_params_variogram_model(self) -> None:
def test_estimate_model_spatial_correlation_and_infer_from_stable(self) -> None:
"""Test consistency of outputs and errors in wrapper functions for estimation of spatial correlation"""

warnings.filterwarnings("ignore", category=RuntimeWarning, message="Mean of empty slice")

# Keep only data on stable
diff_on_stable = self.diff.copy()
diff_on_stable.set_mask(self.mask)
Expand Down
9 changes: 5 additions & 4 deletions tests/test_terrain.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ def run_gdaldem(filepath: str, processing: str, options: str | None = None) -> M
"""Run GDAL's DEMProcessing and return the read numpy array."""
# Rasterio strongly recommends against importing gdal along rio, so this is done here instead.
from osgeo import gdal
gdal.UseExceptions()

# Converting string into gdal processing options here to avoid import gdal outside this function:
# Riley or Wilson for Terrain Ruggedness, and Zevenberg or Horn for slope, aspect and hillshade
Expand Down Expand Up @@ -123,7 +124,10 @@ def test_attribute_functions_against_gdaldem(self, attribute: str) -> None:

# For hillshade, we round into an integer to match GDAL's output
if attribute in ["hillshade_Horn", "hillshade_Zevenberg"]:
attr_xdem = attr_xdem.astype("int").astype("float32")
with warnings.catch_warnings():
# Normal that a warning would be raised here, so we catch it
warnings.filterwarnings("ignore", message="invalid value encountered in cast", category=RuntimeWarning)
attr_xdem = attr_xdem.astype("int").astype("float32")

# We compute the difference and keep only valid values
diff = (attr_xdem - attr_gdal).filled(np.nan)
Expand Down Expand Up @@ -171,9 +175,6 @@ def test_attribute_functions_against_gdaldem(self, attribute: str) -> None:
# Validate that this doesn't raise weird warnings after introducing nans.
functions[attribute](dem)

@pytest.mark.skip(
"richdem wheels don't build on latest GDAL versions, " "need to circumvent that problem..."
) # type: ignore
@pytest.mark.parametrize(
"attribute",
["slope_Horn", "aspect_Horn", "hillshade_Horn", "curvature", "profile_curvature", "planform_curvature"],
Expand Down

0 comments on commit d8e139d

Please sign in to comment.