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')
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))
Can't open an multi-dataset. Use `xsar.Sentinel1Meta('/tmp/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
[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:/tmp/S1A_WV_SLC__1SSV_20160510T101603_20160510T102143_011195_010EA1_Z010.SAFE:WV_001 | POLYGON ((-59.85301 41.55527, -60.09758 41.592... |
SENTINEL1_DS:/tmp/S1A_WV_SLC__1SSV_20160510T101603_20160510T102143_011195_010EA1_Z010.SAFE:WV_002 | POLYGON ((-62.25718 40.99591, -62.49659 41.028... |
SENTINEL1_DS:/tmp/S1A_WV_SLC__1SSV_20160510T101603_20160510T102143_011195_010EA1_Z010.SAFE:WV_003 | POLYGON ((-60.32554 39.79481, -60.56392 39.832... |
SENTINEL1_DS:/tmp/S1A_WV_SLC__1SSV_20160510T101603_20160510T102143_011195_010EA1_Z010.SAFE:WV_004 | POLYGON ((-62.67301 39.23473, -62.90617 39.267... |
SENTINEL1_DS:/tmp/S1A_WV_SLC__1SSV_20160510T101603_20160510T102143_011195_010EA1_Z010.SAFE:WV_005 | POLYGON ((-60.78958 38.03459, -61.02191 38.071... |
SENTINEL1_DS:/tmp/S1A_WV_SLC__1SSV_20160510T101603_20160510T102143_011195_010EA1_Z010.SAFE:WV_006 | POLYGON ((-63.07917 37.47335, -63.30661 37.505... |
SENTINEL1_DS:/tmp/S1A_WV_SLC__1SSV_20160510T101603_20160510T102143_011195_010EA1_Z010.SAFE:WV_007 | POLYGON ((-61.24056 36.27251, -61.46734 36.309... |
SENTINEL1_DS:/tmp/S1A_WV_SLC__1SSV_20160510T101603_20160510T102143_011195_010EA1_Z010.SAFE:WV_008 | POLYGON ((-63.47425 35.71019, -63.69651 35.742... |
SENTINEL1_DS:/tmp/S1A_WV_SLC__1SSV_20160510T101603_20160510T102143_011195_010EA1_Z010.SAFE:WV_009 | POLYGON ((-61.67968 34.50950, -61.90138 34.546... |
SENTINEL1_DS:/tmp/S1A_WV_SLC__1SSV_20160510T101603_20160510T102143_011195_010EA1_Z010.SAFE:WV_010 | POLYGON ((-63.86507 33.94662, -64.08250 33.979... |
SENTINEL1_DS:/tmp/S1A_WV_SLC__1SSV_20160510T101603_20160510T102143_011195_010EA1_Z010.SAFE:WV_011 | POLYGON ((-62.10818 32.74584, -62.32521 32.782... |
SENTINEL1_DS:/tmp/S1A_WV_SLC__1SSV_20160510T101603_20160510T102143_011195_010EA1_Z010.SAFE:WV_012 | POLYGON ((-64.24941 32.18295, -64.46241 32.215... |
SENTINEL1_DS:/tmp/S1A_WV_SLC__1SSV_20160510T101603_20160510T102143_011195_010EA1_Z010.SAFE:WV_013 | POLYGON ((-62.52305 30.98017, -62.73607 31.016... |
SENTINEL1_DS:/tmp/S1A_WV_SLC__1SSV_20160510T101603_20160510T102143_011195_010EA1_Z010.SAFE:WV_014 | POLYGON ((-64.62841 30.41779, -64.83735 30.450... |
SENTINEL1_DS:/tmp/S1A_WV_SLC__1SSV_20160510T101603_20160510T102143_011195_010EA1_Z010.SAFE:WV_015 | POLYGON ((-62.93453 29.21381, -63.14361 29.250... |
SENTINEL1_DS:/tmp/S1A_WV_SLC__1SSV_20160510T101603_20160510T102143_011195_010EA1_Z010.SAFE:WV_016 | POLYGON ((-65.00266 28.65191, -65.20787 28.685... |
SENTINEL1_DS:/tmp/S1A_WV_SLC__1SSV_20160510T101603_20160510T102143_011195_010EA1_Z010.SAFE:WV_017 | POLYGON ((-63.33859 27.44647, -63.54408 27.483... |
SENTINEL1_DS:/tmp/S1A_WV_SLC__1SSV_20160510T101603_20160510T102143_011195_010EA1_Z010.SAFE:WV_018 | POLYGON ((-65.37115 26.88431, -65.57301 26.917... |
SENTINEL1_DS:/tmp/S1A_WV_SLC__1SSV_20160510T101603_20160510T102143_011195_010EA1_Z010.SAFE:WV_019 | POLYGON ((-63.73627 25.67826, -63.93849 25.715... |
SENTINEL1_DS:/tmp/S1A_WV_SLC__1SSV_20160510T101603_20160510T102143_011195_010EA1_Z010.SAFE:WV_020 | POLYGON ((-65.73824 25.11662, -65.93698 25.150... |
SENTINEL1_DS:/tmp/S1A_WV_SLC__1SSV_20160510T101603_20160510T102143_011195_010EA1_Z010.SAFE:WV_021 | POLYGON ((-64.12556 23.90869, -64.32495 23.945... |
SENTINEL1_DS:/tmp/S1A_WV_SLC__1SSV_20160510T101603_20160510T102143_011195_010EA1_Z010.SAFE:WV_022 | POLYGON ((-66.10242 23.34860, -66.29834 23.382... |
SENTINEL1_DS:/tmp/S1A_WV_SLC__1SSV_20160510T101603_20160510T102143_011195_010EA1_Z010.SAFE:WV_023 | POLYGON ((-64.51285 22.13895, -64.70954 22.175... |
SENTINEL1_DS:/tmp/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
[5]:
<xarray.Dataset> Dimensions: (pol: 1, line: 4923, sample: 5681) Coordinates: * pol (pol) object 'VV' * line (line) int64 0 1 2 3 4 5 6 ... 4917 4918 4919 4920 4921 4922 * sample (sample) int64 0 1 2 3 4 5 ... 5675 5676 5677 5678 5679 5680 Data variables: digital_number (pol, line, sample) complex128 dask.array<chunksize=(1, 4923, 5000), meta=np.ndarray> Attributes: (12/17) name: SENTINEL1_DS:/tmp/S1A_WV_SLC__1SSV_20160510T101603_201... short_name: SENTINEL1_DS:S1A_WV_SLC__1SSV_20160510T101603_20160510... product: SLC safe: S1A_WV_SLC__1SSV_20160510T101603_20160510T102143_01119... swath: WV multidataset: False ... ... footprint: POLYGON ((-59.80263505017974 41.73435353976264, -60.04... coverage: 20km * 20km (line * sample ) pixel_line_m: <xarray.DataArray 'azimuthPixelSpacing' ()>\narray(4.1... pixel_sample_m: <xarray.DataArray 'groundRangePixelSpacing' ()>\narray... 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)
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
[8]:
name | ipf | platform | swath | product | pols | meta | ||
---|---|---|---|---|---|---|---|---|
path | dsid | |||||||
/tmp/S1A_WV_SLC__1SSV_20160510T101603_20160510T102143_011195_010EA1_Z010.SAFE | WV_001 | SENTINEL1_DS:/tmp/S1A_WV_SLC__1SSV_20160510T10... | 2.7 | SENTINEL-1A | WV | SLC | VV | <Sentinel1Meta single object> |
WV_002 | SENTINEL1_DS:/tmp/S1A_WV_SLC__1SSV_20160510T10... | 2.7 | SENTINEL-1A | WV | SLC | VV | <Sentinel1Meta single object> | |
WV_003 | SENTINEL1_DS:/tmp/S1A_WV_SLC__1SSV_20160510T10... | 2.7 | SENTINEL-1A | WV | SLC | VV | <Sentinel1Meta single object> | |
WV_004 | SENTINEL1_DS:/tmp/S1A_WV_SLC__1SSV_20160510T10... | 2.7 | SENTINEL-1A | WV | SLC | VV | <Sentinel1Meta single object> | |
WV_005 | SENTINEL1_DS:/tmp/S1A_WV_SLC__1SSV_20160510T10... | 2.7 | SENTINEL-1A | WV | SLC | VV | <Sentinel1Meta single object> | |
WV_006 | SENTINEL1_DS:/tmp/S1A_WV_SLC__1SSV_20160510T10... | 2.7 | SENTINEL-1A | WV | SLC | VV | <Sentinel1Meta single object> | |
WV_007 | SENTINEL1_DS:/tmp/S1A_WV_SLC__1SSV_20160510T10... | 2.7 | SENTINEL-1A | WV | SLC | VV | <Sentinel1Meta single object> | |
WV_008 | SENTINEL1_DS:/tmp/S1A_WV_SLC__1SSV_20160510T10... | 2.7 | SENTINEL-1A | WV | SLC | VV | <Sentinel1Meta single object> | |
WV_009 | SENTINEL1_DS:/tmp/S1A_WV_SLC__1SSV_20160510T10... | 2.7 | SENTINEL-1A | WV | SLC | VV | <Sentinel1Meta single object> | |
WV_010 | SENTINEL1_DS:/tmp/S1A_WV_SLC__1SSV_20160510T10... | 2.7 | SENTINEL-1A | WV | SLC | VV | <Sentinel1Meta single object> | |
WV_011 | SENTINEL1_DS:/tmp/S1A_WV_SLC__1SSV_20160510T10... | 2.7 | SENTINEL-1A | WV | SLC | VV | <Sentinel1Meta single object> | |
WV_012 | SENTINEL1_DS:/tmp/S1A_WV_SLC__1SSV_20160510T10... | 2.7 | SENTINEL-1A | WV | SLC | VV | <Sentinel1Meta single object> | |
WV_013 | SENTINEL1_DS:/tmp/S1A_WV_SLC__1SSV_20160510T10... | 2.7 | SENTINEL-1A | WV | SLC | VV | <Sentinel1Meta single object> | |
WV_014 | SENTINEL1_DS:/tmp/S1A_WV_SLC__1SSV_20160510T10... | 2.7 | SENTINEL-1A | WV | SLC | VV | <Sentinel1Meta single object> | |
WV_015 | SENTINEL1_DS:/tmp/S1A_WV_SLC__1SSV_20160510T10... | 2.7 | SENTINEL-1A | WV | SLC | VV | <Sentinel1Meta single object> | |
WV_016 | SENTINEL1_DS:/tmp/S1A_WV_SLC__1SSV_20160510T10... | 2.7 | SENTINEL-1A | WV | SLC | VV | <Sentinel1Meta single object> | |
WV_017 | SENTINEL1_DS:/tmp/S1A_WV_SLC__1SSV_20160510T10... | 2.7 | SENTINEL-1A | WV | SLC | VV | <Sentinel1Meta single object> | |
WV_018 | SENTINEL1_DS:/tmp/S1A_WV_SLC__1SSV_20160510T10... | 2.7 | SENTINEL-1A | WV | SLC | VV | <Sentinel1Meta single object> | |
WV_019 | SENTINEL1_DS:/tmp/S1A_WV_SLC__1SSV_20160510T10... | 2.7 | SENTINEL-1A | WV | SLC | VV | <Sentinel1Meta single object> | |
WV_020 | SENTINEL1_DS:/tmp/S1A_WV_SLC__1SSV_20160510T10... | 2.7 | SENTINEL-1A | WV | SLC | VV | <Sentinel1Meta single object> | |
WV_021 | SENTINEL1_DS:/tmp/S1A_WV_SLC__1SSV_20160510T10... | 2.7 | SENTINEL-1A | WV | SLC | VV | <Sentinel1Meta single object> | |
WV_022 | SENTINEL1_DS:/tmp/S1A_WV_SLC__1SSV_20160510T10... | 2.7 | SENTINEL-1A | WV | SLC | VV | <Sentinel1Meta single object> | |
WV_023 | SENTINEL1_DS:/tmp/S1A_WV_SLC__1SSV_20160510T10... | 2.7 | SENTINEL-1A | WV | SLC | VV | <Sentinel1Meta single object> | |
WV_024 | SENTINEL1_DS:/tmp/S1A_WV_SLC__1SSV_20160510T10... | 2.7 | SENTINEL-1A | WV | SLC | VV | <Sentinel1Meta single object> | |
/tmp/S1A_IW_SLC__1SDV_20170907T102951_20170907T103021_018268_01EB76_Z010.SAFE | IW1 | SENTINEL1_DS:/tmp/S1A_IW_SLC__1SDV_20170907T10... | 2.84 | SENTINEL-1A | IW | SLC | VV VH | <Sentinel1Meta single object> |
IW2 | SENTINEL1_DS:/tmp/S1A_IW_SLC__1SDV_20170907T10... | 2.84 | SENTINEL-1A | IW | SLC | VV VH | <Sentinel1Meta single object> | |
IW3 | SENTINEL1_DS:/tmp/S1A_IW_SLC__1SDV_20170907T10... | 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'])
[9]:
[10]:
gdf_info.iloc[0]['meta']
[10]:
<Sentinel1Meta single object>
[ ]: