| 1 |
{ |
| 2 |
"cells": [ |
| 3 |
{ |
| 4 |
"cell_type": "markdown", |
| 5 |
"metadata": {}, |
| 6 |
"source": [ |
| 7 |
"# Yamaguchi 4-component decomposition" |
| 8 |
] |
| 9 |
}, |
| 10 |
{ |
| 11 |
"cell_type": "markdown", |
| 12 |
"metadata": {}, |
| 13 |
"source": [ |
| 14 |
"This notebook shows how to apply the Yamaguchi 4-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 yamaguchi4\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 |
"mode = \"y4r\" # choose mode among \"y4o\", \"y4r\", \"s4r\"\n", |
| 89 |
"\n", |
| 90 |
"with ProgressBar():\n", |
| 91 |
" yamaguchi4(S, boxcar_size=[7, 7], mode=mode).to_netcdf(file_out)" |
| 92 |
] |
| 93 |
}, |
| 94 |
{ |
| 95 |
"cell_type": "markdown", |
| 96 |
"metadata": {}, |
| 97 |
"source": [ |
| 98 |
"## Display outputs" |
| 99 |
] |
| 100 |
}, |
| 101 |
{ |
| 102 |
"cell_type": "markdown", |
| 103 |
"metadata": {}, |
| 104 |
"source": [ |
| 105 |
"We open the previously saved dataset:" |
| 106 |
] |
| 107 |
}, |
| 108 |
{ |
| 109 |
"cell_type": "code", |
| 110 |
"execution_count": null, |
| 111 |
"metadata": {}, |
| 112 |
"outputs": [], |
| 113 |
"source": [ |
| 114 |
"res = xr.open_dataset(file_out)" |
| 115 |
] |
| 116 |
}, |
| 117 |
{ |
| 118 |
"cell_type": "markdown", |
| 119 |
"metadata": {}, |
| 120 |
"source": [ |
| 121 |
"Then we may plot individual parameters:" |
| 122 |
] |
| 123 |
}, |
| 124 |
{ |
| 125 |
"cell_type": "code", |
| 126 |
"execution_count": null, |
| 127 |
"metadata": {}, |
| 128 |
"outputs": [], |
| 129 |
"source": [ |
| 130 |
"# odd bounce / surface component\n", |
| 131 |
"res.odd.plot.imshow(vmin=0, vmax=1)" |
| 132 |
] |
| 133 |
}, |
| 134 |
{ |
| 135 |
"cell_type": "code", |
| 136 |
"execution_count": null, |
| 137 |
"metadata": {}, |
| 138 |
"outputs": [], |
| 139 |
"source": [ |
| 140 |
"# double bounce\n", |
| 141 |
"res.double.plot.imshow(vmin=0, vmax=1)" |
| 142 |
] |
| 143 |
}, |
| 144 |
{ |
| 145 |
"cell_type": "code", |
| 146 |
"execution_count": null, |
| 147 |
"metadata": {}, |
| 148 |
"outputs": [], |
| 149 |
"source": [ |
| 150 |
"# volume component\n", |
| 151 |
"res.volume.plot.imshow(vmin=0, vmax=1)" |
| 152 |
] |
| 153 |
}, |
| 154 |
{ |
| 155 |
"cell_type": "code", |
| 156 |
"execution_count": null, |
| 157 |
"metadata": {}, |
| 158 |
"outputs": [], |
| 159 |
"source": [ |
| 160 |
"# helix component\n", |
| 161 |
"res.helix.plot.imshow(vmin=0, vmax=1)" |
| 162 |
] |
| 163 |
} |
| 164 |
], |
| 165 |
"metadata": { |
| 166 |
"kernelspec": { |
| 167 |
"display_name": "psp", |
| 168 |
"language": "python", |
| 169 |
"name": "python3" |
| 170 |
}, |
| 171 |
"language_info": { |
| 172 |
"codemirror_mode": { |
| 173 |
"name": "ipython", |
| 174 |
"version": 3 |
| 175 |
}, |
| 176 |
"file_extension": ".py", |
| 177 |
"mimetype": "text/x-python", |
| 178 |
"name": "python", |
| 179 |
"nbconvert_exporter": "python", |
| 180 |
"pygments_lexer": "ipython3", |
| 181 |
"version": "3.12.12" |
| 182 |
} |
| 183 |
}, |
| 184 |
"nbformat": 4, |
| 185 |
"nbformat_minor": 2 |
| 186 |
} |