version  0.0.1
Defines the C++ API for MsPASS
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. More...
 
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/2]

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

Default construtor. Does nothing but create empty gap container.

28 {};

◆ DataGap() [2/2]

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

Construct with an initial list of TimeWindows defining gaps.

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.

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

References mspass::algorithms::TimeWindow::end, 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.

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

References gaps.

◆ get_gaps()

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

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

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

◆ 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.
56 {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
50 {
51  if(gaps.empty())return false;
52  if(gaps.find(twin)==gaps.end())
53  return(false);
54  else
55  return(true);
56 }

◆ 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.
37 {
38  const double dt(0.001); // used to define small time interval smaller than most sampling
39  if(gaps.empty())return false;
40  TimeWindow twin;
41  twin.start = ttest - dt*0.5;
42  twin.end = ttest + dt*0.5;
43  if(gaps.find(twin)==gaps.end())
44  return false;
45  else
46  return true;
47 }

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

◆ number_gaps()

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

Return number of defined gaps.

77 {return gaps.size();};

References gaps.

◆ operator+=()

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

Add contents of another DataGap container to this one.

114 {
115  for(auto ptr=parent.gaps.begin();ptr!=parent.gaps.end();++ptr) this->add_gap(*ptr);
116  return *this;
117 }
void add_gap(const mspass::algorithms::TimeWindow tw)
Definition: DataGap.cc:14

References gaps.

◆ operator=()

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

Standard assignment operator.

106 {
107  if(this!=(&parent))
108  {
109  gaps=parent.gaps;
110  }
111  return *this;
112 }

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.
65 {
66  /* This could be implemented with the set equal_range method
67  * but these objects are expected to normally be very small
68  * and it is a lot clearer what this algorithm does.
69  * */
70  DataGap result;
71  std::list<TimeWindow> gaplist = this->get_gaps();
72  for(auto twptr= gaplist.begin();twptr!=gaplist.end();++twptr)
73  {
74  if( ((twptr->end)>tw.start) && ((twptr->start)<tw.end))
75  {
76  result.add_gap(*twptr);
77  }
78  }
79  return result;
80 }
Definition: DataGap.h:25
std::list< mspass::algorithms::TimeWindow > get_gaps() const
Definition: DataGap.cc:57

References add_gap(), mspass::algorithms::TimeWindow::end, 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.

92 {
93  std::set<TimeWindow,TimeWindowCmp> translated_gaps;
94  for(auto ptr=this->gaps.begin();ptr!=this->gaps.end();++ptr)
95  {
96  TimeWindow tw(*ptr);
97  tw.start -= origin_time;
98  tw.end -= origin_time;
99  translated_gaps.insert(tw);
100  }
101  this->clear_gaps();
102  for(auto ptr=translated_gaps.begin();ptr!=translated_gaps.end();++ptr)
103  this->add_gap(*ptr);
104 }
void clear_gaps()
Clear gaps.
Definition: DataGap.h:75

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


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