Skip to content

Commit

Permalink
Merge pull request #31 from TUW-GEO/unit2
Browse files Browse the repository at this point in the history
Unit2
  • Loading branch information
MartinSchobben authored Nov 5, 2024
2 parents d9bbbf1 + deafcc6 commit 8a947b4
Show file tree
Hide file tree
Showing 9 changed files with 609 additions and 349 deletions.

Large diffs are not rendered by default.

137 changes: 78 additions & 59 deletions unit_02/04_l-band-sar.ipynb → unit_02/04_in_class_exercise.ipynb

Large diffs are not rendered by default.

13 changes: 0 additions & 13 deletions unit_02/04_l-band-sar.yml

This file was deleted.

8 changes: 0 additions & 8 deletions unit_02/05_c-and-l-band-comparison.yml

This file was deleted.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

21 changes: 0 additions & 21 deletions unit_02/06_backscatter-variability.yml

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"# Exercise: Dielectric Properties of Natural Media\n",
"# Homework Exercise: Dielectric Properties of Natural Media\n",
"\n",
"## RGB Composite\n",
"Not only radar reflectivity vary according to different land cover classes. The backscattered signal also depends on the change of the imagined natural media over time. We may want to capture in one single image how different land covers comparably change across the same time range. A way to do achieve that is by generating a RGB composite. But what is a RGB composite? It all comes down to combining three image bands into one picture by setting each band as either Red, Green or Blue channel.\n",
Expand Down Expand Up @@ -41,11 +41,11 @@
"metadata": {},
"outputs": [],
"source": [
"data_path = Path('~/shared/datasets/rs/sentinel-1/neusiedler').expanduser()\n",
"data_path = Path(\"~/shared/datasets/rs/sentinel-1/neusiedler\").expanduser()\n",
"\n",
"\n",
"def _preprocess(x, bbox):\n",
" '''\n",
" \"\"\"\n",
" Preprocess file.\n",
"\n",
" Parameters\n",
Expand All @@ -57,21 +57,19 @@
" Returns\n",
" -------\n",
" xarray.Dataset\n",
" '''\n",
" file = x.encoding['source']\n",
" \"\"\"\n",
" file = x.encoding[\"source\"]\n",
"\n",
" with rasterio.open(file) as src:\n",
" scale_factor = pd.to_numeric(src.tags().get('scale_factor'))\n",
" time_value = pd.to_datetime(src.tags().get('time_begin'))\n",
" scale_factor = pd.to_numeric(src.tags().get(\"scale_factor\"))\n",
" time_value = pd.to_datetime(src.tags().get(\"time_begin\"))\n",
"\n",
" x = x / scale_factor\n",
" x = x.assign_coords(time=time_value).expand_dims(\"time\")\n",
"\n",
" x = x.rio.clip_box(*bbox, crs=\"EPSG:4326\")\n",
"\n",
" return x.rename(\n",
" {\"band_data\": \"sig0\"}\n",
" ).squeeze(\"band\").drop_vars(\"band\")\n",
" return x.rename({\"band_data\": \"sig0\"}).squeeze(\"band\").drop_vars(\"band\")\n",
"\n",
"\n",
"bbox = box(16.6, 47.7, 16.75, 47.8)\n",
Expand All @@ -80,11 +78,10 @@
"sig0_ds = xr.open_mfdataset(\n",
" data_path.glob(\"*.tif\"),\n",
" engine=\"rasterio\",\n",
" combine='nested',\n",
" combine=\"nested\",\n",
" concat_dim=\"time\",\n",
" preprocess=partial_func\n",
" ).\\\n",
" sortby(\"time\")\n",
" preprocess=partial_func,\n",
").sortby(\"time\")\n",
"\n",
"sig0_da = sig0_ds.sig0\n",
"sig0_da"
Expand All @@ -94,7 +91,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"### Select the dates of interest\n",
"## Select the Dates of Interest\n",
"\n",
"To create an RGB composite, we need to choose three distinct dates. It's recommended to select dates that are spaced out to capture noticeable changes over time. Pay attention to the season as well, as vegetation and other environmental factors often change significantly throughout the year.\n",
"\n",
Expand Down Expand Up @@ -144,14 +141,29 @@
"\n",
"\n",
"def normalize(val, min, max):\n",
" \"\"\"\n",
" Min-max normalize value\n",
"\n",
" Parameters\n",
" ----------\n",
" val: float\n",
" target\n",
" min: float\n",
" minimum value of range\n",
" max: float\n",
" maximum value of range\n",
" Returns\n",
" -------\n",
" float\n",
" \"\"\"\n",
"\n",
" return (val - min) / (max - min)\n",
"\n",
"\n",
"normalized_ds = normalize(linear_ds, min_value, max_robust).clip(min=0, max=1)\n",
"\n",
"fig, ax = plt.subplots(figsize=(8, 5))\n",
"normalized_ds.isel(time=0).plot.imshow()\n",
"ax.set_aspect('equal')\n",
"normalized_ds.isel(time=0).plot().axes.set_aspect(\"equal\")\n",
"plt.tight_layout()"
]
},
Expand All @@ -172,17 +184,16 @@
"source": [
"fig, axes = plt.subplots(1, 3, figsize=(15, 5))\n",
"\n",
"normalized_ds.isel(time=0).plot(ax=axes[0], cmap='Reds')\n",
"normalized_ds.isel(time=1).plot(ax=axes[1], cmap='Greens')\n",
"normalized_ds.isel(time=2).plot(ax=axes[2], cmap='Blues')\n",
"normalized_ds.isel(time=0).plot(ax=axes[0], cmap=\"Reds\")\n",
"normalized_ds.isel(time=1).plot(ax=axes[1], cmap=\"Greens\")\n",
"normalized_ds.isel(time=2).plot(ax=axes[2], cmap=\"Blues\")\n",
"\n",
"axes[0].set_aspect('equal')\n",
"axes[1].set_aspect('equal')\n",
"axes[2].set_aspect('equal')\n",
"axes[0].set_aspect(\"equal\")\n",
"axes[1].set_aspect(\"equal\")\n",
"axes[2].set_aspect(\"equal\")\n",
"\n",
"\n",
"plt.tight_layout()\n",
"plt.show()"
"plt.tight_layout()"
]
},
{
Expand All @@ -201,11 +212,8 @@
"outputs": [],
"source": [
"fig, ax = plt.subplots(figsize=(8, 5))\n",
"normalized_ds.plot.imshow()\n",
"ax.set_aspect('equal')\n",
"plt.tight_layout()\n",
"\n",
"plt.show()"
"normalized_ds.plot().axes.set_aspect(\"equal\")\n",
"plt.tight_layout()"
]
}
],
Expand Down
Loading

0 comments on commit 8a947b4

Please sign in to comment.