diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 4e69eef9..1ed6a718 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -52,17 +52,17 @@ jobs: python=${{ matrix.python-version }} - name: Conda and Mamba versions run: | - micromamba --version + echo "mircomamba $(micromamba --version)" conda --version - name: Install RavenWPS run: | - pip install -e ".[dev]" + python3 -m pip install -e ".[dev]" - name: List installed packages run: | conda list - name: Test RavenPy run: | - pytest tests + python3 -m pytest tests finish: name: Finish diff --git a/environment.yml b/environment.yml index 6c8b109c..c65d6324 100644 --- a/environment.yml +++ b/environment.yml @@ -23,6 +23,7 @@ dependencies: - psutil - psycopg2 - pymetalink + - pyogrio - pyproj >=3.4 - pysheds - rasterio diff --git a/pyproject.toml b/pyproject.toml index 98748ddb..2b67f591 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -51,9 +51,9 @@ dependencies = [ # GIS libraries "affine", "fiona>=1.9.0,<2.0", - "gdal", "geojson", "geopandas", + "pyogrio", "pyproj>=3.4", "pysheds", "rasterio", @@ -113,7 +113,7 @@ docs = [ ] [project.scripts] -raven = "raven.cli:cli" +raven-wps = "raven.cli:cli" [project.urls] "Homepage" = "https://pavics-raven.readthedocs.io/" diff --git a/raven/utilities/geoserver.py b/raven/utilities/geoserver.py index f70e8fc8..7a4b3fdc 100644 --- a/raven/utilities/geoserver.py +++ b/raven/utilities/geoserver.py @@ -15,8 +15,8 @@ import inspect import json import os +import urllib.request import warnings -from io import BytesIO from pathlib import Path from typing import Iterable, Optional, Sequence, Tuple, Union from urllib.parse import urljoin @@ -52,11 +52,11 @@ # We store the contour of different hydrobasins domains hybas_dir = Path(__file__).parent.parent / "data" / "hydrobasins_domains" -hybas_pat = "hybas_lake_{}_lev01_v1c.zip" +hybas_pat = "hybas_lake_{domain}_lev01_v1c.zip" # This could be inferred from existing files in hybas_dir hybas_regions = ["na", "ar"] -hybas_domains = {dom: hybas_dir / hybas_pat.format(dom) for dom in hybas_regions} +hybas_domains = {dom: hybas_dir / hybas_pat.format(domain=dom) for dom in hybas_regions} def _get_location_wfs( @@ -362,10 +362,11 @@ def hydrobasins_upstream(feature: dict, domain: str) -> pd.DataFrame: # filter = PropertyIsEqualTo(propertyname=basin_family, literal=feature[basin_family]) # Fetch all features in the same basin - req = filter_hydrobasins_attributes_wfs( + request_url = filter_hydrobasins_attributes_wfs( attribute=basin_family, value=feature[basin_family], domain=domain ) - df = gpd.read_file(req) + with urllib.request.urlopen(url=request_url) as req: + df = gpd.read_file(filename=req, engine="pyogrio") # Filter upstream watersheds return _determine_upstream_ids( diff --git a/tests/test_wps_generic_shape_properties.py b/tests/test_wps_generic_shape_properties.py index 28bbf731..d7673e33 100644 --- a/tests/test_wps_generic_shape_properties.py +++ b/tests/test_wps_generic_shape_properties.py @@ -79,10 +79,10 @@ def test_simple(self): props = json.loads(out["properties"]) assert {"centroid", "area", "perimeter", "gravelius"}.issubset(props[0].keys()) + np.testing.assert_allclose(props[0]["perimeter"], 673431, atol=1) np.testing.assert_approx_equal(props[0]["area"], 6258366698.5253, 4) np.testing.assert_approx_equal(props[0]["centroid"][0], -73.41117680) np.testing.assert_approx_equal(props[0]["centroid"][1], 46.46286765) - np.testing.assert_approx_equal(props[0]["perimeter"], 673430.9089454) np.testing.assert_approx_equal(props[0]["gravelius"], 2.4013618703) def test_geographic_epsg(self): @@ -161,16 +161,16 @@ def test_multifeature_geojson(self, get_local_testdata): props[i].keys() ) - np.testing.assert_approx_equal(props[0]["area"], 111417901.6141605) + np.testing.assert_allclose(props[0]["area"], 111417901, atol=1) np.testing.assert_approx_equal(props[0]["centroid"][0], -71.8223648) np.testing.assert_approx_equal(props[0]["centroid"][1], 48.8974365) - np.testing.assert_approx_equal(props[0]["perimeter"], 46351.1628725) np.testing.assert_approx_equal(props[0]["gravelius"], 1.2387344) + np.testing.assert_approx_equal(props[0]["perimeter"], 46351.1628725) - np.testing.assert_approx_equal(props[-1]["area"], 334136117.9693527) + np.testing.assert_allclose(props[-1]["area"], 334136220, atol=100) + np.testing.assert_allclose(props[-1]["perimeter"], 92477.3, atol=0.1) np.testing.assert_approx_equal(props[-1]["centroid"][0], -72.6117018) np.testing.assert_approx_equal(props[-1]["centroid"][1], 46.3632907) - np.testing.assert_approx_equal(props[-1]["perimeter"], 92477.2915962) np.testing.assert_approx_equal(props[-1]["gravelius"], 1.4271461) def test_multifeature_zipped_shapefile(self, get_local_testdata): @@ -210,14 +210,14 @@ def test_multifeature_zipped_shapefile(self, get_local_testdata): props[i].keys() ) - np.testing.assert_approx_equal(props[0]["area"], 111417901.6141605) + np.testing.assert_allclose(props[0]["area"], 111417901, atol=1) np.testing.assert_approx_equal(props[0]["centroid"][0], -71.8223648) np.testing.assert_approx_equal(props[0]["centroid"][1], 48.8974365) - np.testing.assert_approx_equal(props[0]["perimeter"], 46351.1628725) np.testing.assert_approx_equal(props[0]["gravelius"], 1.2387344) + np.testing.assert_approx_equal(props[0]["perimeter"], 46351.1628725) - np.testing.assert_approx_equal(props[-1]["area"], 334136117.9693527) + np.testing.assert_allclose(props[-1]["area"], 334136220, atol=1) + np.testing.assert_allclose(props[-1]["perimeter"], 92477.3, atol=0.1) np.testing.assert_approx_equal(props[-1]["centroid"][0], -72.6117018) np.testing.assert_approx_equal(props[-1]["centroid"][1], 46.3632907) - np.testing.assert_approx_equal(props[-1]["perimeter"], 92477.2915962) np.testing.assert_approx_equal(props[-1]["gravelius"], 1.4271461)