1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227
|
import pathlib
import pytest
import xarray as xr
from xarray_sentinel import esa_safe
DATA_FOLDER = pathlib.Path(__file__).parent / "data"
COMMON_ATTRIBUTES = {
"family_name": "SENTINEL-1",
"number": "B",
"mode": "IW",
"swaths": ["IW1", "IW2", "IW3"],
"orbit_number": 26269,
"relative_orbit_number": 168,
"pass": "DESCENDING",
"ascending_node_time": "2021-04-01T04:49:55.637823",
"transmitter_receiver_polarisations": ["VV", "VH"],
"product_type": "SLC",
}
SENTINEL1_SLC_PRODUCTS = [
(
DATA_FOLDER
/ "S1B_IW_SLC__1SDV_20210401T052622_20210401T052650_026269_032297_EFA4.SAFE",
"IW1/VV",
),
(
DATA_FOLDER
/ "S1A_EW_SLC__1SDH_20210403T122536_20210403T122630_037286_046484_8152.SAFE",
"EW1/HH",
),
(
DATA_FOLDER
/ "S1A_S3_SLC__1SDV_20210401T152855_20210401T152914_037258_04638E_6001.SAFE",
"S3/VH",
),
]
SENTINEL1_GRD_PRODUCTS = [
(
DATA_FOLDER
/ "S1B_IW_GRDH_1SDV_20210401T052623_20210401T052648_026269_032297_ECC8.SAFE",
"IW/VV",
),
]
SENTINEL1_PRODUCTS = SENTINEL1_SLC_PRODUCTS + SENTINEL1_GRD_PRODUCTS
def test_open_dataset_root() -> None:
product_path = (
DATA_FOLDER
/ "S1B_IW_SLC__1SDV_20210401T052622_20210401T052650_026269_032297_EFA4.SAFE"
)
res = xr.open_dataset(product_path, engine="sentinel-1")
assert isinstance(res, xr.Dataset)
for attr_name in COMMON_ATTRIBUTES:
assert attr_name in res.attrs
assert res.attrs[attr_name] == COMMON_ATTRIBUTES[attr_name]
res = xr.open_dataset(product_path)
assert isinstance(res, xr.Dataset)
product_path = product_path / "manifest.safe"
res = xr.open_dataset(product_path, engine="sentinel-1")
assert isinstance(res, xr.Dataset)
res = xr.open_dataset(product_path)
assert isinstance(res, xr.Dataset)
with pytest.raises(ValueError):
xr.open_dataset("")
@pytest.mark.parametrize("product_path,swath_pol", SENTINEL1_SLC_PRODUCTS)
def test_open_dataset_polarisation_slc(
product_path: esa_safe.PathType,
swath_pol: str,
) -> None:
res = xr.open_dataset(product_path, engine="sentinel-1", group=swath_pol)
assert isinstance(res, xr.Dataset)
assert set(res.dims) == {"line", "pixel"} or set(res.dims) == {
"azimuth_time",
"slant_range_time",
}
assert set(res.coords) == {"azimuth_time", "slant_range_time", "line", "pixel"}
@pytest.mark.parametrize("product_path,swath_pol", SENTINEL1_GRD_PRODUCTS)
def test_open_dataset_polarisation_grd(
product_path: esa_safe.PathType,
swath_pol: str,
) -> None:
res = xr.open_dataset(product_path, engine="sentinel-1", group=swath_pol)
assert isinstance(res, xr.Dataset)
assert set(res.dims) == {"line", "pixel"} or set(res.dims) == {
"azimuth_time",
"ground_range",
}
assert set(res.coords) == {"azimuth_time", "ground_range", "line", "pixel"}
@pytest.mark.parametrize("product_path,swath_pol", SENTINEL1_PRODUCTS)
def test_open_dataset_orbit(
product_path: esa_safe.PathType,
swath_pol: str,
) -> None:
res = xr.open_dataset(product_path, engine="sentinel-1", group=f"{swath_pol}/orbit")
assert isinstance(res, xr.Dataset)
assert set(res.dims) == {"axis", "azimuth_time"}
assert set(res.variables) == {"azimuth_time", "axis", "velocity", "position"}
@pytest.mark.parametrize("product_path,swath_pol", SENTINEL1_PRODUCTS)
def test_open_dataset_attitude(
product_path: esa_safe.PathType,
swath_pol: str,
) -> None:
res = xr.open_dataset(
product_path, engine="sentinel-1", group=f"{swath_pol}/attitude"
)
assert isinstance(res, xr.Dataset)
assert set(res.dims) == {"azimuth_time"}
expected = {
"azimuth_time",
"roll",
"pitch",
"yaw",
"q0",
"q1",
"q2",
"q3",
"wx",
"wy",
"wz",
}
assert set(res.variables) == expected
@pytest.mark.parametrize("product_path,swath_pol", SENTINEL1_PRODUCTS)
def test_open_dataset_gcp(
product_path: esa_safe.PathType,
swath_pol: str,
) -> None:
res = xr.open_dataset(product_path, engine="sentinel-1", group=f"{swath_pol}/gcp")
assert isinstance(res, xr.Dataset)
assert set(res.dims) == {"azimuth_time", "slant_range_time"}
@pytest.mark.parametrize("product_path,swath_pol", SENTINEL1_PRODUCTS)
def test_open_dataset_dc_estimate(
product_path: esa_safe.PathType,
swath_pol: str,
) -> None:
res = xr.open_dataset(
product_path, engine="sentinel-1", group=f"{swath_pol}/dc_estimate"
)
assert isinstance(res, xr.Dataset)
assert set(res.dims) == {"azimuth_time", "degree"}
def test_open_pol_dataset() -> None:
product_path = (
DATA_FOLDER
/ "S1B_IW_SLC__1SDV_20210401T052622_20210401T052650_026269_032297_EFA4.SAFE"
)
expected_variables = {
"measurement",
"line",
"pixel",
"slant_range_time",
"azimuth_time",
}
res = xr.open_dataset(product_path, engine="sentinel-1", group="IW1/VV")
assert isinstance(res, xr.Dataset)
for attr_name in COMMON_ATTRIBUTES:
assert attr_name in res.attrs
assert res.attrs[attr_name] == COMMON_ATTRIBUTES[attr_name]
assert set(res.dims) == {"line", "pixel"}
assert set(res.variables) == expected_variables
def test_burst_id_attribute() -> None:
product_path = (
DATA_FOLDER
/ "S1A_IW_SLC__1SDH_20220414T102209_20220414T102236_042768_051AA4_E677.SAFE"
)
res = xr.open_dataset(product_path, engine="sentinel-1", group="IW1/HH")
assert "burst_ids" in res.attrs
assert len(res.attrs["burst_ids"]) == res.attrs["number_of_bursts"]
product_path = (
DATA_FOLDER
/ "S1B_IW_SLC__1SDV_20210401T052622_20210401T052650_026269_032297_EFA4.SAFE"
)
res = xr.open_dataset(product_path, engine="sentinel-1", group="IW1/VV")
assert "burst_ids" not in res.attrs
def test_open_calibration_dataset() -> None:
annotation_path = (
DATA_FOLDER
/ "S1B_IW_SLC__1SDV_20210401T052622_20210401T052650_026269_032297_EFA4.SAFE"
)
res = xr.open_dataset(
annotation_path, engine="sentinel-1", group="IW1/VV/calibration"
)
assert isinstance(res, xr.Dataset)
assert set(res.dims) == {"line", "pixel"}
|