version  0.0.1
Defines the C++ API for MsPASS
Loading...
Searching...
No Matches
Public Member Functions | Protected Attributes | List of all members
mspass::seismic::DataGap Class Reference
Inheritance diagram for mspass::seismic::DataGap:
mspass::seismic::SeismogramWGaps mspass::seismic::TimeSeriesWGaps

Public Member Functions

 DataGap ()
 
 DataGap (const std::list< mspass::algorithms::TimeWindow > &twlist)
 
 DataGap (const DataGap &parent)
 
bool is_gap (const double ttest)
 
bool has_gap (const mspass::algorithms::TimeWindow twin)
 
bool has_gap ()
 
void add_gap (const mspass::algorithms::TimeWindow tw)
 
std::list< mspass::algorithms::TimeWindowget_gaps () const
 
void clear_gaps ()
 Clear gaps.
 
int number_gaps () const
 
DataGap subset (const mspass::algorithms::TimeWindow tw) const
 
void translate_origin (double time_of_new_origin)
 
DataGapoperator= (const DataGap &parent)
 
DataGapoperator+= (const DataGap &other)
 

Protected Attributes

std::set< mspass::algorithms::TimeWindow, mspass::algorithms::TimeWindowCmpgaps
 Holds data gap definitions. We use an STL set object to define data gaps for any time series object derived from this base class. The set is keyed by a TimeWindow which allows a simple, fast way to define a time range with invalid data.
 

Constructor & Destructor Documentation

◆ DataGap() [1/3]

mspass::seismic::DataGap::DataGap ( )
inline

Default construtor. Does nothing but create empty gap container.

27{};

◆ DataGap() [2/3]

mspass::seismic::DataGap::DataGap ( const std::list< mspass::algorithms::TimeWindow > &  twlist)

Construct with an initial list of TimeWindows defining gaps.

◆ DataGap() [3/3]

mspass::seismic::DataGap::DataGap ( const DataGap parent)
inline
30: gaps(parent.gaps) {};
std::set< mspass::algorithms::TimeWindow, mspass::algorithms::TimeWindowCmp > gaps
Holds data gap definitions. We use an STL set object to define data gaps for any time series object d...
Definition DataGap.h:110

◆ ~DataGap()

virtual mspass::seismic::DataGap::~DataGap ( )
inlinevirtual
31{};

Member Function Documentation

◆ add_gap()

void mspass::seismic::DataGap::add_gap ( const mspass::algorithms::TimeWindow  tw)

Adds a gap to the gap definitions for this data object. Sometimes an algorithm detects or needs to create a gap (e.g. a mute, or a constructor). This function provides a common mechanism to define such a gap in the data.

13 {
14 auto insert_result = this->gaps.insert(tw);
15 if (!insert_result.second) {
16 /* We land here if tw overlaps or duplicates something already in
17 * the gaps container. first in this case contains an iterator to
18 * the potential duplicate. We have to resolve which to keep*/
19 TimeWindow old_tw(*insert_result.first);
20 TimeWindow new_tw;
21 if (tw.start < old_tw.start)
22 new_tw.start = tw.start;
23 else
24 new_tw.start = old_tw.start;
25 if (tw.end > old_tw.end)
26 new_tw.end = tw.end;
27 else
28 new_tw.end = old_tw.end;
29 gaps.erase(insert_result.first);
30 gaps.insert(new_tw);
31 }
32}
double start
Definition TimeWindow.h:17
double end
Definition TimeWindow.h:21

References mspass::algorithms::TimeWindow::end, gaps, and mspass::algorithms::TimeWindow::start.

◆ clear_gaps()

void mspass::seismic::DataGap::clear_gaps ( )
inline

Clear gaps.

It is sometimes necessary to clear gap definitions. This is particularly important when a descendent of this class is cloned and then morphed into something else. This method clears the entire content. This class assumes gaps are an immutable property of recorded data. A subclass could be used to add that functionality.

74 {
75 if (!gaps.empty())
76 gaps.clear();
77 };

References gaps.

◆ get_gaps()

std::list< TimeWindow > mspass::seismic::DataGap::get_gaps ( ) const

Getter returns a list of TimeWindows defining a set of gaps.

55 {
56 std::list<TimeWindow> result;
57 for (auto sptr = this->gaps.begin(); sptr != this->gaps.end(); ++sptr)
58 result.push_back(*sptr);
59 return result;
60}

References gaps.

◆ has_gap() [1/2]

bool mspass::seismic::DataGap::has_gap ( )
inline

Global test to see if data has any gaps defined. Gap processing is expensive and we need this simple method to test to see if the associated object has any gaps defined.

