From 349add68ef77c19c38f2895cbf95be043024a3a8 Mon Sep 17 00:00:00 2001 From: Zeitsperre <10819524+Zeitsperre@users.noreply.github.com> Date: Mon, 15 May 2023 10:52:24 -0400 Subject: [PATCH 1/6] fix cli calls --- .github/workflows/main.yml | 4 ++-- pyproject.toml | 3 +-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 4e69eef9..6527f13d 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -56,13 +56,13 @@ jobs: 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/pyproject.toml b/pyproject.toml index 98748ddb..55fbace8 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -51,7 +51,6 @@ dependencies = [ # GIS libraries "affine", "fiona>=1.9.0,<2.0", - "gdal", "geojson", "geopandas", "pyproj>=3.4", @@ -113,7 +112,7 @@ docs = [ ] [project.scripts] -raven = "raven.cli:cli" +raven-wps = "raven.cli:cli" [project.urls] "Homepage" = "https://pavics-raven.readthedocs.io/" From d59999349778b219f6114092c91b123eb2c68c09 Mon Sep 17 00:00:00 2001 From: Zeitsperre <10819524+Zeitsperre@users.noreply.github.com> Date: Mon, 15 May 2023 11:09:31 -0400 Subject: [PATCH 2/6] adjust test expectations --- tests/test_wps_generic_shape_properties.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/tests/test_wps_generic_shape_properties.py b/tests/test_wps_generic_shape_properties.py index 28bbf731..de912e69 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,17 +161,17 @@ 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_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) + np.testing.assert_approx_equal(props[-1]["perimeter"], 92477.2915962) def test_multifeature_zipped_shapefile(self, get_local_testdata): """Calculate shape properties for multiple features in a shape""" @@ -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_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) + np.testing.assert_approx_equal(props[-1]["perimeter"], 92477.2915962) From b7ae7f5deb23ee261bbac9f7d410c84278fa258a Mon Sep 17 00:00:00 2001 From: Zeitsperre <10819524+Zeitsperre@users.noreply.github.com> Date: Mon, 15 May 2023 11:09:43 -0400 Subject: [PATCH 3/6] better printout --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 6527f13d..1ed6a718 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -52,7 +52,7 @@ jobs: python=${{ matrix.python-version }} - name: Conda and Mamba versions run: | - micromamba --version + echo "mircomamba $(micromamba --version)" conda --version - name: Install RavenWPS run: | From 25b488ae7ce05f60a14544e0bedcbcf2c3128d47 Mon Sep 17 00:00:00 2001 From: Zeitsperre <10819524+Zeitsperre@users.noreply.github.com> Date: Mon, 15 May 2023 11:24:34 -0400 Subject: [PATCH 4/6] more tolerance --- tests/test_wps_generic_shape_properties.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_wps_generic_shape_properties.py b/tests/test_wps_generic_shape_properties.py index de912e69..d7673e33 100644 --- a/tests/test_wps_generic_shape_properties.py +++ b/tests/test_wps_generic_shape_properties.py @@ -168,10 +168,10 @@ def test_multifeature_geojson(self, get_local_testdata): np.testing.assert_approx_equal(props[0]["perimeter"], 46351.1628725) 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]["gravelius"], 1.4271461) - np.testing.assert_approx_equal(props[-1]["perimeter"], 92477.2915962) def test_multifeature_zipped_shapefile(self, get_local_testdata): """Calculate shape properties for multiple features in a shape""" @@ -217,7 +217,7 @@ def test_multifeature_zipped_shapefile(self, get_local_testdata): np.testing.assert_approx_equal(props[0]["perimeter"], 46351.1628725) 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]["gravelius"], 1.4271461) - np.testing.assert_approx_equal(props[-1]["perimeter"], 92477.2915962) From d21f30a9bbd0d7c64280617c1b923cbcce31ee54 Mon Sep 17 00:00:00 2001 From: Zeitsperre <10819524+Zeitsperre@users.noreply.github.com> Date: Wed, 17 May 2023 15:52:04 -0400 Subject: [PATCH 5/6] port compatibility changes for GeoPandas --- raven/utilities/geoserver.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) 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( From 25f56ef86723843e39c363e4430d6de4f3d9a902 Mon Sep 17 00:00:00 2001 From: Zeitsperre <10819524+Zeitsperre@users.noreply.github.com> Date: Wed, 17 May 2023 16:01:15 -0400 Subject: [PATCH 6/6] add pyogrio to dependencies --- environment.yml | 1 + pyproject.toml | 1 + 2 files changed, 2 insertions(+) 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 55fbace8..2b67f591 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -53,6 +53,7 @@ dependencies = [ "fiona>=1.9.0,<2.0", "geojson", "geopandas", + "pyogrio", "pyproj>=3.4", "pysheds", "rasterio",