version  0.0.1
Defines the C++ API for MsPASS
Loading...
Searching...
No Matches
Public Member Functions | Friends | List of all members
mspass::algorithms::LinearTaper Class Reference

Used to construct an operator to apply a linear taper to either end. More...

#include <Taper.h>

Inheritance diagram for mspass::algorithms::LinearTaper:
mspass::algorithms::BasicTaper

Public Member Functions

 LinearTaper (const double t0head, const double t1head, const double t1tail, const double t0tail)
 primary constructor.
 
int apply (mspass::seismic::TimeSeries &d)
 
int apply (mspass::seismic::Seismogram &d)
 
double get_t0head () const
 
double get_t1head () const
 
double get_t0tail () const
 
double get_t1tail () const
 
- Public Member Functions inherited from mspass::algorithms::BasicTaper
void enable_head ()
 
void disable_head ()
 
void enable_tail ()
 
void disable_tail ()
 
bool head_is_enabled ()
 
bool tail_is_enable ()
 

Friends

class boost::serialization::access
 

Additional Inherited Members

- Protected Attributes inherited from mspass::algorithms::BasicTaper
bool head
 
bool tail
 
bool all
 

Detailed Description

Used to construct an operator to apply a linear taper to either end.

Linear tapers are defined here as a time spanning a ramp running from 0 to 1. Data will be zeroed on each end of a 0 mark and a linear weight applied between 0 points and 1 points. Postive ramp slope on left and negative slope ramp on right.

Constructor & Destructor Documentation

◆ LinearTaper() [1/2]

mspass::algorithms::LinearTaper::LinearTaper ( )
7 {
8 head = false;
9 tail = false;
10 all = false;
11}

◆ LinearTaper() [2/2]

mspass::algorithms::LinearTaper::LinearTaper ( const double  t0head,
const double  t1head,
const double  t1tail,
const double  t0tail 
)

primary constructor.

Defines linear taper for front and/or back end of a time range. Zero times before t0head and after t0tail. Linear ramp between t0head and t1head and in opposite sense from t1tail to t0tail. Setting 0 value = 1 value should be used as a signal to disable.

13 {
14 t0head = t0h;
15 t1head = t1h;
16 t0tail = t0t;
17 t1tail = t1t;
18 if (t1head > t0head)
19 head = true;
20 else
21 head = false;
22 if (t1tail < t0tail)
23 tail = true;
24 else
25 tail = false;
26 if (head && tail)
27 all = true;
28 else
29 all = false;
30 if (!(head || tail)) {
31 stringstream ss;
32 ss << "LinearTaper constructor: illegal input. No valid taper parameters"
33 << endl
34 << "Input defines front end ramp defined as 0 at " << t0h
35 << " rising to 1 at " << t1h << endl
36 << "Tail end ramp defined with 1 at " << t1t << " dropping to 0 at "
37 << t0t << endl;
38 throw MsPASSError(ss.str(), ErrorSeverity::Invalid);
39 }
40}

Member Function Documentation

◆ apply() [1/2]

int mspass::algorithms::LinearTaper::apply ( mspass::seismic::Seismogram d)
virtual

Implements mspass::algorithms::BasicTaper.

