pub struct Interp2d<F> { /* private fields */ }Expand description
2D interpolator for data on regular grids
This struct provides functionality similar to SciPy’s interp2d for interpolating 2D data defined on regular grids.
Implementations§
Source§impl<F> Interp2d<F>
impl<F> Interp2d<F>
Sourcepub fn new(
x: &ArrayView1<'_, F>,
y: &ArrayView1<'_, F>,
z: &ArrayView2<'_, F>,
kind: Interp2dKind,
) -> InterpolateResult<Self>
pub fn new( x: &ArrayView1<'_, F>, y: &ArrayView1<'_, F>, z: &ArrayView2<'_, F>, kind: Interp2dKind, ) -> InterpolateResult<Self>
Create a new 2D interpolator
§Arguments
x- X coordinates (must be sorted), length n_xy- Y coordinates (must be sorted), length n_yz- Z values with shape (n_y, n_x)kind- Interpolation method
§Returns
New 2D interpolator
§Errors
ShapeMismatch- If z.shape() != (y.len(), x.len())InvalidInput- If x or y are not sorted
§Examples
use scirs2_core::ndarray::{array, Array2};
use scirs2_interpolate::interp2d::{Interp2d, Interp2dKind};
// Define grid
let x = array![0.0, 1.0, 2.0];
let y = array![0.0, 1.0];
// Define function z = x + y on the grid
let z = Array2::from_shape_fn((2, 3), |(i, j)| {
y[i] + x[j]
});
let interp = Interp2d::new(&x.view(), &y.view(), &z.view(),
Interp2dKind::Linear)?;
// Interpolate at a point
let result = interp.evaluate(0.5, 0.5)?;Sourcepub fn evaluate(&self, x_new: F, ynew: F) -> InterpolateResult<F>
pub fn evaluate(&self, x_new: F, ynew: F) -> InterpolateResult<F>
Evaluate the interpolator at a single point
§Arguments
x_new- X coordinate for evaluationynew- Y coordinate for evaluation
§Returns
Interpolated value at (x_new, ynew)
§Examples
use scirs2_core::ndarray::{array, Array2};
use scirs2_interpolate::interp2d::{Interp2d, Interp2dKind};
let x = array![0.0, 1.0, 2.0];
let y = array![0.0, 1.0];
let z = Array2::from_shape_fn((2, 3), |(i, j)| {
y[i] + x[j] // z = x + y
});
let interp = Interp2d::new(&x.view(), &y.view(), &z.view(),
Interp2dKind::Linear)?;
let result = interp.evaluate(0.5, 0.5)?;
// Should be approximately 1.0 (0.5 + 0.5)Sourcepub fn evaluate_array(
&self,
x_new: &ArrayView1<'_, F>,
ynew: &ArrayView1<'_, F>,
) -> InterpolateResult<Array1<F>>
pub fn evaluate_array( &self, x_new: &ArrayView1<'_, F>, ynew: &ArrayView1<'_, F>, ) -> InterpolateResult<Array1<F>>
Sourcepub fn evaluate_grid(
&self,
x_new: &ArrayView1<'_, F>,
ynew: &ArrayView1<'_, F>,
) -> InterpolateResult<Array2<F>>
pub fn evaluate_grid( &self, x_new: &ArrayView1<'_, F>, ynew: &ArrayView1<'_, F>, ) -> InterpolateResult<Array2<F>>
Trait Implementations§
Auto Trait Implementations§
impl<F> Freeze for Interp2d<F>
impl<F> RefUnwindSafe for Interp2d<F>where
F: RefUnwindSafe,
impl<F> Send for Interp2d<F>where
F: Send,
impl<F> Sync for Interp2d<F>where
F: Sync,
impl<F> Unpin for Interp2d<F>
impl<F> UnsafeUnpin for Interp2d<F>
impl<F> UnwindSafe for Interp2d<F>where
F: RefUnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
The inverse inclusion map: attempts to construct
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
Checks if
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
Use with care! Same as
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
The inclusion map: converts
self to the equivalent element of its superset.