Skip to content

Commit cf5f616

Browse files
committed
Complete coverage of crop_burst_dataset and improve exceptions
1 parent 810c294 commit cf5f616

2 files changed

Lines changed: 25 additions & 6 deletions

File tree

tests/test_20_sentinel1.py

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -230,9 +230,28 @@ def test_open_dataset_chunks() -> None:
230230

231231

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

235-
res = sentinel1.crop_burst_dataset(swath_polarisation_ds, 8)
235+
res1 = sentinel1.crop_burst_dataset(swath_ds, 8)
236236

237-
assert set(res.dims) == {"azimuth_time", "slant_range_time"}
238-
assert res.dims["azimuth_time"] == swath_polarisation_ds.attrs["lines_per_burst"]
237+
assert set(res1.dims) == {"azimuth_time", "slant_range_time"}
238+
assert res1.dims["azimuth_time"] == swath_ds.attrs["lines_per_burst"]
239+
240+
res2 = sentinel1.crop_burst_dataset(swath_ds, azimuth_anx_time=2210)
241+
242+
assert res2.equals(res1)
243+
244+
res3 = sentinel1.crop_burst_dataset(
245+
swath_ds, azimuth_anx_time=2213, use_center=True
246+
)
247+
248+
assert res3.equals(res1)
249+
250+
with pytest.raises(TypeError):
251+
sentinel1.crop_burst_dataset(swath_ds)
252+
253+
with pytest.raises(TypeError):
254+
sentinel1.crop_burst_dataset(swath_ds, burst_index=8, azimuth_anx_time=2213)
255+
256+
with pytest.raises(IndexError):
257+
sentinel1.crop_burst_dataset(swath_ds, burst_index=-1)

xarray_sentinel/sentinel1.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@ def crop_burst_dataset(
405405
use_center: bool = False,
406406
) -> xr.Dataset:
407407
if (burst_index is not None) and (azimuth_anx_time is not None):
408-
raise ValueError(
408+
raise TypeError(
409409
"only one keyword between 'burst_index' and 'azimuth_anx_time' must be defined"
410410
)
411411

@@ -415,7 +415,7 @@ def crop_burst_dataset(
415415
pol_dataset, azimuth_anx_time, use_center=use_center
416416
)
417417
else:
418-
raise ValueError(
418+
raise TypeError(
419419
"one keyword between 'burst_index' and 'azimuth_anx_time' must be defined"
420420
)
421421

0 commit comments

Comments
 (0)