[][src]Struct sacio::Sac

pub struct Sac {
    pub y: Vec<f32>,
    pub x: Vec<f32>,
    pub file: String,
    pub a: f32,
    pub fmt: f32,
    pub t0: f32,
    pub t1: f32,
    pub t2: f32,
    pub t3: f32,
    pub t4: f32,
    pub t5: f32,
    pub t6: f32,
    pub t7: f32,
    pub t8: f32,
    pub t9: f32,
    pub f: f32,
    pub resp0: f32,
    pub resp1: f32,
    pub resp2: f32,
    pub resp3: f32,
    pub resp4: f32,
    pub resp5: f32,
    pub resp6: f32,
    pub resp7: f32,
    pub resp8: f32,
    pub resp9: f32,
    pub mag: f32,
    pub user0: f32,
    pub user1: f32,
    pub user2: f32,
    pub user3: f32,
    pub user4: f32,
    pub user5: f32,
    pub user6: f32,
    pub user7: f32,
    pub user8: f32,
    pub user9: f32,
    // some fields omitted
}

SAC file data and metadata

Fields

y: Vec<f32>

Dependent variable

  • Amplitude for time series data
  • Amplitude for Amplitude Phase data
  • Real for Real Imaginary data
  • Z for XYZ data
  • Y for XY data
x: Vec<f32>

Indepenent variable, Time for time series data

  • Timing for time series data, only for uneven data
  • Phase for Amplitude Phase data
  • Imaginary for Real Imaginary data
  • X for XY data
file: String

Filename of the Sac Data File

a: f32fmt: f32t0: f32t1: f32t2: f32t3: f32t4: f32t5: f32t6: f32t7: f32t8: f32t9: f32f: f32resp0: f32resp1: f32resp2: f32resp3: f32resp4: f32resp5: f32resp6: f32resp7: f32resp8: f32resp9: f32mag: f32user0: f32user1: f32user2: f32user3: f32user4: f32user5: f32user6: f32user7: f32user8: f32user9: f32

Methods

impl Sac[src]

Sac Implementation

pub fn from_file<P: AsRef<Path>>(path: P) -> Result<Sac, SacError>[src]

Read a sac file

use sacio::Sac;

let s = Sac::from_file("tests/file.sac")?;
assert_eq!(s.delta(), 0.01);

pub fn read<R: Read + Seek>(buf: &mut R) -> Result<Sac, SacError>[src]

Read a sac file from a buffer

use sacio::Sac;

// This simulates having the data already in memory
let mut buf = std::fs::read("tests/file.sac")?;
let mut rdr = std::io::Cursor::new(&mut buf);

let s = Sac::read(&mut rdr)?;
assert_eq!(s.delta(), 0.01);

pub fn to_file<P: AsRef<Path>>(&mut self, path: P) -> Result<(), SacError>[src]

Write a sac file

use sacio::Sac;

let mut s = Sac::from_file("tests/file.sac")?;
 
s.to_file("tests/to_file.sac")?;

let s2 = Sac::from_file("tests/to_file.sac")?;
assert_eq!(s.delta(), s2.delta());
assert_eq!(s.npts(), s2.npts());

pub fn write<W: Write>(&mut self, buf: &mut W) -> Result<(), SacError>[src]

Write a sac file to a buffer

use sacio::Sac;

let mut s = Sac::from_file("tests/file.sac")?;
let mut buf = vec![];
s.write(&mut buf)?;

let mut rdr = std::io::Cursor::new(&mut buf);
let s2 = Sac::read(&mut rdr)?;
assert_eq!(s.delta(), s2.delta());
assert_eq!(s.npts(), s2.npts());

Write a SAC file

pub fn swapped(&self) -> bool[src]

Determine if file is to be swapped on output

use sacio::Sac;

let mut s = Sac::from_file("tests/file.sac")?;
assert_eq!(s.swapped(), false);

let mut s = Sac::from_file("tests/file.sac.swap")?;
assert_eq!(s.swapped(), true);

pub fn set_swap(&mut self, swap: bool)[src]

Determine if file is to be swapped on output

use sacio::Sac;

let mut s = Sac::from_file("tests/file.sac")?;
assert_eq!(s.swapped(), false);

s.set_swap(true);
s.to_file("tests/set_swap.sac")?;

let mut s = Sac::from_file("tests/set_swap.sac")?;
assert_eq!(s.swapped(), true);

pub fn new() -> Sac[src]

Create an empty SAC file

use sacio::Sac;
use sacio::SacString;
use sacio::SacZeroTime;
use sacio::SacFileType;
use sacio::SacDataType;

let s = Sac::new();
assert_eq!(s.delta(), -12345.0);
assert_eq!(s.string(SacString::EventName), "-12345  ");
assert_eq!(s.zero_time(), SacZeroTime::None);
assert_eq!(s.file_type(), SacFileType::Time);
assert_eq!(s.data_type(), SacDataType::None);

assert_eq!(s.version(), 6);
assert_eq!(s.station_polarity(), false);
assert_eq!(s.mutability(), true);
assert_eq!(s.calc_dist_az(), true);

assert_eq!(s.npts(), 0);

pub fn is_spectral(&self) -> bool[src]

Check if file is spectral

 use sacio::Sac;
 let s = Sac::from_amp(vec![0.,1.,2.], 0.0, 1.0);
 assert!( ! s.is_spectral() );

pub fn is_real_imag(&self) -> bool[src]

Check is file is a Real/Imaginary Pair

use sacio::Sac;
let s = Sac::from_amp(vec![0.,1.,2.],0.0, 1.0);
assert!( ! s.is_real_imag() );

pub fn is_amp_phase(&self) -> bool[src]

Check if file is a Amplitude/Phase Pair

use sacio::Sac;
let s = Sac::from_amp(vec![0.,1.,2.],0.0, 1.0);
assert!( ! s.is_amp_phase() );

pub fn is_time(&self) -> bool[src]

Check if file is a time series file

use sacio::Sac;
let s = Sac::from_amp(vec![0.,1.,2.],0.0, 1.0);
assert!( s.is_time() );

pub fn file_type(&self) -> SacFileType[src]

Get File type (iftype)

use sacio::Sac;
use sacio::SacFileType;

let s = Sac::from_file("tests/file.sac")?;
assert_eq!(s.file_type(), SacFileType::Time);

pub fn set_file_type(&mut self, file_type: SacFileType)[src]

Set File type (iftype)

pub fn ncomps(&self) -> usize[src]

Determine the number of data components

use sacio::Sac;

let s = Sac::from_file("tests/file.sac")?;
assert_eq!(s.ncomps(), 1);

pub fn npts(&self) -> i32[src]

Get number of data points

use sacio::Sac;

let s = Sac::from_file("tests/file.sac")?;
assert_eq!(s.npts(), 1000);

pub fn version(&self) -> i32[src]

Get Header Version

Should be 6

use sacio::Sac;

let s = Sac::from_file("tests/file.sac")?;
assert_eq!(s.version(), 6);

pub fn time(&self) -> NaiveDateTime[src]

Get Reference Time

use sacio::Sac;
use chrono::{NaiveDateTime, NaiveDate, NaiveTime};

let s = Sac::from_file("tests/file.sac")?;
let date = NaiveDate::from_yo(1981, 88);
let time = NaiveTime::from_hms_milli(10, 38, 14, 0);
assert_eq!(s.time(), NaiveDateTime::new(date, time));

pub fn set_time(&mut self, time: NaiveDateTime)[src]

Set Refernce Time

use sacio::Sac;
use chrono::{NaiveDateTime, NaiveDate, NaiveTime};

let mut s = Sac::from_file("tests/file.sac")?;
let date = NaiveDate::from_yo(1984, 29);
let time = NaiveTime::from_hms_milli(15, 12, 59, 456);
let when = NaiveDateTime::new(date, time);
s.set_time(when);

assert_eq!(s.time(), when);

pub fn calc_max_amp(&self) -> f32[src]

Compute the maximum amplitude

use sacio::Sac;

let s = Sac::from_file("tests/file.sac")?;
assert_eq!(s.calc_max_amp(), s.max_amp());

pub fn calc_min_amp(&self) -> f32[src]

Compute the minimum amplitude

use sacio::Sac;

let s = Sac::from_file("tests/file.sac")?;
assert_eq!(s.calc_min_amp(), s.min_amp());

pub fn calc_mean_amp(&self) -> f32[src]

Compute the mean amplitude

use sacio::Sac;

let s = Sac::from_file("tests/file.sac")?;
assert_eq!(s.calc_mean_amp(), s.mean_amp());

pub fn extrema_amp(&mut self)[src]

Compute and set min, man and mean amplitudes of the y component

use sacio::Sac;

let mut s = Sac::from_file("tests/file.sac")?;

assert_eq!(s.mean_amp(), -0.09854721);
assert_eq!(s.min_amp(), -1.56928);
assert_eq!(s.max_amp(), 1.52064);

s.y.iter_mut().for_each(|v| *v *= 2.0);

s.extrema_amp();

assert_eq!(s.mean_amp(), -0.09854721 * 2.0);
assert_eq!(s.min_amp(), -1.56928 * 2.0);
assert_eq!(s.max_amp(), 1.52064 * 2.0);

pub fn extrema(&mut self)[src]

Compute and set extremas in x and y

File Type y-min y-max y-mean x-min x-max
time / even min(amp)min(amp) mean(amp)b e = b + (n-1)*dt
time / uneven min(amp)min(amp) mean(amp)b = min(x) e = max(x)
general xy min(amp)min(amp) mean(amp)b e = b + (n-1)*dt
amp / phase - - - b = 0 e = f_nyquist
real/ imag - - - b = 0 e = f_nyquist
general xyz - - - - -

pub fn with_new_data(&self, y: Vec<f32>) -> Self[src]

Create a SAC File with new data, copying header values

use sacio::Sac;

let s = Sac::from_file("tests/file.sac")?;

let t = s.with_new_data(vec![0., 1., 0.0]);

assert_eq!(t.min_amp(), 0.0);
assert_eq!(t.max_amp(), 1.0);
assert_eq!(t.npts(), 3);

pub fn from_amp(y: Vec<f32>, b: f64, dt: f64) -> Sac[src]

Create new sac from data from amplitude, begin value, b, and sample rate, dt

use sacio::Sac;
let s = Sac::from_amp(vec![0., 1., 2.], 0.0, 0.1);
assert!( s.is_time() );
assert!( s.y == &[0., 1., 2.] );

pub fn is_finite(&self) -> bool[src]

Determine if all data is finite, not NaN, inf

use sacio::Sac;

let s = Sac::from_amp(vec![0.,1.], 0.0, 1.0);
assert_eq!(s.is_finite(), true);

pub fn zero_time(&self) -> SacZeroTime[src]

Get Zero Time Equivalent

use sacio::Sac;
use sacio::SacZeroTime;

let s = Sac::from_file("tests/file.sac")?;
assert_eq!(s.zero_time(), SacZeroTime::B);

pub fn station_polarity(&self) -> bool[src]

Get Station_polarity

pub fn set_station_polarity(&mut self, flipped: bool)[src]

Set Station polarity

pub fn evenly_spaced(&self) -> bool[src]

Determine is file is evenly spaced

pub fn calc_dist_az(&self) -> bool[src]

Determine is file should calculate the distance and azimuth (lcalda)

pub fn set_calc_dist_az(&mut self, value: bool)[src]

Set if file should calculate the distance and azimuth (lcalda)

pub fn mutability(&self) -> bool[src]

Check is file can be overwritten (lovrok)

pub fn set_mutability(&mut self, value: bool)[src]

Set the file as mutable (lovrok)

pub fn event_type(&self) -> SacEventType[src]

Get Event type (ievtyp)

pub fn set_event_type(&mut self, etype: SacEventType)[src]

Set Event ytpe (ievtyp)

pub fn data_quality(&self) -> SacQuality[src]

Get Data Quality

pub fn set_data_quality(&mut self, qual: SacQuality)[src]

Set Data Quality

pub fn data_type(&self) -> SacDataType[src]

Get Amplitude Type (idep)

pub fn synthetic(&self) -> bool[src]

Set synthetic flag (isynth)

pub fn set_synthetic(&mut self, synth: bool)[src]

Set synthetic flag (isynth)

pub fn set_zero_time_type(&mut self, ztype: SacZeroTime)[src]

Set Zero Time Type

pub fn magnitude_type(&self) -> SacMagnitudeType[src]

Get Magnitude Type

pub fn set_magnitude_type(&mut self, mag: SacMagnitudeType)[src]

Set Magnitude Type

pub fn magnitude_source(&self) -> SacMagnitudeSource[src]

Get Magnitude Source

pub fn set_magnitude_source(&mut self, magsrc: SacMagnitudeSource)[src]

Set Magnitude Source

pub fn instrument_type(&self) -> SacInstrument[src]

Get Instrument Type

This type is historical, you probably want SacStrings::Instrument

pub fn set_instrument_type(&mut self, itype: SacInstrument)[src]

Set Instrument Type

This type is historical, you probably want SacStrings::Instrument

pub fn set_amp_type(&mut self, amp_type: SacDataType)[src]

Set Amplitude Type (idep)

pub fn compute_dist_az(&mut self)[src]

Compute Distance and Azimuth between station and event

pub fn event_region(&self) -> i32[src]

Get event region

pub fn station_region(&self) -> i32[src]

Get station region

pub fn update_regions(&mut self)[src]

Update event and station regions

This assumes the station and event locations are defined

pub fn filename(&self) -> &str[src]

Get Current filename

pub fn set_filename(&mut self, filename: &str)[src]

Set Filename

pub fn id(&self, key: SacInt) -> i32[src]

pub fn set_id(&mut self, key: SacInt, value: i32)[src]

pub fn string(&self, key: SacString) -> &str[src]

pub fn set_string(&mut self, key: SacString, value: &str)[src]

pub fn delta(&self) -> f32[src]

Get Sampling

pub fn mean_amp(&self) -> f32[src]

Get Mean amplitude value

pub fn min_amp(&self) -> f32[src]

Get Minimum amplitude value

pub fn max_amp(&self) -> f32[src]

Get Maximum amplitude value

pub fn station_lat(&self) -> f32[src]

pub fn station_lon(&self) -> f32[src]

pub fn station_elevation(&self) -> f32[src]

pub fn event_lat(&self) -> f32[src]

pub fn event_lon(&self) -> f32[src]

pub fn event_depth(&self) -> f32[src]

pub fn dist_km(&self) -> f32[src]

pub fn dist_deg(&self) -> f32[src]

pub fn az(&self) -> f32[src]

pub fn baz(&self) -> f32[src]

pub fn set_station_location(
    &mut self,
    lat: f32,
    lon: f32,
    elev: f32
) -> Result<(), SacError>
[src]

pub fn set_event_location(
    &mut self,
    lat: f32,
    lon: f32,
    depth: f32
) -> Result<(), SacError>
[src]

pub fn cmpaz(&self) -> f32[src]

Get Component Azimuth

North is 0 degrees, with positive values rotating clockwise. This is a geographic coordinate system.

Direction Value
North 0
East 90
South 180
West 270 or -90

pub fn set_cmpaz(&mut self, az: f32) -> Result<(), SacError>[src]

Set Component Azimuth

Accepted must be between [-360, 360]

pub fn cmpinc(&self) -> f32[src]

Get Component Inclination or Incident angle

Values are defined from vertical

Diretion Value
Vertical Up 0
Horizontal 90

pub fn set_cmpinc(&mut self, inc: f32) -> Result<(), SacError>[src]

Set Component Inclination

Values must be between [-180, 180]

pub fn b(&self) -> f32[src]

Get Beginning time value

pub fn e(&self) -> f32[src]

Get Ending time value

pub fn o(&self) -> f32[src]

Get Origin time value

pub fn set_b(&mut self, time: TimeValue)[src]

Set beginning time value

pub fn set_o(&mut self, time: TimeValue)[src]

Set origin time value

Trait Implementations

impl PartialEq<Sac> for Sac[src]

#[must_use]
fn ne(&self, other: &Rhs) -> bool
1.0.0[src]

This method tests for !=.

impl Clone for Sac[src]

fn clone_from(&mut self, source: &Self)1.0.0[src]

Performs copy-assignment from source. Read more

impl Default for Sac[src]

impl Debug for Sac[src]

Auto Trait Implementations

impl Send for Sac

impl Sync for Sac

Blanket Implementations

impl<T> From<T> for T[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]