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

Add first draft of geomad notebook #1

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.ipynb_checkpoints/

212 changes: 212 additions & 0 deletions S1_GeoMAD_Mosaic_Test.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,212 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Sentinel-1 GeoMAD\n",
"\n",
"This notebook runs a process to load Sentinel-1 data and produce\n",
"a geometric median and median absolute deviations. Two test regions\n",
"are currently available, one in Tasmania and one in Moretons Bay.\n",
"\n",
"Key requirements include Datacube and a specific branch of\n",
"[odc-algo](https://github.com/opendatacube/odc-algo/tree/add-rust-geomedian-impl)."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"import odc.geo.xr # noqa: F401\n",
"from datacube import Datacube\n",
"from distributed import Client\n",
"from dask import config\n",
"from numpy import log10\n",
"\n",
"from odc.algo import geomedian_with_mads\n",
"from odc.stac import configure_rio\n",
"\n",
"from collections import namedtuple\n",
"\n",
"# from easi_tools.notebook_utils import localcluster_dashboard\n",
"# from easi_tools import EasiDefaults"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"# Connect to the datacube and set up some config\n",
"dc = Datacube()\n",
"\n",
"# Rasterio defaults\n",
"configure_rio(cloud_defaults=True)\n",
"\n",
"# Easi defaults\n",
"# easi = EasiDefaults()\n",
"\n",
"# A simple data structure for our study sites\n",
"study_site = namedtuple(\"study_site\", [\"name\", \"bbox\"])"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"# Configure Dask using defaults\n",
"client = Client()\n",
"\n",
"# print(localcluster_dashboard(client=client, server=easi.hub))"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"# Change process parameters here\n",
"\n",
"# Study site in Tasmania\n",
"site = study_site(\"southern_tasmania\", [146.2357, -43.6796, 147.147, -42.9305])\n",
"\n",
"# Study site in Moreton Bay\n",
"# site = study_site(\"moreton_bay\", [152.00, -27.50, 153.20, -26.50])\n",
"\n",
"year = \"2023\"\n",
"\n",
"data = dc.load(\n",
" product=\"sentinel1_grd_gamma0_beta\",\n",
" lon=(site.bbox[0], site.bbox[2]),\n",
" lat=(site.bbox[1], site.bbox[3]),\n",
" time=year,\n",
" resolution=(-20, 20),\n",
" output_crs=\"EPSG:3577\",\n",
" dask_chunks=dict(x=2048, y=2048),\n",
" group_by=\"solar_day\",\n",
" measurements=[\"vv\", \"vh\"],\n",
")\n",
"\n",
"# Mask out nodata values\n",
"data = data.where(data.vv > 0)\n",
"\n",
"data"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"# Get the geomedian and mad bands\n",
"geomad = geomedian_with_mads(data, work_chunks=(2048, 2048), num_threads=32)\n",
"\n",
"# Calculate means\n",
"for band in [\"vv\", \"vh\"]:\n",
" geomad[f\"{band}_mean\"] = data[band].mean(\"time\")\n",
"\n",
"geomad"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"# This step run the computation on Dask. Open the dashboard\n",
"# link above to watch it process.\n",
"computed = geomad.compute()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"computed[\"vv\"].plot.imshow(robust=True)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"computed[\"vv_mean\"].plot.imshow(robust=True)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"(computed[\"vv\"] - computed[\"vv_mean\"]).plot.imshow(robust=True)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"computed[\"vv_log\"] = 10 * log10(computed.vv)\n",
"computed[\"vh_log\"] = 10 * log10(computed.vh)\n",
"computed[\"vh_vv_log\"] = 0.5 * (computed.vh_log / computed.vv_log)\n",
"\n",
"computed.odc.explore(bands=[\"vv_log\", \"vh_log\", \"vh_vv_log\"], vmin=-30, vmax=0)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Alex Test Environment",
"language": "python",
"name": "test"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.12"
}
},
"nbformat": 4,
"nbformat_minor": 4
}