{ "cells": [ { "cell_type": "markdown", "id": "db8d71aa", "metadata": {}, "source": [ "## Radiometric terrain correction qualitative assessment \n", "\n", "[sarsen](https://github.com/bopen/sarsen) radiometric correction implements the gamma flatting algorithm proposed by Small, David (2011). [Flattening Gamma: Radiometric Terrain Correction for SAR Imagery. Geoscience and Remote Sensing, IEEE Transactions on. 49. 3081 - 3093. 10.1109/TGRS.2011.2120616](https://www.researchgate.net/publication/224230688_Flattening_Gamma_Radiometric_Terrain_Correction_for_SAR_Imagery)\n", "\n", "In this notebook, we perform the same qualitative test done by the authors to evaluate the goodness of the gamma flattening correction. For an introduction to terrain correction, see [Customizable radiometric terrain corrections of Sentinel-1 products\n", "](https://planetarycomputer.microsoft.com/docs/tutorials/customizable-rtc-sentinel1/)." ] }, { "cell_type": "markdown", "id": "6d604a80-9222-46f2-97cb-afe5bfb9bdbd", "metadata": {}, "source": [ "### Install Dependencies and Imports\n", "Additional dependencies: `sarsen==0.9.2`" ] }, { "cell_type": "code", "execution_count": 1, "id": "ce375bf1-9ec8-4aa5-b3ce-cbfe5995c31e", "metadata": {}, "outputs": [], "source": [ "# !pip install sarsen==0.9.2" ] }, { "cell_type": "code", "execution_count": 2, "id": "9f82185a-60a4-4651-8bdf-6fb1ee82c884", "metadata": {}, "outputs": [], "source": [ "%matplotlib inline\n", "%config InlineBackend.figure_format = 'retina'\n", "\n", "\n", "import matplotlib.pyplot as plt\n", "from matplotlib.colors import Normalize\n", "from matplotlib import cm\n", "\n", "plt.rcParams[\"figure.figsize\"] = (10, 7)\n", "plt.rcParams[\"font.size\"] = 14" ] }, { "cell_type": "code", "execution_count": 3, "id": "1391c47f-d76e-4840-8eed-d547b4784331", "metadata": {}, "outputs": [], "source": [ "import os\n", "import tempfile\n", "\n", "import numpy as np\n", "import xarray as xr\n", "from scipy.stats import gaussian_kde as kde\n", "from sarsen import apps, geocoding, orbit, scene\n", "\n", "import adlfs\n", "import planetary_computer\n", "import pystac_client\n", "import stackstac\n", "import rioxarray # noqa: F401\n", "\n", "plt.rcParams[\"figure.figsize\"] = (10, 7)" ] }, { "cell_type": "markdown", "id": "86970ee8", "metadata": {}, "source": [ "### Processing definitions" ] }, { "cell_type": "code", "execution_count": 4, "id": "107608ba-51f5-4a3d-ab70-bc9fb34eafed", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'/tmp'" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# create a temporary directory where to store downloaded data\n", "tmp_dir = tempfile.gettempdir()\n", "\n", "# DEM path\n", "dem_path = os.path.join(tmp_dir, \"South-of-Redmond-10m.tif\")\n", "\n", "# path to Sentinel-1 input product in the Planetary Computer\n", "product_folder = \"GRD/2021/12/17/IW/DV/S1B_IW_GRDH_1SDV_20211217T141304_20211217T141329_030066_039705_9048\" # noqa: E501\n", "\n", "# band to be processed\n", "measurement_group = \"IW/VV\"\n", "\n", "tmp_dir" ] }, { "cell_type": "markdown", "id": "4dd0a0f2-4476-48fa-bceb-6f5a872c59de", "metadata": {}, "source": [ "#### Area of interest definition: South-of-Redmond (Seattle, US)" ] }, { "cell_type": "code", "execution_count": 5, "id": "8ec8652a-7736-40cc-b8d9-1134493e5888", "metadata": {}, "outputs": [], "source": [ "lon, lat = [-121.95, 47.04]\n", "buffer = 0.2\n", "bbox = [lon - buffer, lat - buffer, lon + buffer, lat + buffer]" ] }, { "cell_type": "markdown", "id": "b144d7a4-839b-4e41-95ca-6d20418432d9", "metadata": {}, "source": [ "#### DEMs discovery\n", "\n", "Here we use the DEM with a 10-meter ground sample distance (GDS) available on the Planetary Computer. Note that **any DEM supported by GDAL/Proj can be used**.\n", "\n", "Using `pystac_client` we can search the Planetary Computer's STAC endpoint for items matching our query parameters. \n", "As multiple DEMs acquired at different times are available in this area, we select the DEMs with 10-meter GDS and perform the average of the remaining DEMs along the time dimension." ] }, { "cell_type": "code", "execution_count": 6, "id": "e08b28b1-a706-4005-b1e8-633a748e7f69", "metadata": {}, "outputs": [], "source": [ "catalog = pystac_client.Client.open(\n", " \"https://planetarycomputer.microsoft.com/api/stac/v1\",\n", " modifier=planetary_computer.sign_inplace,\n", ")\n", "search = catalog.search(\n", " collections=\"3dep-seamless\", bbox=bbox, query={\"gsd\": {\"eq\": 10}}\n", ")\n", "items = search.item_collection()" ] }, { "cell_type": "markdown", "id": "7503fa77-ba5a-492c-9662-ae2f9b2ba5f4", "metadata": {}, "source": [ "Here we load the data into an xarray `DataArray` using stackstac." ] }, { "cell_type": "code", "execution_count": 7, "id": "625eb3d3-90b0-429b-addc-e0ac59e60942", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
<xarray.DataArray 'stackstac-6fbfb106cd445ae5ea0f677ec80c3c41' (time: 4,\n", " y: 4321, x: 4321)>\n", "dask.array<getitem, shape=(4, 4321, 4321), dtype=float64, chunksize=(1, 1024, 1024), chunktype=numpy.ndarray>\n", "Coordinates: (12/13)\n", " * time (time) datetime64[ns] 2018-02-02 2018-02-08 ... 2020-01-07\n", " id (time) <U10 'n48w122-13' 'n47w122-13' ... 'n48w123-13'\n", " band <U4 'data'\n", " * x (x) float64 -122.2 -122.1 -122.1 ... -121.8 -121.8 -121.8\n", " * y (y) float64 47.24 47.24 47.24 47.24 ... 46.84 46.84 46.84\n", " start_datetime (time) <U20 '1952-01-01T00:00:00Z' ... '2017-09-14T00:00...\n", " ... ...\n", " proj:shape object {10812}\n", " proj:epsg int64 5498\n", " threedep:region <U7 'n40w130'\n", " gsd int64 10\n", " description <U1849 'This tile of the 3D Elevation Program (3DEP) sea...\n", " epsg int64 5498\n", "Attributes:\n", " spec: RasterSpec(epsg=5498, bounds=(-122.15000053746, 46.839907613...\n", " crs: epsg:5498\n", " transform: | 0.00, 0.00,-122.15|\\n| 0.00,-0.00, 47.24|\\n| 0.00, 0.00, 1...\n", " resolution: 9.2592593e-05
<xarray.DataArray 'stackstac-6fbfb106cd445ae5ea0f677ec80c3c41' (y: 4487, x: 3100)>\n", "array([[1.79769313e+308, 1.79769313e+308, 1.79769313e+308, ...,\n", " 1.79769313e+308, 1.79769313e+308, 1.79769313e+308],\n", " [1.79769313e+308, 1.79769313e+308, 1.79769313e+308, ...,\n", " 1.79769313e+308, 1.79769313e+308, 1.79769313e+308],\n", " [1.79769313e+308, 1.79769313e+308, 1.79769313e+308, ...,\n", " 1.79769313e+308, 1.79769313e+308, 1.79769313e+308],\n", " ...,\n", " [1.79769313e+308, 1.79769313e+308, 1.79769313e+308, ...,\n", " 1.79769313e+308, 1.79769313e+308, 1.79769313e+308],\n", " [1.79769313e+308, 1.79769313e+308, 1.79769313e+308, ...,\n", " 1.79769313e+308, 1.79769313e+308, 1.79769313e+308],\n", " [1.79769313e+308, 1.79769313e+308, 1.79769313e+308, ...,\n", " 1.79769313e+308, 1.79769313e+308, 1.79769313e+308]])\n", "Coordinates:\n", " * x (x) float64 5.643e+05 5.643e+05 ... 5.953e+05 5.953e+05\n", " * y (y) float64 5.233e+06 5.233e+06 ... 5.188e+06 5.188e+06\n", " proj:shape object {10812}\n", " epsg int64 5498\n", " threedep:region <U7 'n40w130'\n", " proj:epsg int64 5498\n", " gsd int64 10\n", " band <U4 'data'\n", " description <U1849 'This tile of the 3D Elevation Program (3DEP) sea...\n", " spatial_ref int64 0\n", "Attributes:\n", " _FillValue: 1.7976931348623157e+308" ], "text/plain": [ "
<xarray.DataArray 'stackstac-6fbfb106cd445ae5ea0f677ec80c3c41' (y: 1500, x: 1400)>\n", "array([[ 840.86486816, 837.69940186, 836.6675415 , ..., 1222.60290527,\n", " 1224.68151855, 1229.60192871],\n", " [ 847.59912109, 843.43511963, 841.19110107, ..., 1226.77722168,\n", " 1229.88330078, 1235.05480957],\n", " [ 853.09313965, 849.24804688, 847.56011963, ..., 1231.57214355,\n", " 1235.27197266, 1240.26989746],\n", " ...,\n", " [1057.71154785, 1056.44726562, 1053.34716797, ..., 1967.21203613,\n", " 1966.72473145, 1967.17895508],\n", " [1053.78833008, 1052.40124512, 1049.59545898, ..., 1970.66943359,\n", " 1969.1439209 , 1969.60314941],\n", " [1049.06298828, 1048.03967285, 1045.55126953, ..., 1973.11730957,\n", " 1971.60437012, 1971.93334961]])\n", "Coordinates:\n", " * x (x) float64 5.79e+05 5.79e+05 ... 5.93e+05 5.93e+05\n", " * y (y) float64 5.21e+06 5.21e+06 ... 5.195e+06 5.195e+06\n", " proj:shape object {10812}\n", " epsg int64 5498\n", " threedep:region <U7 'n40w130'\n", " proj:epsg int64 5498\n", " gsd int64 10\n", " band <U4 'data'\n", " description <U1849 'This tile of the 3D Elevation Program (3DEP) sea...\n", " spatial_ref int64 0\n", "Attributes:\n", " _FillValue: 1.7976931348623157e+308" ], "text/plain": [ "