Skip to content

Commit

Permalink
Make xml parsing more robust
Browse files Browse the repository at this point in the history
  • Loading branch information
mraspaud committed Mar 8, 2024
1 parent c45cbb0 commit ae140b3
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions satpy/readers/sar_c_safe.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
from collections import defaultdict
from datetime import timezone as tz
from functools import cached_property
from pathlib import Path
from threading import Lock

import defusedxml.ElementTree as ET
Expand Down Expand Up @@ -107,7 +108,10 @@ def __init__(self, filename, filename_info, filetype_info,
self._start_time = filename_info["start_time"].replace(tzinfo=tz.utc)
self._end_time = filename_info["end_time"].replace(tzinfo=tz.utc)
self._polarization = filename_info["polarization"]
self.root = ET.parse(open_file_or_filename(self.filename))
if isinstance(self.filename, str):
self.filename = Path(self.filename)
with self.filename.open() as fd:
self.root = ET.parse(fd)
self._image_shape = image_shape

def get_metadata(self):
Expand Down Expand Up @@ -579,7 +583,7 @@ def get_dataset(self, key, info):

@cached_property
def _data(self):
data = xr.open_dataarray(self.filename, engine="rasterio",
data = xr.open_dataarray(open_file_or_filename(self.filename), engine="rasterio",
chunks="auto"
).squeeze()
self.chunks = data.data.chunksize
Expand Down Expand Up @@ -629,7 +633,7 @@ def _get_lonlatalts_uncached(self):

fine_points = [np.arange(size) for size in shape]
x, y, z = lonlat2xyz(gcp_lons, gcp_lats)
interpolator = MultipleGridInterpolator((xpoints, ypoints), x, y, z, gcp_alts)
interpolator = MultipleGridInterpolator((ypoints, xpoints), x, y, z, gcp_alts)
hx, hy, hz, altitudes = interpolator.interpolate(fine_points, method="cubic", chunks=self.chunks)
longitudes, latitudes = xyz2lonlat(hx, hy, hz)

Expand Down

0 comments on commit ae140b3

Please sign in to comment.