Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

interp1d does not accept scalar variable as input #3360

Open
nvaytet opened this issue Jan 16, 2024 · 0 comments
Open

interp1d does not accept scalar variable as input #3360

nvaytet opened this issue Jan 16, 2024 · 0 comments

Comments

@nvaytet
Copy link
Member

nvaytet commented Jan 16, 2024

Example:

x = sc.linspace(dim='x', start=0.1, stop=1.4, num=4, unit='rad')
da = sc.DataArray(sc.sin(x), coords={'x': x})
from scipp.scipy.interpolate import interp1d
f = interp1d(da, 'x')

xnew = sc.scalar(0.333, unit='rad')
f(xnew) 

raises

File ~/code/scipp/install/scipp/scipy/interpolate/__init__.py:188, in interp1d.<locals>.func(xnew, midpoints)
    182 if xnew.unit != da.coords[dim].unit:
    183     raise UnitError(
    184         f"Unit of interpolation points '{xnew.unit}' does not match unit "
    185         f"'{da.coords[dim].unit}' of points defining the interpolation "
    186         "function along dimension '{dim}'."
    187     )
--> 188 if xnew.dim != dim:
    189     raise DimensionError(
    190         f"Dimension of interpolation points '{xnew.dim}' does not match "
    191         f"interpolation dimension '{dim}'"
    192     )
    193 f = inter.interp1d(
    194     x=_as_interpolation_type(da.coords[dim].values),
    195     y=da.values,
   (...)
    198     **kwargs,
    199 )

DimensionError: Expected 1 dimensions, got 0

It would be nice if we could also send a single value and get a scalar back.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant