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

RavenGIS #127

Open
wants to merge 36 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
5db84b4
First pass at refactoring GIS functions out of RavenPy with their ass…
Zeitsperre Aug 5, 2021
e3db46a
Run pre-commit checks
Zeitsperre Aug 6, 2021
e7d1e70
Move vector transformation logic into RavenPy, rewrite generic vector…
Zeitsperre Aug 6, 2021
5ba73d9
Working version of generic reproject with shapefile - No GDAL
Zeitsperre Aug 6, 2021
0541e2e
First pass at remove ogr from routing_product.py, fix pyproj transfor…
Zeitsperre Aug 6, 2021
b728a11
Low-level ogr/osr calls removed
Zeitsperre Aug 6, 2021
29d9f06
First half of geopandas calls replaced
Zeitsperre Aug 6, 2021
e447868
Removed more GeoPandas logic - WIP
Zeitsperre Aug 7, 2021
78839a3
Removed more of the GDAL-dependent functions from routing - Tests fai…
Zeitsperre Aug 9, 2021
7b731e1
removed last GeoPandas import - Broken
Zeitsperre Aug 9, 2021
c1d0e07
Fix some docstrings and refactor transformation logic into vector.py,
Zeitsperre Aug 9, 2021
cc4da77
Fix NumberHRUs bug, some refactoring
Zeitsperre Aug 9, 2021
e2acdcc
Added class field for CRS specifications since projection cannot be i…
Zeitsperre Aug 10, 2021
8960255
Force to always use XY for grid transforms (for now)
Zeitsperre Aug 10, 2021
4c98279
Skip slow tests for tox builds
Zeitsperre Aug 10, 2021
fef1d67
Leverage pandas dataframes with geometries constructed via shapely
Zeitsperre Aug 10, 2021
9fac999
remove some useless imports
Zeitsperre Aug 10, 2021
dd74de1
Fix unnecessary shape conversion, stricter CRS transformation controls
Zeitsperre Aug 11, 2021
5fc918d
Re-enabled some GDAL-based logic by applying dataframe approach to fi…
Zeitsperre Aug 17, 2021
1c3c14c
Fix geopandas triggering, delete fully-removed dependencies, add a no…
Zeitsperre Aug 18, 2021
d0c21f6
explicitly install libnetcdf headers
Zeitsperre Aug 18, 2021
620eb68
Install geopandas in tox recipe
Zeitsperre Aug 18, 2021
c308271
run slow tests
Zeitsperre Aug 18, 2021
d1a9b7d
Try another logic syntax
Zeitsperre Aug 18, 2021
31ed75c
hmmm
Zeitsperre Aug 18, 2021
0b7fdc1
hmmm again
Zeitsperre Aug 18, 2021
588479b
another try
Zeitsperre Aug 18, 2021
29f5772
Try another approach
Zeitsperre Aug 18, 2021
8438cb2
Fix a forgotten inplace=True flag
Zeitsperre Aug 18, 2021
a107436
testing - Use STRtree shapely speedup
Zeitsperre Aug 18, 2021
8d245f1
Shapely speedup final version
Zeitsperre Aug 18, 2021
813e819
Add geos
Zeitsperre Aug 19, 2021
9e386cf
Merge branch 'master' into raven-gis-refactor
Zeitsperre Aug 19, 2021
a8cfb57
Merge branch 'master' into raven-gis-refactor
Zeitsperre Aug 31, 2021
87ddddb
WIP - add pygml for gmlv32 reading
Zeitsperre Sep 8, 2021
0e78f5a
add pygml dependency
Zeitsperre Sep 24, 2021
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
21 changes: 18 additions & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,32 +24,47 @@ jobs:
run: tox -e ${{ matrix.tox-env }}

pip:
name: Pip with Python${{ matrix.python-version }}
name: Pip with Python${{ matrix.python-version }} (GDAL=${{ matrix.uses-gdal }})
needs: black
runs-on: ubuntu-latest
strategy:
matrix:
include:
- tox-env: py37
python-version: 3.7
uses-gdal: true
- tox-env: py38
python-version: 3.8
uses-gdal: true
- tox-env: py38
python-version: 3.8
uses-gdal: false
- tox-env: py39
python-version: 3.9
uses-gdal: true
steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Install NetCDF and GEOS
run: |
sudo apt-get update
sudo apt-get install libnetcdf-dev libgeos-dev
- name: Install GDAL
if: ${{ matrix.uses-gdal }}
run: |
sudo apt-get update
sudo apt-get install libgdal-dev
- name: Install tox
run: pip install tox
- name: Test with tox
run: env GDAL_VERSION="$(gdal-config --version)" tox -e ${{ matrix.tox-env }}
- name: Test with tox (GDAL)
if: ${{ matrix.uses-gdal }}
run: env GDAL_VERSION="$(gdal-config --version)" tox -e ${{ matrix.tox-env }}-gdal-slow
- name: Test with tox (no GDAL)
if: ${{ !matrix.uses-gdal }}
run: tox -e ${{ matrix.tox-env }}-slow

