Skip to content

Commit

Permalink
LNT: Run pre-commit. [skip ci]
Browse files Browse the repository at this point in the history
  • Loading branch information
Taher Chegini committed Oct 21, 2024
1 parent d8f3f6f commit 63f9ecc
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 20 deletions.
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion src/pygeoutils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@
gtiff2vrt,
gtiff2xarray,
json2geodf,
sample_window,
xarray2geodf,
xarray_geomask,
sample_window,
)
from pygeoutils.smoothing import (
GeoSpline,
Expand Down
11 changes: 5 additions & 6 deletions src/pygeoutils/pygeoutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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 (
Expand Down Expand Up @@ -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 <https://rasterio.readthedocs.io/en/latest/api/rasterio.sample.html#rasterio.sample.sample_gen>`__.
Expand Down
2 changes: 1 addition & 1 deletion tests/test_pygeoutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
33 changes: 21 additions & 12 deletions tests/test_smoothing.py
Original file line number Diff line number Diff line change
@@ -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)])
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)])
Expand Down

0 comments on commit 63f9ecc

Please sign in to comment.