Skip to content

Commit

Permalink
Merge pull request #15 from ecmwf/develop
Browse files Browse the repository at this point in the history
Raise useful error when scipy is not installed
  • Loading branch information
JamesVarndell authored Sep 24, 2024
2 parents d88da6f + 9b33c73 commit 5a684b7
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 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,10 @@ 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 5a684b7

Please sign in to comment.