Skip to content

Commit

Permalink
Complete coverage of crop_burst_dataset and improve exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
alexamici committed Jan 18, 2022
1 parent 810c294 commit cf5f616
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
27 changes: 23 additions & 4 deletions tests/test_20_sentinel1.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,9 +230,28 @@ def test_open_dataset_chunks() -> None:


def test_crop_burst_dataset() -> None:
swath_polarisation_ds = sentinel1.open_sentinel1_dataset(SLC_IW, group="IW1/VH")
swath_ds = sentinel1.open_sentinel1_dataset(SLC_IW, group="IW1/VH")

res = sentinel1.crop_burst_dataset(swath_polarisation_ds, 8)
res1 = sentinel1.crop_burst_dataset(swath_ds, 8)

assert set(res.dims) == {"azimuth_time", "slant_range_time"}
assert res.dims["azimuth_time"] == swath_polarisation_ds.attrs["lines_per_burst"]
assert set(res1.dims) == {"azimuth_time", "slant_range_time"}
assert res1.dims["azimuth_time"] == swath_ds.attrs["lines_per_burst"]

res2 = sentinel1.crop_burst_dataset(swath_ds, azimuth_anx_time=2210)

assert res2.equals(res1)

res3 = sentinel1.crop_burst_dataset(
swath_ds, azimuth_anx_time=2213, use_center=True
)

assert res3.equals(res1)

with pytest.raises(TypeError):
sentinel1.crop_burst_dataset(swath_ds)

with pytest.raises(TypeError):
sentinel1.crop_burst_dataset(swath_ds, burst_index=8, azimuth_anx_time=2213)

with pytest.raises(IndexError):
sentinel1.crop_burst_dataset(swath_ds, burst_index=-1)
4 changes: 2 additions & 2 deletions xarray_sentinel/sentinel1.py
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ def crop_burst_dataset(
use_center: bool = False,
) -> xr.Dataset:
if (burst_index is not None) and (azimuth_anx_time is not None):
raise ValueError(
raise TypeError(
"only one keyword between 'burst_index' and 'azimuth_anx_time' must be defined"
)

Expand All @@ -415,7 +415,7 @@ def crop_burst_dataset(
pol_dataset, azimuth_anx_time, use_center=use_center
)
else:
raise ValueError(
raise TypeError(
"one keyword between 'burst_index' and 'azimuth_anx_time' must be defined"
)

Expand Down

0 comments on commit cf5f616

Please sign in to comment.