diff --git a/codemeta.json b/codemeta.json index 51939ad..2030c55 100644 --- a/codemeta.json +++ b/codemeta.json @@ -5,12 +5,12 @@ "codeRepository": "https://github.com/eoap/mastering-app-package.git", "dateCreated": "2022-09-01", "datePublished": "2022-09-25", - "dateModified": "2024-11-07", + "dateModified": "2025-08-18", "name": "Water Bodies Detection", - "version": "1.1.0", + "version": "1.1.1", "description": "The Water Bodies Detection is an Application that uses the NDWI index and the Otsu threshold to detect water bodies using Sentinel-2 or Landsat-9 data", "developmentStatus": "active", - "downloadUrl": "https://github.com/eoap/mastering-app-package/releases/tag/1.1.0", + "downloadUrl": "https://github.com/eoap/mastering-app-package/releases/tag/1.1.1", "relatedLink": [ "https://eoap.github.io/mastering-app-package" ], diff --git a/water-bodies/command-line-tools/crop/Dockerfile b/water-bodies/command-line-tools/crop/Dockerfile index 7a9f1b2..189cf67 100644 --- a/water-bodies/command-line-tools/crop/Dockerfile +++ b/water-bodies/command-line-tools/crop/Dockerfile @@ -1,6 +1,6 @@ FROM docker.io/library/python:3.10-slim@sha256:80619a5316afae7045a3c13371b0ee670f39bac46ea1ed35081d2bf91d6c3dbd -RUN pip install --no-cache-dir rasterio click pystac loguru pyproj shapely && \ +RUN pip install --no-cache-dir rasterio click pystac loguru pyproj shapely planetary_computer && \ python -c "import rasterio" ADD app.py /app/app.py diff --git a/water-bodies/command-line-tools/crop/app.py b/water-bodies/command-line-tools/crop/app.py index 606fb9b..a4bd344 100644 --- a/water-bodies/command-line-tools/crop/app.py +++ b/water-bodies/command-line-tools/crop/app.py @@ -6,19 +6,26 @@ from pyproj import Transformer from shapely import box from loguru import logger - +import planetary_computer def aoi2box(aoi): """Converts an area of interest expressed as a bounding box to a list of floats""" return [float(c) for c in aoi.split(",")] +def sign_asset_href(asset): + """Adjusts the asset href to be relative to the current working directory""" + signed_asset = planetary_computer.sign(asset) # asset is the pystac Asset object genetated from the STAC item + #logger.info(f"Signed asset href: {signed_asset.get_absolute_href()}") + return signed_asset def get_asset(item, common_name): """Returns the asset of a STAC Item defined with its common band name""" for _, asset in item.get_assets().items(): + if not "data" in asset.to_dict()["roles"]: continue - + if 'https://planetarycomputer.microsoft.com/api/stac/v1' in item.get_self_href(): + asset = sign_asset_href(asset) eo_asset = pystac.extensions.eo.AssetEOExtension(asset) if not eo_asset.bands: continue @@ -77,16 +84,15 @@ def crop(item_url, aoi, band, epsg): raise ValueError(msg) bbox = aoi2box(aoi) - with rasterio.open(asset.get_absolute_href()) as src: transformer = Transformer.from_crs(epsg, src.crs, always_xy=True) - + print(epsg, src.crs) minx, miny = transformer.transform(bbox[0], bbox[1]) maxx, maxy = transformer.transform(bbox[2], bbox[3]) transformed_bbox = box(minx, miny, maxx, maxy) - + logger.info(f"Transformed bounding box: {transformed_bbox}") logger.info(f"Crop {asset.get_absolute_href()}") out_image, out_transform = rasterio.mask.mask(