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 gis module #213

Merged
merged 2 commits into from
Oct 11, 2024
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
14 changes: 14 additions & 0 deletions docs/notebooks/gis.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -849,6 +849,13 @@
")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"We can also extract the surface properties for the same `gpd.GeoDataFrame` : "
]
},
{
"cell_type": "code",
"execution_count": 10,
Expand Down Expand Up @@ -972,6 +979,13 @@
"xhgis.surface_properties(gdf)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Again, for convenience, we can output the results in `xarray.Dataset` format : "
]
},
{
"cell_type": "code",
"execution_count": 11,
Expand Down
7 changes: 5 additions & 2 deletions docs/notebooks/hydrological_modelling.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
"metadata": {},
"outputs": [],
"source": [
"import planetary_computer\n",
"\n",
"import xhydro as xh\n",
"import xhydro.modelling as xhm\n",
"\n",
Expand All @@ -52,7 +54,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 3,
"id": "3",
"metadata": {
"editable": true,
Expand Down Expand Up @@ -166,7 +168,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 9,
"id": "7",
"metadata": {},
"outputs": [],
Expand All @@ -179,6 +181,7 @@
"# Acquire the Copernicus DEM for the area covered by the watershed\n",
"catalog = pystac_client.Client.open(\n",
" \"https://planetarycomputer.microsoft.com/api/stac/v1\",\n",
" modifier=planetary_computer.sign_inplace,\n",
")\n",
"search = catalog.search(\n",
" collections=[\"cop-dem-glo-90\"],\n",
Expand Down
12 changes: 7 additions & 5 deletions src/xhydro/gis.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
import planetary_computer
import pystac_client
import rasterio
import rasterio.features
Expand Down Expand Up @@ -270,11 +271,9 @@ def _recursive_upstream_lookup(


def _flatten(x, dim="time"):
# FIXME: assert statements should only be found in test code
assert isinstance(x, xr.DataArray) # noqa: S101
if len(x[dim].values) > len(set(x[dim].values)):
x = x.groupby(dim).map(stackstac.mosaic)

if isinstance(x, xr.DataArray):
if len(x[dim].values) > len(set(x[dim].values)):
x = x.groupby(dim).map(stackstac.mosaic)
return x


Expand Down Expand Up @@ -324,6 +323,7 @@ def surface_properties(

catalog = pystac_client.Client.open(
"https://planetarycomputer.microsoft.com/api/stac/v1",
modifier=planetary_computer.sign_inplace,
)

search = catalog.search(
Expand Down Expand Up @@ -489,6 +489,7 @@ def land_use_classification(
"""
catalog = pystac_client.Client.open(
"https://planetarycomputer.microsoft.com/api/stac/v1",
modifier=planetary_computer.sign_inplace,
)
collection = catalog.get_collection(collection)
ia = ItemAssetsExtension.ext(collection)
Expand Down Expand Up @@ -552,6 +553,7 @@ def land_use_plot(
"""
catalog = pystac_client.Client.open(
"https://planetarycomputer.microsoft.com/api/stac/v1",
modifier=planetary_computer.sign_inplace,
)

collection = catalog.get_collection(collection)
Expand Down