Skip to content

Commit 0fb1ed3

Browse files
committed
Add geospatial attrs by default
1 parent 2bf4b00 commit 0fb1ed3

2 files changed

Lines changed: 11 additions & 7 deletions

File tree

tests/test_20_sentinel1.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,9 +226,10 @@ def test_open_pol_dataset_iw() -> None:
226226
"10.876144717121 45.73265733767158,12.04397933341514 45.57910451206848,"
227227
"12.42647347821595 47.09200435560957,11.26870151724317 47.24053130234206))"
228228
)
229+
gcp_ds = sentinel1.open_gcp_dataset(SLC_IW1_VV_annotation)
229230

230231
res = sentinel1.open_pol_dataset(
231-
SLC_IW1_VV_measurement, SLC_IW1_VV_annotation, geospatial_attrs=True
232+
SLC_IW1_VV_measurement, SLC_IW1_VV_annotation, gcp=gcp_ds
232233
)
233234

234235
assert res.attrs["geospatial_bounds"] == expected_geospatial_bounds

xarray_sentinel/sentinel1.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -532,7 +532,7 @@ def open_pol_dataset(
532532
annotation: esa_safe.PathOrFileType,
533533
fs: Optional[fsspec.AbstractFileSystem] = None,
534534
attrs: Dict[str, Any] = {},
535-
geospatial_attrs: bool = False,
535+
gcp: Optional[xr.Dataset] = None,
536536
) -> xr.Dataset:
537537

538538
product_information = esa_safe.parse_tag(annotation, ".//productInformation")
@@ -651,8 +651,7 @@ def open_pol_dataset(
651651
arr = arr.assign_coords(coords) # type: ignore
652652
arr = arr.swap_dims(swap_dims)
653653

654-
if geospatial_attrs:
655-
gcp = open_gcp_dataset(annotation)
654+
if gcp:
656655
attrs.update(gcp.attrs) # type: ignore
657656

658657
arr.attrs.update(attrs)
@@ -920,7 +919,7 @@ def open_sentinel1_dataset(
920919
storage_options: Optional[Dict[str, Any]] = None,
921920
check_files_exist: bool = False,
922921
override_product_files: Optional[str] = None,
923-
geospatial_attrs: bool = False,
922+
parse_geospatial_attrs: bool = True,
924923
) -> xr.Dataset:
925924
if drop_variables is not None:
926925
warnings.warn("'drop_variables' is currently ignored")
@@ -949,6 +948,7 @@ def open_sentinel1_dataset(
949948
metadata = ""
950949

951950
ds = xr.Dataset(attrs=common_attrs)
951+
gcp = None
952952
if group == "":
953953
subgroups = list(groups)
954954
else:
@@ -958,12 +958,15 @@ def open_sentinel1_dataset(
958958

959959
if group.count("/") == 1:
960960
with fs.open(groups[group][1]) as annotation:
961+
if parse_geospatial_attrs:
962+
gcp = open_gcp_dataset(annotation, attrs=common_attrs)
963+
961964
ds = open_pol_dataset(
962965
groups[group][0],
963966
annotation,
964967
fs=fs,
965968
attrs=common_attrs,
966-
geospatial_attrs=geospatial_attrs,
969+
gcp=gcp,
967970
)
968971
elif group.count("/") == 2:
969972
_, _, metadata = group.split("/", 2)
@@ -975,7 +978,7 @@ def open_sentinel1_dataset(
975978
ds.attrs["subgroups"] = subgroups
976979

977980
if group.count("/") == 1 and burst_index is not None:
978-
ds = crop_burst_dataset(ds, burst_index=burst_index)
981+
ds = crop_burst_dataset(ds, burst_index=burst_index, gcp=gcp)
979982

980983
conventions.update_attributes(ds, group=metadata)
981984

0 commit comments

Comments
 (0)