跳转到主要内容

轻松访问和探索Copernicus Sentinel-1卫星任务的SAR数据产品

项目描述

xarray-sentinel

在Python中轻松访问和探索Copernicus Sentinel-1卫星任务的SAR数据产品。

此开源项目由B-Open赞助 - https://www.bopen.eu

功能

xarray-sentinel是一个Python库和Xarray后端,具有以下功能

  • 支持以下由ESA分发的数据产品
    • Sentinel-1地面范围检测(GRD)
      • 条带图(SM)
      • 干涉合成孔径(IW)
      • 超宽条带(EW)
    • Sentinel-1单视复数(SLC)SM/IW/EW
  • 创建可立即使用的Xarray Dataset,以高效的方式映射数据,在内存使用和磁盘/网络访问方面都进行了优化
  • 读取所有SAR图像数据:GRD图像、SLC条带和SLC脉冲
  • 读取多个元数据元素:卫星轨道和姿态、地面控制点、辐射校准查找表、多普勒质心估计等
  • (部分损坏,见#127)在本地计算机或网络上通过fsspec读取未压缩和压缩的SAFE数据产品
  • 支持通过Daskrioxarray / rasterio / GDAL进行大于内存的分布式数据访问
  • 提供了一些辅助工具,用于涉及元数据的简单操作,例如从IW SLC swaths中裁剪单个脉冲,应用辐射校正多项式,将斜距转换为GRD产品的地面距离,以及计算地理空间元数据。

总体而言,该软件处于beta阶段,并适用常规警告。

安装

安装xarray-sentinel的最简单方法是在conda环境中。以下命令创建了一个新的环境,激活它,并安装了该包及其依赖项

    conda create -n XARRAY-SENTINEL
    conda activate XARRAY-SENTINEL
    conda install -c conda-forge dask "rasterio=>1.3.0" xarray-sentinel

用法

哥白尼哨兵-1卫星任务的中继数据产品以SAFE格式分布,由几个TIFF格式的栅格数据文件和几个XML格式的元数据文件组成。xarray-sentinel的目的是提供一种开发者友好的Python接口,将所有数据和几个元数据元素作为Xarray Dataset提供,以便轻松地将SAR数据转换为增值产品。

由于SAFE格式的固有复杂性和冗余,xarray-sentinel将其映射到一个的树中,其中每个都可以作为Dataset打开,但它也可能包含子组,这些子组列在subgroups属性中。

以下各节展示了xarray-sentinel的一些用法示例。在notebooks文件夹中,您还可以找到每个支持的产品的一个笔记本,允许您使用xarray-sentinel函数更详细地探索数据。

根数据集

例如,让我们探索本地文件夹./S1A_S3_SLC__1SDV_20210401T152855_20210401T152914_037258_04638E_6001.SAFE中的哨兵-1 SLC Stripmap产品。首先,我们可以通过将engine="sentinel-1"选项传递给xr.open_dataset来打开SAR数据产品,并访问产品的根组,也称为/

>>> 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>
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.8
    history:                             created by xarray_sentinel-...

Dataset不包含任何数据变量,但只包含提供有关产品的一般信息和数据树结构的描述的属性。group属性包含当前组名,而subgroups属性显示所有可用组。

测量数据集

要打开其他组,我们需要将group关键字添加到xr.open_dataset。然后可以通过选择所需的波束模式和极化来读取测量。在这个例子中,选择的数据包含S3波束模式和VH极化,带有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>
Dimensions:           (slant_range_time: 18998, azimuth_time: 36895)
Coordinates:
    pixel             (slant_range_time) int64 ...
    line              (azimuth_time) int64 ...
  * azimuth_time      (azimuth_time) datetime64[ns] ...
  * slant_range_time  (slant_range_time) float64 ...
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.772483374347
    geospatial_lon_max:                  43.75770573943618
    group:                               /S3/VH
    subgroups:                           ['orbit', 'attitude', 'azimuth_fm_ra...
    Conventions:                         CF-1.8
    history:                             created by xarray_sentinel-...

measurement变量包含以complex64表示的单视复数测量值,具有slant_range_timeazimuth_time维度。azimuth_time是一个np.datetime64坐标,包含与图像线相关的UTC零多普勒时间,而slant_range_time是一个np.float64坐标,包含与图像像素相关的往返距离时间间隔(以秒为单位)。

由于Sentinel-1 IPF版本3.40,已将脉冲的唯一标识符添加到SLC产品元数据中。对于这些产品,脉冲ID列表存储在burst_ids数据集属性中。

元数据数据集

测量组包含与图像相关的元数据的几个子组。目前,xarray-sentinel支持以下元数据数据集

  • 产品XML文件
    • orbit来自<orbit>标签
    • attitude来自<attitude>标签
    • azimuth_fm_rate来自<azimuthFmRate>标签
    • dc_estimate来自<dcEstimate>标签
    • gcp来自<geolocationGridPoint>标签
    • coordinate_conversion来自<coordinateConversion>标签
  • 校准XML文件
    • calibration 来自 <calibrationVector> 标签
  • 噪声XML文件
    • noise_range 来自 <noiseRangeVector> 标签
    • noise_azimuth 来自 <noiseAzimuthVector> 标签

例如,与 S3/VH 图像关联的图像校准元数据可以使用 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>
Dimensions:       (line: 22, pixel: 476)
Coordinates:
  * line          (line) int64 0 1925 3850 5775 7700 ... 34649 36574 38499 40424
  * pixel         (pixel) int64 0 40 80 120 160 ... 18880 18920 18960 18997
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
    ...
    stop_time:                           2021-04-01T15:29:14.277650
    group:                               /S3/VH/calibration
    Conventions:                         CF-1.8
    title:                               Calibration coefficients
    comment:                             The dataset contains calibration inf...
    history:                             created by xarray_sentinel-...

请注意,在这种情况下,维度是 linepixel,坐标对应于定义校准查找表的原始图像的子网格

典型Sentinel-1 Stripmap产品中存在的组

/
└─ 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

高级用法

TOPS脉冲数据集

使用地形观测渐进式扫描(TOPS)采集模式的IW和EW产品更为复杂,因为它们在同一个SAFE包中包含多个波束模式,同时也因为测量阵列是由称为 burst 的子图像拼贴而成的。

xarray-sentinel 提供了一个辅助函数,可以从测量数据集中为您裁剪出burst。

首先需要打开所需的测量数据集,例如,在当前文件夹中打开 S1A_IW_SLC__1SDH_20220414T102209_20220414T102236_042768_051AA4_E677.SAFE 产品HH极化的第一个IW条带

>>> slc_iw_v340_path = "tests/data/S1A_IW_SLC__1SDH_20220414T102209_20220414T102236_042768_051AA4_E677.SAFE"
>>> slc_iw1_v340_hh = xr.open_dataset(slc_iw_v340_path, group="IW1/HH", engine="sentinel-1")
>>> slc_iw1_v340_hh
<xarray.Dataset>
Dimensions:           (pixel: 21169, line: 13500)
Coordinates:
  * pixel             (pixel) int64 0 1 2 3 4 ... 21164 21165 21166 21167 21168
  * line              (line) int64 0 1 2 3 4 5 ... 13495 13496 13497 13498 13499
    azimuth_time      (line) datetime64[ns] ...
    slant_range_time  (pixel) float64 ...
Data variables:
    measurement       (line, pixel) complex64 ...
Attributes: ...
    family_name:                         SENTINEL-1
    number:                              A
    mode:                                IW
    swaths:                              ['IW1', 'IW2', 'IW3']
    orbit_number:                        42768
    relative_orbit_number:               171
    ...
    geospatial_lon_min:                  -61.94949110259839
    geospatial_lon_max:                  -60.24826879672774
    group:                               /IW1/HH
    subgroups:                           ['orbit', 'attitude', 'azimuth_fm_ra...
    Conventions:                         CF-1.8
    history:                             created by xarray_sentinel-...

请注意,由于图像的拼贴特性,IW和EW采集模式的测量数据无法通过物理坐标索引

现在可以使用 burst_index=8 从条带数据中裁剪出9个burst中的第9个

>>> import xarray_sentinel
>>> xarray_sentinel.crop_burst_dataset(slc_iw1_v340_hh, burst_index=8)
<xarray.Dataset>
Dimensions:           (slant_range_time: 21169, azimuth_time: 1500)
Coordinates:
    pixel             (slant_range_time) int64 0 1 2 3 ... 21166 21167 21168
    line              (azimuth_time) int64 12000 12001 12002 ... 13498 13499
  * azimuth_time      (azimuth_time) datetime64[ns] 2022-04-14T10:22:33.80763...
  * slant_range_time  (slant_range_time) float64 0.005348 0.005349 ... 0.005677
Data variables:
    measurement       (azimuth_time, slant_range_time) complex64 ...
Attributes: ...
    family_name:                         SENTINEL-1
    number:                              A
    mode:                                IW
    swaths:                              ['IW1', 'IW2', 'IW3']
    orbit_number:                        42768
    relative_orbit_number:               171
    ...
    group:                               /IW1/HH
    Conventions:                         CF-1.8
    history:                             created by xarray_sentinel-...
    azimuth_anx_time:                    2136.774327
    burst_index:                         8
    burst_id:                            365923

如果IPF处理器版本为3.40或更高,还可以使用 burst_id 键选择要裁剪的burst

>>> xarray_sentinel.crop_burst_dataset(slc_iw1_v340_hh, burst_id=365923)
<xarray.Dataset>
Dimensions:           (slant_range_time: 21169, azimuth_time: 1500)
Coordinates:
    pixel             (slant_range_time) int64 0 1 2 3 ... 21166 21167 21168
    line              (azimuth_time) int64 12000 12001 12002 ... 13498 13499
  * azimuth_time      (azimuth_time) datetime64[ns] 2022-04-14T10:22:33.80763...
  * slant_range_time  (slant_range_time) float64 0.005348 0.005349 ... 0.005677
Data variables:
    measurement       (azimuth_time, slant_range_time) complex64 ...
Attributes: ...
    family_name:                         SENTINEL-1
    number:                              A
    mode:                                IW
    swaths:                              ['IW1', 'IW2', 'IW3']
    orbit_number:                        42768
    relative_orbit_number:               171
    ...
    group:                               /IW1/HH
    Conventions:                         CF-1.8
    history:                             created by xarray_sentinel-...
    azimuth_anx_time:                    2136.774327
    burst_index:                         8
    burst_id:                            365923

请注意,辅助函数还执行了其他更改,例如交换维度到物理坐标并添加burst属性。

作为快速访问burst数据的方法,您可以在打开时将 burst_index 添加到组规范中,例如,group="IW1/VH/8"。由于burst组不是结构性的,因此它们未列入 subgroup 属性中。

>>> slc_iw_v330_path = "tests/data/S1B_IW_SLC__1SDV_20210401T052622_20210401T052650_026269_032297_EFA4.SAFE"
>>> xr.open_dataset(slc_iw_v330_path, group="IW1/VH/8", engine="sentinel-1")
<xarray.Dataset>
Dimensions:           (slant_range_time: 21632, azimuth_time: 1501)
Coordinates:
    pixel             (slant_range_time) int64 ...
    line              (azimuth_time) int64 ...
  * azimuth_time      (azimuth_time) datetime64[ns] 2021-04-01T05:26:46.27227...
  * slant_range_time  (slant_range_time) float64 0.005343 0.005343 ... 0.005679
Data variables:
    measurement       (azimuth_time, slant_range_time) complex64 ...
Attributes: ...
    family_name:                         SENTINEL-1
    number:                              B
    mode:                                IW
    swaths:                              ['IW1', 'IW2', 'IW3']
    orbit_number:                        26269
    relative_orbit_number:               168
    ...
    geospatial_lon_max:                  12.093126130070317
    group:                               /IW1/VH
    azimuth_anx_time:                    2210.634453
    burst_index:                         8
    Conventions:                         CF-1.8
    history:                             created by xarray_sentinel-...

校准

xarray-sentinel 提供了辅助函数,使用校准元数据对数据进行校准。您可以使用以下方法计算条带图像上部分区域的伽马强度

>>> xarray_sentinel.calibrate_intensity(slc_s3_vh.measurement[:2048, :2048], slc_s3_vh_calibration.gamma)
<xarray.DataArray (azimuth_time: 2048, slant_range_time: 2048)>
dask.array<pow, shape=(2048, 2048), dtype=float32, chunksize=(2048, 2048), chunktype=numpy.ndarray>
Coordinates:
    pixel             (slant_range_time) int64 dask.array<chunksize=(2048,), meta=np.ndarray>
    line              (azimuth_time) int64 dask.array<chunksize=(2048,), meta=np.ndarray>
  * azimuth_time      (azimuth_time) datetime64[ns] 2021-04-01T15:28:55.11150...
  * slant_range_time  (slant_range_time) float64 0.005273 0.005273 ... 0.005303
Attributes: ...
    family_name:                         SENTINEL-1
    number:                              A
    mode:                                SM
    swaths:                              ['S3']
    orbit_number:                        37258
    relative_orbit_number:               86
    ...
    geospatial_lat_min:                  -12.17883496921861
    geospatial_lat_max:                  -10.85986742252814
    geospatial_lon_min:                  42.772483374347
    geospatial_lon_max:                  43.75770573943618
    units:                               m2 m-2
    long_name:                           gamma

通过fsspec进行高级数据访问

您需要未发布的rasterio >= 1.3.0,以便fsspec可以在测量数据上工作

xarray-sentinel 可以从各种数据存储中读取数据,包括本地文件系统、网络文件系统、云对象存储和压缩文件格式,如Zip。这是通过将 fsspec 兼容的URL传递到 xr.open_dataset 并可选地传递 storage_options 关键字参数来完成的。

例如,您可以直接从zip文件中打开产品

>>> slc_iw_zip_path = "tests/data/S1B_IW_SLC__1SDV_20210401T052622_20210401T052650_026269_032297_EFA4.zip"
>>> xr.open_dataset(f"zip://*/manifest.safe::{slc_iw_zip_path}", group="IW1/VH", engine="sentinel-1")  # doctest: +SKIP
<xarray.Dataset>
Dimensions:           (pixel: 21632, line: 13509)
Coordinates:
  * pixel             (pixel) int64 0 1 2 3 4 ... 21627 21628 21629 21630 21631
  * line              (line) int64 0 1 2 3 4 5 ... 13504 13505 13506 13507 13508
    azimuth_time      (line) datetime64[ns] ...
    slant_range_time  (pixel) float64 ...
Data variables:
    measurement       (line, pixel) complex64 ...
Attributes: ...
    family_name:                         SENTINEL-1
    number:                              B
    mode:                                IW
    swaths:                              ['IW1', 'IW2', 'IW3']
    orbit_number:                        26269
    relative_orbit_number:               168
    ...
    number_of_bursts:                    9
    lines_per_burst:                     1501
    group:                               /IW1/VH
    subgroups:                           ['orbit', 'attitude', 'azimuth_fm_ra...
    Conventions:                         CF-1.8
    history:                             created by xarray_sentinel-...

作为远程访问的示例,您可以直接从GitHub存储库中打开产品

>>> xr.open_dataset(f"github://bopen:xarray-sentinel@/{slc_iw_path}", group="IW1/VH", engine="sentinel-1")  # doctest: +SKIP
<xarray.Dataset>
Dimensions:           (pixel: 21632, line: 13509)
Coordinates:
  * pixel             (pixel) int64 0 1 2 3 4 ... 21627 21628 21629 21630 21631
  * line              (line) int64 0 1 2 3 4 5 ... 13504 13505 13506 13507 13508
    azimuth_time      (line) datetime64[ns] ...
    slant_range_time  (pixel) float64 ...
Data variables:
    measurement       (line, pixel) complex64 ...
Attributes: ...
    family_name:                         SENTINEL-1
    number:                              B
    mode:                                IW
    swaths:                              ['IW1', 'IW2', 'IW3']
    orbit_number:                        26269
    relative_orbit_number:               168
    ...
    number_of_bursts:                    9
    lines_per_burst:                     1501
    group:                               /IW1/VH
    subgroups:                           ['orbit', 'attitude', 'azimuth_fm_ra...
    Conventions:                         CF-1.8
    history:                             created by xarray_sentinel-...

fsspec 非常强大,支持缓存和链式调用,例如,您可以从GitHub存储库中打开zip文件并将其本地缓存

>>> xr.open_dataset(
...     f"zip://*/manifest.safe::simplecache::github://bopen:xarray-sentinel@/{slc_iw_zip_path}",
...     engine="sentinel-1",
...     group="IW1/VH",
...     storage_options={
...         "simplecache": {"cache_storage": "/tmp/zipfiles/"},
...     },
... )  # doctest: +SKIP
<xarray.Dataset>
Dimensions:           (pixel: 21632, line: 13509)
Coordinates:
  * pixel             (pixel) int64 0 1 2 3 4 ... 21627 21628 21629 21630 21631
  * line              (line) int64 0 1 2 3 4 5 ... 13504 13505 13506 13507 13508
    azimuth_time      (line) datetime64[ns] ...
    slant_range_time  (pixel) float64 ...
Data variables:
    measurement       (line, pixel) complex64 ...
Attributes: ...
    family_name:                         SENTINEL-1
    number:                              B
    mode:                                IW
    swaths:                              ['IW1', 'IW2', 'IW3']
    orbit_number:                        26269
    relative_orbit_number:               168
    ...
    number_of_bursts:                    9
    lines_per_burst:                     1501
    group:                               /IW1/VH
    subgroups:                           ['orbit', 'attitude', 'azimuth_fm_ra...
    Conventions:                         CF-1.8
    history:                             created by xarray_sentinel-...

参考文档

这是参考文档的列表

设计决策

  • xarray-sentinel 的主要设计选择是使其尽可能地成为SAFE数据包内容的纯映射,尽可能少地进行解释。
    • 即使对于不同波束模式,预期信息(如轨道和姿态)相同,树状结构也遵循SAFE包的结构。我们观察到至少有一个情况,不同波束模式之间报告的轨道状态向量数量不同。
    • 数据和元数据被转换为Python / numpy中最接近的数据类型。最重要的转换是将SLC测量中的CInt16转换为np.complex64,这使数据的空间需求加倍。此外,xarray-sentinel将UTC时间转换为np.datetime64,并且不尝试支持闰秒,包含闰秒的获取可能会崩溃或静默返回损坏的数据。下面将解释坐标数据类型选择的理由。
    • 我们尽量使所有命名尽可能接近原始名称。特别是对于元数据,我们使用XML标签的名称,仅将它们从camelCase转换为snake_case
  • 尽可能时,xarray-sentinel使用物理坐标azimuth_timeslant_range_time索引数据,但保留图像linepixel作为辅助坐标。
  • 作为上述元数据命名规则的例外,我们添加了一些属性以获得CF-Conventions合规性。
  • 我们的目标是即使对于部分SAFE包,也打开可用的数据和元数据,例如,xarray-sentinel可以打开一个波束模式的测量数据集,即使其他波束模式/极化的TIFF文件缺失。
  • 精度考虑和坐标数据类型选择的理由
    • azimuth_time可以表示为np.datetime64[ns],因为LEO速度下的空间分辨率为10km/s * 1ns ~= 0.001cm。
    • 另一方面,slant_range_time不能表示为np.timedelta64[ns],因为光速下的空间分辨率为300_000km/s * 1ns / 2 ~= 15cm,即不足以进行干涉测量应用。slant_range_time需要在1_000km的距离上达到0.001cm的空间分辨率,即大约1e-9,这完全在IEEE-754 float64的1e-15分辨率范围内。

项目徽章

on-push codecov

贡献

主要仓库托管在GitHub上。测试、错误报告和贡献都受到高度欢迎和赞赏。

https://github.com/bopen/xarray-sentinel

主要开发者

主要贡献者

还可以查看参与此项目的贡献者名单。

赞助

B-Open 承诺长期维护项目,我们很高兴接受赞助以开发新功能。

我们希望对项目赞助商表示感谢

  • Microsoft 已赞助对GRD产品和支持fsspec数据访问的支持。

许可证

Copyright 2021-2022, B-Open Solutions srl and the xarray-sentinel authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    https://apache.ac.cn/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

项目详情


下载文件

下载适合您平台的文件。如果您不确定选择哪个,请了解有关安装包的更多信息。

源分布

xarray-sentinel-0.9.5.tar.gz (4.9 MB 查看哈希值)

上传时间: 源代码

构建版本

xarray_sentinel-0.9.5-py3-none-any.whl (64.2 kB 查看哈希值)

上传时间: Python 3

支持