version  0.0.1
Defines the C++ API for MsPASS
Public Member Functions | Protected Attributes | List of all members
mspass::seismic::BasicSpectrum Class Referenceabstract

#include <BasicSpectrum.h>

Inheritance diagram for mspass::seismic::BasicSpectrum:
mspass::seismic::PowerSpectrum

Public Member Functions

 BasicSpectrum ()
 
 BasicSpectrum (const double dfin, const double f0in, const double dtin, const int npts_in)
 
 BasicSpectrum (const BasicSpectrum &parent)
 
BasicSpectrumoperator= (const BasicSpectrum &parent)
 
bool live () const
 
bool dead () const
 
void kill ()
 
void set_live ()
 
double df () const
 
double f0 () const
 
double dt () const
 Return the original sample interval of data used to generate spectrum. More...
 
double rayleigh () const
 Return the Rayleigh bin size for this spectrum. More...
 
int timeseries_npts () const
 
int sample_number (const double f) const
 
void set_df (const double dfin)
 
void set_f0 (const double f0in)
 
void set_dt (const double dtin)
 
void set_npts (const int npts_in)
 
virtual std::vector< double > frequencies () const =0
 
virtual double frequency (const int sample_number) const =0
 
virtual size_t nf () const =0
 
virtual double Nyquist () const =0
 

Protected Attributes

double dfval
 
double f0val
 
double parent_dt
 
double parent_npts
 
bool is_live
 

Detailed Description

Base class for family of data objects created by Fourier transforms.

There are a range of algorithms used in seismology that center on the use of Fourier Transforms. This base class is intended to be used as the base for any mspass C++ data object based on Fourier transforms where the data are stored with a vector defined on a uniform grid in frequency. That means any algorithm based on fFTs. The value of using a base class is that power spectra and complex spectra have many common concpets shared by this base class. Classic use of inheritance to avoid redundant code.

Constructor & Destructor Documentation

◆ BasicSpectrum() [1/3]

mspass::seismic::BasicSpectrum::BasicSpectrum ( )
inline

Default constructor. sets frequency interval to 1 and f0 to 0

23 {dfval=1.0;f0val=0.0;};

◆ BasicSpectrum() [2/3]

mspass::seismic::BasicSpectrum::BasicSpectrum ( const double  dfin,
const double  f0in,
const double  dtin,
const int  npts_in 
)
inline

Parameterized constructor.

Parameters
dfinfrequency bin size
f0infrequency of first component of data vector of regular frequency grid.
dtinparent sample interval of spectrum estimate.
npts_innumber of actual samples of parent time series (may not be the same as spectrum link when zero padding is used. subclasses should provide a way to handle zero padding
36  {
37  is_live=false;
38  dfval=dfin;
39  f0val=f0in;
40  parent_dt=dtin;
41  parent_npts=npts_in;
42  };

◆ BasicSpectrum() [3/3]

mspass::seismic::BasicSpectrum::BasicSpectrum ( const BasicSpectrum parent)
inline

Standard copy constructor

45  {
46  is_live=parent.is_live;
47  dfval=parent.dfval;
48  f0val=parent.f0val;
49  parent_dt=parent.parent_dt;
50  parent_npts=parent.parent_npts;
51  };

Member Function Documentation

◆ dead()

bool mspass::seismic::BasicSpectrum::dead ( ) const
inline

Test live condition of the data.

Returns true if the data are marked as being bad This method is part of a four methods for handling the concept of "live"==gppd versus "dead" == bad. The concept was borrowed from seismic reflection processing. This method is the negation of the live method.

80 {return !is_live;};

◆ df()

double mspass::seismic::BasicSpectrum::df ( ) const
inline

Return the (fixed) frequemcy bin size.

96 {return this->dfval;};

◆ dt()

double mspass::seismic::BasicSpectrum::dt ( ) const
inline

Return the original sample interval of data used to generate spectrum.

When zero padding is used the original sample interval of data cannot be known without additional data. In this implementation we require the user to store that information with a protected attribute within the object. This retrieves that stored value.

108 {return this->parent_dt;};

◆ f0()

double mspass::seismic::BasicSpectrum::f0 ( ) const
inline

Return the frequency of the first (0) component of the spectrum vector. This value is normally 0 but the api allows it to be nonzero. That is useful for windowing to store only data in a limited passband.

101 {return this->f0val;};

◆ frequencies()

virtual std::vector<double> mspass::seismic::BasicSpectrum::frequencies ( ) const
pure virtual

Return an std::vector container containing the frequency of each sample in the spectrum vector. Commonly necessary for plotting. Made virtual because nf method needs to be virtual.

Implemented in mspass::seismic::PowerSpectrum.

◆ frequency()

virtual double mspass::seismic::BasicSpectrum::frequency ( const int  sample_number) const
pure virtual

Return frequency at a specified sample number. Virtual to allow subclasses to throw an error for illegal value.

Implemented in mspass::seismic::PowerSpectrum.

◆ kill()

void mspass::seismic::BasicSpectrum::kill ( )
inline

Mark this datum bad.

Returns true if the data are marked as being good. This method is part of a four methods for handling the concept of "live"==gppd versus "dead" == bad. The concept was borrowed from seismic reflection processing.

87 {is_live=false;};

◆ live()

bool mspass::seismic::BasicSpectrum::live ( ) const
inline

Test live condition of the data.

Returns true if the data are marked as being good. This method is part of a four methods for handling the concept of "live"==gppd versus "dead" == bad. The concept was borrowed from seismic reflection processing.

72 {return is_live;};

◆ nf()

virtual size_t mspass::seismic::BasicSpectrum::nf ( ) const
pure virtual

Return the number of frequency bin.

Implemented in mspass::seismic::PowerSpectrum.

◆ Nyquist()

virtual double mspass::seismic::BasicSpectrum::Nyquist ( ) const
pure virtual

Return the Nyquist frequency. Virtual because if f0 is not zero and the number of points is not the full fft output this needs to be handled differently.

Implemented in mspass::seismic::PowerSpectrum.

◆ rayleigh()

double mspass::seismic::BasicSpectrum::rayleigh ( ) const
inline

Return the Rayleigh bin size for this spectrum.

The Rayleigh bin size of a spectrum is 1/T where T is the length of the original time series. This method returns that attribute of this spectrum. Note the rayleigh and df methods will return the same number only when a spectrum is computed with no zero padding.

116  {
117  return 1.0/(this->parent_dt*static_cast<double>(this->parent_npts));
118  };

◆ sample_number()

int mspass::seismic::BasicSpectrum::sample_number ( const double  f) const
inline

Return the integer sample number of the closest sample to the specified frequency. Uses rounding. Will throw a MsPASSError object if the specified frequency is not within the range of the data.

129  {
130  int itest=static_cast<int>( round( (f-f0val)/dfval ) );
131  if(itest<0)
132  {
134  "BasicSpectrum::sample_number: f must be positive or greater than f0 if f0!=0",
135  mspass::utility::ErrorSeverity::Fatal);
136  }
137  else if(itest>=this->nf())
138  {
140  "BasicSpectrum::sample_number: f received exceeds the length of stored vector",
141  mspass::utility::ErrorSeverity::Fatal);
142  }
143  else
144  {
145  return itest;
146  }
147  };
virtual size_t nf() const =0
Base class for error object thrown by MsPASS library routines.
Definition: MsPASSError.h:40

◆ set_df()

void mspass::seismic::BasicSpectrum::set_df ( const double  dfin)
inline

Setter for the frequency bin interval - use with caution.

149 {dfval=dfin;};

◆ set_dt()

void mspass::seismic::BasicSpectrum::set_dt ( const double  dtin)
inline

Setter for internally stored parent data sample interval.

153 {parent_dt=dtin;};

◆ set_f0()

void mspass::seismic::BasicSpectrum::set_f0 ( const double  f0in)
inline

Setter for the initial frequency value.

151 {f0val=f0in;};

◆ set_live()

void mspass::seismic::BasicSpectrum::set_live ( )
inline

Mark this datum good..

Returns true if the data are marked as being good. This method is part of a four methods for handling the concept of "live"==gppd versus "dead" == bad. The concept was borrowed from seismic reflection processing.

94 {is_live=true;};

◆ set_npts()

void mspass::seismic::BasicSpectrum::set_npts ( const int  npts_in)
inline

Setter for internal parent number of data points (need by rayleigh method). Note one should only use this in constructors and when creating an instance from pieces.

157 {parent_npts=npts_in;};

◆ timeseries_npts()

int mspass::seismic::BasicSpectrum::timeseries_npts ( ) const
inline

Return number of points in parent time series. Of use mostly internally.

121  {
122  return parent_npts;
123  }

The documentation for this class was generated from the following file: