Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix raven-wps CLI entrypoint #475

Merged
merged 6 commits into from
May 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ dependencies:
- psutil
- psycopg2
- pymetalink
- pyogrio
- pyproj >=3.4
- pysheds
- rasterio
Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ dependencies = [
# GIS libraries
"affine",
"fiona>=1.9.0,<2.0",
"gdal",
"geojson",
"geopandas",
"pyogrio",
"pyproj>=3.4",
"pysheds",
"rasterio",
Expand Down Expand Up @@ -113,7 +113,7 @@ docs = [
]

[project.scripts]
raven = "raven.cli:cli"
raven-wps = "raven.cli:cli"

[project.urls]
"Homepage" = "https://pavics-raven.readthedocs.io/"
Expand Down
11 changes: 6 additions & 5 deletions raven/utilities/geoserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down
18 changes: 9 additions & 9 deletions tests/test_wps_generic_shape_properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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)