Returns
true if the associated object has any gaps defined.
55{ return (!gaps.empty()); };

References gaps.

◆ has_gap() [2/2]

bool mspass::seismic::DataGap::has_gap ( const mspass::algorithms::TimeWindow  twin)

Checks if a given data segment has a gap. For efficiency it is often useful to ask if a whole segment of data is free of gaps. Most time series algorithms cannot process through data gaps so normal practice would be to drop data with any gaps in a requested time segment.

Returns
true if time segment has any data gaps
Parameters
twintime window of data to test defined by a TimeWindow object
47 {
48 if (gaps.empty())
49 return false;
50 if (gaps.find(twin) == gaps.end())
51 return (false);
52 else
53 return (true);
54}

References gaps.

◆ is_gap()

bool mspass::seismic::DataGap::is_gap ( const double  ttest)

Checks if data at time ttest is a gap or valid data. This function is like the overloaded version with an int argument except it uses a time instead of sample number for the query.

Parameters
ttest- time to be tested.
33 {
34 const double dt(
35 0.001); // used to define small time interval smaller than most sampling
36 if (gaps.empty())
37 return false;
38 TimeWindow twin;
39 twin.start = ttest - dt * 0.5;
40 twin.end = ttest + dt * 0.5;
41 if (gaps.find(twin) == gaps.end())
42 return false;
43 else
44 return true;
45}

References mspass::algorithms::TimeWindow::end, gaps, and mspass::algorithms::TimeWindow::start.

◆ number_gaps()

int mspass::seismic::DataGap::number_gaps ( ) const
inline

Return number of defined gaps.

79{ return gaps.size(); };

References gaps.

◆ operator+=()

DataGap & mspass::seismic::DataGap::operator+= ( const DataGap other)

Add contents of another DataGap container to this one.

103 {
104 for (auto ptr = parent.gaps.begin(); ptr != parent.gaps.end(); ++ptr)
105 this->add_gap(*ptr);
106 return *this;
107}
void add_gap(const mspass::algorithms::TimeWindow tw)
Definition DataGap.cc:13

References add_gap(), and gaps.

◆ operator=()

DataGap & mspass::seismic::DataGap::operator= ( const DataGap parent)

Standard assignment operator.

97 {
98 if (this != (&parent)) {
99 gaps = parent.gaps;
100 }
101 return *this;
102}

References gaps.

◆ subset()

DataGap mspass::seismic::DataGap::subset ( const mspass::algorithms::TimeWindow  tw) const

Return the subset of gaps within a specified time interval.

Parameters
twTimeWindow defining range to be returned. Note overlaps with the edge will be returned with range outside the range defined by tw. If the tw is larger than the range of the current content returns a copy of itself.
61 {
62 /* This could be implemented with the set equal_range method
63 * but these objects are expected to normally be very small
64 * and it is a lot clearer what this algorithm does.
65 * */
66 DataGap result;
67 std::list<TimeWindow> gaplist = this->get_gaps();
68 for (auto twptr = gaplist.begin(); twptr != gaplist.end(); ++twptr) {
69 if (((twptr->end) > tw.start) && ((twptr->start) < tw.end)) {
70 result.add_gap(*twptr);
71 }
72 }
73 return result;
74}
DataGap()
Definition DataGap.h:27
std::list< mspass::algorithms::TimeWindow > get_gaps() const
Definition DataGap.cc:55

References add_gap(), mspass::algorithms::TimeWindow::end, get_gaps(), and mspass::algorithms::TimeWindow::start.

◆ translate_origin()

void mspass::seismic::DataGap::translate_origin ( double  time_of_new_origin)

Shift the times of all gaps by a value.

When used with a TimeSeries or Seismogram the concept of UTC versus relative time requires shifting the time origin. This method should be used in that context or any other context where the data origin is shifted. The number passed as shift is subtracted from all the window start and end times that define data gaps.

85 {
86 std::set<TimeWindow, TimeWindowCmp> translated_gaps;
87 for (auto ptr = this->gaps.begin(); ptr != this->gaps.end(); ++ptr) {
88 TimeWindow tw(*ptr);
89 tw.start -= origin_time;
90 tw.end -= origin_time;
91 translated_gaps.insert(tw);
92 }
93 this->clear_gaps();
94 for (auto ptr = translated_gaps.begin(); ptr != translated_gaps.end(); ++ptr)
95 this->add_gap(*ptr);
96}
void clear_gaps()
Clear gaps.
Definition DataGap.h:74

References add_gap(), clear_gaps(), mspass::algorithms::TimeWindow::end, gaps, and mspass::algorithms::TimeWindow::start.


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