Cameron decomposition¶
This notebook shows how to apply the Cameron 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 cameron
# 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 cameron
# 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():
cameron(S).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():
cameron(S).to_netcdf(file_out)
[########################################] | 100% Completed | 20.22 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 the outputs:
In [ ]:
Copied!
# the image is cropped for better visualization
res.cameron[8000:12000,200:1100].plot.imshow(cmap="Dark2")
# the image is cropped for better visualization
res.cameron[8000:12000,200:1100].plot.imshow(cmap="Dark2")
Out[ ]:
<matplotlib.image.AxesImage at 0x7a15a957c0b0>