Download this notebook from github.


XSAR simple example

just open a dataset with xsar.open_dataset, and display denoised sigma0 in ‘VH’ polarisation

[1]:
import xarray as xr
import xsar
import os
[2]:
import holoviews as hv
hv.extension('bokeh')
from holoviews.operation.datashader import datashade,rasterize
import datashader as dh
/home/datawork-cersat-public/cache/project/mpc-sentinel1/workspace/mamba/envs/testgeoviewsnumpy/lib/python3.11/site-packages/dask/dataframe/__init__.py:42: FutureWarning:
Dask dataframe query planning is disabled because dask-expr is not installed.

You can install it with `pip install dask[dataframe]` or `conda install dask`.
This will raise in a future version.

  warnings.warn(msg, FutureWarning)

Sentinel 1 Example

[3]:
# 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
[3]:
'/home1/scratch/agrouaze/xsardatasync/xsardata/S1A_IW_GRDH_1SDV_20170907T103020_20170907T103045_018268_01EB76_Z010.SAFE'
[4]:
# open the datatree with xarray
dt_xsar = xsar.open_datatree(filename,resolution='100m')
dt_xsar
/home/datawork-cersat-public/cache/project/mpc-sentinel1/workspace/mamba/envs/testgeoviewsnumpy/lib/python3.11/site-packages/numpy/_core/numeric.py:452: RuntimeWarning: invalid value encountered in cast
  multiarray.copyto(res, fill_value, casting='unsafe')
[4]:
<xarray.DatasetView> Size: 0B
Dimensions:  ()
Data variables:
    *empty*
Attributes: (12/15)
    name:              SENTINEL1_DS:/home1/scratch/agrouaze/xsardatasync/xsar...
    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
[5]:
# open the dataset with xarray
ds_xsar = xsar.open_dataset(filename, resolution='100m')
ds_xsar
/home/datawork-cersat-public/cache/project/mpc-sentinel1/workspace/mamba/envs/testgeoviewsnumpy/lib/python3.11/site-packages/numpy/_core/numeric.py:452: RuntimeWarning: invalid value encountered in cast
  multiarray.copyto(res, fill_value, casting='unsafe')
[5]:
<xarray.Dataset> Size: 950MB
Dimensions:               (line: 1677, sample: 2518, pol: 2)
Coordinates:
  * line                  (line) float64 13kB 4.5 14.5 ... 1.675e+04 1.676e+04
  * sample                (sample) float64 20kB 4.5 14.5 ... 2.516e+04 2.517e+04
  * pol                   (pol) object 16B 'VV' 'VH'
    spatial_ref           int64 8B 0
Data variables: (12/27)
    digital_number        (pol, line, sample) uint16 17MB dask.array<chunksize=(1, 1677, 2518), meta=np.ndarray>
    time                  (line) datetime64[ns] 13kB 2017-09-07T10:30:20.9438...
    sampleSpacing         float64 8B 100.0
    lineSpacing           float64 8B 100.0
    gamma0_lut            (pol, line, sample) float64 68MB dask.array<chunksize=(1, 1677, 2518), meta=np.ndarray>
    noise_lut_azi         (pol, line, sample) float32 34MB dask.array<chunksize=(1, 1677, 2518), meta=np.ndarray>
    ...                    ...
    sigma0_raw            (pol, line, sample) float64 68MB dask.array<chunksize=(1, 1677, 2518), meta=np.ndarray>
    nesz                  (pol, line, sample) float64 68MB dask.array<chunksize=(1, 1677, 2518), meta=np.ndarray>
    gamma0_raw            (pol, line, sample) float64 68MB dask.array<chunksize=(1, 1677, 2518), meta=np.ndarray>
    negz                  (pol, line, sample) float64 68MB dask.array<chunksize=(1, 1677, 2518), meta=np.ndarray>
    sigma0                (pol, line, sample) float64 68MB dask.array<chunksize=(1, 1677, 2518), meta=np.ndarray>
    gamma0                (pol, line, sample) float64 68MB dask.array<chunksize=(1, 1677, 2518), meta=np.ndarray>
