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

Update S-1 process to work with the new dep-tools #3

Merged
merged 1 commit into from
Mar 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
16 changes: 16 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
build:
docker build --tag dep/s1 .

run:
docker run -it --rm \
-e PC_SDK_SUBSCRIPTION_KEY=${PC_SDK_SUBSCRIPTION_KEY} \
-e AZURE_STORAGE_ACCOUNT="deppcpublicstorage" \
-e AZURE_STORAGE_SAS_TOKEN=${AZURE_STORAGE_SAS_TOKEN} \
dep/s1 \
python src/run_task.py \
--region-code "64,20" \
--datetime 2023 \
--version "0.0.0t0" \
--resolution 100 \
--output-bucket files.auspatious.com \
--overwrite
105 changes: 61 additions & 44 deletions Test_S1_Mosaic.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@
"source": [
"from datacube.utils.dask import start_local_dask\n",
"from dep_tools.namers import LocalPath\n",
"from dep_tools.writers import LocalDsWriter\n",
"from dep_tools.writers import LocalDsCogWriter\n",
"\n",
"from src.run_task import get_grid, S1Processor, Sentinel1Loader\n",
"from src.run_task import get_grid, S1Processor\n",
"\n",
"from pystac import Item\n",
"from odc.stac import load"
"from dep_tools.searchers import PystacSearcher\n",
"from dep_tools.loaders import OdcLoader\n",
"\n",
"from planetary_computer import sign_url"
]
},
{
Expand Down Expand Up @@ -52,8 +54,8 @@
"\n",
"# And get the study site\n",
"grid = get_grid()\n",
"cell = grid.loc[[(region_code)]]\n",
"cell.explore()"
"area = grid.loc[[(region_code)]]\n",
"area.explore()"
]
},
{
Expand All @@ -62,23 +64,17 @@
"metadata": {},
"outputs": [],
"source": [
"# Set up a data loader\n",
"loader = Sentinel1Loader(\n",
" epsg=3832,\n",
"# Find some items\n",
"searcher = PystacSearcher(\n",
" catalog=\"https://planetarycomputer.microsoft.com/api/stac/v1/\",\n",
" collections=[\"sentinel-1-rtc\"],\n",
" datetime=datetime,\n",
" dask_chunksize=dict(time=1, x=4096, y=4096),\n",
" odc_load_kwargs=dict(\n",
" fail_on_error=False,\n",
" resolution=100,\n",
" bands=[\"vv\", \"vh\"],\n",
" groupby=\"solar_day\",\n",
" ),\n",
" load_as_dataset=True,\n",
" query = {\"sat:orbit_state\": {\"eq\": \"descending\"}}\n",
")\n",
"\n",
"# Run the load process, which is lazy-loaded\n",
"input_data = loader.load(cell)\n",
"input_data"
"items = searcher.search(area)\n",
"\n",
"print(f\"Found {len(items)} items\")"
]
},
{
Expand All @@ -87,12 +83,20 @@
"metadata": {},
"outputs": [],
"source": [
"# Set up a data processor\n",
"processor = S1Processor()\n",
"# Set up a data loader\n",
"loader = OdcLoader(\n",
" crs=3832,\n",
" resolution=100,\n",
" bands=[\"vv\", \"vh\"],\n",
" groupby=\"solar_day\",\n",
" chunks=dict(time=1, x=4096, y=4096),\n",
" fail_on_error=False,\n",
" patch_url=sign_url\n",
")\n",
"\n",
"# Plan the processing.\n",
"output_data = processor.process(input_data)\n",
"output_data"
"# Run the load process, which is lazy-loaded\n",
"input_data = loader.load(items, area)\n",
"input_data"
]
},
{
Expand All @@ -101,7 +105,12 @@
"metadata": {},
"outputs": [],
"source": [
"output_data[\"count\"].plot.imshow(size=10)"
"# Set up a data processor\n",
"processor = S1Processor()\n",
"\n",
"# Plan the processing.\n",
"output_data = processor.process(input_data)\n",
"output_data"
]
},
{
Expand All @@ -110,7 +119,7 @@
"metadata": {},
"outputs": [],
"source": [
"output_data[[\"median_vv\", \"median_vh\", \"median_vv_vh\"]].to_array().plot.imshow(size=10, vmin=0, vmax=0.1)"
"output_data[\"count\"].plot.imshow(size=10)"
]
},
{
Expand All @@ -119,7 +128,8 @@
"metadata": {},
"outputs": [],
"source": [
"output_data[[\"mean_vv\", \"mean_vh\", \"mean_vv_vh\"]].to_array().plot.imshow(size=10, vmin=0, vmax=0.2)"
"output_data[\"mean_vv_vh\"] = (output_data[\"mean_vv\"] / output_data[\"mean_vh\"])\n",
"output_data[[\"mean_vv\", \"mean_vh\", \"mean_vv_vh\"]].to_array().plot.imshow(size=10, vmin=0, vmax=0.1)"
]
},
{
Expand Down Expand Up @@ -151,13 +161,22 @@
"metadata": {},
"outputs": [],
"source": [
"from odc.stac import load\n",
"from pystac import Item\n",
"# Testing the AWS writer\n",
"\n",
"item = Item.from_file(\"https://deppcpublicstorage.blob.core.windows.net/output/dep_geomad_test/0-0/test/2023-01/dep_geomad_test_test_2023-01.stac-item.json\")\n",
"from dep_tools.writers import AwsDsCogWriter\n",
"from dep_tools.namers import DepItemPath\n",
"\n",
"data = load([item], chunks={})\n",
"data"
"itempath = DepItemPath(\"geomad\", \"test\", \"0.0\", datetime)\n",
"\n",
"writer = AwsDsCogWriter(\n",
" itempath=itempath,\n",
" overwrite=False,\n",
" convert_to_int16=False,\n",
" extra_attrs=dict(dep_version=\"0.0\"),\n",
" bucket=\"files.auspatious.com\"\n",
")\n",
"\n",
"writer.write(output_data, \"test\")"
]
},
{
Expand All @@ -166,7 +185,13 @@
"metadata": {},
"outputs": [],
"source": [
"data.red.isel(time=0).plot.imshow(size=8, robust=True)"
"from odc.stac import load\n",
"from pystac import Item\n",
"\n",
"item = Item.from_file(\"https://deppcpublicstorage.blob.core.windows.net/output/dep_geomad_test/0-0/test/2023-01/dep_geomad_test_test_2023-01.stac-item.json\")\n",
"\n",
"data = load([item], chunks={})\n",
"data"
]
},
{
Expand Down Expand Up @@ -216,16 +241,8 @@
"metadata": {},
"outputs": [],
"source": [
"d = load([item])"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"d[\"count\"].plot()"
"from pystac import Item\n",
"item = Item.from_file(\"https://s3.ap-southeast-2.amazonaws.com/files.auspatious.com/dep_geomad_test/0-0/test/2023/dep_geomad_test_test_2023.stac-item.json\")"
]
},
{
Expand Down
4 changes: 3 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
boto3
typer
git+https://github.com/digitalearthpacific/dep-tools.git
git+https://github.com/digitalearthpacific/dep-tools.git@add-s3-writer


--no-binary gdal
--no-binary rasterio
Loading
Loading