Skip to content

Commit 03f8b7f

Browse files
committed
Fix CI compatibility and notebook links
1 parent 6589e05 commit 03f8b7f

9 files changed

Lines changed: 477 additions & 440 deletions

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ If you are working with cloudy imagery, either:
107107

108108
This matters because OWM optimises its detection thresholds both **locally** (per region/patch) and **globally** (across the whole scene). Cloud and cloud-shadow pixels are out-of-distribution and can skew those optimisations, so bad data in one part of a scene can degrade the water prediction in other, otherwise-clean parts. Masking those pixels to no-data removes them from the optimisation entirely.
109109

110-
[OmniCloudMask](https://github.com/DPIRD-DMA/OmniCloudMask) is a good choice for the masking step. See the [cloudy Sentinel-2 example](https://github.com/DPIRD-DMA/OmniWaterMask/blob/main/examples/Sentinel-2%20example.ipynb) for an end-to-end mask-then-infer workflow.
110+
[OmniCloudMask](https://github.com/DPIRD-DMA/OmniCloudMask) is a good choice for the masking step. See the [cloudy Sentinel-2 example](https://github.com/DPIRD-DMA/OmniWaterMask/blob/main/examples/Sentinel%202%20cloudy%20example.ipynb) for an end-to-end mask-then-infer workflow.
111111

112112

113113
## Parameters
@@ -159,7 +159,7 @@ Example notebooks are available in the [examples/](https://github.com/DPIRD-DMA/
159159

160160
- [NAIP example](https://github.com/DPIRD-DMA/OmniWaterMask/blob/main/examples/NAIP%20example.ipynb) — Water segmentation on NAIP aerial imagery from HuggingFace
161161
- [Sentinel-2 example](https://github.com/DPIRD-DMA/OmniWaterMask/blob/main/examples/Sentinel%202%20example.ipynb) — Water segmentation on a Sentinel-2 mosaic using [s2mosaic](https://github.com/DPIRD-DMA/s2mosaic)
162-
- [Cloudy Sentinel-2 example](https://github.com/DPIRD-DMA/OmniWaterMask/blob/main/examples/Sentinel-2%20example.ipynb) — Masking clouds with [OmniCloudMask](https://github.com/DPIRD-DMA/OmniCloudMask) before running OWM on a cloudy AWS scene
162+
- [Cloudy Sentinel-2 example](https://github.com/DPIRD-DMA/OmniWaterMask/blob/main/examples/Sentinel%202%20cloudy%20example.ipynb) — Masking clouds with [OmniCloudMask](https://github.com/DPIRD-DMA/OmniCloudMask) before running OWM on a cloudy AWS scene
163163

164164
## Changelog
165165

examples/NAIP example.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@
8787
{
8888
"data": {
8989
"application/vnd.jupyter.widget-view+json": {
90-
"model_id": "15c5ab4ffab546538750e0eed14c8f3d",
90+
"model_id": "b2ecf3ebe7e64707aaa2f12927561f7f",
9191
"version_major": 2,
9292
"version_minor": 0
9393
},

examples/Sentinel 2 cloudy example.ipynb

Lines changed: 401 additions & 0 deletions
Large diffs are not rendered by default.

examples/Sentinel 2 example.ipynb

Lines changed: 43 additions & 51 deletions
Large diffs are not rendered by default.

examples/Sentinel-2 example.ipynb

Lines changed: 0 additions & 377 deletions
This file was deleted.

omniwatermask/download_models.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
except ImportError:
1515
omniwatermask_version = "0.0.0+unknown"
1616

17+
gdown_download: Any = getattr(gdown, "download") # noqa: B009
18+
1719

1820
def download_file_from_google_drive(file_id: str, destination: Path) -> None:
1921
"""
@@ -24,7 +26,7 @@ def download_file_from_google_drive(file_id: str, destination: Path) -> None:
2426
destination (Path): The local path where the file should be saved.
2527
"""
2628
url = f"https://drive.google.com/uc?id={file_id}"
27-
gdown.download(url, str(destination), quiet=False)
29+
gdown_download(url, str(destination), quiet=False)
2830

2931

3032
def download_file_from_hugging_face(destination: Path) -> None:
@@ -60,11 +62,25 @@ def download_file(file_id: str, destination: Path, source: str) -> None:
6062
)
6163

6264

65+
def _release_version(version: str) -> str:
66+
"""Return only the public release portion of a version string.
67+
68+
Tag-based versioning produces dev/dirty suffixes between releases
69+
(e.g. "0.5.1.dev3+g1a2b3c4"). Keying the model cache on the full
70+
string would create a new empty directory for every commit and force
71+
a re-download. Stripping the ".dev*"/"+local" suffix keeps the cache
72+
stable between releases while still refreshing on real version bumps.
73+
"""
74+
return version.split("+")[0].split(".dev")[0]
75+
76+
6377
def get_model_data_dir() -> Path:
6478
"""Get the user data directory for model files"""
6579
data_dir = Path(
6680
platformdirs.user_data_dir(
67-
"omniwatermask", version=omniwatermask_version, ensure_exists=True
81+
"omniwatermask",
82+
version=_release_version(omniwatermask_version),
83+
ensure_exists=True,
6884
)
6985
)
7086
return data_dir

omniwatermask/raster_helpers.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import geopandas as gpd
55
import numpy as np
66
import rasterio as rio
7+
from numpy.typing import NDArray
78
from rasterio import features
89
from rasterio.transform import from_bounds
910

@@ -39,11 +40,11 @@ def resample_input(
3940

4041

4142
def export_to_disk(
42-
array: np.ndarray,
43+
array: NDArray[Any],
4344
export_path: Path,
4445
source_path: Path,
4546
layer_names: list[str],
46-
nodata_mask: Optional[np.ndarray] = None,
47+
nodata_mask: Optional[NDArray[Any]] = None,
4748
) -> None:
4849
"""Export the array to disk as a GeoTIFF.
4950
@@ -76,7 +77,7 @@ def export_to_disk(
7677

7778
def rasterize_vector(
7879
gdf: gpd.GeoDataFrame, reference_profile: dict[str, Any], all_touched: bool = False
79-
) -> np.ndarray:
80+
) -> NDArray[Any]:
8081
"""Rasterize a GeoDataFrame into a binary array using the reference rio profile.
8182
8283
With ``all_touched=False`` (the default) a pixel is only set when its centre

omniwatermask/water_inf_helpers.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import numpy as np
99
import rasterio as rio
1010
import torch
11+
from numpy.typing import NDArray
1112
from omnicloudmask import predict_from_array
1213
from scipy.optimize import minimize_scalar
1314

@@ -253,7 +254,7 @@ def multi_scale_optimisation(
253254

254255

255256
def get_NDWI(
256-
input_bands: np.ndarray, mosaic_device: Union[str, torch.device]
257+
input_bands: NDArray[Any], mosaic_device: Union[str, torch.device]
257258
) -> torch.Tensor:
258259
input_bands_tensor = torch.from_numpy(input_bands.astype(np.float16)).to(
259260
mosaic_device
@@ -267,7 +268,7 @@ def get_NDWI(
267268

268269
def make_composite_output(
269270
input_dict: dict[str, Optional[torch.Tensor]],
270-
) -> tuple[np.ndarray, list[str]]:
271+
) -> tuple[NDArray[Any], list[str]]:
271272
output_layers = []
272273
layer_names = []
273274
# Get the shape of the first non-None layer
@@ -289,7 +290,7 @@ def make_composite_output(
289290

290291

291292
def integrate_water_detection_methods(
292-
input_bands: np.ndarray,
293+
input_bands: NDArray[Any],
293294
input_path: Path,
294295
cache_dir: Path,
295296
inference_dtype: torch.dtype,
@@ -311,7 +312,7 @@ def integrate_water_detection_methods(
311312
mosaic_device: Union[str, torch.device] = "cpu",
312313
no_data_value: int = 0,
313314
optimise_model: bool = True,
314-
) -> tuple[np.ndarray, list[str], Optional[np.ndarray]]:
315+
) -> tuple[NDArray[Any], list[str], Optional[NDArray[Any]]]:
315316
"""Combine the NDWI, model predictions and vector targets.
316317
317318
Returns the stacked output array, the per-band layer names, and an optional

pyproject.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ dependencies = [
2525
"tqdm>=4.0",
2626
"platformdirs>=4.0.0",
2727
"fastai>=2.7",
28+
# spaCy 3.8.14 advertises Python 3.14 support but does not publish an
29+
# installable cp314 artifact for the GitHub Actions Linux runner.
30+
"spacy!=3.8.14",
2831
]
2932
license = "MIT"
3033
license-files = ["LICENSE"]

0 commit comments

Comments
 (0)