From b0e2bff0938df8aacbd0d7f12d2f7a6b6b5b0896 Mon Sep 17 00:00:00 2001 From: Romain Hugonnet Date: Fri, 7 Jun 2024 21:15:29 -0800 Subject: [PATCH] Linting --- geoutils/raster/interpolate.py | 5 +++-- tests/test_raster/test_raster.py | 18 ++++++++++++------ 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/geoutils/raster/interpolate.py b/geoutils/raster/interpolate.py index 4a85e456..f92da04e 100644 --- a/geoutils/raster/interpolate.py +++ b/geoutils/raster/interpolate.py @@ -5,13 +5,14 @@ import numpy as np import rasterio as rio from scipy.interpolate import RectBivariateSpline, RegularGridInterpolator -from scipy.ndimage import map_coordinates, binary_dilation +from scipy.ndimage import binary_dilation, map_coordinates from geoutils._typing import NDArrayNum, Number from geoutils.raster.georeferencing import _coords, _outside_image, _res, _xy2ij method_to_order = {"nearest": 0, "linear": 1, "cubic": 3, "quintic": 5, "slinear": 1, "pchip": 3, "splinef2d": 3} + def _interpn_interpolator( coords: tuple[NDArrayNum, NDArrayNum], values: NDArrayNum, @@ -35,7 +36,7 @@ def _interpn_interpolator( # Adding masking of NaNs for methods not supporting it method_support_nan = method in ["nearest"] order = method_to_order[method] - dist_nodata_spread = int(np.ceil(order/2)) + dist_nodata_spread = int(np.ceil(order / 2)) # If NaNs are not supported if not method_support_nan: diff --git a/tests/test_raster/test_raster.py b/tests/test_raster/test_raster.py index 9cfa0dea..ce38ee28 100644 --- a/tests/test_raster/test_raster.py +++ b/tests/test_raster/test_raster.py @@ -27,8 +27,8 @@ from geoutils._typing import MArrayNum, NDArrayNum from geoutils.misc import resampling_method_from_str from geoutils.projtools import reproject_to_latlon -from geoutils.raster.raster import _default_nodata, _default_rio_attrs from geoutils.raster.interpolate import method_to_order +from geoutils.raster.raster import _default_nodata, _default_rio_attrs DO_PLOT = False @@ -2273,7 +2273,7 @@ def test_interp_points__synthetic(self, tag_aop: str | None, shift_aop: bool) -> assert all(~np.isfinite(raster_points_mapcoords_edge)) assert all(~np.isfinite(raster_points_interpn_edge)) - @pytest.mark.parametrize("example", [landsat_b4_path, aster_dem_path]) + @pytest.mark.parametrize("example", [landsat_b4_path, aster_dem_path]) # type: ignore @pytest.mark.parametrize( "method", ["nearest", "linear", "cubic", "quintic", "slinear", "pchip", "splinef2d"] ) # type: ignore @@ -2320,8 +2320,10 @@ def test_interp_points__real( order = 1 d = int(np.ceil(order / 2)) # No NaN propagation for linear - indices_nan = [(i0 + i, j0 + j) for i in np.arange(-d, d+1) for j in np.arange(-d, d+1) if (np.abs(i) + np.abs(j)) <= d] - i,j = list(zip(*indices_nan)) + indices_nan = [ + (i0 + i, j0 + j) for i in np.arange(-d, d + 1) for j in np.arange(-d, d + 1) if (np.abs(i) + np.abs(j)) <= d + ] + i, j = list(zip(*indices_nan)) x, y = r.ij2xy(i, j) vals = r.interp_points((x, y), method=method, force_scipy_function="map_coordinates")[0] vals2 = r.interp_points((x, y), method=method, force_scipy_function="interpn")[0] @@ -2337,7 +2339,12 @@ def test_interp_points__real( # should be exactly the same # We get the indexes of valid pixels just at the edge of NaNs - indices_edge = [(i0 + i, j0 + j) for i in np.arange(-d-1, d+2) for j in np.arange(-d-1, d+2) if (np.abs(i) + np.abs(j)) == d+1] + indices_edge = [ + (i0 + i, j0 + j) + for i in np.arange(-d - 1, d + 2) + for j in np.arange(-d - 1, d + 2) + if (np.abs(i) + np.abs(j)) == d + 1 + ] i, j = list(zip(*indices_edge)) x, y = r.ij2xy(i, j) # And get their interpolated value @@ -2362,7 +2369,6 @@ def test_interp_points__real( assert np.allclose(vals, vals_near, equal_nan=False) assert np.allclose(vals2, vals2_near, equal_nan=False) - def test_value_at_coords(self) -> None: """ Test that value at coords works as intended