Download this notebook from github.


Xsarsea example

The Normalized Radar Cross Section (sigma0) as computed from Level-1 SAR data can be detrended in the case of ocean scenes.

The goal is to remove the averaged trend (decreasing) of the NRCS with (increasing) incidence angle observed for acquisitions over ocean.

The detrend maximizes the contrasts in the image due to geophysical phenomena and improves the visualization experience of ocean scenes.

Sigma0_detrend is also termed image roughness or nice display.

[1]:
import xsar
import xsarsea
[2]:
# use holoviews for plots
import bokeh.io
bokeh.io.output_notebook()
import holoviews as hv
hv.extension('bokeh')
from holoviews.operation.datashader import datashade,rasterize
Loading BokehJS ...
[3]:
# optional debug message
import logging
logging.basicConfig()
logging.getLogger('xsarsea').setLevel(logging.INFO) # .setLevel(logging.DEBUG) for more messages

read the dataset with xsar

[4]:
# get test file. You can replace with an path to other SAFE
filename = xsar.get_test_file('S1A_IW_GRDH_1SDV_20170907T103020_20170907T103045_018268_01EB76_Z010.SAFE')
filename
[4]:
'/tmp/S1A_IW_GRDH_1SDV_20170907T103020_20170907T103045_018268_01EB76_Z010.SAFE'
[5]:
# open the dataset with xsar
sar_ds = xsar.open_dataset(filename, resolution='1000m')
sar_ds[['longitude','latitude','sigma0','incidence']]

[5]:
<xarray.Dataset>
Dimensions:      (line: 167, sample: 251, pol: 2)
Coordinates:
  * pol          (pol) object 'VV' 'VH'
  * line         (line) float64 49.5 149.5 249.5 ... 1.655e+04 1.665e+04
  * sample       (sample) float64 49.5 149.5 249.5 ... 2.495e+04 2.505e+04
    spatial_ref  int64 0
Data variables:
    longitude    (line, sample) float64 dask.array<chunksize=(167, 251), meta=np.ndarray>
    latitude     (line, sample) float64 dask.array<chunksize=(167, 251), meta=np.ndarray>
    sigma0       (pol, line, sample) float64 dask.array<chunksize=(1, 167, 251), meta=np.ndarray>
    incidence    (line, sample) float64 dask.array<chunksize=(167, 251), meta=np.ndarray>
