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