Freeman-Durden decomposition¶
This notebook shows how to apply the Freeman-Durden 3-component decomposition to a PolSARpro NetCDF dataset.
Import packages and set directories¶
In [1]:
Copied!
import os
from pathlib import Path
import xarray as xr
from polsarpro.io import open_netcdf_beam
from polsarpro.decompositions import freeman
# optional import for progress bar
from dask.diagnostics import ProgressBar
# change to your data paths
# original dataset
input_alos_data = Path("/data/psp/test_files/SAN_FRANCISCO_ALOS1_slc.nc")
output_dir = Path("/data/psp/res")
import os
from pathlib import Path
import xarray as xr
from polsarpro.io import open_netcdf_beam
from polsarpro.decompositions import freeman
# optional import for progress bar
from dask.diagnostics import ProgressBar
# change to your data paths
# original dataset
input_alos_data = Path("/data/psp/test_files/SAN_FRANCISCO_ALOS1_slc.nc")
output_dir = Path("/data/psp/res")
Load data¶
We load the SNAP NetCDF-BEAM dataset using the open_netcdf_beam function.
To obtain such a dataset, please refer to the "Getting Started" tutorial or the quickstart-tutorial.ipynb notebook.
In [2]:
Copied!
# uncomment to test on S matrix made with SNAP
S = open_netcdf_beam(input_alos_data)
# uncomment to test on S matrix made with SNAP
S = open_netcdf_beam(input_alos_data)
Apply the decomposition¶
Let's apply the decomposition and write the result to a NetCDF file. Optionally we can use a progress bar to monitor the progress of the computation.
In [3]:
Copied!
# change to the name of your liking
file_out = output_dir / "psp_freeman.nc"
# netcdf writer cannot overwrite
if os.path.isfile(file_out):
os.remove(file_out)
with ProgressBar():
freeman(S, boxcar_size=[7, 7]).to_netcdf(file_out)
# change to the name of your liking
file_out = output_dir / "psp_freeman.nc"
# netcdf writer cannot overwrite
if os.path.isfile(file_out):
os.remove(file_out)
with ProgressBar():
freeman(S, boxcar_size=[7, 7]).to_netcdf(file_out)
[########################################] | 100% Completed | 15.82 s
Display outputs¶
We open the previously saved dataset:
In [4]:
Copied!
res = xr.open_dataset(file_out)
res = xr.open_dataset(file_out)
Then we may plot individual parameters:
In [ ]:
Copied!
# odd bounce / surface component
res.odd.plot.imshow(vmin=0, vmax=1)
# odd bounce / surface component
res.odd.plot.imshow(vmin=0, vmax=1)
Out[ ]:
<matplotlib.image.AxesImage at 0x783e191d34d0>
In [6]:
Copied!
# double bounce
res.double.plot.imshow(vmin=0, vmax=1)
# double bounce
res.double.plot.imshow(vmin=0, vmax=1)
Out[6]:
<matplotlib.image.AxesImage at 0x783e17c60c80>
In [7]:
Copied!
# volume component
res.volume.plot.imshow(vmin=0, vmax=1)
# volume component
res.volume.plot.imshow(vmin=0, vmax=1)
Out[7]:
<matplotlib.image.AxesImage at 0x783e180616d0>