Attributes: (12/15)
    name:              SENTINEL1_DS:/home1/scratch/agrouaze/xsardatasync/xsar...
    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
[6]:
# we use here 'rasterize' to display the image, because the full image is really big
rasterize(hv.Image(ds_xsar.sigma0.sel(pol='VH')).opts(cmap='gray',colorbar=True,tools=['hover'],title="xsar",width=800,height=800,clim=(0,0.02)))
[6]:

RadarSat2 example

[7]:
# get test file. You can replace with an path to other SAFE
filename = xsar.get_test_file('RS2_OK135107_PK1187782_DK1151894_SCWA_20220407_182127_VV_VH_SGF')
filename
[7]:
'/home1/scratch/agrouaze/xsardatasync/xsardata/RS2_OK135107_PK1187782_DK1151894_SCWA_20220407_182127_VV_VH_SGF'
[8]:
# open the datatree with xarray
dt_xsar = xsar.open_datatree(filename,resolution='100m')
dt_xsar
/home/datawork-cersat-public/cache/project/mpc-sentinel1/workspace/mamba/envs/testgeoviewsnumpy/lib/python3.11/site-packages/xradarsat2/radarSat2_xarray_reader.py:299: UserWarning: no explicit representation of timezones available for np.datetime64
  timestamp.append(np.datetime64(value["timeStamp"]).astype("datetime64[ns]"))
/home/datawork-cersat-public/cache/project/mpc-sentinel1/workspace/mamba/envs/testgeoviewsnumpy/lib/python3.11/site-packages/xradarsat2/radarSat2_xarray_reader.py:462: UserWarning: no explicit representation of timezones available for np.datetime64
  timestamp.append(np.datetime64(value["timeStamp"]).astype("datetime64[ns]"))
/home/datawork-cersat-public/cache/project/mpc-sentinel1/workspace/mamba/envs/testgeoviewsnumpy/lib/python3.11/site-packages/xradarsat2/radarSat2_xarray_reader.py:570: UserWarning: no explicit representation of timezones available for np.datetime64
  times.append(np.datetime64(value["timeOfDopplerCentroidEstimate"]).astype("datetime64[ns]"))
/home/datawork-cersat-public/cache/project/mpc-sentinel1/workspace/mamba/envs/testgeoviewsnumpy/lib/python3.11/site-packages/xradarsat2/radarSat2_xarray_reader.py:2056: UserWarning: no explicit representation of timezones available for np.datetime64
  final_dic[key] = np.datetime64(dic[key]).astype("datetime64[ns]")
[8]:
<xarray.DatasetView> Size: 0B
Dimensions:  ()
Data variables:
    *empty*
