diff --git a/pyproject.toml b/pyproject.toml index 54bbbfd..0260428 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -26,6 +26,7 @@ classifiers = [ "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", "Programming Language :: Python :: 3.12", + "Programming Language :: Python :: 3.13", "Topic :: Scientific/Engineering", "Topic :: Scientific/Engineering :: GIS", "Topic :: Scientific/Engineering :: Hydrology", diff --git a/src/pygeoutils/__init__.py b/src/pygeoutils/__init__.py index b8e5e7d..4e9fb42 100644 --- a/src/pygeoutils/__init__.py +++ b/src/pygeoutils/__init__.py @@ -27,9 +27,9 @@ gtiff2vrt, gtiff2xarray, json2geodf, + sample_window, xarray2geodf, xarray_geomask, - sample_window, ) from pygeoutils.smoothing import ( GeoSpline, diff --git a/src/pygeoutils/pygeoutils.py b/src/pygeoutils/pygeoutils.py index e3b1fb3..392fc07 100644 --- a/src/pygeoutils/pygeoutils.py +++ b/src/pygeoutils/pygeoutils.py @@ -6,6 +6,7 @@ import contextlib import subprocess import warnings +from itertools import islice from pathlib import Path from typing import TYPE_CHECKING, Any, TypeVar, Union, cast, overload @@ -20,14 +21,12 @@ import ujson as json import xarray as xr from rasterio import MemoryFile -from rioxarray.exceptions import OneDimensionalRaster -from shapely import MultiPolygon, Polygon -from itertools import islice -import pyproj -import numpy as np from rasterio.enums import MaskFlags, Resampling from rasterio.transform import rowcol from rasterio.windows import Window +from rioxarray.exceptions import OneDimensionalRaster +from shapely import MultiPolygon, Polygon + from pygeoutils import _utils as utils from pygeoutils import geotools from pygeoutils.exceptions import ( @@ -545,7 +544,7 @@ def sample_window( """Interpolate pixel values at given coordinates by interpolation. .. note:: - + This function is adapted from the ``rasterio.sample.sample_gen`` function of `RasterIO `__. diff --git a/tests/test_pygeoutils.py b/tests/test_pygeoutils.py index f20b91d..a568643 100644 --- a/tests/test_pygeoutils.py +++ b/tests/test_pygeoutils.py @@ -8,10 +8,10 @@ import geopandas as gpd import numpy as np import pytest +import rasterio import rioxarray as rxr from scipy.interpolate import UnivariateSpline from shapely import LineString, MultiPolygon, Point, Polygon, box -import rasterio import pygeoutils as geoutils from pygeoogc import ArcGISRESTful, ServiceURL diff --git a/tests/test_smoothing.py b/tests/test_smoothing.py index eb94157..3d1fbbf 100644 --- a/tests/test_smoothing.py +++ b/tests/test_smoothing.py @@ -1,11 +1,15 @@ +from __future__ import annotations + import numpy as np from shapely import LineString, MultiLineString -from pygeoutils import anchored_smoothing, smooth_multilinestring, smooth_linestring -import pytest + +from pygeoutils import anchored_smoothing, smooth_linestring, smooth_multilinestring + def assert_close(a: float, b: float, rtol: float = 1e-3) -> bool: assert np.allclose(a, b, rtol=rtol) + class TestAnchoredSmoothing: def setup_method(self): self.line = LineString([(0, 0), (1, 1), (2, 0), (3, 1)]) @@ -39,12 +43,12 @@ def test_complex_line(self): assert_close(smoothed_complex_line.coords[0], (0, 0)) assert_close(smoothed_complex_line.coords[-1], (4, 0)) + class TestSmoothMultiLineString: def setup_method(self): - self.mline = MultiLineString([ - LineString([(0, 0), (1, 1), (2, 0)]), - LineString([(2, 0), (3, 1), (4, 0)]) - ]) + self.mline = MultiLineString( + [LineString([(0, 0), (1, 1), (2, 0)]), LineString([(2, 0), (3, 1), (4, 0)])] + ) def test_simple_multilinestring(self): smoothed_mline = smooth_multilinestring(self.mline, npts_list=[10, 10], sigma=1.0) @@ -73,18 +77,22 @@ def test_default_npts_list(self): assert isinstance(smoothed_mline_default_npts, MultiLineString) assert len(smoothed_mline_default_npts.geoms) == 2 assert all(isinstance(line, LineString) for line in smoothed_mline_default_npts.geoms) - assert all(len(line.coords) == len(orig_line.coords) for line, orig_line in zip(smoothed_mline_default_npts.geoms, self.mline.geoms)) + assert all( + len(line.coords) == len(orig_line.coords) + for line, orig_line in zip(smoothed_mline_default_npts.geoms, self.mline.geoms) + ) assert_close(smoothed_mline_default_npts.geoms[0].coords[0], (0, 0)) assert_close(smoothed_mline_default_npts.geoms[0].coords[-1], (2, 0)) assert_close(smoothed_mline_default_npts.geoms[1].coords[0], (2, 0)) assert_close(smoothed_mline_default_npts.geoms[1].coords[-1], (4, 0)) def test_complex_multilinestring(self): - complex_mline = MultiLineString([ - LineString([(0, 0), (1, 2), (2, 1)]), - LineString([(2, 1), (3, 3), (4, 0)]) - ]) - smoothed_complex_mline = smooth_multilinestring(complex_mline, npts_list=[20, 20], sigma=2.0) + complex_mline = MultiLineString( + [LineString([(0, 0), (1, 2), (2, 1)]), LineString([(2, 1), (3, 3), (4, 0)])] + ) + smoothed_complex_mline = smooth_multilinestring( + complex_mline, npts_list=[20, 20], sigma=2.0 + ) assert isinstance(smoothed_complex_mline, MultiLineString) assert len(smoothed_complex_mline.geoms) == 2 assert all(isinstance(line, LineString) for line in smoothed_complex_mline.geoms) @@ -94,6 +102,7 @@ def test_complex_multilinestring(self): assert_close(smoothed_complex_mline.geoms[1].coords[0], (2, 1)) assert_close(smoothed_complex_mline.geoms[1].coords[-1], (4, 0)) + class TestSmoothLineString: def setup_method(self): self.line = LineString([(0, 0), (1, 1), (2, 0), (3, 1)])