Skip to main content

FromFile

Struct FromFile 

Source
pub struct FromFile<S: Scalar> { /* private fields */ }
Expand description

Signal loaded from a CSV file.

Reads time-value pairs from a file and interpolates. This is useful for loading earthquake records, experimental data, etc.

§File Format

The file should be in CSV format with two columns: time and value. Lines starting with ‘#’ are treated as comments.

# Time, Value
0.0, 0.0
0.1, 0.5
0.2, 1.0

§Example

use numra_core::signal::{Signal, FromFile};

// Load a CSV file with time,value columns
let signal: FromFile<f64> = FromFile::load("test_data/earthquake.csv").unwrap();
let accel = signal.eval(0.15);  // Interpolated value at t=0.15
assert!(accel > 0.0 && accel < 1.0);  // Interpolated between 0.5 and 1.0

Implementations§

Source§

impl<S: Scalar + FromStr> FromFile<S>

Source

pub fn load<P: AsRef<Path>>(path: P) -> Result<Self, String>

Load signal data from a CSV file.

§Arguments
  • path - Path to the CSV file
§Returns
  • Ok(FromFile) if the file was loaded successfully
  • Err(String) if there was an error reading or parsing the file
Source

pub fn load_with_interpolation<P: AsRef<Path>>( path: P, interp: Interpolation, ) -> Result<Self, String>

Load signal data with specified interpolation method.

Source

pub fn from_csv_string( content: &str, interp: Interpolation, ) -> Result<Self, String>

Load from raw CSV string content.

Source

pub fn len(&self) -> usize

Get the number of data points.

Source

pub fn is_empty(&self) -> bool

Check if the signal is empty.

Source

pub fn time_range(&self) -> (S, S)

Get the time range.

Source

pub fn path(&self) -> &str

Get the file path.

Source

pub fn as_tabulated(&self) -> &Tabulated<S>

Get the underlying tabulated data.

Trait Implementations§

Source§

impl<S: Clone + Scalar> Clone for FromFile<S>

Source§

fn clone(&self) -> FromFile<S>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<S: Debug + Scalar> Debug for FromFile<S>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<S: Scalar + FromStr> Signal<S> for FromFile<S>

Available on crate feature std only.
Source§

fn eval(&self, t: S) -> S

Evaluate the signal at time t.
Source§

fn eval_derivative(&self, t: S) -> S

Compute the derivative of the signal at time t. Read more

Auto Trait Implementations§

§

impl<S> Freeze for FromFile<S>

§

impl<S> RefUnwindSafe for FromFile<S>
where S: RefUnwindSafe,

§

impl<S> Send for FromFile<S>

§

impl<S> Sync for FromFile<S>

§

impl<S> Unpin for FromFile<S>
where S: Unpin,

§

impl<S> UnsafeUnpin for FromFile<S>

§

impl<S> UnwindSafe for FromFile<S>
where S: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.