geocat-comp
geocat-comp copied to clipboard
Interpolation point out of data bounds encountered
Internal package interpolation.py
currently throws a UserWarning for interpolation test test_interp_hybrid_to_pressure_extrap_geopotential
interpolation.py:133: UserWarning: Interpolation point out of data bounds encountered
return func_interpolate(new_levels, xcoords, data, axis=interp_axis)
The interpolation warning is generated by the test test_interp_hybrid_to_pressure_extrap_geopotential
that is populated from press_in
which is populated with the values
[[[68619.195 68619.195]
[69344.43 69290.68 ]
[70799.516 70643.86 ]]]
To be interpolated along the values
[ 50000 92500 95000 100000]
The test calls interp_hybrid_to_pressure
as linear
, so it ends up calling metpy interpolate_1d
. Specifically, the error being thrown is because the interpolate values and the coordinates shapes are equal without a fill_value
Metpy will raise a warning that:
Warn if interpolated values are outside data bounds, will make these the values at end of data range.
Since the input values max value 70272.49076537043
is less than max interpolate value 100000
it can't interpolate to the bounds outside the range (without setting a fill_value). So, by default, It adds the values to the end of the range
An easy way to see this is interpolating to 4.5 when the range is to 4:
import metpy.interpolate
import numpy as np
x = np.array([1., 2., 3., 4.])
y = np.array([1., 2., 3., 4.])
x_interp = np.array([2.5, 3.5])
metpy.interpolate.interpolate_1d(x_interp, x, y)
Where the array position of the max value is out of bounds, so the array appends nan
metpy.interpolate.interpolate_1d(x_interp, x, y)
<stdin>:1: UserWarning: Interpolation point out of data bounds encountered
array([2.5, nan])
When the values are within range, it returns the interpolated values without a nan
import metpy.interpolate
import numpy as np
x = np.array([1., 2., 3., 4.])
y = np.array([1., 2., 3., 4.])
x_interp = np.array([2.5, 3.5])
metpy.interpolate.interpolate_1d(x_interp, x, y)
array([2.5, 3.5])