xarray-sentinel
Read Copernicus Sentinel-1 SAFE
products in Xarray as the new EOPF DataTrees or as the classic xarray-sentinel Datasets.
Convert them to EOPF Zarr with one command: xarray-sentinel to-eopf-zarr.
This Open Source project is sponsored by B-Open - https://www.bopen.eu.
Features
xarray-sentinel is a Python library, an Xarray backend
and a command line tool with the following functionalities:
- opens a whole SAFE product in Xarray as an EOPF
DataTree, the layout of the new ESA
Zarr products
- converts a SAFE product to EOPF Zarr with the
xarray-sentinel command
- opens every group of a SAFE product as a classic Xarray
Dataset that follows the SAFE
structure
- supports the following data products as distributed by ESA:
- Sentinel-1 Ground Range Detected (GRD):
- Stripmap (SM)
- Interferometric Wide Swath (IW)
- Extra Wide Swath (EW)
- Sentinel-1 Single Look Complex (SLC) SM/IW/EW
- creates ready-to-use Xarray
DataTrees and Datasets that map the data
lazily and efficiently in terms of both memory usage and disk / network access
- reads all SAR imagery data: GRD images, SLC swaths and SLC bursts
- reads several metadata elements:
satellite orbit and attitude, ground control points, radiometric calibration look up tables,
Doppler centroid estimation and more
- reads uncompressed and compressed SAFE data products on the local computer or
on a network via fsspec:
metadata is read through fsspec on any filesystem, while measurements require a
URL scheme that rasterio / GDAL opens natively (e.g.
http(s), s3, gs, az);
measurements on other filesystems, such as zip or chained caching filesystems,
are currently broken (see #127)
- supports larger-than-memory and distributed data access via Dask and
rioxarray /
rasterio / GDAL
- provides a few helpers for simple operations involving metadata like
cropping individual bursts out of IW SLC swaths,
applying radiometric calibration polynomials,
converting slant to ground range for GRD products and
computing geospatial metadata.
Overall, the software is in the beta phase and the usual caveats apply.
Install
xarray-sentinel needs Python 3.11 or later. The easiest way to install it is via pip:
pip install xarray-sentinel
The optional extras are zarr, needed by the to-eopf-zarr command, s3, to read
products from S3 object stores, and scipy, needed by the calibration with a non
constant LUT and the slant / ground range conversions,
e.g. pip install "xarray-sentinel[zarr,s3,scipy]".
If you have uv installed the simplest way to test the library is to start an ipython session with:
uvx --with xarray-sentinel ipython
and to run the xarray-sentinel command without installing it:
uvx xarray-sentinel --help
Usage
The SAR data products of the Copernicus Sentinel-1 satellite mission are distributed in
the SAFE format, composed of a few raster data files in TIFF and several metadata files in XML.
xarray-sentinel opens them in two ways: as an EOPF DataTree, with the layout of
the new ESA Zarr products, or as classic Datasets that follow the SAFE structure group
by group.
EOPF DataTree (beta)
xr.open_datatree opens the whole product as an xarray.DataTree
with the layout of the ESA EOPF products, the format written by the EOPF CPM 3.0
converter: one node per swath and burst for TOPS SLC, and one node for SM and GRD.
The layout is in beta and changes only to follow the EOPF format.
dt = xr.open_datatree("S1A_IW_SLC__1SDV_....SAFE", engine="sentinel-1")
slc = dt["S01SIWSLC_20260731T234807_0014_C050_C079_0116E8_IW3_258176/measurements/slc"]
Polarisations are stacked along polarization. The root carries the product level
stac_discovery and other_metadata attributes, and every node its own
stac_discovery and other_metadata.
WV products are not supported yet and raise an error. See
DATATREE.md
for the layout and the deliberate differences from EOPF.
The xarray-sentinel command (beta)
to-eopf-zarr converts a SAFE product to an EOPF Zarr store,
replacing the target if it exists, and info prints the product level STAC
metadata reading only the manifest.
to-eopf-zarr needs the zarr extra, i.e. pip install "xarray-sentinel[zarr]":
uvx 'xarray-sentinel[zarr]' to-eopf-zarr S1A_IW_SLC__1SDV_....SAFE product.zarr
uvx xarray-sentinel info S1A_IW_SLC__1SDV_....SAFE
The source may be any local or fsspec URL path. Reading from the Copernicus Data
Space Ecosystem S3 store needs the s3 extra and the .env file
with your CDSE S3 credentials as described here:
uvx --env-file .env 'xarray-sentinel[zarr,s3]' to-eopf-zarr \
s3://eodata/Sentinel-1/SAR/IW_SLC__1S/2026/10/29/S1C_IW_SLC__1SDV_20261029T051055_20261029T051123_010095_014269_D7D7.SAFE \
product.zarr
Classic Datasets by group
Due to the inherent complexity and redundancy of the SAFE format xarray-sentinel
maps it to a tree of groups where every group may be opened as a Dataset,
but it may also contain subgroups, that are listed in the subgroups attribute.
The following sections show some examples of xarray-sentinel usage.
In the notebooks folder you
can also find notebooks, one for each supported product, that allow you to explore the
data in more detail using the xarray-sentinel functions.
The root dataset
For example, let's explore the Sentinel-1 SLC Stripmap product in the local folder
tests/data/S1A_S3_SLC__1SDV_20210401T152855_20210401T152914_037258_04638E_6001.SAFE.
First, we can open the SAR data product by passing the engine="sentinel-1" option to xr.open_dataset
and access the root group of the product, also known as /:
>>> import xarray as xr
>>> slc_sm_path = "tests/data/S1A_S3_SLC__1SDV_20210401T152855_20210401T152914_037258_04638E_6001.SAFE"
>>> xr.open_dataset(slc_sm_path, engine="sentinel-1")
<xarray.Dataset> Size: 0B
Dimensions: ()
Data variables:
*empty*
Attributes: ...
family_name: SENTINEL-1
number: A
mode: SM
swaths: ['S3']
orbit_number: 37258
relative_orbit_number: 86
...
start_time: 2021-04-01T15:28:55.111501
stop_time: 2021-04-01T15:29:14.277650
group: /
subgroups: ['S3', 'S3/VH', 'S3/VH/orbit', 'S3/V...
Conventions: CF-1.11
history: created by xarray_sentinel-...
The root Dataset does not contain any data variable, but only attributes that provide general information
on the product and a description of the tree structure of the data.
The group attribute contains the name of the current group and the subgroups attribute shows
the names of all available groups below this one.
Measurements datasets
To open any subgroup, pass its name with the group keyword to xr.open_dataset.
Measurements are read by selecting the swath and polarization, for example group="S3/VH":
>>> slc_s3_vh = xr.open_dataset(
... slc_sm_path, group="S3/VH", engine="sentinel-1", chunks=2048
... )
>>> slc_s3_vh
<xarray.Dataset> Size: 6GB
Dimensions: (slant_range_time: 18998, azimuth_time: 36895)
Coordinates:
* slant_range_time (slant_range_time) float64 ...
pixel (slant_range_time) int64 ...
* azimuth_time (azimuth_time) datetime64[ns] ...
line (azimuth_time) int64 ...
Data variables:
measurement (azimuth_time, slant_range_time) complex64 ...
Attributes: ...
family_name: SENTINEL-1
number: A
mode: SM
swaths: ['S3']
orbit_number: 37258
relative_orbit_number: 86
...
geospatial_lon_min: 42.772483
geospatial_lon_max: 43.757706
group: /S3/VH
subgroups: ['orbit', 'attitude', 'azimuth_fm_ra...
Conventions: CF-1.11
history: created by xarray_sentinel-...
The measurement variable contains the Single Look Complex measurements as complex64
and has dimensions slant_range_time and azimuth_time.
The azimuth_time is an np.datetime64 coordinate that contains the UTC zero-Doppler time
associated with the image line
and slant_range_time is an np.float64 coordinate that contains the two-way range time interval
in seconds associated with the image pixel.
Since Sentinel-1 IPF version 3.40, a unique identifier for bursts has been added to the SLC product metadata.
For these products, the list of the burst ids is stored in the burst_ids dataset attribute.
Metadata datasets
Every swath and polarization group, such as /S3/VH, holds the measurement variable plus the
following metadata subgroups:
- product XML file
orbit from the <orbit> tags
attitude from the <attitude> tags
azimuth_fm_rate from the <azimuthFmRate> tags
dc_estimate from the <dcEstimate> tags
gcp from the <geolocationGridPoint> tags
coordinate_conversion from the <coordinateConversion> tags
- calibration XML file
calibration from the <calibrationVector> tags
- noise XML file
noise_range from the <noiseRangeVector> tags
noise_azimuth from the <noiseAzimuthVector> tags
For example, the image calibration metadata associated with the S3/VH image can be read using
group="S3/VH/calibration":
>>> slc_s3_vh_calibration = xr.open_dataset(
... slc_sm_path, group="S3/VH/calibration", engine="sentinel-1"
... )
>>> slc_s3_vh_calibration
<xarray.Dataset> Size: 172kB
Dimensions: (line: 22, pixel: 476)
Coordinates:
* line (line) int64 ...
* pixel (pixel) int64 ...
Data variables:
azimuth_time (line) datetime64[ns] ...
sigmaNought (line, pixel) float32 ...
betaNought (line, pixel) float32 ...
gamma (line, pixel) float32 ...
dn (line, pixel) float32 ...
Attributes: ...
family_name: SENTINEL-1
number: A
mode: SM
swaths: ['S3']
orbit_number: 37258
relative_orbit_number: 86
...
absoluteCalibrationConstant: 1.0
group: /S3/VH/calibration
Conventions: CF-1.11
title: Calibration coefficients
comment: The dataset contains calibration inf...
history: created by xarray_sentinel-...
Note that in this case, the dimensions are line and pixel with coordinates corresponding to
the sub-grid of the original image where the calibration Look Up Table is defined.
The groups present in a typical Sentinel-1 Stripmap product are:
/
└─ S3
├─ VH
│ ├─ orbit
│ ├─ attitude
│ ├─ azimuth_fm_rate
│ ├─ dc_estimate
│ ├─ gcp
│ ├─ coordinate_conversion
│ ├─ calibration
│ ├─ noise_range
│ └─ noise_azimuth
└─ VV
├─ orbit
├─ attitude
├─ azimuth_fm_rate
├─ dc_estimate
├─ gcp
├─ coordinate_conversion
├─ calibration
├─ noise_range
└─ noise_azimuth
Advanced usage
TOPS burst datasets
The IW and EW products, that use the Terrain Observation with Progressive Scan (TOPS) acquisition mode,
are more complex because they contain several swaths in the same SAFE package,
but also because the measurement array is a collage of sub-images called bursts.
xarray-sentinel provides a helper function that crops a burst out of a measurement dataset for you.
First, open the desired measurement dataset: here, the HH polarization of the first IW swath
of the tests/data/S1A_IW_SLC__1SDH_20220414T102209_20220414T102236_042768_051AA4_E677.SAFE
product: