Skip to content

Commit

Permalink
Add geospatial attrs by default
Browse files Browse the repository at this point in the history
  • Loading branch information
alexamici committed Jul 9, 2022
1 parent 2bf4b00 commit 0fb1ed3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
3 changes: 2 additions & 1 deletion tests/test_20_sentinel1.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,9 +226,10 @@ def test_open_pol_dataset_iw() -> None:
"10.876144717121 45.73265733767158,12.04397933341514 45.57910451206848,"
"12.42647347821595 47.09200435560957,11.26870151724317 47.24053130234206))"
)
gcp_ds = sentinel1.open_gcp_dataset(SLC_IW1_VV_annotation)

res = sentinel1.open_pol_dataset(
SLC_IW1_VV_measurement, SLC_IW1_VV_annotation, geospatial_attrs=True
SLC_IW1_VV_measurement, SLC_IW1_VV_annotation, gcp=gcp_ds
)

assert res.attrs["geospatial_bounds"] == expected_geospatial_bounds
Expand Down
15 changes: 9 additions & 6 deletions xarray_sentinel/sentinel1.py
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,7 @@ def open_pol_dataset(
annotation: esa_safe.PathOrFileType,
fs: Optional[fsspec.AbstractFileSystem] = None,
attrs: Dict[str, Any] = {},
geospatial_attrs: bool = False,
gcp: Optional[xr.Dataset] = None,
) -> xr.Dataset:

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

if geospatial_attrs:
gcp = open_gcp_dataset(annotation)
if gcp:
attrs.update(gcp.attrs) # type: ignore

arr.attrs.update(attrs)
Expand Down Expand Up @@ -920,7 +919,7 @@ def open_sentinel1_dataset(
storage_options: Optional[Dict[str, Any]] = None,
check_files_exist: bool = False,
override_product_files: Optional[str] = None,
geospatial_attrs: bool = False,
parse_geospatial_attrs: bool = True,
) -> xr.Dataset:
if drop_variables is not None:
warnings.warn("'drop_variables' is currently ignored")
Expand Down Expand Up @@ -949,6 +948,7 @@ def open_sentinel1_dataset(
metadata = ""

ds = xr.Dataset(attrs=common_attrs)
gcp = None
if group == "":
subgroups = list(groups)
else:
Expand All @@ -958,12 +958,15 @@ def open_sentinel1_dataset(

if group.count("/") == 1:
with fs.open(groups[group][1]) as annotation:
if parse_geospatial_attrs:
gcp = open_gcp_dataset(annotation, attrs=common_attrs)

ds = open_pol_dataset(
groups[group][0],
annotation,
fs=fs,
attrs=common_attrs,
geospatial_attrs=geospatial_attrs,
gcp=gcp,
)
elif group.count("/") == 2:
_, _, metadata = group.split("/", 2)
Expand All @@ -975,7 +978,7 @@ def open_sentinel1_dataset(
ds.attrs["subgroups"] = subgroups

if group.count("/") == 1 and burst_index is not None:
ds = crop_burst_dataset(ds, burst_index=burst_index)
ds = crop_burst_dataset(ds, burst_index=burst_index, gcp=gcp)

conventions.update_attributes(ds, group=metadata)

Expand Down

0 comments on commit 0fb1ed3

Please sign in to comment.