97 {
98 int k;
99 double rampslope;
100 if (head) {
101 if (d.endtime() < t0head) {
102 stringstream ss;
103 ss << "LinearTaper::apply: inconsistent head taper parameters" << endl
104 << "Data endtime=" << d.endtime()
105 << " which is earlier than start of head taper=" << t0head << endl
106 << "Data vector was not altered" << endl;
107 d.elog.log_error("LinearTaper", ss.str(), ErrorSeverity::Complaint);
108 return -1;
109 }
110 int is;
111 double t, wt;
112 for (t = d.t0(); t < t0head; t += d.dt()) {
113 is = d.sample_number(t);
114 if (is >= 0 && is < d.npts()) {
115 for (k = 0; k < 3; ++k)
116 d.u(k, is) = 0.0;
117 }
118 }
119 rampslope = 1.0 / (t1head - t0head);
120 for (t = t0head; t < t1head; t += d.dt()) {
121 is = d.sample_number(t);
122 if (is >= 0) {
123 wt = rampslope * (t - t0head);
124 for (k = 0; k < 3; ++k)
125 d.u(k, is) *= wt;
126 }
127 }
128 }
129 if (tail) {
130 if (d.t0() > t0tail) {
131 stringstream ss;
132 ss << "LinearTaper::apply: inconsistent tail taper parameters" << endl
133 << "Data start time=" << d.t0()
134 << " is after the end of the tail taper = " << t0tail << endl
135 << "Data vector was not altered" << endl;
136 MsPASSError merr(ss.str(), ErrorSeverity::Complaint);
137 d.elog.log_error("LinearTaper", ss.str(), ErrorSeverity::Complaint);
138 return -1;
139 }
140 int is;
141 double t, wt;
142 for (t = d.endtime(); t >= t0tail; t -= d.dt()) {
143 is = d.sample_number(t);
144 if (is >= 0 && is < d.npts()) {
145 for (k = 0; k < 3; ++k)
146 d.u(k, is) = 0.0;
147 }
148 }
149 rampslope = 1.0 / (t0tail - t1tail);
150 for (t = t0tail; t >= t1tail; t -= d.dt()) {
151 is = d.sample_number(t);
152 if (is >= 0) {
153 wt = rampslope * (t - t1tail);
154 for (k = 0; k < 3; ++k)
155 d.u(k, is) *= wt;
156 }
157 }
158 }
159 return 0;
160}
size_t npts() const
Definition BasicTimeSeries.h:171
double t0() const
Definition BasicTimeSeries.h:174
int sample_number(double t) const
Definition BasicTimeSeries.h:72
double dt() const
Definition BasicTimeSeries.h:153
mspass::utility::dmatrix u
Definition CoreSeismogram.h:52
double endtime() const noexcept
Definition CoreSeismogram.h:497
int log_error(const mspass::utility::MsPASSError &merr)
Definition ErrorLogger.cc:72

◆ apply() [2/2]

int mspass::algorithms::LinearTaper::apply ( mspass::seismic::TimeSeries d)
virtual

Implements mspass::algorithms::BasicTaper.

41 {
42 double rampslope;
43 if (head) {
44 if (d.endtime() < t0head) {
45 stringstream ss;
46 ss << "LinearTaper::apply: inconsistent head taper parameters" << endl
47 << "Data endtime=" << d.endtime()
48 << " which is earlier than start of head taper=" << t0head << endl
49 << "Data vector was not altered" << endl;
50 d.elog.log_error("LinearTaper", ss.str(), ErrorSeverity::Complaint);
51 return -1;
52 }
53 int is;
54 double t, wt;
55 for (t = d.t0(); t < t0head; t += d.dt()) {
56 is = d.sample_number(t);
57 if (is >= 0 && is < d.npts())
58 d.s[is] = 0.0;
59 }
60 rampslope = 1.0 / (t1head - t0head);
61 for (t = t0head; t < t1head; t += d.dt()) {
62 is = d.sample_number(t);
63 if (is >= 0) {
64 wt = rampslope * (t - t0head);
65 d.s[is] *= wt;
66 }
67 }
68 }
69 if (tail) {
70 if (d.t0() > t0tail) {
71 stringstream ss;
72 ss << "LinearTaper::apply: inconsistent tail taper parameters" << endl
73 << "Data start time=" << d.t0()
74 << " is after the end of the tail taper = " << t0tail << endl
75 << "Data vector was not altered" << endl;
76 d.elog.log_error("LinearTaper", ss.str(), ErrorSeverity::Complaint);
77 return -1;
78 }
79 int is;
80 double t, wt;
81 for (t = d.endtime(); t >= t0tail; t -= d.dt()) {
82 is = d.sample_number(t);
83 if (is >= 0 && is < d.npts())
84 d.s[is] = 0.0;
85 }
86 rampslope = 1.0 / (t0tail - t1tail);
87 for (t = t0tail; t >= t1tail; t -= d.dt()) {
88 is = d.sample_number(t);
89 if (is >= 0) {
90 wt = rampslope * (t0tail - t);
91 d.s[is] *= wt;
92 }
93 }
94 }
95 return 0;
96}
double endtime() const noexcept
Definition BasicTimeSeries.h:77
std::vector< double > s
Definition CoreTimeSeries.h:27

◆ get_t0head()

double mspass::algorithms::LinearTaper::get_t0head ( ) const
inlinevirtual

Implements mspass::algorithms::BasicTaper.

91{ return t0head; };

◆ get_t0tail()

double mspass::algorithms::LinearTaper::get_t0tail ( ) const
inline
93{ return t0tail; };

◆ get_t1head()

double mspass::algorithms::LinearTaper::get_t1head ( ) const
inlinevirtual

Implements mspass::algorithms::BasicTaper.

92{ return t1head; };

◆ get_t1tail()

double mspass::algorithms::LinearTaper::get_t1tail ( ) const
inline
94{ return t1tail; };

The documentation for this class was generated from the following files: