Skip to content

Commit

Permalink
Raise if value not present
Browse files Browse the repository at this point in the history
  • Loading branch information
alexamici committed Nov 1, 2022
1 parent 3772aea commit b541f6d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
3 changes: 3 additions & 0 deletions tests/test_20_sentinel1.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = (
Expand Down
19 changes: 10 additions & 9 deletions xarray_sentinel/sentinel1.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
Expand All @@ -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)

Expand Down

0 comments on commit b541f6d

Please sign in to comment.