MsPASS C++ API  2.4.1.dev4+g92330b7a
Defines the C++ API for MsPASS
Loading...
Searching...
No Matches
Public Member Functions | Public Attributes | List of all members
mspass::algorithms::SegmentVectorProperties Class Reference
Collaboration diagram for mspass::algorithms::SegmentVectorProperties:
Collaboration graph
[legend]

Public Member Functions

 SegmentVectorProperties ()
 
 SegmentVectorProperties (const std::vector< TimeSeries > &segments)
 
 SegmentVectorProperties (const SegmentVectorProperties &parent)
 

Public Attributes

bool dt_constant
 
bool has_dead_components
 
bool is_sorted
 
bool has_overlaps
 
bool has_gaps
 
int number_live
 
int first_live
 
double t0
 
double endtime
 
double dt
 
size_t spliced_nsamp
 
ErrorLogger elog
 

Detailed Description

File scope class to enscapsulate set of possible data problems.

Merging multiple data segments to a single time series, which is a common need with continous data, is prone to a number of practical problems. Clock issues and the design of modern digitizers can cause a mismatch in time computed by dt*nsamp and data time tags with formats like miniseed. This can create apparent gaps or overlaps. This class is intended to be used to scan a vector of time-sorted segment to flag issues that need to be handled downstream in algorithms later in this file. Issues it addresses at present are:

  1. irregular dt
  2. segments marked dead
  3. overlaps
  4. gaps
  5. Computes the length of the data being merged. Callers should test that that number is not absurd and could cause a memory alloc fault.

All attributes of this class are intentionally public as it should be thought of as a struct with convenient constructors.

Constructor & Destructor Documentation

◆ SegmentVectorProperties() [1/3]

mspass::algorithms::SegmentVectorProperties::SegmentVectorProperties ( )

Construct an empty property set with conservative defaults.

81 : elog() {
82 dt_constant = true;
83 has_dead_components = false;
84 is_sorted = true;
85 has_overlaps = false;
86 has_gaps = false;
87 number_live = 0;
88 first_live = 0;
89 t0 = 0.0;
90 endtime = 0.0;
91 dt = 0.0;
92 spliced_nsamp = 0;
93}
size_t spliced_nsamp
Definition splicing.cc:67
bool has_overlaps
Definition splicing.cc:53
double dt
Definition splicing.cc:65
double t0
Definition splicing.cc:61
bool has_gaps
Definition splicing.cc:55
bool has_dead_components
Definition splicing.cc:49
int number_live
Definition splicing.cc:57
bool dt_constant
Definition splicing.cc:47
int first_live
Definition splicing.cc:59
ErrorLogger elog
Definition splicing.cc:69
double endtime
Definition splicing.cc:63
bool is_sorted
Definition splicing.cc:51

References dt, dt_constant, endtime, first_live, has_dead_components, has_gaps, has_overlaps, is_sorted, number_live, spliced_nsamp, and t0.

◆ SegmentVectorProperties() [2/3]

mspass::algorithms::SegmentVectorProperties::SegmentVectorProperties ( const std::vector< TimeSeries > &  segments)

Scan a vector of segments and summarize ordering, gaps, overlaps, and size.

