Skip to content

Commit

Permalink
Fix gcps type for newer rioxarray versions
Browse files Browse the repository at this point in the history
  • Loading branch information
mraspaud committed Jun 25, 2024
1 parent df4a1ba commit ad353f0
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions satpy/readers/sar_c_safe.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"""

import functools
import json
import logging
import warnings
from collections import defaultdict
Expand Down Expand Up @@ -664,7 +665,7 @@ def get_gcps(self):
gcp_coords (tuple): longitude and latitude 1d arrays
"""
gcps = self._data.coords["spatial_ref"].attrs["gcps"]
gcps = get_gcps_from_array(self._data)
crs = self._data.rio.crs

gcp_list = [(feature["properties"]["row"], feature["properties"]["col"], *feature["geometry"]["coordinates"])
Expand Down Expand Up @@ -726,7 +727,7 @@ def load(self, dataset_keys, **kwargs):
if key["name"] not in ["longitude", "latitude"]:
lonlats = self.load([DataID(self._id_keys, name="longitude", polarization=key["polarization"]),
DataID(self._id_keys, name="latitude", polarization=key["polarization"])])
gcps = val.coords["spatial_ref"].attrs["gcps"]
gcps = get_gcps_from_array(val)
from pyresample.future.geometry import SwathDefinition
val.attrs["area"] = SwathDefinition(lonlats["longitude"], lonlats["latitude"],
attrs=dict(gcps=gcps))
Expand Down Expand Up @@ -797,3 +798,11 @@ def _create_measurement_handlers(self, calibrators, denoisers):
filetype_info=None)

return measurement_handlers


def get_gcps_from_array(val):
"""Get the gcps from the spatial_ref coordinate as a geojson dict."""
gcps = val.coords["spatial_ref"].attrs["gcps"]
if isinstance(gcps, str):
gcps = json.loads(gcps)
return gcps

0 comments on commit ad353f0

Please sign in to comment.