version  0.0.1
Defines the C++ API for MsPASS
Loading...
Searching...
No Matches
BasicSpectrum.h
1#ifndef _BASIC_SPECTRUM_H_
2#define _BASIC_SPECTRUM_H_
3#include "mspass/utility/MsPASSError.h"
4#include <math.h>
5#include <vector>
6namespace mspass::seismic {
20public:
23 dfval = 1.0;
24 f0val = 0.0;
25 };
35 BasicSpectrum(const double dfin, const double f0in, const double dtin,
36 const int npts_in) {
37 is_live = false;
38 dfval = dfin;
39 f0val = f0in;
40 parent_dt = dtin;
41 parent_npts = npts_in;
42 };
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 };
51 BasicSpectrum &operator=(const BasicSpectrum &parent) {
52 if (this != (&parent)) {
53 is_live = parent.is_live;
54 dfval = parent.dfval;
55 f0val = parent.f0val;
56 parent_dt = parent.parent_dt;
57 parent_npts = parent.parent_npts;
58 }
59 return *this;
60 };
61 /*~ Destructor.*/
62 virtual ~BasicSpectrum() {};
69 bool live() const { return is_live; };
77 bool dead() const { return !is_live; };
84 void kill() { is_live = false; };
91 void set_live() { is_live = true; };
93 double df() const { return this->dfval; };
98 double f0() const { return this->f0val; };
106 double dt() const { return this->parent_dt; };
114 double rayleigh() const {
115 return 1.0 / (this->parent_dt * static_cast<double>(this->parent_npts));
116 };
119 int timeseries_npts() const { return parent_npts; }
124 int sample_number(const double f) const {
125 int itest = static_cast<int>(round((f - f0val) / dfval));
126 if (itest < 0) {
128 "BasicSpectrum::sample_number: f must be positive or greater than "
129 "f0 if f0!=0",
130 mspass::utility::ErrorSeverity::Fatal);
131 } else if (itest >= this->nf()) {
133 "BasicSpectrum::sample_number: f received exceeds the length of "
134 "stored vector",
135 mspass::utility::ErrorSeverity::Fatal);
136 } else {
137 return itest;
138 }
139 };
141 void set_df(const double dfin) { dfval = dfin; };
143 void set_f0(const double f0in) { f0val = f0in; };
145 void set_dt(const double dtin) { parent_dt = dtin; };
149 void set_npts(const int npts_in) { parent_npts = npts_in; };
153 virtual std::vector<double> frequencies() const = 0;
156 virtual double frequency(const int sample_number) const = 0;
158 virtual size_t nf() const = 0;
162 virtual double Nyquist() const = 0;
163
164protected:
165 double dfval;
166 double f0val;
167 double parent_dt;
168 double parent_npts;
169 bool is_live;
170};
171} // namespace mspass::seismic
172#endif
Definition BasicSpectrum.h:19
virtual double frequency(const int sample_number) const =0
int sample_number(const double f) const
Definition BasicSpectrum.h:124
double dt() const
Return the original sample interval of data used to generate spectrum.
Definition BasicSpectrum.h:106
void set_live()
Definition BasicSpectrum.h:91
bool live() const
Definition BasicSpectrum.h:69
bool dead() const
Definition BasicSpectrum.h:77
BasicSpectrum(const BasicSpectrum &parent)
Definition BasicSpectrum.h:44
int timeseries_npts() const
Definition BasicSpectrum.h:119
void set_f0(const double f0in)
Definition BasicSpectrum.h:143
double rayleigh() const
Return the Rayleigh bin size for this spectrum.
Definition BasicSpectrum.h:114
void set_dt(const double dtin)
Definition BasicSpectrum.h:145
void kill()
Definition BasicSpectrum.h:84
virtual size_t nf() const =0
void set_npts(const int npts_in)
Definition BasicSpectrum.h:149
double df() const
Definition BasicSpectrum.h:93
virtual std::vector< double > frequencies() const =0
BasicSpectrum(const double dfin, const double f0in, const double dtin, const int npts_in)
Definition BasicSpectrum.h:35
double f0() const
Definition BasicSpectrum.h:98
BasicSpectrum()
Definition BasicSpectrum.h:22
virtual double Nyquist() const =0
void set_df(const double dfin)
Definition BasicSpectrum.h:141
Base class for error object thrown by MsPASS library routines.
Definition MsPASSError.h:38
Define metadata keys.
Definition BasicSpectrum.h:6