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

Taper front and/or end of a time seris with a half cosine function. More...

#include <Taper.h>

Inheritance diagram for mspass::algorithms::CosineTaper:
mspass::algorithms::BasicTaper

Public Member Functions

 CosineTaper (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

Taper front and/or end of a time seris with a half cosine function.

A sine taper is a common, simple approach to taper data. When applied at the front it defnes a half cycle of a cosine curve +1.0 in range -pi to 0. On the right it defines the same function for the range 0 to pi. The period of the left and right operator can be different. Turn off left or right by giving illegal start and end points and the operator will silently be only one sided.

Constructor & Destructor Documentation

◆ CosineTaper() [1/2]

mspass::algorithms::CosineTaper::CosineTaper ( )
181 {
182 head = false;
183 tail = false;
184 all = false;
185}

◆ CosineTaper() [2/2]

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

primary constructor.

Defines half-cycle sine taper for front and/or back end of a time range. Zero times before t0head and after t0tail. Taper between t0head and t1head and in opposite sense from t1tail to t0tail.

187 {
188 t0head = t0h;
189 t1head = t1h;
190 t0tail = t0t;
191 t1tail = t1t;
192 if (t1head > t0head)
193 head = true;
194 if (t1tail < t0tail)
195 tail = true;
196 if (head && tail)
197 all = true;
198 else
199 all = false;
200 if (!(head || tail)) {
201 stringstream ss;
202 ss << "CosineTaper constructor: illegal input. No valid taper parameters"
203 << endl
204 << "Input defines front end ramp defined as 0 at " << t0h
205 << " rising to 1 at " << t1h << endl
206 << "Tail end ramp defined with 1 at " << t1t << " dropping to 0 at "
207 << t0t << endl;
208 throw MsPASSError(ss.str(), ErrorSeverity::Invalid);
209 }
210}

Member Function Documentation

◆ apply() [1/2]

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

Implements mspass::algorithms::BasicTaper.

265 {
266 if (head) {
267 if (d.endtime() < t0head) {
268 stringstream ss;
269 ss << "CosineTaper::apply: inconsistent head taper parameters" << endl
270 << "Data endtime=" << d.endtime()
271 << " which is earlier than start of head taper=" << t0head << endl
272 << "Data vector was not altered" << endl;
273 d.elog.log_error("CosineTaper", ss.str(), ErrorSeverity::Complaint);
274 return -1;
275 }
276 int is;
277 double t, wt;
278 for (t = d.t0(); t < t0head; t += d.dt()) {
279 is = d.sample_number(t);
280 if (is >= 0 && is < d.npts()) {
281 for (int k = 0; k < 3; ++k)
282 d.u(k, is) = 0.0;
283 }
284 }
285 for (t = t0head; t < t1head; t += d.dt()) {
286 is = d.sample_number(t);
287 if (is >= 0) {
288 wt = headcos(t0head, t1head, t);
289 for (int k = 0; k < 3; ++k)
290 d.u(k, is) *= wt;
291 }
292 }
293 }
294 if (tail) {
295 if (d.t0() > t0tail) {
296 stringstream ss;
297 ss << "CosineTaper::apply: inconsistent tail taper parameters" << endl
298 << "Data start time=" << d.t0()
299 << " is after the end of the tail taper = " << t0tail << endl
300 << "Data vector was not altered" << endl;
301 d.elog.log_error("CosineTaper", ss.str(), ErrorSeverity::Complaint);
302 return -1;
303 }
304 int is;
305 double t, wt;
306 for (t = d.endtime(); t >= t0tail; t -= d.dt()) {
307 is = d.sample_number(t);
308 if (is >= 0 && is < d.npts()) {
309 for (int k = 0; k < 3; ++k)
310 d.u(k, is) = 0.0;
311 }
312 }
313 for (t = t1tail; t < t0tail; t += d.dt()) {
314 is = d.sample_number(t);
315 if (is >= 0) {
316 wt = tailcos(t0tail, t1tail, t);
317 for (int k = 0; k < 3; ++k)
318 d.u(k, is) *= wt;
319 }
320 }
321 }
322 return 0;
323}
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::CosineTaper::apply ( mspass::seismic::TimeSeries d)
virtual

Implements mspass::algorithms::BasicTaper.

211 {
212 if (head) {
213 if (d.endtime() < t0head) {
214 stringstream ss;
215 ss << "CosineTaper::apply: inconsistent head taper parameters" << endl
216 << "Data endtime=" << d.endtime()
217 << " which is earlier than start of head taper=" << t0head << endl
218 << "Data vector was not altered" << endl;
219 d.elog.log_error("CosineTaper", ss.str(), ErrorSeverity::Complaint);
220 return -1;
221 }
222 int is;
223 double t, wt;
224 for (t = d.t0(); t < t0head; t += d.dt()) {
225 is = d.sample_number(t);
226 if (is >= 0 && is < d.npts())
227 d.s[is] = 0.0;
228 }
229 for (t = t0head; t < t1head; t += d.dt()) {
230 is = d.sample_number(t);
231 if (is >= 0) {
232 wt = headcos(t0head, t1head, t);
233 d.s[is] *= wt;
234 }
235 }
236 }
237 if (tail) {
238 if (d.t0() > t0tail) {
239 stringstream ss;
240 ss << "CosineTaper::apply: inconsistent tail taper parameters" << endl
241 << "Data start time=" << d.t0()
242 << " is after the end of the tail taper = " << t0tail << endl
243 << "Data vector was not altered" << endl;
244 d.elog.log_error("CosineTaper", ss.str(), ErrorSeverity::Complaint);
245 return -1;
246 }
247 int is;
248 double t, wt;
249 for (t = d.endtime(); t >= t0tail; t -= d.dt()) {
250 is = d.sample_number(t);
251 if (is >= 0 && is < d.npts()) {
252 d.s[is] = 0.0;
253 }
254 }
255 for (t = t1tail; t < t0tail; t += d.dt()) {
256 is = d.sample_number(t);
257 if (is >= 0) {
258 wt = tailcos(t0tail, t1tail, t);
259 d.s[is] *= wt;
260 }
261 }
262 }
263 return 0;
264}
double endtime() const noexcept
Definition BasicTimeSeries.h:77
std::vector< double > s
Definition CoreTimeSeries.h:27

◆ get_t0head()

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

Implements mspass::algorithms::BasicTaper.

130{ return t0head; };

◆ get_t0tail()

double mspass::algorithms::CosineTaper::get_t0tail ( ) const
inline
132{ return t0tail; };

◆ get_t1head()

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

Implements mspass::algorithms::BasicTaper.

131{ return t1head; };

◆ get_t1tail()

double mspass::algorithms::CosineTaper::get_t1tail ( ) const
inline
133{ return t1tail; };

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