Skip to content

Commit

Permalink
Merge pull request #10 from digitalearthpacific/fix-stac-asset-path-w…
Browse files Browse the repository at this point in the history
…riting

Fix stac asset path writing
  • Loading branch information
alexgleith authored Sep 26, 2023
2 parents 598c4bf + 5a89538 commit 43eadef
Show file tree
Hide file tree
Showing 4 changed files with 1,332 additions and 306 deletions.
1,594 changes: 1,307 additions & 287 deletions Test_Mangroves.ipynb

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
typer
git+https://github.com/digitalearthpacific/dep-tools.git@b47153b
git+https://github.com/digitalearthpacific/dep-tools.git@e5bf3f8
git+https://github.com/jessjaco/azure-logger.git@b23c9c7
xarray-spatial

Expand Down
7 changes: 0 additions & 7 deletions src/grid.py

This file was deleted.

35 changes: 24 additions & 11 deletions src/run_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,17 @@
from dep_tools.azure import get_container_client
from dep_tools.loaders import Sentinel2OdcLoader
from dep_tools.namers import DepItemPath
from dep_tools.runner import run_by_area_dask_local, run_by_area_dask
from dep_tools.runner import run_by_area_dask_local
from dep_tools.s2_utils import S2Processor
from dep_tools.stac_utils import set_stac_properties
from dep_tools.writers import AzureDsWriter

from grid import grid
import geopandas as gpd
import fsspec


GRID_URL = "https://deppcpublicstorage.blob.core.windows.net/input/gmw/grid_gmw_v3_2020_vec.parquet"


MANGROVES_BASE_PRODUCT = "s2"
MANGROVES_DATASET_ID = "mangroves"
Expand All @@ -40,6 +45,21 @@ def process(self, xr: DataArray) -> DataArray:
return set_stac_properties(xr, ds)


def get_areas(region_code: str, region_index: str) -> gpd.GeoDataFrame:
with fsspec.open(GRID_URL) as f:
grid = gpd.read_parquet(f)
areas = None

# None would be better for default but typer doesn't support it (str|None)
if region_code != "":
areas = grid[grid.index.get_level_values("code").isin([region_code])]

if region_index != "":
areas = grid[grid.index == (region_code, region_index)]

return areas


def main(
datetime: Annotated[str, typer.Option()],
version: Annotated[str, typer.Option()],
Expand All @@ -48,16 +68,9 @@ def main(
local_cluster_kwargs: Annotated[str, typer.Option()] = "",
dataset_id: str = MANGROVES_DATASET_ID,
) -> None:
areas = grid

# None would be better for default but typer doesn't support it (str|None)
if region_code != "":
areas = grid[grid.index.get_level_values("code").isin([region_code])]

if region_index != "":
areas = grid[grid.index == (region_code, region_index)]
areas = get_areas(region_code, region_index)

if len(areas) == 0:
if areas is None or len(areas) == 0:
warnings.warn(
f"index ({region_code}, {region_index}) not found in grid, no output produced"
)
Expand Down

0 comments on commit 43eadef

Please sign in to comment.