conda:
name: Conda
Expand Down
1 change: 0 additions & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ include LICENSE
include README.rst
include requirements_dev.txt
include requirements_docs.txt
include requirements_gis.txt

recursive-include tests *
recursive-exclude * __pycache__
Expand Down
9 changes: 2 additions & 7 deletions environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,10 @@ dependencies:
- raven-hydro ==3.0.4.322
- ostrich ==21.03.16
- python >=3.7
- affine
- cf_xarray
- click
- climpred >=2.1
- dask
- fiona
- gdal >=3.0.0
- geopandas >=0.9
- haversine
- holoviews
- hvplot
Expand All @@ -25,16 +21,15 @@ dependencies:
- pip
- pre-commit
- pydantic
- pygml
- pyproj>=3
- rasterio
- requests
- rioxarray
- scikit-learn ==0.24.2
- scipy
- setuptools >50.0
- shapely
- statsmodels
- xarray >=0.18
- xclim >=0.26.1,<0.29.0
- xclim >=0.28.1,<0.29.0
- xskillscore
- wheel
30 changes: 20 additions & 10 deletions ravenpy/cli/collect_subbasins_upstream_of_gauge.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
from pathlib import Path

import click
import geopandas as gpd

from ravenpy.utilities.vector import archive_sniffer, vector_to_dataframe

# import geopandas as gpd


@click.command()
Expand All @@ -22,11 +25,16 @@ def collect_subbasins_upstream_of_gauge(

GAUGE_ID: ID of the target gauge, to be found in the "Obs_NM" column (e.g. "02LE024").
"""
if Path(input_file).suffix == ".zip":
input_file = f"zip://{input_file}"
gdf = gpd.read_file(input_file)
input_file = Path(input_file)

if gauge_id not in gdf.Obs_NM.values:
if input_file.suffix == ".zip":
input_file = next(iter(archive_sniffer(input_file)))
if input_file.suffix.lower() == ".shp":
df = vector_to_dataframe(input_file.as_posix())
else:
raise FileNotFoundError()

if gauge_id not in df.Obs_NM.values:
raise click.ClickException(f"Cannot find gauge {gauge_id} in `Obs_NM` column")

if not output:
Expand All @@ -37,11 +45,11 @@ def collect_subbasins_upstream_of_gauge(

downsubid_to_subids = defaultdict(set)

for _, r in gdf.iterrows():
for _, r in df.iterrows():
downsubid_to_subids[r.DowSubId].add(r.SubId)

# Starting from the SubId of the gauge, iteratively expand the set of upstream subbasin SubIds
upstream_subids = {gdf[gdf.Obs_NM == gauge_id].iloc[0].SubId}
upstream_subids = {df[df.Obs_NM == gauge_id].iloc[0].SubId}
prev = upstream_subids.copy()
while True:
curr = set()
Expand All @@ -53,10 +61,12 @@ def collect_subbasins_upstream_of_gauge(
else:
break

gdf_upstream = gdf[gdf.SubId.isin(upstream_subids)]
df_upstream = df[df.SubId.isin(upstream_subids)]

df_upstream.to_json(output_file)

gpd.GeoDataFrame(gdf_upstream).to_file(output_file)
# pd.GeoDataFrame(gdf_upstream).to_file(output_file)

click.echo(
f"Found {len(gdf_upstream)} upstream subbasins, saved them in {output_file}"
f"Found {len(df_upstream)} upstream subbasins, saved them in {output_file}"
)
22 changes: 22 additions & 0 deletions ravenpy/cli/generate_grid_weights.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

from ravenpy.extractors.routing_product import RoutingProductGridWeightExtractor

WGS84 = 4326


@click.command()
@click.argument("input-file", type=click.Path(exists=True))
Expand Down Expand Up @@ -74,6 +76,22 @@
type=click.Path(),
help="Text field that will contain the results as a single :GridWeights Raven command containing the weights.",
)
@click.option(
"-i",
"--input-shape-crs",
type=int,
default=WGS84,
show_default=True,
help="Coordinate reference system (EPSG) of the shapefile INPUT_FILE.",
)
@click.option(
"-r",
"--routing-shape-crs",
type=int,
default=WGS84,
show_default=True,
help="Coordinate reference system (EPSG) of the shapefile ROUTING_FILE.",
)
def generate_grid_weights(
input_file,
routing_file,
Expand All @@ -85,6 +103,8 @@ def generate_grid_weights(
sub_ids,
area_error_threshold,
output,
input_shape_crs,
routing_shape_crs,
):
"""
Generate grid weights in various formats.
Expand Down Expand Up @@ -119,6 +139,8 @@ def generate_grid_weights(
gauge_ids,
sub_ids,
area_error_threshold,
input_shape_crs,
routing_shape_crs,
)
gw_cmd = extractor.extract()

Expand Down
Binary file not shown.
Binary file not shown.
Loading