Attributes: (12/18)
    product_path:           /home1/scratch/agrouaze/xsardatasync/xsardata/RS2...
    satellite:              RADARSAT-2
    inputDatasetId:         /Fred/RSAT-2/610044P
    rawDataStartTime:       2022-04-07T18:21:27.688416000
    satelliteHeight_units:  m
    satelliteHeight:        800612.0083192665
    ...                     ...
    stop_date:              2022-04-07 18:22:44.030964
    footprint:              POLYGON ((168.8147284622835 -19.82390747944243, 1...
    coverage:               515km * 530km (line * sample )
    pixel_line_m:           50.0
    pixel_sample_m:         50.0
    approx_transform:       |-0.00,-0.00, 168.85|\n|-0.00, 0.00,-19.85|\n| 0....
[9]:
# open the dataset with xarray
ds_xsar = xsar.open_dataset(filename, resolution='100m')
ds_xsar
/home/datawork-cersat-public/cache/project/mpc-sentinel1/workspace/mamba/envs/testgeoviewsnumpy/lib/python3.11/site-packages/xradarsat2/radarSat2_xarray_reader.py:299: UserWarning: no explicit representation of timezones available for np.datetime64
  timestamp.append(np.datetime64(value["timeStamp"]).astype("datetime64[ns]"))
/home/datawork-cersat-public/cache/project/mpc-sentinel1/workspace/mamba/envs/testgeoviewsnumpy/lib/python3.11/site-packages/xradarsat2/radarSat2_xarray_reader.py:462: UserWarning: no explicit representation of timezones available for np.datetime64
  timestamp.append(np.datetime64(value["timeStamp"]).astype("datetime64[ns]"))
/home/datawork-cersat-public/cache/project/mpc-sentinel1/workspace/mamba/envs/testgeoviewsnumpy/lib/python3.11/site-packages/xradarsat2/radarSat2_xarray_reader.py:570: UserWarning: no explicit representation of timezones available for np.datetime64
  times.append(np.datetime64(value["timeOfDopplerCentroidEstimate"]).astype("datetime64[ns]"))
/home/datawork-cersat-public/cache/project/mpc-sentinel1/workspace/mamba/envs/testgeoviewsnumpy/lib/python3.11/site-packages/xradarsat2/radarSat2_xarray_reader.py:2056: UserWarning: no explicit representation of timezones available for np.datetime64
  final_dic[key] = np.datetime64(dic[key]).astype("datetime64[ns]")
[9]:
<xarray.Dataset> Size: 5GB
Dimensions:          (line: 5138, pol: 2, sample: 5309)
Coordinates:
  * line             (line) float64 41kB 0.5 2.5 4.5 ... 1.027e+04 1.027e+04
  * pol              (pol) <U2 16B 'VV' 'VH'
  * sample           (sample) float64 42kB 0.5 2.5 4.5 ... 1.061e+04 1.062e+04
Data variables: (12/23)
    digital_number   (pol, line, sample) uint16 109MB dask.array<chunksize=(1, 5000, 309), meta=np.ndarray>
    lines_flipped    bool 1B False
    samples_flipped  bool 1B True
    sampleSpacing    float64 8B 100.0
    lineSpacing      float64 8B 100.0
    sigma0_raw       (pol, line, sample) float64 436MB dask.array<chunksize=(1, 5000, 309), meta=np.ndarray>
    ...               ...
    time             (line) datetime64[ns] 41kB dask.array<chunksize=(5000,), meta=np.ndarray>
    latitude         (line, sample) float64 218MB dask.array<chunksize=(5000, 309), meta=np.ndarray>
    longitude        (line, sample) float64 218MB dask.array<chunksize=(5000, 309), meta=np.ndarray>
    altitude         (line, sample) float64 218MB dask.array<chunksize=(5000, 309), meta=np.ndarray>
    incidence        (line, sample) float64 218MB dask.array<chunksize=(5000, 309), meta=np.ndarray>
    elevation        (line, sample) float64 218MB dask.array<chunksize=(5000, 309), meta=np.ndarray>
Attributes: (12/18)
    product_path:           /home1/scratch/agrouaze/xsardatasync/xsardata/RS2...
    satellite:              RADARSAT-2
    inputDatasetId:         /Fred/RSAT-2/610044P
    rawDataStartTime:       2022-04-07T18:21:27.688416000
    satelliteHeight_units:  m
    satelliteHeight:        800612.0083192665
    ...                     ...
    stop_date:              2022-04-07 18:22:44.030964
    footprint:              POLYGON ((168.8147284622835 -19.82390747944243, 1...
    coverage:               515km * 530km (line * sample )
    pixel_line_m:           50.0
    pixel_sample_m:         50.0
    approx_transform:       |-0.00,-0.00, 168.85|\n|-0.00, 0.00,-19.85|\n| 0....
[10]:
# we use here 'rasterize' to display the image, because the full image is really big
rasterize(hv.Image(ds_xsar.sigma0.sel(pol='VH')).opts(cmap='gray',colorbar=True,tools=['hover'],title="xsar",width=800,height=800,clim=(0,0.02)))
[10]:

RCM example

[11]:
import warnings
warnings.filterwarnings('ignore')
[12]:
# get test file. You can replace with an path to other SAFE
filename = xsar.get_test_file('RCM1_OK1050603_PK1050605_1_SC50MB_20200214_115905_HH_HV_Z010')
filename
[12]:
'/home1/scratch/agrouaze/xsardatasync/xsardata/RCM1_OK1050603_PK1050605_1_SC50MB_20200214_115905_HH_HV_Z010'
[13]:
# open the datatree with xarray
dt_xsar = xsar.open_datatree(filename,resolution='100m')
dt_xsar
[13]:
<xarray.DatasetView> Size: 0B
Dimensions:  ()
Data variables:
    *empty*
Attributes: (12/18)
    name:                    RCM_DS:/home1/scratch/agrouaze/xsardatasync/xsar...
    short_name:              RCM_DS:RCM1_OK1050603_PK1050605_1_SC50MB_2020021...
    product:                 Z010
    safe:                    RCM1_OK1050603_PK1050605_1_SC50MB_20200214_11590...
    swath:                   SC50MB
    multidataset:            False
    ...                      ...
    stop_date:               2020-02-14 12:00:02.000000
    footprint:               POLYGON ((-84.63397773377159 48.71534850877886, ...
    coverage:                381km * 359km (line * sample )
    pixel_line_m:            20.0
    pixel_sample_m:          20.0
    approx_transform:        |-0.00,-0.00,-84.71|\n|-0.00, 0.00, 48.73|\n| 0....
[14]:
# open the dataset with xarray
ds_xsar = xsar.open_dataset(filename, resolution='100m')
ds_xsar
[14]:
<xarray.Dataset> Size: 2GB
Dimensions:          (line: 3825, pol: 2, sample: 3608)
Coordinates:
  * line             (line) float64 31kB 2.0 7.0 12.0 ... 1.912e+04 1.912e+04
  * pol              (pol) <U2 16B 'HH' 'HV'
  * sample           (sample) float64 29kB 2.0 7.0 12.0 ... 1.803e+04 1.804e+04
Data variables: (12/21)
    digital_number   (pol, line, sample) uint16 55MB dask.array<chunksize=(1, 3825, 3608), meta=np.ndarray>
    lines_flipped    bool 1B False
    samples_flipped  bool 1B True
    sampleSpacing    float64 8B 100.0
    lineSpacing      float64 8B 100.0
    sigma0_raw       (pol, line, sample) float64 221MB dask.array<chunksize=(1, 3825, 3608), meta=np.ndarray>
    ...               ...
    ground_heading   (line, sample) float32 55MB dask.array<chunksize=(3825, 3608), meta=np.ndarray>
    latitude         (line, sample) float64 110MB dask.array<chunksize=(3825, 3608), meta=np.ndarray>
    longitude        (line, sample) float64 110MB dask.array<chunksize=(3825, 3608), meta=np.ndarray>
    altitude         (line, sample) float64 110MB dask.array<chunksize=(3825, 3608), meta=np.ndarray>
    incidence        (line, sample) float32 55MB dask.array<chunksize=(3825, 3608), meta=np.ndarray>
    elevation        (line, sample) float64 110MB dask.array<chunksize=(3825, 3608), meta=np.ndarray>
Attributes: (12/18)
    name:                    RCM_DS:/home1/scratch/agrouaze/xsardatasync/xsar...
    short_name:              RCM_DS:RCM1_OK1050603_PK1050605_1_SC50MB_2020021...
    product:                 Z010
    safe:                    RCM1_OK1050603_PK1050605_1_SC50MB_20200214_11590...
    swath:                   SC50MB
    multidataset:            False
    ...                      ...
    stop_date:               2020-02-14 12:00:02.000000
    footprint:               POLYGON ((-84.63397773377159 48.71534850877886, ...
    coverage:                381km * 359km (line * sample )
    pixel_line_m:            20.0
    pixel_sample_m:          20.0
    approx_transform:        |-0.00,-0.00,-84.71|\n|-0.00, 0.00, 48.73|\n| 0....
[15]:
# we use here 'rasterize' to display the image, because the full image is really big
rasterize(hv.Image(ds_xsar.sigma0.sel(pol='HV')).opts(cmap='gray',colorbar=True,tools=['hover'],title="xsar",width=800,height=800,clim=(0,0.02)))
[15]: