From b541f6d523e48ade3897371ce2213060d19ab2d1 Mon Sep 17 00:00:00 2001 From: Alessandro Amici Date: Tue, 1 Nov 2022 08:17:56 +0100 Subject: [PATCH] Raise if value not present --- tests/test_20_sentinel1.py | 3 +++ xarray_sentinel/sentinel1.py | 19 ++++++++++--------- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/tests/test_20_sentinel1.py b/tests/test_20_sentinel1.py index d011736..e92e8b1 100644 --- a/tests/test_20_sentinel1.py +++ b/tests/test_20_sentinel1.py @@ -121,6 +121,9 @@ def test_open_coordinate_conversion_dataset() -> None: assert isinstance(res, xr.Dataset) assert set(res.coords) == {"azimuth_time", "degree"} + with pytest.raises(TypeError): + sentinel1.open_coordinate_conversion_dataset(SLC_IW1_VV_annotation) + def test_open_gcp_dataset() -> None: expected_geospatial_bounds = ( diff --git a/xarray_sentinel/sentinel1.py b/xarray_sentinel/sentinel1.py index 1ea6946..8d2c169 100644 --- a/xarray_sentinel/sentinel1.py +++ b/xarray_sentinel/sentinel1.py @@ -182,6 +182,8 @@ def open_coordinate_conversion_dataset( coordinate_conversion = esa_safe.parse_tag_as_list( annotation_path, ".//coordinateConversionList/coordinateConversion" ) + if len(coordinate_conversion) == 0: + raise TypeError("coordinateConversion tag not present in annotations") gr0 = [] sr0 = [] @@ -203,15 +205,14 @@ def open_coordinate_conversion_dataset( coords: Dict[str, Any] = {} data_vars: Dict[str, Any] = {} - if srgrCoefficients: - coords["azimuth_time"] = [np.datetime64(dt) for dt in azimuth_time] - coords["degree"] = list(range(len(srgrCoefficients[0]))) - - data_vars["gr0"] = ("azimuth_time", gr0) - data_vars["sr0"] = ("azimuth_time", sr0) - data_vars["slant_range_time"] = ("azimuth_time", slant_range_time) - data_vars["srgrCoefficients"] = (("azimuth_time", "degree"), srgrCoefficients) - data_vars["grsrCoefficients"] = (("azimuth_time", "degree"), grsrCoefficients) + coords["azimuth_time"] = [np.datetime64(dt) for dt in azimuth_time] + coords["degree"] = list(range(len(srgrCoefficients[0]))) + + data_vars["gr0"] = ("azimuth_time", gr0) + data_vars["sr0"] = ("azimuth_time", sr0) + data_vars["slant_range_time"] = ("azimuth_time", slant_range_time) + data_vars["srgrCoefficients"] = (("azimuth_time", "degree"), srgrCoefficients) + data_vars["grsrCoefficients"] = (("azimuth_time", "degree"), grsrCoefficients) return xr.Dataset(data_vars=data_vars, coords=coords, attrs=attrs)