XSAR simple example

[1]:
import xsar

[2]:
import rasterio
rasterio.__version__
[2]:
'1.2.1'
[3]:
import gdal
gdal.VersionInfo()
[3]:
'3010400'
[4]:
import holoviews as hv
hv.extension('bokeh')
from holoviews.operation.datashader import datashade,rasterize
import datashader as dh
[5]:
# archive SAFE L1
# for example is the SAFE archive of Irma cyclone
filename = '/tmp/S1A_IW_GRDH_1SDV_20170907T103020_20170907T103045_018268_01EB76_992F.SAFE'
[6]:
# define the resolution in pixel
# the default value is None you read the data with high resolution
resolution = {'atrack': 30, 'xtrack': 30}
[7]:
# open_dataset funcion return the list of dataset in your SAFE
sar_ds = xsar.open_dataset(filename, resolution=resolution)
sar_ds
[7]:
<xarray.Dataset>
Dimensions:         (atrack: 600, pol: 2, xtrack: 840)
Coordinates:
  * pol             (pol) object 'VV' 'VH'
  * atrack          (atrack) float64 15.0 45.0 75.0 ... 1.796e+04 1.798e+04
  * xtrack          (xtrack) float64 15.0 45.0 75.0 ... 2.516e+04 2.518e+04
Data variables:
    digital_number  (pol, atrack, xtrack) float32 dask.array<chunksize=(1, 600, 840), meta=np.ndarray>
    time            (atrack) datetime64[ns] 2017-09-07T10:30:20.936409088 ......
    longitude       (atrack, xtrack) float32 dask.array<chunksize=(600, 840), meta=np.ndarray>
    latitude        (atrack, xtrack) float32 dask.array<chunksize=(600, 840), meta=np.ndarray>
    elevation       (atrack, xtrack) float32 dask.array<chunksize=(600, 840), meta=np.ndarray>
    incidence       (atrack, xtrack) float32 dask.array<chunksize=(600, 840), meta=np.ndarray>
    sigma0_raw      (pol, atrack, xtrack) float64 dask.array<chunksize=(1, 600, 840), meta=np.ndarray>
    nesz            (pol, atrack, xtrack) float64 dask.array<chunksize=(1, 600, 840), meta=np.ndarray>
    gamma0_raw      (pol, atrack, xtrack) float64 dask.array<chunksize=(1, 600, 840), meta=np.ndarray>
    negz            (pol, atrack, xtrack) float64 dask.array<chunksize=(1, 600, 840), meta=np.ndarray>
    sigma0          (pol, atrack, xtrack) float64 dask.array<chunksize=(1, 600, 840), meta=np.ndarray>
    gamma0          (pol, atrack, xtrack) float64 dask.array<chunksize=(1, 600, 840), meta=np.ndarray>
