Download this notebook from github.
Open multiples datasets
Some safe files have multiples subdatasets, like WV or IW_SLC. This notebook show how to handle them, or how to handle multiple datasets.
[1]:
import xsar
import xarray as xr
import glob
import holoviews as hv
import geoviews as gv
hv.extension('bokeh')
/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)
SAFES containings multiples subdatasets like WV_SLC cannot be openned with xsar.open_dataset
given the safe path.
[2]:
try:
wv_slc_ds = xsar.open_dataset(xsar.get_test_file('S1A_WV_SLC__1SSV_20160510T101603_20160510T102143_011195_010EA1_Z010.SAFE'))
except IndexError as e:
print(str(e))
/home1/datahome/agrouaze/sources/git/xsar/src/xsar/xsar.py:212: UserWarning: Downloading https://cyclobs.ifremer.fr/static/sarwing_datarmor/xsardata/S1A_WV_SLC__1SSV_20160510T101603_20160510T102143_011195_010EA1_Z010.SAFE.zip
warnings.warn("Downloading %s" % file_url)
/home1/datahome/agrouaze/sources/git/xsar/src/xsar/xsar.py:214: UserWarning: Unzipping /home1/scratch/agrouaze/xsardatasync/xsardata/S1A_WV_SLC__1SSV_20160510T101603_20160510T102143_011195_010EA1_Z010.SAFE
warnings.warn("Unzipping %s" % os.path.join(res_path, fname))
multidataset
Can't open an multi-dataset. Use `xsar.Sentinel1Meta('/home1/scratch/agrouaze/xsardatasync/xsardata/S1A_WV_SLC__1SSV_20160510T101603_20160510T102143_011195_010EA1_Z010.SAFE').subdatasets` to show availables ones
An IndexError
is raised, with an advice to use xsar.Sentinel1Meta to get the available subdatasets list.
[3]:
wv_slc_meta = xsar.Sentinel1Meta(xsar.get_test_file('S1A_WV_SLC__1SSV_20160510T101603_20160510T102143_011195_010EA1_Z010.SAFE'))
wv_slc_meta
multidataset
[3]:
<Sentinel1Meta multi (24) object>
Note that the abose wv_slc_meta
object is a multi dataset
Subdatasets list is available with xsar.Sentinel1Meta.subdatasets property
[4]:
wv_slc_meta.subdatasets
[4]:
geometry | |
---|---|
SENTINEL1_DS:/home1/scratch/agrouaze/xsardatasync/xsardata/S1A_WV_SLC__1SSV_20160510T101603_20160510T102143_011195_010EA1_Z010.SAFE:WV_001 | POLYGON ((-59.85301 41.55527, -60.09758 41.592... |
SENTINEL1_DS:/home1/scratch/agrouaze/xsardatasync/xsardata/S1A_WV_SLC__1SSV_20160510T101603_20160510T102143_011195_010EA1_Z010.SAFE:WV_002 | POLYGON ((-62.25718 40.99591, -62.49659 41.028... |
SENTINEL1_DS:/home1/scratch/agrouaze/xsardatasync/xsardata/S1A_WV_SLC__1SSV_20160510T101603_20160510T102143_011195_010EA1_Z010.SAFE:WV_003 | POLYGON ((-60.32554 39.79482, -60.56392 39.832... |
SENTINEL1_DS:/home1/scratch/agrouaze/xsardatasync/xsardata/S1A_WV_SLC__1SSV_20160510T101603_20160510T102143_011195_010EA1_Z010.SAFE:WV_004 | POLYGON ((-62.67301 39.23473, -62.90617 39.267... |
SENTINEL1_DS:/home1/scratch/agrouaze/xsardatasync/xsardata/S1A_WV_SLC__1SSV_20160510T101603_20160510T102143_011195_010EA1_Z010.SAFE:WV_005 | POLYGON ((-60.78958 38.03459, -61.02192 38.071... |
SENTINEL1_DS:/home1/scratch/agrouaze/xsardatasync/xsardata/S1A_WV_SLC__1SSV_20160510T101603_20160510T102143_011195_010EA1_Z010.SAFE:WV_006 | POLYGON ((-63.07917 37.47335, -63.30661 37.505... |
SENTINEL1_DS:/home1/scratch/agrouaze/xsardatasync/xsardata/S1A_WV_SLC__1SSV_20160510T101603_20160510T102143_011195_010EA1_Z010.SAFE:WV_007 | POLYGON ((-61.24056 36.27251, -61.46734 36.309... |
SENTINEL1_DS:/home1/scratch/agrouaze/xsardatasync/xsardata/S1A_WV_SLC__1SSV_20160510T101603_20160510T102143_011195_010EA1_Z010.SAFE:WV_008 | POLYGON ((-63.47426 35.71019, -63.69651 35.742... |
SENTINEL1_DS:/home1/scratch/agrouaze/xsardatasync/xsardata/S1A_WV_SLC__1SSV_20160510T101603_20160510T102143_011195_010EA1_Z010.SAFE:WV_009 | POLYGON ((-61.67968 34.5095, -61.90138 34.5464... |
SENTINEL1_DS:/home1/scratch/agrouaze/xsardatasync/xsardata/S1A_WV_SLC__1SSV_20160510T101603_20160510T102143_011195_010EA1_Z010.SAFE:WV_010 | POLYGON ((-63.86507 33.94662, -64.0825 33.9794... |
SENTINEL1_DS:/home1/scratch/agrouaze/xsardatasync/xsardata/S1A_WV_SLC__1SSV_20160510T101603_20160510T102143_011195_010EA1_Z010.SAFE:WV_011 | POLYGON ((-62.10818 32.74584, -62.32521 32.782... |
SENTINEL1_DS:/home1/scratch/agrouaze/xsardatasync/xsardata/S1A_WV_SLC__1SSV_20160510T101603_20160510T102143_011195_010EA1_Z010.SAFE:WV_012 | POLYGON ((-64.24941 32.18295, -64.46241 32.215... |
SENTINEL1_DS:/home1/scratch/agrouaze/xsardatasync/xsardata/S1A_WV_SLC__1SSV_20160510T101603_20160510T102143_011195_010EA1_Z010.SAFE:WV_013 | POLYGON ((-62.52305 30.98017, -62.73606 31.016... |
SENTINEL1_DS:/home1/scratch/agrouaze/xsardatasync/xsardata/S1A_WV_SLC__1SSV_20160510T101603_20160510T102143_011195_010EA1_Z010.SAFE:WV_014 | POLYGON ((-64.62841 30.41779, -64.83735 30.450... |
SENTINEL1_DS:/home1/scratch/agrouaze/xsardatasync/xsardata/S1A_WV_SLC__1SSV_20160510T101603_20160510T102143_011195_010EA1_Z010.SAFE:WV_015 | POLYGON ((-62.93453 29.21381, -63.14361 29.250... |
SENTINEL1_DS:/home1/scratch/agrouaze/xsardatasync/xsardata/S1A_WV_SLC__1SSV_20160510T101603_20160510T102143_011195_010EA1_Z010.SAFE:WV_016 | POLYGON ((-65.00266 28.65192, -65.20787 28.685... |
SENTINEL1_DS:/home1/scratch/agrouaze/xsardatasync/xsardata/S1A_WV_SLC__1SSV_20160510T101603_20160510T102143_011195_010EA1_Z010.SAFE:WV_017 | POLYGON ((-63.33859 27.44647, -63.54408 27.483... |
SENTINEL1_DS:/home1/scratch/agrouaze/xsardatasync/xsardata/S1A_WV_SLC__1SSV_20160510T101603_20160510T102143_011195_010EA1_Z010.SAFE:WV_018 | POLYGON ((-65.37115 26.88431, -65.57301 26.917... |
SENTINEL1_DS:/home1/scratch/agrouaze/xsardatasync/xsardata/S1A_WV_SLC__1SSV_20160510T101603_20160510T102143_011195_010EA1_Z010.SAFE:WV_019 | POLYGON ((-63.73628 25.67826, -63.93849 25.715... |
SENTINEL1_DS:/home1/scratch/agrouaze/xsardatasync/xsardata/S1A_WV_SLC__1SSV_20160510T101603_20160510T102143_011195_010EA1_Z010.SAFE:WV_020 | POLYGON ((-65.73824 25.11662, -65.93698 25.150... |
SENTINEL1_DS:/home1/scratch/agrouaze/xsardatasync/xsardata/S1A_WV_SLC__1SSV_20160510T101603_20160510T102143_011195_010EA1_Z010.SAFE:WV_021 | POLYGON ((-64.12556 23.90869, -64.32495 23.945... |
SENTINEL1_DS:/home1/scratch/agrouaze/xsardatasync/xsardata/S1A_WV_SLC__1SSV_20160510T101603_20160510T102143_011195_010EA1_Z010.SAFE:WV_022 | POLYGON ((-66.10242 23.3486, -66.29834 23.3826... |
SENTINEL1_DS:/home1/scratch/agrouaze/xsardatasync/xsardata/S1A_WV_SLC__1SSV_20160510T101603_20160510T102143_011195_010EA1_Z010.SAFE:WV_023 | POLYGON ((-64.51285 22.13895, -64.70954 22.175... |
SENTINEL1_DS:/home1/scratch/agrouaze/xsardatasync/xsardata/S1A_WV_SLC__1SSV_20160510T101603_20160510T102143_011195_010EA1_Z010.SAFE:WV_024 | POLYGON ((-66.46441 21.57984, -66.65776 21.614... |
A subdataset can be directly be opened by xsar.open_dataset
[5]:
wv_slc_ds1 = xsar.open_dataset(wv_slc_meta.subdatasets.index[0])
wv_slc_ds1
/home/datawork-cersat-public/cache/project/mpc-sentinel1/workspace/mamba/envs/testgeoviewsnumpy/lib/python3.11/site-packages/dask/array/utils.py:105: ComplexWarning: Casting complex values to real discards the imaginary part
meta = meta.astype(dtype)
[5]:
<xarray.Dataset> Size: 448MB Dimensions: (line: 4923, sample: 5681, pol: 1) Coordinates: * line (line) int64 39kB 0 1 2 3 4 5 ... 4918 4919 4920 4921 4922 * sample (sample) int64 45kB 0 1 2 3 4 5 ... 5676 5677 5678 5679 5680 * pol (pol) object 8B 'VV' Data variables: digital_number (pol, line, sample) complex128 447MB dask.array<chunksize=(1, 4923, 5000), meta=np.ndarray> time (line) datetime64[ns] 39kB 2016-05-10T10:16:03.843409920 ... sampleSpacing float64 8B 1.498 lineSpacing float64 8B 4.125 Attributes: (12/15) name: SENTINEL1_DS:/home1/scratch/agrouaze/xsardatasync/xsar... short_name: SENTINEL1_DS:S1A_WV_SLC__1SSV_20160510T101603_20160510... product: SLC safe: S1A_WV_SLC__1SSV_20160510T101603_20160510T102143_01119... swath: WV multidataset: False ... ... start_date: 2016-05-10 10:16:03.843410 stop_date: 2016-05-10 10:16:06.826137 footprint: POLYGON ((-59.80263505017974 41.73435353976264, -60.04... coverage: 20km * 20km (line * sample ) orbit_pass: Descending platform_heading: -166.3012322109123
Or we can get a single dataset by using xsar.Sentinel1Meta
[6]:
wv_slc_meta1 = xsar.Sentinel1Meta(wv_slc_meta.subdatasets.index[0])
wv_slc_meta1
[6]:
<Sentinel1Meta single object>
And use this wv_slc_meta1
object with xsar.open_dataset
[7]:
wv_slc_ds1 = xsar.open_dataset(wv_slc_meta1)
/home/datawork-cersat-public/cache/project/mpc-sentinel1/workspace/mamba/envs/testgeoviewsnumpy/lib/python3.11/site-packages/dask/array/utils.py:105: ComplexWarning: Casting complex values to real discards the imaginary part
meta = meta.astype(dtype)
Getting all xsar.Sentinel1Meta objects from a list of path
xsar.Sentinel1Meta can only handle one path at a time.
With xsar.product_info, you can provide a list of path, and get a pandas.DataFrame
with all meta
objects.
[8]:
df_info = xsar.product_info([
xsar.get_test_file('S1A_WV_SLC__1SSV_20160510T101603_20160510T102143_011195_010EA1_Z010.SAFE'),
xsar.get_test_file('S1A_IW_SLC__1SDV_20170907T102951_20170907T103021_018268_01EB76_Z010.SAFE')
])
df_info
/home1/datahome/agrouaze/sources/git/xsar/src/xsar/xsar.py:212: UserWarning: Downloading https://cyclobs.ifremer.fr/static/sarwing_datarmor/xsardata/S1A_IW_SLC__1SDV_20170907T102951_20170907T103021_018268_01EB76_Z010.SAFE.zip
warnings.warn("Downloading %s" % file_url)
/home1/datahome/agrouaze/sources/git/xsar/src/xsar/xsar.py:214: UserWarning: Unzipping /home1/scratch/agrouaze/xsardatasync/xsardata/S1A_IW_SLC__1SDV_20170907T102951_20170907T103021_018268_01EB76_Z010.SAFE
warnings.warn("Unzipping %s" % os.path.join(res_path, fname))
multidataset
multidataset
[8]:
name | ipf | platform | swath | product | pols | meta | ||
---|---|---|---|---|---|---|---|---|
path | dsid | |||||||
/home1/scratch/agrouaze/xsardatasync/xsardata/S1A_WV_SLC__1SSV_20160510T101603_20160510T102143_011195_010EA1_Z010.SAFE | WV_001 | SENTINEL1_DS:/home1/scratch/agrouaze/xsardatas... | 2.7 | SENTINEL-1A | WV | SLC | VV | <Sentinel1Meta single object> |
WV_002 | SENTINEL1_DS:/home1/scratch/agrouaze/xsardatas... | 2.7 | SENTINEL-1A | WV | SLC | VV | <Sentinel1Meta single object> | |
WV_003 | SENTINEL1_DS:/home1/scratch/agrouaze/xsardatas... | 2.7 | SENTINEL-1A | WV | SLC | VV | <Sentinel1Meta single object> | |
WV_004 | SENTINEL1_DS:/home1/scratch/agrouaze/xsardatas... | 2.7 | SENTINEL-1A | WV | SLC | VV | <Sentinel1Meta single object> | |
WV_005 | SENTINEL1_DS:/home1/scratch/agrouaze/xsardatas... | 2.7 | SENTINEL-1A | WV | SLC | VV | <Sentinel1Meta single object> | |
WV_006 | SENTINEL1_DS:/home1/scratch/agrouaze/xsardatas... | 2.7 | SENTINEL-1A | WV | SLC | VV | <Sentinel1Meta single object> | |
WV_007 | SENTINEL1_DS:/home1/scratch/agrouaze/xsardatas... | 2.7 | SENTINEL-1A | WV | SLC | VV | <Sentinel1Meta single object> | |
WV_008 | SENTINEL1_DS:/home1/scratch/agrouaze/xsardatas... | 2.7 | SENTINEL-1A | WV | SLC | VV | <Sentinel1Meta single object> | |
WV_009 | SENTINEL1_DS:/home1/scratch/agrouaze/xsardatas... | 2.7 | SENTINEL-1A | WV | SLC | VV | <Sentinel1Meta single object> | |
WV_010 | SENTINEL1_DS:/home1/scratch/agrouaze/xsardatas... | 2.7 | SENTINEL-1A | WV | SLC | VV | <Sentinel1Meta single object> | |
WV_011 | SENTINEL1_DS:/home1/scratch/agrouaze/xsardatas... | 2.7 | SENTINEL-1A | WV | SLC | VV | <Sentinel1Meta single object> | |
WV_012 | SENTINEL1_DS:/home1/scratch/agrouaze/xsardatas... | 2.7 | SENTINEL-1A | WV | SLC | VV | <Sentinel1Meta single object> | |
WV_013 | SENTINEL1_DS:/home1/scratch/agrouaze/xsardatas... | 2.7 | SENTINEL-1A | WV | SLC | VV | <Sentinel1Meta single object> | |
WV_014 | SENTINEL1_DS:/home1/scratch/agrouaze/xsardatas... | 2.7 | SENTINEL-1A | WV | SLC | VV | <Sentinel1Meta single object> | |
WV_015 | SENTINEL1_DS:/home1/scratch/agrouaze/xsardatas... | 2.7 | SENTINEL-1A | WV | SLC | VV | <Sentinel1Meta single object> | |
WV_016 | SENTINEL1_DS:/home1/scratch/agrouaze/xsardatas... | 2.7 | SENTINEL-1A | WV | SLC | VV | <Sentinel1Meta single object> | |
WV_017 | SENTINEL1_DS:/home1/scratch/agrouaze/xsardatas... | 2.7 | SENTINEL-1A | WV | SLC | VV | <Sentinel1Meta single object> | |
WV_018 | SENTINEL1_DS:/home1/scratch/agrouaze/xsardatas... | 2.7 | SENTINEL-1A | WV | SLC | VV | <Sentinel1Meta single object> | |
WV_019 | SENTINEL1_DS:/home1/scratch/agrouaze/xsardatas... | 2.7 | SENTINEL-1A | WV | SLC | VV | <Sentinel1Meta single object> | |
WV_020 | SENTINEL1_DS:/home1/scratch/agrouaze/xsardatas... | 2.7 | SENTINEL-1A | WV | SLC | VV | <Sentinel1Meta single object> | |
WV_021 | SENTINEL1_DS:/home1/scratch/agrouaze/xsardatas... | 2.7 | SENTINEL-1A | WV | SLC | VV | <Sentinel1Meta single object> | |
WV_022 | SENTINEL1_DS:/home1/scratch/agrouaze/xsardatas... | 2.7 | SENTINEL-1A | WV | SLC | VV | <Sentinel1Meta single object> | |
WV_023 | SENTINEL1_DS:/home1/scratch/agrouaze/xsardatas... | 2.7 | SENTINEL-1A | WV | SLC | VV | <Sentinel1Meta single object> | |
WV_024 | SENTINEL1_DS:/home1/scratch/agrouaze/xsardatas... | 2.7 | SENTINEL-1A | WV | SLC | VV | <Sentinel1Meta single object> | |
/home1/scratch/agrouaze/xsardatasync/xsardata/S1A_IW_SLC__1SDV_20170907T102951_20170907T103021_018268_01EB76_Z010.SAFE | IW1 | SENTINEL1_DS:/home1/scratch/agrouaze/xsardatas... | 2.84 | SENTINEL-1A | IW | SLC | VV VH | <Sentinel1Meta single object> |
IW2 | SENTINEL1_DS:/home1/scratch/agrouaze/xsardatas... | 2.84 | SENTINEL-1A | IW | SLC | VV VH | <Sentinel1Meta single object> | |
IW3 | SENTINEL1_DS:/home1/scratch/agrouaze/xsardatas... | 2.84 | SENTINEL-1A | IW | SLC | VV VH | <Sentinel1Meta single object> |
By default, xsar.product_info only return a minimal set of columns.
Columns list can be given by the columns=
keyword.
Columns name can be any attributes from xsar.Sentinel1Meta, with the addition of the ‘meta’ column name, who refer to the xsar.Sentinel1Meta objet itself.
If the columns list include ‘geometry’, the result will by a geopandas.GeoDataframe
, who can be displayed whith holoviews.
[9]:
gdf_info = xsar.product_info(
[
xsar.get_test_file('S1A_WV_SLC__1SSV_20160510T101603_20160510T102143_011195_010EA1_Z010.SAFE'),
xsar.get_test_file('S1A_IW_SLC__1SDV_20170907T102951_20170907T103021_018268_01EB76_Z010.SAFE')
],
columns=[ 'safe', 'dsid', 'meta', 'geometry' ]
)
# 'meta' column is dropped for display
gv.feature.land * gv.Polygons(gdf_info.drop(['meta'], axis=1)).opts(tools=['hover'])
multidataset
multidataset
[9]:
[10]:
gdf_info.iloc[0]['meta']
[10]:
<Sentinel1Meta single object>