Attributes: (12/15)
    name:              SENTINEL1_DS:/tmp/S1A_IW_GRDH_1SDV_20170907T103020_201...
    short_name:        SENTINEL1_DS:S1A_IW_GRDH_1SDV_20170907T103020_20170907...
    product:           GRDH
    safe:              S1A_IW_GRDH_1SDV_20170907T103020_20170907T103045_01826...
    swath:             IW
    multidataset:      False
    ...                ...
    start_date:        2017-09-07 10:30:20.936409
    stop_date:         2017-09-07 10:30:45.935264
    footprint:         POLYGON ((-67.84221143971432 20.72564283093837, -70.22...
    coverage:          170km * 251km (line * sample )
    orbit_pass:        Descending
    platform_heading:  -167.7668824808032

Sigma0 detrending with xsarsea

Sigma0 detrending is done by xsarsea.sigma0_detrend function

As the resulting xarray dataset have the same coordinates as the original sigma0, we can add a sigma0_detrend variable to the dataset.

By default, analytical models are available. We load all luts : replace paths by your own path containing all luts

[6]:
nc_luts_path = xsarsea.get_test_file('nc_luts_reduce')
path_cmod7 = xsarsea.get_test_file("cmod7_and_python_script")
xsarsea.windspeed.register_luts(nc_luts_path, path_cmod7)
xsarsea.windspeed.available_models()
DEBUG:xsarsea.windspeed:register model nc_lut_gmf_cmod5n_Rlow_hh_mouche1 pol=HH units=linear
 inc_range=[17.0, 50.0] wspd_range=[0.2, 50.0] phi_range=[0.0, 180.0]
 inc_step=0.1 wspd_step=0.1 phi_step=1.0
 inc_step_lr=1.0 wspd_step_lr=0.2 phi_step_lr=2.5
DEBUG:xsarsea.windspeed:register model nc_lut_cmodms1ahw pol=VH units=dB
 inc_range=[17.0, 50.0] wspd_range=[3.0, 80.0] phi_range=None
 inc_step=0.1 wspd_step=0.1 phi_step=1.0
 inc_step_lr=1.0 wspd_step_lr=0.2 phi_step_lr=2.5
DEBUG:xsarsea.windspeed:register model nc_lut_gmf_cmod5n_Rlow_hh_zhangB pol=HH units=linear
 inc_range=[17.0, 50.0] wspd_range=[0.2, 50.0] phi_range=[0.0, 180.0]
 inc_step=0.1 wspd_step=0.1 phi_step=1.0
 inc_step_lr=1.0 wspd_step_lr=0.2 phi_step_lr=2.5
DEBUG:xsarsea.windspeed:register model nc_lut_gmf_cmod5n_Rlow_hh_zhangA pol=HH units=linear
 inc_range=[17.0, 50.0] wspd_range=[0.2, 50.0] phi_range=[0.0, 180.0]
 inc_step=0.1 wspd_step=0.1 phi_step=1.0
 inc_step_lr=1.0 wspd_step_lr=0.2 phi_step_lr=2.5
DEBUG:xsarsea.windspeed:register model nc_lut_gmf_cmod7_Rlow_hh_zhangB pol=HH units=linear
 inc_range=[16.0, 66.0] wspd_range=[0.2, 50.0] phi_range=[0.0, 180.0]
 inc_step=0.1 wspd_step=0.1 phi_step=1.0
 inc_step_lr=1 wspd_step_lr=0.2 phi_step_lr=2.5
DEBUG:xsarsea.windspeed:register model nc_lut_gmf_cmod7_Rlow_hh_zhangA pol=HH units=linear
 inc_range=[16.0, 66.0] wspd_range=[0.2, 50.0] phi_range=[0.0, 180.0]
 inc_step=0.1 wspd_step=0.1 phi_step=1.0
 inc_step_lr=1 wspd_step_lr=0.2 phi_step_lr=2.5
DEBUG:xsarsea.windspeed:register model nc_lut_gmf_cmod7_Rlow_hh_mouche1 pol=HH units=linear
 inc_range=[16.0, 66.0] wspd_range=[0.2, 50.0] phi_range=[0.0, 180.0]
 inc_step=0.1 wspd_step=0.1 phi_step=1.0
 inc_step_lr=1 wspd_step_lr=0.2 phi_step_lr=2.5
DEBUG:xsarsea.windspeed:register model gmf_cmod7 pol=VV units=None
 inc_range=[16.0, 66.0] wspd_range=None phi_range=None
 inc_step=0.1 wspd_step=0.1 phi_step=1.0
 inc_step_lr=1.0 wspd_step_lr=0.2 phi_step_lr=2.5
[6]:
alias pol model
gmf_cmod7 cmod7 VV <Cmod7Model('gmf_cmod7') pol=VV>
gmf_cmod5 cmod5 VV <GmfModel('gmf_cmod5') pol=VV>
gmf_cmod5n cmod5n VV <GmfModel('gmf_cmod5n') pol=VV>
gmf_cmodifr2 cmodifr2 VV <GmfModel('gmf_cmodifr2') pol=VV>
gmf_rs2_v2 rs2_v2 VH <GmfModel('gmf_rs2_v2') pol=VH>
gmf_s1_v2 s1_v2 VH <GmfModel('gmf_s1_v2') pol=VH>
gmf_rcm_noaa rcm_noaa VH <GmfModel('gmf_rcm_noaa') pol=VH>
nc_lut_gmf_cmod5n_Rlow_hh_mouche1 cmod5n_Rlow_hh_mouche1 HH <NcLutModel('nc_lut_gmf_cmod5n_Rlow_hh_mouche1...
nc_lut_cmodms1ahw cmodms1ahw VH <NcLutModel('nc_lut_cmodms1ahw') pol=VH>
nc_lut_gmf_cmod5n_Rlow_hh_zhangB cmod5n_Rlow_hh_zhangB HH <NcLutModel('nc_lut_gmf_cmod5n_Rlow_hh_zhangB'...
nc_lut_gmf_cmod5n_Rlow_hh_zhangA cmod5n_Rlow_hh_zhangA HH <NcLutModel('nc_lut_gmf_cmod5n_Rlow_hh_zhangA'...
nc_lut_gmf_cmod7_Rlow_hh_zhangB cmod7_Rlow_hh_zhangB HH <NcLutModel('nc_lut_gmf_cmod7_Rlow_hh_zhangB')...
nc_lut_gmf_cmod7_Rlow_hh_zhangA cmod7_Rlow_hh_zhangA HH <NcLutModel('nc_lut_gmf_cmod7_Rlow_hh_zhangA')...
nc_lut_gmf_cmod7_Rlow_hh_mouche1 cmod7_Rlow_hh_mouche1 HH <NcLutModel('nc_lut_gmf_cmod7_Rlow_hh_mouche1'...

default detrend with gmf_cmod5n

[7]:
sar_ds['sigma0'] = sar_ds.sigma0
sar_ds['sigma0_detrend'] = xsarsea.sigma0_detrend(sar_ds.sigma0, sar_ds.incidence)
DEBUG:xsarsea.windspeed:timing _gmf_function : 0.92s. mem: +13.9Mb
INFO:xsarsea:timing sigma0_detrend : 0.95s. mem: +15.2Mb
[8]:
original_sigma0_plot = hv.Image(sar_ds.sigma0.sel(pol='VV')).opts(
    title="Original Sigma0",
    cmap='gray',
    clim=(0, 0.4),
    colorbar=True,
    width=400,
    height=400,
    tools=['hover']
)

detrended_sigma0_plot = hv.Image(sar_ds.sigma0_detrend.isel(pol=0)).opts(
    title="Detrended Sigma0",
    cmap='gray',
    clim=(0, 0.4),
    colorbar=True,
    width=400,
    height=400,
    tools=['hover']
)

(original_sigma0_plot + detrended_sigma0_plot).cols(2)
/home/vincelhx/miniconda3/envs/xsar_N3_local/lib/python3.10/site-packages/holoviews/plotting/bokeh/plot.py:987: UserWarning: found multiple competing values for 'toolbar.active_drag' property; using the latest value
  layout_plot = gridplot(
/home/vincelhx/miniconda3/envs/xsar_N3_local/lib/python3.10/site-packages/holoviews/plotting/bokeh/plot.py:987: UserWarning: found multiple competing values for 'toolbar.active_scroll' property; using the latest value
  layout_plot = gridplot(
[8]:

custom detrend

very small differences

[9]:
detrend_vv_gmf_cmod7 = xsarsea.sigma0_detrend(sar_ds.sigma0.sel(pol='VV'), sar_ds.incidence, model='gmf_cmod7')
detrend_vv_gmf_cmod5 = xsarsea.sigma0_detrend(sar_ds.sigma0.sel(pol='VV'), sar_ds.incidence, model='gmf_cmod5')
detrend_vv_gmf_cmod5n = xsarsea.sigma0_detrend(sar_ds.sigma0.sel(pol='VV'), sar_ds.incidence, model='gmf_cmod5n')
## HH GMF
detrend_vv_gmf_cmod5n_zhangA = xsarsea.sigma0_detrend(sar_ds.sigma0.sel(pol='VV'), sar_ds.incidence, model='cmod5n_Rlow_hh_zhangA')

INFO:xsarsea.windspeed:load gmf lut from /tmp/cmod7_and_python_script
DEBUG:xsarsea.windspeed:lut_resolution gmf_cmod7 from _raw_lut : low
DEBUG:xsarsea.windspeed:desired gmf_cmod7 resolution : high
DEBUG:xsarsea.windspeed:interp lut gmf_cmod7 to high res
INFO:xsarsea:timing sigma0_detrend : 1.04s. mem: +6.5Mb
DEBUG:xsarsea.windspeed:timing _gmf_function : 0.66s. mem: +4.5Mb
INFO:xsarsea:timing sigma0_detrend : 0.69s. mem: +4.6Mb
DEBUG:xsarsea.windspeed:timing _gmf_function : 0.00s. mem: +0.0Mb
INFO:xsarsea:timing sigma0_detrend : 0.02s. mem: +0.2Mb
DEBUG:xsarsea.windspeed:lut_resolution nc_lut_gmf_cmod5n_Rlow_hh_zhangA from _raw_lut : low
DEBUG:xsarsea.windspeed:desired nc_lut_gmf_cmod5n_Rlow_hh_zhangA resolution : high
DEBUG:xsarsea.windspeed:interp lut nc_lut_gmf_cmod5n_Rlow_hh_zhangA to high res
INFO:xsarsea:timing sigma0_detrend : 0.68s. mem: +2.7Mb
[10]:
import matplotlib.pyplot as plt
from mpl_toolkits.axes_grid1 import make_axes_locatable
import numpy as np

fig, axs = plt.subplots(1, 4, figsize=(20, 5))

datasets = [detrend_vv_gmf_cmod7, detrend_vv_gmf_cmod5, detrend_vv_gmf_cmod5n, detrend_vv_gmf_cmod5n_zhangA]
titles = ['GMF CMOD7', 'GMF CMOD5', 'GMF CMOD5N', 'GMF CMOD5N ZhangA']

for ax, data, title in zip(axs, datasets, titles):
    img = ax.pcolormesh(sar_ds.longitude, sar_ds.latitude, data, cmap='gray', vmin=0, vmax=0.4)
    ax.set_title(title)
    ax.set_xlabel("longitude")
    ax.set_ylabel("latitude")
    divider = make_axes_locatable(ax)
    cax = divider.append_axes("right", size="5%", pad=0.05)
    plt.colorbar(img, cax=cax)

# Improve spacing between plots
plt.tight_layout()
plt.show()

../_images/examples_xsarsea_15_0.png
[ ]: