MsPASS C++ API  2.4.1.dev4+g92330b7a
Defines the C++ API for MsPASS
Loading...
Searching...
No Matches
Public Member Functions | Protected Attributes | List of all members
mspass::seismic::BasicSpectrum Class Referenceabstract

#include <BasicSpectrum.h>

Inheritance diagram for mspass::seismic::BasicSpectrum:
Inheritance graph
[legend]

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.
 
double rayleigh () const
 Return the Rayleigh bin size for this spectrum.
 
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

22 {
23 dfval = 1.0;
24 f0val = 0.0;
25 };
double f0val
Definition BasicSpectrum.h:169
double dfval
Definition BasicSpectrum.h:167

References dfval, and f0val.

◆ 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 };
bool is_live
Definition BasicSpectrum.h:175
double parent_npts
Definition BasicSpectrum.h:173
double parent_dt
Definition BasicSpectrum.h:171

References dfval, f0val, is_live, parent_dt, and parent_npts.

◆ BasicSpectrum() [3/3]

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

Standard copy constructor

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

References dfval, f0val, is_live, parent_dt, and parent_npts.

◆ ~BasicSpectrum()

virtual mspass::seismic::BasicSpectrum::~BasicSpectrum ( )
inlinevirtual
63{};

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.

78{ return !is_live; };

References is_live.

◆ df()

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

Return the (fixed) frequemcy bin size.

94{ return this->dfval; };

References 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.

107{ return this->parent_dt; };

References 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.

99{ return this->f0val; };

References 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.

85{ is_live = false; };

References is_live.

◆ 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.

70{ return is_live; };

References 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.

◆ operator=()

BasicSpectrum & mspass::seismic::BasicSpectrum::operator= ( const BasicSpectrum parent)
inline

Standard assignment operator.

52 {
53 if (this != (&parent)) {
54 is_live = parent.is_live;
55 dfval = parent.dfval;
56 f0val = parent.f0val;
57 parent_dt = parent.parent_dt;
58 parent_npts = parent.parent_npts;
59 }
60 return *this;
61 };

References dfval, f0val, is_live, parent_dt, and parent_npts.

◆ 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.

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

References parent_dt, and parent_npts.

◆ 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.

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

References dfval, f0val, and nf().

◆ set_df()

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

Setter for the frequency bin interval - use with caution.

142{ dfval = dfin; };

References dfval.

◆ set_dt()

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

Setter for internally stored parent data sample interval.

146{ parent_dt = dtin; };

References parent_dt.

◆ set_f0()

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

Setter for the initial frequency value.

144{ f0val = f0in; };

References f0val.

◆ 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.

92{ is_live = true; };

References is_live.

◆ 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.

150{ parent_npts = npts_in; };

References parent_npts.

◆ timeseries_npts()

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

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

120{ return parent_npts; }

References parent_npts.

Member Data Documentation

◆ dfval

double mspass::seismic::BasicSpectrum::dfval
protected

Frequency bin spacing for the regular spectrum grid.

◆ f0val

double mspass::seismic::BasicSpectrum::f0val
protected

Frequency of component zero in the stored spectrum vector.

◆ is_live

bool mspass::seismic::BasicSpectrum::is_live
protected

True when the spectrum is marked as containing valid data.

◆ parent_dt

double mspass::seismic::BasicSpectrum::parent_dt
protected

Sample interval of the time series used to compute this spectrum.

◆ parent_npts

double mspass::seismic::BasicSpectrum::parent_npts
protected

Number of samples in the parent time series before any zero padding.


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