Skip to content

Commit

Permalink
Raise useful error when scipy is not installed but a user tries to ap…
Browse files Browse the repository at this point in the history
…ply interpolation
  • Loading branch information
JamesVarndell committed Sep 24, 2024
1 parent 0ec5a35 commit 221c6d4
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/earthkit/plots/geo/grids.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,12 @@
# limitations under the License.

import numpy as np
from scipy.interpolate import griddata

_NO_SCIPY = False
try:
from scipy.interpolate import griddata
except ImportError:
_NO_SCIPY = True


def is_structured(lat, lon, tol=1e-5):
Expand Down Expand Up @@ -70,6 +75,8 @@ def interpolate_unstructured(x, y, z, resolution=1000, method="linear"):
- grid_y: 2D grid of y-coordinates.
- grid_z: 2D grid of interpolated z-values, with NaNs in large gap regions.
"""
if _NO_SCIPY:
raise ImportError("The 'scipy' package is required for interpolating unstructured data.")
# Filter out NaN values from z and corresponding x, y
mask = ~np.isnan(z)
x_filtered = x[mask]
Expand Down

0 comments on commit 221c6d4

Please sign in to comment.