20
20
import geoutils as gu
21
21
import geoutils .projtools as pt
22
22
from geoutils import examples
23
+ from geoutils ._typing import MArrayNum , NDArrayNum
23
24
from geoutils .misc import resampling_method_from_str
24
25
from geoutils .projtools import reproject_to_latlon
25
26
from geoutils .raster .raster import _default_nodata , _default_rio_attrs
29
30
30
31
def run_gdal_proximity (
31
32
input_raster : gu .Raster , target_values : list [float ] | None , distunits : str = "GEO"
32
- ) -> np . ndarray :
33
+ ) -> NDArrayNum :
33
34
"""Run GDAL's ComputeProximity and return the read numpy array."""
34
35
# Rasterio strongly recommends against importing gdal along rio, so this is done here instead.
35
36
from osgeo import gdal , gdalconst
@@ -412,8 +413,8 @@ def test_data_setter(self, dtype: str, nodata_init: str | None) -> None:
412
413
413
414
# Create random values between the lower and upper limit of the data type, max absolute 99999 for floats
414
415
if "int" in dtype :
415
- val_min = np .iinfo (int_type = dtype ).min
416
- val_max = np .iinfo (int_type = dtype ).max
416
+ val_min : int = np .iinfo (int_type = dtype ).min # type: ignore
417
+ val_max : int = np .iinfo (int_type = dtype ).max # type: ignore
417
418
randint_dtype = dtype
418
419
else :
419
420
val_min = - 99999
@@ -422,7 +423,9 @@ def test_data_setter(self, dtype: str, nodata_init: str | None) -> None:
422
423
423
424
# Fix the random seed
424
425
np .random .seed (42 )
425
- arr = np .random .randint (low = val_min , high = val_max , size = (width , height ), dtype = randint_dtype ).astype (dtype )
426
+ arr = np .random .randint (
427
+ low = val_min , high = val_max , size = (width , height ), dtype = randint_dtype # type: ignore
428
+ ).astype (dtype )
426
429
mask = np .random .randint (0 , 2 , size = (width , height ), dtype = bool )
427
430
428
431
# Check that we are actually masking stuff
@@ -1675,7 +1678,7 @@ def test_xy2ij_and_interp(self) -> None:
1675
1678
assert img [int (i ), int (j )] == val
1676
1679
1677
1680
# Finally, check that interp convert to latlon
1678
- lat , lon = gu .projtools .reproject_to_latlon (( x , y ) , in_crs = r .crs )
1681
+ lat , lon = gu .projtools .reproject_to_latlon ([[ x ], [ y ]] , in_crs = r .crs )
1679
1682
val_latlon = r .interp_points ([(lat , lon )], order = 1 , input_latlon = True )[0 ]
1680
1683
assert val == pytest .approx (val_latlon , abs = 0.0001 )
1681
1684
@@ -1718,7 +1721,7 @@ def test_value_at_coords(self) -> None:
1718
1721
# -- Tests 2: check arguments work as intended --
1719
1722
1720
1723
# 1/ Lat-lon argument check by getting the coordinates of our last test point
1721
- lat , lon = reproject_to_latlon (pts = [xtest0 , ytest0 ], in_crs = r .crs )
1724
+ lat , lon = reproject_to_latlon (pts = [[ xtest0 ], [ ytest0 ] ], in_crs = r .crs )
1722
1725
z_val_2 = r .value_at_coords (lon , lat , latlon = True )
1723
1726
assert z_val == z_val_2
1724
1727
@@ -2039,13 +2042,13 @@ def test_default_nodata(self) -> None:
2039
2042
2040
2043
# Check it works with most frequent np.dtypes too
2041
2044
assert _default_nodata (np .dtype ("uint8" )) == np .iinfo ("uint8" ).max
2042
- for dtype in [np .dtype ("int32" ), np .dtype ("float32" ), np .dtype ("float64" )]:
2043
- assert _default_nodata (dtype ) == - 99999
2045
+ for dtype_obj in [np .dtype ("int32" ), np .dtype ("float32" ), np .dtype ("float64" )]:
2046
+ assert _default_nodata (dtype_obj ) == - 99999 # type: ignore
2044
2047
2045
2048
# Check it works with most frequent types too
2046
2049
assert _default_nodata (np .uint8 ) == np .iinfo ("uint8" ).max
2047
- for dtype in [np .int32 , np .float32 , np .float64 ]:
2048
- assert _default_nodata (dtype ) == - 99999
2050
+ for dtype_obj in [np .int32 , np .float32 , np .float64 ]:
2051
+ assert _default_nodata (dtype_obj ) == - 99999
2049
2052
2050
2053
# Check that an error is raised for other types
2051
2054
expected_message = "No default nodata value set for dtype."
@@ -2105,9 +2108,8 @@ def test_astype(self) -> None:
2105
2108
assert np .dtype (rout .dtypes [0 ]) == dtype
2106
2109
assert rout .data .dtype == dtype
2107
2110
2108
- @pytest .mark .parametrize (
2109
- "example" , [landsat_b4_path , landsat_b4_crop_path , landsat_rgb_path , aster_dem_path ]
2110
- ) # type: ignore
2111
+ # The multi-band example will not have a colorbar, so not used in tests
2112
+ @pytest .mark .parametrize ("example" , [landsat_b4_path , landsat_b4_crop_path , aster_dem_path ]) # type: ignore
2111
2113
@pytest .mark .parametrize ("figsize" , np .arange (2 , 20 , 2 )) # type: ignore
2112
2114
def test_show_cbar (self , example , figsize ) -> None :
2113
2115
"""
@@ -3216,7 +3218,7 @@ def test_reflectivity(self, ops: list[str]) -> None:
3216
3218
@classmethod
3217
3219
def from_array (
3218
3220
cls : type [TestArithmetic ],
3219
- data : np . ndarray | np . ma . masked_array ,
3221
+ data : NDArrayNum | MArrayNum ,
3220
3222
rst_ref : gu .RasterType ,
3221
3223
nodata : int | float | list [int ] | list [float ] | None = None ,
3222
3224
) -> gu .Raster :
@@ -3595,7 +3597,7 @@ def test_array_ufunc_1nin_1nout(self, ufunc_str: str, nodata_init: None | str, d
3595
3597
warnings .filterwarnings ("ignore" , category = RuntimeWarning )
3596
3598
3597
3599
# Check if our input dtype is possible on this ufunc, if yes check that outputs are identical
3598
- if com_dtype in ( str (np .dtype (t [0 ])) for t in ufunc .types ):
3600
+ if com_dtype in [ str (np .dtype (t [0 ])) for t in ufunc .types ]: # noqa
3599
3601
# For a single output
3600
3602
if ufunc .nout == 1 :
3601
3603
assert np .ma .allequal (ufunc (rst .data ), ufunc (rst ).data )
@@ -3680,7 +3682,7 @@ def test_array_ufunc_2nin_1nout(
3680
3682
warnings .filterwarnings ("ignore" , category = UserWarning )
3681
3683
3682
3684
# Check if both our input dtypes are possible on this ufunc, if yes check that outputs are identical
3683
- if com_dtype_tuple in (( str ( np .dtype (t [0 ])), str ( np .dtype (t [1 ]))) for t in ufunc .types ):
3685
+ if com_dtype_tuple in [( np .dtype (t [0 ]), np .dtype (t [1 ])) for t in ufunc .types ]: # noqa
3684
3686
# For a single output
3685
3687
if ufunc .nout == 1 :
3686
3688
# There exists a single exception due to negative integers as exponent of integers in "power"
0 commit comments