Attributes: (12/13)
    ipf:             2.84
    platform:        SENTINEL-1A
    swath:           IW
    product:         GRD
    pols:            VV VH
    name:            SENTINEL1_DS:/tmp/S1A_IW_GRDH_1SDV_20170907T103020_20170...
    ...              ...
    stop_date:       2017-09-07 10:30:45.935264
    footprint:       POLYGON ((-67.84221143971432 20.72564283093837, -70.2216...
    coverage:        251km * 170km (xtrack * atrack )
    pixel_atrack_m:  10.2
    pixel_xtrack_m:  10.0
    Conventions:     CF-1.7
[8]:
rasterize(hv.Image(sar_ds.sigma0.sel(pol='VV')).opts(clim=(0,0.4), cmap='gray',colorbar=True,tools=['hover'],title="xsar"))
[8]:
[9]:
# you can select a specific polarization or zone in your SAFE with function xarray.sel
sar_ds = sar_ds.sel(pol='VV')
sar_ds = sar_ds.sel(xtrack=slice(5000, 9999, 1), atrack=slice(7000, 11999, 1)) # irma eye
sar_ds
[9]:
<xarray.Dataset>
Dimensions:         (atrack: 167, xtrack: 166)
Coordinates:
    pol             <U2 'VV'
  * atrack          (atrack) float64 7.005e+03 7.035e+03 ... 1.196e+04 1.198e+04
  * xtrack          (xtrack) float64 5.025e+03 5.055e+03 ... 9.945e+03 9.975e+03
Data variables:
    digital_number  (atrack, xtrack) float32 dask.array<chunksize=(167, 166), meta=np.ndarray>
    time            (atrack) datetime64[ns] 2017-09-07T10:30:30.660504576 ......
    longitude       (atrack, xtrack) float32 dask.array<chunksize=(167, 166), meta=np.ndarray>
    latitude        (atrack, xtrack) float32 dask.array<chunksize=(167, 166), meta=np.ndarray>
    elevation       (atrack, xtrack) float32 dask.array<chunksize=(167, 166), meta=np.ndarray>
    incidence       (atrack, xtrack) float32 dask.array<chunksize=(167, 166), meta=np.ndarray>
    sigma0_raw      (atrack, xtrack) float64 dask.array<chunksize=(167, 166), meta=np.ndarray>
    nesz            (atrack, xtrack) float64 dask.array<chunksize=(167, 166), meta=np.ndarray>
    gamma0_raw      (atrack, xtrack) float64 dask.array<chunksize=(167, 166), meta=np.ndarray>
    negz            (atrack, xtrack) float64 dask.array<chunksize=(167, 166), meta=np.ndarray>
    sigma0          (atrack, xtrack) float64 dask.array<chunksize=(167, 166), meta=np.ndarray>
    gamma0          (atrack, xtrack) float64 dask.array<chunksize=(167, 166), meta=np.ndarray>
Attributes: (12/13)
    ipf:             2.84
    platform:        SENTINEL-1A
    swath:           IW
    product:         GRD
    pols:            VV VH
    name:            SENTINEL1_DS:/tmp/S1A_IW_GRDH_1SDV_20170907T103020_20170...
    ...              ...
    stop_date:       2017-09-07 10:30:45.935264
    footprint:       POLYGON ((-67.84221143971432 20.72564283093837, -70.2216...
    coverage:        251km * 170km (xtrack * atrack )
    pixel_atrack_m:  10.2
    pixel_xtrack_m:  10.0
    Conventions:     CF-1.7
[10]:
# sigma0 is denoised
sar_ds.sigma0
# sigma0_raw is not denoised
sar_ds.sigma0_raw
[10]:
<xarray.DataArray 'sigma0_raw' (atrack: 167, xtrack: 166)>
dask.array<getitem, shape=(167, 166), dtype=float64, chunksize=(167, 166), chunktype=numpy.ndarray>
Coordinates:
    pol      <U2 'VV'
  * atrack   (atrack) float64 7.005e+03 7.035e+03 ... 1.196e+04 1.198e+04
  * xtrack   (xtrack) float64 5.025e+03 5.055e+03 ... 9.945e+03 9.975e+03
Attributes:
    units:    m2/m2

XSAR advanced example

[11]:
# you can define the specifics chunks
# the default value of chunk is :{xtrack:1000, atrack:1000}
chunks = {'xtrack': 500, 'atrack': 200}
[12]:
# open_dataset funcion return the list of dataset in your SAFE
sar_ds = xsar.open_dataset(filename, chunks=chunks, resolution=resolution)
sar_ds
[12]:
<xarray.Dataset>
Dimensions:         (atrack: 600, pol: 2, xtrack: 1000)
Coordinates:
  * pol             (pol) object 'VV' 'VH'
  * atrack          (atrack) float64 15.0 45.0 75.0 ... 1.796e+04 1.798e+04
  * xtrack          (xtrack) float64 15.0 45.0 75.0 ... 2.996e+04 2.998e+04
Data variables:
    digital_number  (pol, atrack, xtrack) float32 dask.array<chunksize=(1, 600, 1000), meta=np.ndarray>
    time            (atrack) datetime64[ns] 2017-09-07T10:30:20.936409088 ......
    longitude       (atrack, xtrack) float32 dask.array<chunksize=(600, 1000), meta=np.ndarray>
    latitude        (atrack, xtrack) float32 dask.array<chunksize=(600, 1000), meta=np.ndarray>
    elevation       (atrack, xtrack) float32 dask.array<chunksize=(600, 1000), meta=np.ndarray>
    incidence       (atrack, xtrack) float32 dask.array<chunksize=(600, 1000), meta=np.ndarray>
    sigma0_raw      (pol, atrack, xtrack) float64 dask.array<chunksize=(1, 600, 1000), meta=np.ndarray>
    nesz            (pol, atrack, xtrack) float64 dask.array<chunksize=(1, 600, 1000), meta=np.ndarray>
    gamma0_raw      (pol, atrack, xtrack) float64 dask.array<chunksize=(1, 600, 1000), meta=np.ndarray>
    negz            (pol, atrack, xtrack) float64 dask.array<chunksize=(1, 600, 1000), meta=np.ndarray>
    sigma0          (pol, atrack, xtrack) float64 dask.array<chunksize=(1, 600, 1000), meta=np.ndarray>
    gamma0          (pol, atrack, xtrack) float64 dask.array<chunksize=(1, 600, 1000), meta=np.ndarray>
Attributes: (12/13)
    ipf:             2.84
    platform:        SENTINEL-1A
    swath:           IW
    product:         GRD
    pols:            VV VH
    name:            SENTINEL1_DS:/tmp/S1A_IW_GRDH_1SDV_20170907T103020_20170...
    ...              ...
    stop_date:       2017-09-07 10:30:45.935264
    footprint:       POLYGON ((-67.84221143971432 20.72564283093837, -70.2216...
    coverage:        251km * 170km (xtrack * atrack )
    pixel_atrack_m:  10.2
    pixel_xtrack_m:  10.0
    Conventions:     CF-1.7