Parameters
segmentsinput segments to inspect before splicing.
110 {
111 /* Return a type conversion of the input when there is only one
112 segment - nothing to splice in that case. Error if it is empty */
113 if (segments.size() == 1) {
114 dt_constant = true;
115 has_dead_components = false;
116 is_sorted = true;
117 has_overlaps = false;
118 has_gaps = false;
119 if (segments[0].live()) {
120 number_live = 1;
121 first_live = 0;
122 t0 = segments[0].t0();
123 endtime = segments[0].endtime();
124 dt = segments[0].dt();
125 this->spliced_nsamp = segments[0].npts();
126 } else {
127 number_live = 0;
128 first_live = -1;
129 t0 = 0.0;
130 dt = 0.0;
131 endtime = 0.0;
132 this->spliced_nsamp = 0;
133 }
134 } else if (segments.size() == 0) {
135 dt_constant = true;
136 has_dead_components = false;
137 is_sorted = true;
138 has_overlaps = false;
139 has_gaps = false;
140 number_live = 0;
141 first_live = -1;
142 t0 = 0.0;
143 dt = 0.0;
144 endtime = 0.0;
145 this->spliced_nsamp = 0;
146 } else {
147 double test_dt, dtfrac;
148 double first_t0, previous_t0, previous_endtime;
149 /* This algorithm requires the test above that guarantees number of segments
150 is more than 1. Some complexity to handle a dead member 0 is needed. */
151 bool this_is_first(true);
152 has_overlaps = false;
153 is_sorted = true; // initialization
154 has_dead_components = false;
155 /* Declare a sample mismatch if nondimensional sample interval mismatch is
156 less than this constant. */
157 const double dt_fraction_mismatch(0.001);
158 for (size_t i = 0; i < segments.size(); ++i) {
159 if (segments[i].dead()) {
160 has_dead_components = true;
161 continue;
162 }
163 if (this_is_first) {
164 this->dt_constant = true;
165 this->first_live = i;
166 first_t0 = segments[i].t0();
167 previous_t0 = first_t0;
168 test_dt = segments[i].dt();
169 previous_endtime = segments[i].endtime();
170 this_is_first = false;
171 this->dt = test_dt;
172 this->t0 = first_t0;
173 this->number_live = 1;
174 } else {
175 /* This could be true multiple times if data were not sorted.
176 Purpose of this boolean is to define a serious error condition
177 that functions using this class must handle */
178 if (segments[i].t0() < previous_t0)
179 is_sorted = false;
180 /* Test for overlaps - note sign is important */
181 if ((previous_endtime + test_dt * TIME_TEAR_TOLERANCE) >
182 segments[i].t0())
183 has_overlaps = true;
184 /* test for gaps */
185 if ((segments[i].t0() - previous_endtime - test_dt) / test_dt >
186 TIME_TEAR_TOLERANCE)
187 has_gaps = true;
188 /* Check for sample interval mismatch */
189 dtfrac = fabs(segments[i].dt() - test_dt) / test_dt;
190 if (dtfrac > dt_fraction_mismatch)
191 dt_constant = false;
192 previous_endtime = segments[i].endtime();
193 previous_t0 = segments[i].t0();
194 ++this->number_live;
195 }
196 }
197 this->endtime = previous_endtime;
198 this->spliced_nsamp = lround((previous_endtime - this->t0) / this->dt);
199 ++this->spliced_nsamp; // nsamp is always one sample longer than intervals
200 }
201}

References dt, dt_constant, endtime, first_live, has_dead_components, has_gaps, has_overlaps, is_sorted, number_live, spliced_nsamp, and t0.

◆ SegmentVectorProperties() [3/3]

mspass::algorithms::SegmentVectorProperties::SegmentVectorProperties ( const SegmentVectorProperties parent)

Standard copy constructor.

Parameters
parentproperty set to copy.
96 : elog(parent.elog) {
97 dt_constant = parent.dt_constant;
98 has_dead_components = parent.has_dead_components;
99 is_sorted = parent.is_sorted;
100 has_overlaps = parent.has_overlaps;
101 has_gaps = parent.has_gaps;
102 number_live = parent.number_live;
103 first_live = parent.first_live;
104 t0 = parent.t0;
105 endtime = parent.endtime;
106 dt = parent.dt;
107 spliced_nsamp = parent.spliced_nsamp;
108}

References dt, dt_constant, endtime, first_live, has_dead_components, has_gaps, has_overlaps, is_sorted, number_live, spliced_nsamp, and t0.

Member Data Documentation

◆ dt

double mspass::algorithms::SegmentVectorProperties::dt

Sample interval used for the spliced output when dt is constant.

◆ dt_constant

bool mspass::algorithms::SegmentVectorProperties::dt_constant

True when all live segments have the same sample interval.

◆ elog

ErrorLogger mspass::algorithms::SegmentVectorProperties::elog

Messages formed while scanning input segments for downstream logging.

◆ endtime

double mspass::algorithms::SegmentVectorProperties::endtime

Latest end time of the live segments.

◆ first_live

int mspass::algorithms::SegmentVectorProperties::first_live

Index of the first live segment, or -1 when none are live.

◆ has_dead_components

bool mspass::algorithms::SegmentVectorProperties::has_dead_components

True when at least one input segment is marked dead.

◆ has_gaps

bool mspass::algorithms::SegmentVectorProperties::has_gaps

True when adjacent live segments have a gap beyond the time-tear tolerance.

◆ has_overlaps

bool mspass::algorithms::SegmentVectorProperties::has_overlaps

True when adjacent live segments overlap beyond the time-tear tolerance.

◆ is_sorted

bool mspass::algorithms::SegmentVectorProperties::is_sorted

True when live input segments are ordered by increasing start time.

◆ number_live

int mspass::algorithms::SegmentVectorProperties::number_live

Number of live segments found in the input vector.

◆ spliced_nsamp

size_t mspass::algorithms::SegmentVectorProperties::spliced_nsamp

Number of samples needed to hold the spliced output.

◆ t0

double mspass::algorithms::SegmentVectorProperties::t0

Earliest start time of the live segments.


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