Skip to content

Commit

Permalink
extract max_dist keyword from kwargs in read_lon_lat and pass on to p…
Browse files Browse the repository at this point in the history
…ygeogrids nearest neighbor search
  • Loading branch information
sebhahn committed Mar 7, 2023
1 parent 9521b8c commit 7b1361b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ Unreleased changes in master

-

Version 0.6.2
=============

- Extract max_dist keyword from kwargs in read_lon_lat and pass on to pygeogrids nearest neighbor search

Version 0.6.1
=============

Expand Down
19 changes: 8 additions & 11 deletions src/pygeobase/io_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -387,8 +387,7 @@ def _open(self, gp):
except IOError as e:
success = False
self.fid = None
msg = "I/O error({0}): {1}, {2}".format(
e.errno, e.strerror, filename)
msg = f"I/O error({e.errno}): {e.strerror}, {filename}"
warnings.warn(msg, RuntimeWarning)
self.previous_cell = None
else:
Expand All @@ -405,8 +404,7 @@ def _open(self, gp):
except IOError as e:
success = False
self.fid = None
msg = "I/O error({0}): {1}, {2}".format(
e.errno, e.strerror, filename)
msg = f"I/O error({e.errno}): {e.strerror}, {filename}"
warnings.warn(msg, RuntimeWarning)
self.previous_cell = None
else:
Expand All @@ -430,7 +428,8 @@ def _read_lonlat(self, lon, lat, **kwargs):
data : dict of values
data record.
"""
gp, _ = self.grid.find_nearest_gpi(lon, lat)
max_dist = kwargs.pop("max_dist", np.Inf)
gp, _ = self.grid.find_nearest_gpi(lon, lat, max_dist)

return self._read_gp(gp, **kwargs)

Expand Down Expand Up @@ -556,8 +555,7 @@ def iter_gp(self, **kwargs):
try:
data = self._read_gp(gp, **kwargs)
except IOError as e:
msg = "I/O error({0}): {1}, {2}".format(
e.errno, e.strerror, str(gp))
msg = f"I/O error({e.errno}): {e.strerror}, {gp}"
warnings.warn(msg, RuntimeWarning)
data = None

Expand Down Expand Up @@ -801,8 +799,7 @@ def _open(self, filepath):
except IOError as e:
self.fid = None
success = False
warnings.warn("I/O error({0}): {1}".format(e.errno, e.strerror),
RuntimeWarning)
warnings.warn(f"I/O error({e.errno}): {e.strerror}", RuntimeWarning)

return success

Expand Down Expand Up @@ -901,9 +898,9 @@ def _build_filename(self, timestamp, custom_templ=None, str_param=None):
custom_templ=custom_templ,
str_param=str_param)
if len(filename) == 0:
raise IOError("No file found for {:}".format(timestamp.ctime()))
raise IOError(f"No file found for {timestamp.ctime()}")
if len(filename) > 1:
raise IOError("File search is ambiguous {:}".format(filename))
raise IOError(f"File search is ambiguous {filename}")

return filename[0]

Expand Down

0 comments on commit 7b1361b

Please sign in to comment.