version  0.0.1
Defines the C++ API for MsPASS
BasicSpectrum.h
1 #ifndef _BASIC_SPECTRUM_H_
2 #define _BASIC_SPECTRUM_H_
3 #include <vector>
4 #include <math.h>
5 #include "mspass/utility/MsPASSError.h"
6 namespace mspass::seismic{
20 {
21 public:
23  BasicSpectrum(){dfval=1.0;f0val=0.0;};
32  BasicSpectrum(const double dfin,
33  const double f0in,
34  const double dtin,
35  const int npts_in)
36  {
37  is_live=false;
38  dfval=dfin;
39  f0val=f0in;
40  parent_dt=dtin;
41  parent_npts=npts_in;
42  };
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  };
52  BasicSpectrum& operator=(const BasicSpectrum& parent)
53  {
54  if(this!=(&parent))
55  {
56  is_live=parent.is_live;
57  dfval=parent.dfval;
58  f0val=parent.f0val;
59  parent_dt=parent.parent_dt;
60  parent_npts=parent.parent_npts;
61  }
62  return *this;
63  };
64  /*~ Destructor.*/
65  virtual ~BasicSpectrum(){};
72  bool live()const{return is_live;};
80  bool dead()const{return !is_live;};
87  void kill(){is_live=false;};
94  void set_live(){is_live=true;};
96  double df() const{return this->dfval;};
101  double f0() const{return this->f0val;};
108  double dt() const{return this->parent_dt;};
116  double rayleigh() const{
117  return 1.0/(this->parent_dt*static_cast<double>(this->parent_npts));
118  };
120  int timeseries_npts() const
121  {
122  return parent_npts;
123  }
128  int sample_number(const double f) const
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  };
149  void set_df(const double dfin){dfval=dfin;};
151  void set_f0(const double f0in){f0val=f0in;};
153  void set_dt(const double dtin){parent_dt=dtin;};
157  void set_npts(const int npts_in){parent_npts=npts_in;};
161  virtual std::vector<double> frequencies() const = 0;
164  virtual double frequency(const int sample_number) const = 0;
166  virtual size_t nf() const = 0;
170  virtual double Nyquist() const = 0;
171 protected:
172  double dfval;
173  double f0val;
174  double parent_dt;
175  double parent_npts;
176  bool is_live;
177 };
178 } //End namspace
179 #endif
Definition: BasicSpectrum.h:20
virtual double frequency(const int sample_number) const =0
int sample_number(const double f) const
Definition: BasicSpectrum.h:128
double dt() const
Return the original sample interval of data used to generate spectrum.
Definition: BasicSpectrum.h:108
void set_live()
Definition: BasicSpectrum.h:94
bool live() const
Definition: BasicSpectrum.h:72
bool dead() const
Definition: BasicSpectrum.h:80
BasicSpectrum(const BasicSpectrum &parent)
Definition: BasicSpectrum.h:44
int timeseries_npts() const
Definition: BasicSpectrum.h:120
void set_f0(const double f0in)
Definition: BasicSpectrum.h:151
double rayleigh() const
Return the Rayleigh bin size for this spectrum.
Definition: BasicSpectrum.h:116
void set_dt(const double dtin)
Definition: BasicSpectrum.h:153
void kill()
Definition: BasicSpectrum.h:87
virtual size_t nf() const =0
void set_npts(const int npts_in)
Definition: BasicSpectrum.h:157
double df() const
Definition: BasicSpectrum.h:96
BasicSpectrum(const double dfin, const double f0in, const double dtin, const int npts_in)
Definition: BasicSpectrum.h:32
double f0() const
Definition: BasicSpectrum.h:101
BasicSpectrum()
Definition: BasicSpectrum.h:23
virtual std::vector< double > frequencies() const =0
virtual double Nyquist() const =0
void set_df(const double dfin)
Definition: BasicSpectrum.h:149
Base class for error object thrown by MsPASS library routines.
Definition: MsPASSError.h:40
Define metadata keys.
Definition: BasicSpectrum.h:6