helper function to select the appropriate interpolator class returns interpolator class and keyword arguments for the class
(
method: InterpOptions, vectorizeable_only: bool = False, **kwargs
)
| 484 | |
| 485 | |
| 486 | def _get_interpolator( |
| 487 | method: InterpOptions, vectorizeable_only: bool = False, **kwargs |
| 488 | ): |
| 489 | """helper function to select the appropriate interpolator class |
| 490 | |
| 491 | returns interpolator class and keyword arguments for the class |
| 492 | """ |
| 493 | interp_class: Interpolator |
| 494 | interp1d_methods = get_args(Interp1dOptions) |
| 495 | valid_methods = tuple(vv for v in get_args(InterpOptions) for vv in get_args(v)) |
| 496 | |
| 497 | # prefer numpy.interp for 1d linear interpolation. This function cannot |
| 498 | # take higher dimensional data but scipy.interp1d can. |
| 499 | if ( |
| 500 | method == "linear" |
| 501 | and kwargs.get("fill_value") != "extrapolate" |
| 502 | and not vectorizeable_only |
| 503 | ): |
| 504 | kwargs.update(method=method) |
| 505 | interp_class = NumpyInterpolator |
| 506 | |
| 507 | elif method in valid_methods: |
| 508 | if method in interp1d_methods: |
| 509 | kwargs.update(method=method) |
| 510 | interp_class = ScipyInterpolator |
| 511 | elif method == "barycentric": |
| 512 | kwargs.update(axis=-1) |
| 513 | interp_class = _import_interpolant("BarycentricInterpolator", method) |
| 514 | elif method in ["krogh", "krog"]: |
| 515 | kwargs.update(axis=-1) |
| 516 | interp_class = _import_interpolant("KroghInterpolator", method) |
| 517 | elif method == "pchip": |
| 518 | kwargs.update(axis=-1) |
| 519 | # pchip default behavior is to extrapolate |
| 520 | kwargs.setdefault("extrapolate", False) |
| 521 | interp_class = _import_interpolant("PchipInterpolator", method) |
| 522 | elif method == "spline": |
| 523 | utils.emit_user_level_warning( |
| 524 | "The 1d SplineInterpolator class is performing an incorrect calculation and " |
| 525 | "is being deprecated. Please use `method=polynomial` for 1D Spline Interpolation.", |
| 526 | PendingDeprecationWarning, |
| 527 | ) |
| 528 | if vectorizeable_only: |
| 529 | raise ValueError(f"{method} is not a vectorizeable interpolator. ") |
| 530 | kwargs.update(method=method) |
| 531 | interp_class = SplineInterpolator |
| 532 | elif method == "akima": |
| 533 | kwargs.update(axis=-1) |
| 534 | interp_class = _import_interpolant("Akima1DInterpolator", method) |
| 535 | elif method == "makima": |
| 536 | kwargs.update(method="makima", axis=-1) |
| 537 | interp_class = _import_interpolant("Akima1DInterpolator", method) |
| 538 | else: |
| 539 | raise ValueError(f"{method} is not a valid scipy interpolator") |
| 540 | else: |
| 541 | raise ValueError(f"{method} is not a valid interpolator") |
| 542 | |
| 543 | return interp_class, kwargs |
no test coverage detected
searching dependent graphs…