MsPASS C++ API  0.1.dev1+gef6e26c
Defines the C++ API for MsPASS
Loading...
Searching...
No Matches
Taper.h
1#ifndef _TAPER_H_
2#define _TAPER_H_
3// #include <math.h>
4#include <memory>
5#include <vector>
6
7#include <boost/archive/text_iarchive.hpp>
8#include <boost/archive/text_oarchive.hpp>
9#include <boost/serialization/base_object.hpp>
10#include <boost/serialization/shared_ptr.hpp>
11#include <boost/serialization/vector.hpp>
12
13#include "mspass/seismic/Seismogram.h"
14#include "mspass/seismic/TimeSeries.h"
15
16namespace mspass::algorithms {
17
24public:
27 head = false;
28 tail = false;
29 all = false;
30 };
32 virtual ~BasicTaper() {};
38 void enable_head() { head = true; };
40 void disable_head() {
41 head = false;
42 all = false;
43 };
45 void enable_tail() { tail = true; };
47 void disable_tail() {
48 tail = false;
49 all = false;
50 };
53 if (head || all) {
54 return true;
55 }
56 return false;
57 };
60 if (tail || all) {
61 return true;
62 }
63 return false;
64 };
65 /* These virtual methods are a bit of a design flaw as they don't
66 apply well to the vector taper, but we implement them there to just
67 throw an exception */
69 virtual double get_t0head() const = 0;
71 virtual double get_t1head() const = 0;
72
73protected:
74 /* A taper can be head, tail, or all. For efficiency it is required
75 implementations set these three booleans. head or tail may be true.
76 all means a single function is needed to defne the taper. */
77 bool head;
78 bool tail;
79 bool all;
81private:
82 friend class boost::serialization::access;
83 template <class Archive>
84 void serialize(Archive &ar, const unsigned int version) {
85 ar & head;
86 ar & tail;
87 ar & all;
88 };
89};
96class LinearTaper : public BasicTaper {
97public:
106 LinearTaper(const double t0head, const double t1head, const double t1tail,
107 const double t0tail);
113 double get_t0head() const { return t0head; };
115 double get_t1head() const { return t1head; };
117 double get_t0tail() const { return t0tail; };
119 double get_t1tail() const { return t1tail; };
120
121private:
122 double t0head, t1head, t1tail, t0tail;
123 friend class boost::serialization::access;
124 template <class Archive>
125 void serialize(Archive &ar, const unsigned int version) {
126 ar &boost::serialization::base_object<BasicTaper>(*this);
127 ar & t0head;
128 ar & t1head;
129 ar & t1tail;
130 ar & t0tail;
131 };
132};
141class CosineTaper : public BasicTaper {
142public:
143 CosineTaper();
150 CosineTaper(const double t0head, const double t1head, const double t1tail,
151 const double t0tail);
152 /* these need to post to history using new feature*/
158 double get_t0head() const { return t0head; };
160 double get_t1head() const { return t1head; };
162 double get_t0tail() const { return t0tail; };
164 double get_t1tail() const { return t1tail; };
165
166private:
167 double t0head, t1head, t1tail, t0tail;
168 friend class boost::serialization::access;
169 template <class Archive>
170 void serialize(Archive &ar, const unsigned int version) {
171 ar &boost::serialization::base_object<BasicTaper>(*this);
172 ar & t0head;
173 ar & t1head;
174 ar & t1tail;
175 ar & t0tail;
176 };
177};
183class VectorTaper : public BasicTaper {
184public:
185 VectorTaper();
187 VectorTaper(const std::vector<double> taperdata);
193 void disable() { all = false; };
195 void enable() {
196 if (taper.size() > 0)
197 all = true;
198 };
200 std::vector<double> get_taper() { return taper; };
202 double get_t0head() const {
203 std::cerr << "get_t0head not implemented for VectorTaper";
204 return 0.0;
205 };
207 double get_t1head() const {
208 std::cerr << "get_t1head not implemented for VectorTaper";
209 return 0.0;
210 };
211
212private:
213 std::vector<double> taper;
214 friend class boost::serialization::access;
215 template <class Archive>
216 void serialize(Archive &ar, const unsigned int version) {
217 ar &boost::serialization::base_object<BasicTaper>(*this);
218 ar & taper;
219 };
220};
237class TopMute {
238public:
240 TopMute();
258 TopMute(const double t0, const double t1, const std::string type);
260 TopMute(const TopMute &parent);
262 ~TopMute();
264 TopMute &operator=(const TopMute &parent);
271 double get_t0() const { return taper->get_t0head(); };
274 double get_t1() const { return taper->get_t1head(); };
277 std::string taper_type() const;
278
279private:
280 /* We use a shared_ptr to the base class. That allows inheritance to
281 handle the actual form - a classic oop use of a base class. the shared_ptr
282 allows us to get around an abstract base problem. May be other solutions
283 but this should be ok. There may be a problem in parallel environment,
284 however, as not sure how this would be handled by spark or dask. this is
285 in that pickable realm.*/
286 std::shared_ptr<BasicTaper> taper;
287 /* I tried this but couldn't make it work. It compiles but dies at
288 runtime with mysterious errors for me. Internet conversations suggest
289 shared_ptr data with polymorphic types like this is problematic.
290 For mspass the python bindings with pickle are more what is needed anyway
291 so serialization of TopMute is purely done in the pybind11 wrappers.
292 Turns out to be easy because the TopMute taper is actually define donly
293 by two paramters (t0head and t1head).
294 friend class boost::serialization::access;
295 template<class Archive>
296 void serialize(Archive & ar, const unsigned int version)
297 {
298 ar & taper;
299 };
300 */
301};
302} // namespace mspass::algorithms
303#endif // End guard
Abstract base class for taper operators.
Definition Taper.h:23
bool tail_is_enable()
Definition Taper.h:59
void enable_tail()
Definition Taper.h:45
bool head_is_enabled()
Definition Taper.h:52
void enable_head()
Definition Taper.h:38
bool tail
Definition Taper.h:78
bool all
Definition Taper.h:79
virtual double get_t0head() const =0
void disable_tail()
Definition Taper.h:47
virtual int apply(mspass::seismic::TimeSeries &d)=0
BasicTaper()
Definition Taper.h:26
void disable_head()
Definition Taper.h:40
virtual ~BasicTaper()
Definition Taper.h:32
virtual double get_t1head() const =0
bool head
Definition Taper.h:77
virtual int apply(mspass::seismic::Seismogram &d)=0
Taper front and/or end of a time seris with a half cosine function.
Definition Taper.h:141
double get_t1tail() const
Definition Taper.h:164
double get_t0tail() const
Definition Taper.h:162
double get_t0head() const
Definition Taper.h:158
int apply(mspass::seismic::TimeSeries &d)
Definition Taper.cc:211
double get_t1head() const
Definition Taper.h:160
Used to construct an operator to apply a linear taper to either end.
Definition Taper.h:96
double get_t0head() const
Definition Taper.h:113
int apply(mspass::seismic::TimeSeries &d)
Definition Taper.cc:41
double get_t0tail() const
Definition Taper.h:117
double get_t1head() const
Definition Taper.h:115
double get_t1tail() const
Definition Taper.h:119
Mute operator for "top" of signals defined first smaple forward.
Definition Taper.h:237
double get_t0() const
Definition Taper.h:271
TopMute & operator=(const TopMute &parent)
Definition Taper.cc:408
~TopMute()
Definition Taper.cc:378
std::string taper_type() const
Definition Taper.cc:438
double get_t1() const
Definition Taper.h:274
TopMute()
Definition Taper.cc:377
int apply(mspass::seismic::TimeSeries &d)
Definition Taper.cc:414
Definition Taper.h:183
int apply(mspass::seismic::TimeSeries &d)
Definition Taper.cc:337
double get_t1head() const
Definition Taper.h:207
std::vector< double > get_taper()
Definition Taper.h:200
void enable()
Definition Taper.h:195
void disable()
Definition Taper.h:193
double get_t0head() const
Definition Taper.h:202
Implemntation of Seismogram for MsPASS.
Definition Seismogram.h:14
Implemntation of TimeSeries for MsPASS.
Definition TimeSeries.h:14