version  0.0.1
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
19public:
20 BasicTaper() {
21 head = false;
22 tail = false;
23 all = false;
24 };
25 virtual ~BasicTaper() {};
26 virtual int apply(mspass::seismic::TimeSeries &d) = 0;
27 virtual int apply(mspass::seismic::Seismogram &d) = 0;
28 void enable_head() { head = true; };
29 void disable_head() {
30 head = false;
31 all = false;
32 };
33 void enable_tail() { tail = true; };
34 void disable_tail() {
35 tail = false;
36 all = false;
37 };
38 bool head_is_enabled() {
39 if (head || all) {
40 return true;
41 }
42 return false;
43 };
44 bool tail_is_enable() {
45 if (tail || all) {
46 return true;
47 }
48 return false;
49 };
50 /* These virtual methods are a bit of a design flaw as they don't
51 apply well to the vector taper, but we implement them there to just
52 throw an exception */
53 virtual double get_t0head() const = 0;
54 virtual double get_t1head() const = 0;
55
56protected:
57 /* A taper can be head, tail, or all. For efficiency it is required
58 implementations set these three booleans. head or tail may be true.
59 all means a single function is needed to defne the taper. */
60 bool head, tail, all;
61
62private:
63 friend class boost::serialization::access;
64 template <class Archive>
65 void serialize(Archive &ar, const unsigned int version) {
66 ar & head;
67 ar & tail;
68 ar & all;
69 };
70};
77class LinearTaper : public BasicTaper {
78public:
87 LinearTaper(const double t0head, const double t1head, const double t1tail,
88 const double t0tail);
89 int apply(mspass::seismic::TimeSeries &d);
90 int apply(mspass::seismic::Seismogram &d);
91 double get_t0head() const { return t0head; };
92 double get_t1head() const { return t1head; };
93 double get_t0tail() const { return t0tail; };
94 double get_t1tail() const { return t1tail; };
95
96private:
97 double t0head, t1head, t1tail, t0tail;
98 friend class boost::serialization::access;
99 template <class Archive>
100 void serialize(Archive &ar, const unsigned int version) {
101 ar &boost::serialization::base_object<BasicTaper>(*this);
102 ar & t0head;
103 ar & t1head;
104 ar & t1tail;
105 ar & t0tail;
106 };
107};
116class CosineTaper : public BasicTaper {
117public:
118 CosineTaper();
125 CosineTaper(const double t0head, const double t1head, const double t1tail,
126 const double t0tail);
127 /* these need to post to history using new feature*/
128 int apply(mspass::seismic::TimeSeries &d);
129 int apply(mspass::seismic::Seismogram &d);
130 double get_t0head() const { return t0head; };
131 double get_t1head() const { return t1head; };
132 double get_t0tail() const { return t0tail; };
133 double get_t1tail() const { return t1tail; };
134
135private:
136 double t0head, t1head, t1tail, t0tail;
137 friend class boost::serialization::access;
138 template <class Archive>
139 void serialize(Archive &ar, const unsigned int version) {
140 ar &boost::serialization::base_object<BasicTaper>(*this);
141 ar & t0head;
142 ar & t1head;
143 ar & t1tail;
144 ar & t0tail;
145 };
146};
152class VectorTaper : public BasicTaper {
153public:
154 VectorTaper();
155 VectorTaper(const std::vector<double> taperdata);
156 int apply(mspass::seismic::TimeSeries &d);
157 int apply(mspass::seismic::Seismogram &d);
158 void disable() { all = false; };
159 void enable() {
160 if (taper.size() > 0)
161 all = true;
162 };
163 std::vector<double> get_taper() { return taper; };
164 double get_t0head() const {
165 std::cerr << "get_t0head not implemented for VectorTaper";
166 return 0.0;
167 };
168 double get_t1head() const {
169 std::cerr << "get_t1head not implemented for VectorTaper";
170 return 0.0;
171 };
172
173private:
174 std::vector<double> taper;
175 friend class boost::serialization::access;
176 template <class Archive>
177 void serialize(Archive &ar, const unsigned int version) {
178 ar &boost::serialization::base_object<BasicTaper>(*this);
179 ar & taper;
180 };
181};
198class TopMute {
199public:
201 TopMute();
219 TopMute(const double t0, const double t1, const std::string type);
221 TopMute(const TopMute &parent);
223 ~TopMute();
225 TopMute &operator=(const TopMute &parent);
232 double get_t0() const { return taper->get_t0head(); };
235 double get_t1() const { return taper->get_t1head(); };
238 std::string taper_type() const;
239
240private:
241 /* We use a shared_ptr to the base class. That allows inheritance to
242 handle the actual form - a classic oop use of a base class. the shared_ptr
243 allows us to get around an abstract base problem. May be other solutions
244 but this should be ok. There may be a problem in parallel environment,
245 however, as not sure how this would be handled by spark or dask. this is
246 in that pickable realm.*/
247 std::shared_ptr<BasicTaper> taper;
248 /* I tried this but couldn't make it work. It compiles but dies at
249 runtime with mysterious errors for me. Internet conversations suggest
250 shared_ptr data with polymorphic types like this is problematic.
251 For mspass the python bindings with pickle are more what is needed anyway
252 so serialization of TopMute is purely done in the pybind11 wrappers.
253 Turns out to be easy because the TopMute taper is actually define donly
254 by two paramters (t0head and t1head).
255 friend class boost::serialization::access;
256 template<class Archive>
257 void serialize(Archive & ar, const unsigned int version)
258 {
259 ar & taper;
260 };
261 */
262};
263} // namespace mspass::algorithms
264#endif // End guard
Definition Taper.h:18
Taper front and/or end of a time seris with a half cosine function.
Definition Taper.h:116
Used to construct an operator to apply a linear taper to either end.
Definition Taper.h:77
Mute operator for "top" of signals defined first smaple forward.
Definition Taper.h:198
double get_t0() const
Definition Taper.h:232
TopMute & operator=(const TopMute &parent)
Definition Taper.cc:407
~TopMute()
Definition Taper.cc:377
std::string taper_type() const
Definition Taper.cc:437
double get_t1() const
Definition Taper.h:235
TopMute()
Definition Taper.cc:376
int apply(mspass::seismic::TimeSeries &d)
Definition Taper.cc:413
Definition Taper.h:152
Implemntation of Seismogram for MsPASS.
Definition Seismogram.h:14
Implemntation of TimeSeries for MsPASS.
Definition TimeSeries.h:14