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 geoviews as gv
gv.extension('bokeh')
SAFES containings multiples subdatasets like WV_SLC cannot be openned with xarray.open_dataset
given the safe path.
[2]:
try:
wv_slc_ds = xr.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.SentinelMeta 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]:
Multi (24) dataset
SENTINEL1_DS:S1A_WV_SLC__1SSV_20160510T101603_20160510T102143_011195_010EA1_Z010.SAFE: | |||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
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]:
['SENTINEL1_DS:/tmp/S1A_WV_SLC__1SSV_20160510T101603_20160510T102143_011195_010EA1_Z010.SAFE:WV_001',
'SENTINEL1_DS:/tmp/S1A_WV_SLC__1SSV_20160510T101603_20160510T102143_011195_010EA1_Z010.SAFE:WV_002',
'SENTINEL1_DS:/tmp/S1A_WV_SLC__1SSV_20160510T101603_20160510T102143_011195_010EA1_Z010.SAFE:WV_003',
'SENTINEL1_DS:/tmp/S1A_WV_SLC__1SSV_20160510T101603_20160510T102143_011195_010EA1_Z010.SAFE:WV_004',
'SENTINEL1_DS:/tmp/S1A_WV_SLC__1SSV_20160510T101603_20160510T102143_011195_010EA1_Z010.SAFE:WV_005',
'SENTINEL1_DS:/tmp/S1A_WV_SLC__1SSV_20160510T101603_20160510T102143_011195_010EA1_Z010.SAFE:WV_006',
'SENTINEL1_DS:/tmp/S1A_WV_SLC__1SSV_20160510T101603_20160510T102143_011195_010EA1_Z010.SAFE:WV_007',
'SENTINEL1_DS:/tmp/S1A_WV_SLC__1SSV_20160510T101603_20160510T102143_011195_010EA1_Z010.SAFE:WV_008',
'SENTINEL1_DS:/tmp/S1A_WV_SLC__1SSV_20160510T101603_20160510T102143_011195_010EA1_Z010.SAFE:WV_009',
'SENTINEL1_DS:/tmp/S1A_WV_SLC__1SSV_20160510T101603_20160510T102143_011195_010EA1_Z010.SAFE:WV_010',
'SENTINEL1_DS:/tmp/S1A_WV_SLC__1SSV_20160510T101603_20160510T102143_011195_010EA1_Z010.SAFE:WV_011',
'SENTINEL1_DS:/tmp/S1A_WV_SLC__1SSV_20160510T101603_20160510T102143_011195_010EA1_Z010.SAFE:WV_012',
'SENTINEL1_DS:/tmp/S1A_WV_SLC__1SSV_20160510T101603_20160510T102143_011195_010EA1_Z010.SAFE:WV_013',
'SENTINEL1_DS:/tmp/S1A_WV_SLC__1SSV_20160510T101603_20160510T102143_011195_010EA1_Z010.SAFE:WV_014',
'SENTINEL1_DS:/tmp/S1A_WV_SLC__1SSV_20160510T101603_20160510T102143_011195_010EA1_Z010.SAFE:WV_015',
'SENTINEL1_DS:/tmp/S1A_WV_SLC__1SSV_20160510T101603_20160510T102143_011195_010EA1_Z010.SAFE:WV_016',
'SENTINEL1_DS:/tmp/S1A_WV_SLC__1SSV_20160510T101603_20160510T102143_011195_010EA1_Z010.SAFE:WV_017',
'SENTINEL1_DS:/tmp/S1A_WV_SLC__1SSV_20160510T101603_20160510T102143_011195_010EA1_Z010.SAFE:WV_018',
'SENTINEL1_DS:/tmp/S1A_WV_SLC__1SSV_20160510T101603_20160510T102143_011195_010EA1_Z010.SAFE:WV_019',
'SENTINEL1_DS:/tmp/S1A_WV_SLC__1SSV_20160510T101603_20160510T102143_011195_010EA1_Z010.SAFE:WV_020',
'SENTINEL1_DS:/tmp/S1A_WV_SLC__1SSV_20160510T101603_20160510T102143_011195_010EA1_Z010.SAFE:WV_021',
'SENTINEL1_DS:/tmp/S1A_WV_SLC__1SSV_20160510T101603_20160510T102143_011195_010EA1_Z010.SAFE:WV_022',
'SENTINEL1_DS:/tmp/S1A_WV_SLC__1SSV_20160510T101603_20160510T102143_011195_010EA1_Z010.SAFE:WV_023',
'SENTINEL1_DS:/tmp/S1A_WV_SLC__1SSV_20160510T101603_20160510T102143_011195_010EA1_Z010.SAFE:WV_024']
A subdataset can be directly be opened by xsar.open_dataset
[5]:
wv_slc_ds1 = xr.open_dataset(wv_slc_meta.subdatasets[0])
wv_slc_ds1
[5]:
<xarray.Dataset> Dimensions: (atrack: 4923, pol: 1, xtrack: 5681) Coordinates: * pol (pol) object 'VV' * atrack (atrack) float64 0.5 1.5 2.5 ... 4.922e+03 4.922e+03 * xtrack (xtrack) float64 0.5 1.5 2.5 ... 5.678e+03 5.68e+03 5.68e+03 Data variables: (12/14) digital_number (pol, atrack, xtrack) complex128 ... time (atrack) datetime64[ns] 2016-05-10T10:16:03.843409920 ...... longitude (atrack, xtrack) float32 ... latitude (atrack, xtrack) float32 ... land_mask (atrack, xtrack) int8 ... ground_heading (atrack, xtrack) float32 ... ... ... sigma0_raw (pol, atrack, xtrack) float64 ... nesz (pol, atrack, xtrack) float64 ... gamma0_raw (pol, atrack, xtrack) float64 ... negz (pol, atrack, xtrack) float64 ... sigma0 (pol, atrack, xtrack) float64 ... gamma0 (pol, atrack, xtrack) float64 ... Attributes: (12/15) ipf: 2.7 platform: SENTINEL-1A swath: WV product: SLC pols: VV name: SENTINEL1_DS:/tmp/S1A_WV_SLC__1SSV_20160510T101603_201... ... ... coverage: 20km * 20km (atrack * xtrack ) pixel_atrack_m: 4.127512286013487 pixel_xtrack_m: 3.6571523143890947 orbit_pass: Descending platform_heading: -166.3012322109123 Conventions: CF-1.7
- atrack: 4923
- pol: 1
- xtrack: 5681
- pol(pol)object'VV'
array(['VV'], dtype=object)
- atrack(atrack)float640.5 1.5 2.5 ... 4.922e+03 4.922e+03
- units :
- 1
array([5.0000e-01, 1.5000e+00, 2.5000e+00, ..., 4.9205e+03, 4.9215e+03, 4.9225e+03])
- xtrack(xtrack)float640.5 1.5 2.5 ... 5.68e+03 5.68e+03
- units :
- 1
array([5.0000e-01, 1.5000e+00, 2.5000e+00, ..., 5.6785e+03, 5.6795e+03, 5.6805e+03])
- digital_number(pol, atrack, xtrack)complex128...
[27967563 values with dtype=complex128]
- time(atrack)datetime64[ns]...
array(['2016-05-10T10:16:03.843409920', '2016-05-10T10:16:03.844015872', '2016-05-10T10:16:03.844621824', ..., '2016-05-10T10:16:06.824925184', '2016-05-10T10:16:06.825531136', '2016-05-10T10:16:06.826137088'], dtype='datetime64[ns]')
- longitude(atrack, xtrack)float32...
- standard_name :
- longitude
- units :
- degrees_east
[27967563 values with dtype=float32]
- latitude(atrack, xtrack)float32...
- standard_name :
- latitude
- units :
- degrees_north
[27967563 values with dtype=float32]
- land_mask(atrack, xtrack)int8...
[27967563 values with dtype=int8]
- ground_heading(atrack, xtrack)float32...
[27967563 values with dtype=float32]
- elevation(atrack, xtrack)float32...
[27967563 values with dtype=float32]
- incidence(atrack, xtrack)float32...
[27967563 values with dtype=float32]
- sigma0_raw(pol, atrack, xtrack)float64...
- units :
- m2/m2
[27967563 values with dtype=float64]
- nesz(pol, atrack, xtrack)float64...
[27967563 values with dtype=float64]
- gamma0_raw(pol, atrack, xtrack)float64...
- units :
- m2/m2
[27967563 values with dtype=float64]
- negz(pol, atrack, xtrack)float64...
[27967563 values with dtype=float64]
- sigma0(pol, atrack, xtrack)float64...
[27967563 values with dtype=float64]
- gamma0(pol, atrack, xtrack)float64...
[27967563 values with dtype=float64]
- ipf :
- 2.7
- platform :
- SENTINEL-1A
- swath :
- WV
- product :
- SLC
- pols :
- VV
- name :
- SENTINEL1_DS:/tmp/S1A_WV_SLC__1SSV_20160510T101603_20160510T102143_011195_010EA1_Z010.SAFE:WV_001
- 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.04794367802916 41.77204176347002, -60.09752876528052 41.59309352477252, -59.85296208623707 41.55544353659125, -59.80263505017974 41.73435353976264))
- coverage :
- 20km * 20km (atrack * xtrack )
- pixel_atrack_m :
- 4.127512286013487
- pixel_xtrack_m :
- 3.6571523143890947
- orbit_pass :
- Descending
- platform_heading :
- -166.3012322109123
- Conventions :
- CF-1.7
Or we can get a single dataset by using xsar.SentinelMeta
[6]:
wv_slc_meta1 = xsar.Sentinel1Meta(wv_slc_meta.subdatasets[0])
wv_slc_meta1
[6]:
Single dataset
SENTINEL1_DS:S1A_WV_SLC__1SSV_20160510T101603_20160510T102143_011195_010EA1_Z010.SAFE:WV_001 | |||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
And use this wv_slc_meta1
object with xsar.open_dataset
[7]:
wv_slc_ds1 = xr.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 | single Sentinel1Meta object |
WV_002 | SENTINEL1_DS:/tmp/S1A_WV_SLC__1SSV_20160510T10... | 2.7 | SENTINEL-1A | WV | SLC | VV | single Sentinel1Meta object | |
WV_003 | SENTINEL1_DS:/tmp/S1A_WV_SLC__1SSV_20160510T10... | 2.7 | SENTINEL-1A | WV | SLC | VV | single Sentinel1Meta object | |
WV_004 | SENTINEL1_DS:/tmp/S1A_WV_SLC__1SSV_20160510T10... | 2.7 | SENTINEL-1A | WV | SLC | VV | single Sentinel1Meta object | |
WV_005 | SENTINEL1_DS:/tmp/S1A_WV_SLC__1SSV_20160510T10... | 2.7 | SENTINEL-1A | WV | SLC | VV | single Sentinel1Meta object | |
WV_006 | SENTINEL1_DS:/tmp/S1A_WV_SLC__1SSV_20160510T10... | 2.7 | SENTINEL-1A | WV | SLC | VV | single Sentinel1Meta object | |
WV_007 | SENTINEL1_DS:/tmp/S1A_WV_SLC__1SSV_20160510T10... | 2.7 | SENTINEL-1A | WV | SLC | VV | single Sentinel1Meta object | |
WV_008 | SENTINEL1_DS:/tmp/S1A_WV_SLC__1SSV_20160510T10... | 2.7 | SENTINEL-1A | WV | SLC | VV | single Sentinel1Meta object | |
WV_009 | SENTINEL1_DS:/tmp/S1A_WV_SLC__1SSV_20160510T10... | 2.7 | SENTINEL-1A | WV | SLC | VV | single Sentinel1Meta object | |
WV_010 | SENTINEL1_DS:/tmp/S1A_WV_SLC__1SSV_20160510T10... | 2.7 | SENTINEL-1A | WV | SLC | VV | single Sentinel1Meta object | |
WV_011 | SENTINEL1_DS:/tmp/S1A_WV_SLC__1SSV_20160510T10... | 2.7 | SENTINEL-1A | WV | SLC | VV | single Sentinel1Meta object | |
WV_012 | SENTINEL1_DS:/tmp/S1A_WV_SLC__1SSV_20160510T10... | 2.7 | SENTINEL-1A | WV | SLC | VV | single Sentinel1Meta object | |
WV_013 | SENTINEL1_DS:/tmp/S1A_WV_SLC__1SSV_20160510T10... | 2.7 | SENTINEL-1A | WV | SLC | VV | single Sentinel1Meta object | |
WV_014 | SENTINEL1_DS:/tmp/S1A_WV_SLC__1SSV_20160510T10... | 2.7 | SENTINEL-1A | WV | SLC | VV | single Sentinel1Meta object | |
WV_015 | SENTINEL1_DS:/tmp/S1A_WV_SLC__1SSV_20160510T10... | 2.7 | SENTINEL-1A | WV | SLC | VV | single Sentinel1Meta object | |
WV_016 | SENTINEL1_DS:/tmp/S1A_WV_SLC__1SSV_20160510T10... | 2.7 | SENTINEL-1A | WV | SLC | VV | single Sentinel1Meta object | |
WV_017 | SENTINEL1_DS:/tmp/S1A_WV_SLC__1SSV_20160510T10... | 2.7 | SENTINEL-1A | WV | SLC | VV | single Sentinel1Meta object | |
WV_018 | SENTINEL1_DS:/tmp/S1A_WV_SLC__1SSV_20160510T10... | 2.7 | SENTINEL-1A | WV | SLC | VV | single Sentinel1Meta object | |
WV_019 | SENTINEL1_DS:/tmp/S1A_WV_SLC__1SSV_20160510T10... | 2.7 | SENTINEL-1A | WV | SLC | VV | single Sentinel1Meta object | |
WV_020 | SENTINEL1_DS:/tmp/S1A_WV_SLC__1SSV_20160510T10... | 2.7 | SENTINEL-1A | WV | SLC | VV | single Sentinel1Meta object | |
WV_021 | SENTINEL1_DS:/tmp/S1A_WV_SLC__1SSV_20160510T10... | 2.7 | SENTINEL-1A | WV | SLC | VV | single Sentinel1Meta object | |
WV_022 | SENTINEL1_DS:/tmp/S1A_WV_SLC__1SSV_20160510T10... | 2.7 | SENTINEL-1A | WV | SLC | VV | single Sentinel1Meta object | |
WV_023 | SENTINEL1_DS:/tmp/S1A_WV_SLC__1SSV_20160510T10... | 2.7 | SENTINEL-1A | WV | SLC | VV | single Sentinel1Meta object | |
WV_024 | SENTINEL1_DS:/tmp/S1A_WV_SLC__1SSV_20160510T10... | 2.7 | SENTINEL-1A | WV | SLC | VV | single Sentinel1Meta 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 | single Sentinel1Meta object |
IW2 | SENTINEL1_DS:/tmp/S1A_IW_SLC__1SDV_20170907T10... | 2.84 | SENTINEL-1A | IW | SLC | VV VH | single Sentinel1Meta object | |
IW3 | SENTINEL1_DS:/tmp/S1A_IW_SLC__1SDV_20170907T10... | 2.84 | SENTINEL-1A | IW | SLC | VV VH | single Sentinel1Meta 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]:
Single dataset
SENTINEL1_DS:S1A_WV_SLC__1SSV_20160510T101603_20160510T102143_011195_010EA1_Z010.SAFE:WV_001 | |||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|