Debian Codegraph @

notebooks/yamaguchi3-tutorial.ipynb

raw
1 {
2 "cells": [
3 {
4 "cell_type": "markdown",
5 "metadata": {},
6 "source": [
7 "# Yamaguchi 3-component decomposition"
8 ]
9 },
10 {
11 "cell_type": "markdown",
12 "metadata": {},
13 "source": [
14 "This notebook shows how to apply the Yamaguchi 3-component decomposition to a PolSARpro NetCDF dataset."
15 ]
16 },
17 {
18 "cell_type": "markdown",
19 "metadata": {},
20 "source": [
21 "## Import packages and set directories"
22 ]
23 },
24 {
25 "cell_type": "code",
26 "execution_count": null,
27 "metadata": {},
28 "outputs": [],
29 "source": [
30 "import os \n",
31 "from pathlib import Path\n",
32 "import xarray as xr\n",
33 "from polsarpro.io import open_netcdf_beam\n",
34 "from polsarpro.decompositions import yamaguchi3\n",
35 "\n",
36 "# optional import for progress bar\n",
37 "from dask.diagnostics import ProgressBar\n",
38 "\n",
39 "# change to your data paths\n",
40 "# original dataset\n",
41 "input_alos_data = Path(\"/data/psp/test_files/SAN_FRANCISCO_ALOS1_slc.nc\")\n",
42 "output_dir = Path(\"/data/psp/res\")\n"
43 ]
44 },
45 {
46 "cell_type": "markdown",
47 "metadata": {},
48 "source": [
49 "## Load data\n",
50 "\n",
51 "We load the SNAP NetCDF-BEAM dataset using the `open_netcdf_beam` function. \n",
52 "To obtain such a dataset, please refer to the \"Getting Started\" tutorial or the `quickstart-tutorial.ipynb` notebook."
53 ]
54 },
55 {
56 "cell_type": "code",
57 "execution_count": null,
58 "metadata": {},
59 "outputs": [],
60 "source": [
61 "# uncomment to test on S matrix made with SNAP\n",
62 "S = open_netcdf_beam(input_alos_data)"
63 ]
64 },
65 {
66 "cell_type": "markdown",
67 "metadata": {},
68 "source": [
69 "## Apply the decomposition\n",
70 "\n",
71 "Let's apply the decomposition and write the result to a NetCDF file.\n",
72 "Optionally we can use a progress bar to monitor the progress of the computation."
73 ]
74 },
75 {
76 "cell_type": "code",
77 "execution_count": null,
78 "metadata": {},
79 "outputs": [],
80 "source": [
81 "# change to the name of your liking\n",
82 "file_out = output_dir / \"psp_freeman.nc\"\n",
83 "\n",
84 "# netcdf writer cannot overwrite\n",
85 "if os.path.isfile(file_out):\n",
86 " os.remove(file_out)\n",
87 "\n",
88 "with ProgressBar():\n",
89 " yamaguchi3(S, boxcar_size=[7, 7]).to_netcdf(file_out)"
90 ]
91 },
92 {
93 "cell_type": "markdown",
94 "metadata": {},
95 "source": [
96 "## Display outputs"
97 ]
98 },
99 {
100 "cell_type": "markdown",
101 "metadata": {},
102 "source": [
103 "We open the previously saved dataset:"
104 ]
105 },
106 {
107 "cell_type": "code",
108 "execution_count": null,
109 "metadata": {},
110 "outputs": [],
111 "source": [
112 "res = xr.open_dataset(file_out)"
113 ]
114 },
115 {
116 "cell_type": "markdown",
117 "metadata": {},
118 "source": [
119 "Then we may plot individual parameters:"
120 ]
121 },
122 {
123 "cell_type": "code",
124 "execution_count": null,
125 "metadata": {},
126 "outputs": [],
127 "source": [
128 "# odd bounce / surface component\n",
129 "res.odd.plot.imshow(vmin=0, vmax=1)"
130 ]
131 },
132 {
133 "cell_type": "code",
134 "execution_count": null,
135 "metadata": {},
136 "outputs": [],
137 "source": [
138 "# double bounce\n",
139 "res.double.plot.imshow(vmin=0, vmax=1)"
140 ]
141 },
142 {
143 "cell_type": "code",
144 "execution_count": null,
145 "metadata": {},
146 "outputs": [],
147 "source": [
148 "# volume component\n",
149 "res.volume.plot.imshow(vmin=0, vmax=1)"
150 ]
151 }
152 ],
153 "metadata": {
154 "kernelspec": {
155 "display_name": "psp",
156 "language": "python",
157 "name": "python3"
158 },
159 "language_info": {
160 "codemirror_mode": {
161 "name": "ipython",
162 "version": 3
163 },
164 "file_extension": ".py",
165 "mimetype": "text/x-python",
166 "name": "python",
167 "nbconvert_exporter": "python",
168 "pygments_lexer": "ipython3",
169 "version": "3.12.11"
170 }
171 },
172 "nbformat": 4,
173 "nbformat_minor": 2
174 }