STFINV library: seek source wavelet correction filter
stfinvbase.cc
Go to the documentation of this file.
1 
37 #define STFINV_STFINVBASE_CC_VERSION \
38  "STFINV_STFINVBASE_CC V1.2"
39 
40 #include <sstream>
41 #include <cmath>
42 #include <stfinv/stfinvbase.h>
45 #include <stfinv/debug.h>
46 
47 namespace stfinv {
48 
54  const stfinv::Waveform& stf,
55  const stfinv::Tvectorofpairs& pairs,
56  const std::string& parameters)
57  : Mtriples(triples), Mstf(stf), Mpairs(pairs),
58  Mweights(0,triples.size()-1)
59  {
60  this->initialize(parameters);
61  } // STFBaseEngine::STFBaseEngine(const stfinv::Tvectoroftriples& triples,
62 
63  /*----------------------------------------------------------------------*/
64 
70  const stfinv::Waveform& stf,
71  const std::string& parameters)
72  : Mtriples(triples), Mstf(stf), Mweights(0,triples.size()-1)
73  {
74  Mpairs.clear();
75  this->initialize(parameters);
76  } // STFBaseEngine::STFBaseEngine(const stfinv::Tvectoroftriples& triples,
77 
78  /*----------------------------------------------------------------------*/
79 
91  void STFBaseEngine::initialize(const std::string& parameters)
92  {
93  this->parseparameters(parameters);
94 
95  // extract parameters
96  {
97  std::istringstream is(this->parameter("DEBUG","0"));
98  is >> Mdebug;
99  }
100  STFINV_debug(Mdebug>0, "STFBaseEngine::STFBaseEngine",
101  "initializing base class");
102  Mverbose=(this->parameter("verbose","false")=="true");
103  if (this->parameterisset("exp"))
104  {
105  double k;
106  std::istringstream is(this->parameter("exp","0."));
107  is >> k;
108  for (unsigned int i=0; i<Mtriples.size(); ++i)
109  {
110  double offset=Mtriples[i].offset();
111  Mweights(i)=pow(offset,k);
112  }
113  }
114  else
115  {
116  Mweights=1.;
117  }
118 
119  this->checkconsistency();
120 
121  // align index ranges; first index will be zero
122  if (Mstf.series.first()!=0) { Mstf.series.shift(-Mstf.series.first()); }
123 
124  {
125  stfinv::Tvectoroftriples::iterator I=Mtriples.begin();
126  while (I!=Mtriples.end())
127  {
128  if (I->data.first()!=0) { I->data.shift(-(I->data.first())); }
129  if (I->synthetics.first()!=0)
130  { I->synthetics.shift(-(I->synthetics.first())); }
131  if (I->convolvedsynthetics.first()!=0)
132  { I->convolvedsynthetics.shift(-(I->convolvedsynthetics.first())); }
133  ++I;
134  } // while (I!=Mtriples.end())
135  }
136 
137  {
138  stfinv::Tvectorofpairs::iterator I=Mpairs.begin();
139  while (I!=Mpairs.end())
140  {
141  if (I->synthetics.first()!=0)
142  { I->synthetics.shift(-(I->synthetics.first())); }
143  if (I->convolvedsynthetics.first()!=0)
144  { I->convolvedsynthetics.shift(-(I->convolvedsynthetics.first())); }
145  ++I;
146  } // while (I!=Mpairs.end())
147  }
148  } // void STFBaseEngine::initialize(const std::string& parameters)
149 
150  /*----------------------------------------------------------------------*/
151 
160  {
161  const unsigned int& n=Mstf.sampling.n;
162  const double& dt=Mstf.sampling.dt;
164  "inconsistent number of samples");
165  const double tolerance=1.e-4;
166 
167  {
168  stfinv::Tvectoroftriples::const_iterator I=Mtriples.begin();
169  while (I!=Mtriples.end())
170  {
171  CTripleHeader header=I->header;
172  STFINV_assert(header.sampling.n==n,
173  "inconsistent number of samples");
174  STFINV_assert(header.sampling.n==I->data.size(),
175  "inconsistent number of samples");
176  STFINV_assert(header.sampling.n==I->synthetics.size(),
177  "inconsistent number of samples");
178  STFINV_assert(header.sampling.n==I->convolvedsynthetics.size(),
179  "inconsistent number of samples");
180  STFINV_assert(std::abs(1.-header.sampling.dt/dt)<tolerance,
181  "inconsistent values of sampling interval");
182  ++I;
183  } // while (I!=Mtriples.end())
184  }
185 
186  {
187  stfinv::Tvectorofpairs::const_iterator I=Mpairs.begin();
188  while (I!=Mpairs.end())
189  {
190  CWaveformHeader sampling=I->sampling;
191  STFINV_assert(sampling.n==n,
192  "inconsistent number of samples");
193  STFINV_assert(sampling.n==I->synthetics.size(),
194  "inconsistent number of samples");
195  STFINV_assert(sampling.n==I->convolvedsynthetics.size(),
196  "inconsistent number of samples");
197  STFINV_assert(std::abs(1.-sampling.dt/dt)<tolerance,
198  "inconsistent values of sampling interval");
199  ++I;
200  } // while (I!=Mpairs.end())
201  }
202  }
203 
204  /*----------------------------------------------------------------------*/
205 
206  void STFBaseEngine::help(std::ostream& os) const
207  {
209  } // void STFBaseEngine::help(std::ostream& os) const
210 
211  /*----------------------------------------------------------------------*/
212 
213  void STFBaseEngine::classhelp(std::ostream& os)
214  {
216  } // void STFBaseEngine::classhelp(std::ostream& os)
217 
218  /*----------------------------------------------------------------------*/
219 
220  void STFBaseEngine::usage(std::ostream& os) const
221  {
223  } // void STFBaseEngine::usage(std::ostream& os) const
224 
225  /*----------------------------------------------------------------------*/
226 
227  void STFBaseEngine::classusage(std::ostream& os)
228  {
230  } // void STFBaseEngine::classusage(std::ostream& os)
231 
232  /*----------------------------------------------------------------------*/
233 
241  void STFBaseEngine::parseparameters(std::string parameters)
242  {
243  while (parameters.length()>0)
244  {
245  std::string value=stfinv::tools::clipstring(parameters,":");
246  std::string key
248  if (value.length()==0)
249  {
250  this->Mparamap[key]="true";
251  }
252  else
253  {
254  this->Mparamap[key]=value;
255  }
256  } // while (parameters.length()>0)
257  } // void STFBaseEngine::parseparameters(std::string parameters)
258 
259  /*----------------------------------------------------------------------*/
260 
266  bool STFBaseEngine::parameterisset(const std::string& key) const
267  {
268  return (Mparamap.count(key)>0);
269  } // bool STFBaseEngine::parameter(const std::string& key) const
270 
271  /*----------------------------------------------------------------------*/
272 
279  std::string STFBaseEngine::parameter(const std::string& key,
280  const std::string& defvalue) const
281  {
282  std::string retval;
283  if (this->parameterisset(key))
284  {
285  retval=Mparamap[key];
286  }
287  else
288  {
289  retval=defvalue;
290  }
291  return retval;
292  } // std::string STFBaseEngine::parameter()
293 
294  /*----------------------------------------------------------------------*/
295 
296  const char* STFBaseEngine::name() const
297  {
298  return("STFBaseEngine");
299  } // const char const* STFBaseEngine::name() const
300 
301  /*----------------------------------------------------------------------*/
302 
303  Tseries::Tcoc STFBaseEngine::recording(const unsigned int& i) const
304  {
305  this->checkreceiverindex(i);
306  return(Mtriples[i].data);
307  }
308 
309  /*----------------------------------------------------------------------*/
310 
311  Tseries::Tcoc STFBaseEngine::synthetic(const unsigned int& i) const
312  {
313  this->checkreceiverindex(i);
314  return(Mtriples[i].synthetics);
315  }
316 
317  /*----------------------------------------------------------------------*/
318 
319  Tseries STFBaseEngine::convolvedsynthetic(const unsigned int& i) const
320  {
321  this->checkreceiverindex(i);
322  return(Mtriples[i].convolvedsynthetics);
323  }
324 
325  /*----------------------------------------------------------------------*/
326 
327  Tseries::Tcoc STFBaseEngine::series(const unsigned int& i) const
328  {
329  this->checkseriesindex(i);
330  return(Mpairs[i].synthetics);
331  }
332 
333  /*----------------------------------------------------------------------*/
334 
335  Tseries STFBaseEngine::convolvedseries(const unsigned int& i) const
336  {
337  this->checkseriesindex(i);
338  return(Mpairs[i].convolvedsynthetics);
339  }
340 
341  /*----------------------------------------------------------------------*/
342 
343  void STFBaseEngine::checkreceiverindex(const unsigned int& i) const
344  {
345  STFINV_assert(i<Mtriples.size(),
346  "ERROR: receiver index out of range");
347  }
348 
349  /*----------------------------------------------------------------------*/
350 
351  void STFBaseEngine::checkseriesindex(const unsigned int& i) const
352  {
353  STFINV_assert(i<Mpairs.size(),
354  "ERROR: series index out of range");
355  }
356 
357  /*======================================================================*/
358 
359  double WaveformTriple::offset() const
360  {
361  double dx=header.rx-header.sx;
362  double dy=header.ry-header.sy;
363  return (sqrt(dx*dx+dy*dy));
364  } // double WaveformTriple::offset() const
365 
366 } // namespace stfinv
367 
368 /* ----- END OF stfinvbase.cc ----- */
struct CWaveformHeader sampling
Temporal sampling of all three waveforms.
bool parameterisset(const std::string &key) const
check is parameter was set by user
Definition: stfinvbase.cc:266
void checkseriesindex(const unsigned int &i) const
check for vaid index off additional time series pair
Definition: stfinvbase.cc:351
std::vector< stfinv::WaveformPair > Tvectorofpairs
Vector of pairs.
Definition: stfinvbase.h:125
static void classhelp(std::ostream &os=std::cout)
print online help
Definition: stfinvbase.cc:213
void parseparameters(std::string parameters)
parse parameters and store them in Mparamap
Definition: stfinvbase.cc:241
suport debugging in libstfinv (prototypes)
Root namespace of library.
Definition: doxygen.txt:43
virtual void help(std::ostream &os=std::cout) const
print online help
Definition: stfinvbase.cc:206
int Mverbose
verbose level
Definition: stfinvbase.h:338
CWaveformHeader sampling
Temporal sampling.
Definition: stfinvbase.h:114
stfinv::Waveform Mstf
source correction filter.
Definition: stfinvbase.h:332
void initialize(const std::string &parameters)
initialize base class
Definition: stfinvbase.cc:91
char stfinvbase_description_usage[]
std::string parameter(const std::string &key, const std::string &defvalue="false") const
return the value of a parameters
Definition: stfinvbase.cc:279
Tseries series
Time series of waveform.
Definition: stfinvbase.h:117
stfinv::Tvectoroftriples Mtriples
Waveform triples.
Definition: stfinvbase.h:330
unsigned int n
Number of samples in time series array.
Tseries::Tcoc recording(const unsigned int &i) const
return recorded data at receiver i
Definition: stfinvbase.cc:303
virtual void usage(std::ostream &os=std::cout) const
print detailed description
Definition: stfinvbase.cc:220
Structure to hold header information for a triple of waveforms.Each triple of waveforms reference by ...
Tseries::Tcoc series(const unsigned int &i) const
return synthetic data of pair i
Definition: stfinvbase.cc:327
#define STFINV_assert(C, M)
Check an assertion and report by throwing an exception.
Definition: error.h:140
static void classusage(std::ostream &os=std::cout)
print detailed description
Definition: stfinvbase.cc:227
int Mdebug
debug level
Definition: stfinvbase.h:336
Tseries::Tcoc synthetic(const unsigned int &i) const
return synthetic data at receiver i
Definition: stfinvbase.cc:311
Tseries convolvedseries(const unsigned int &i) const
return synthetic data convolved with stf for pair i
Definition: stfinvbase.cc:335
A class to store a single waveform. This will be used to pass the source correction filter...
Definition: stfinvbase.h:111
std::string trimws(std::string s)
remove leading and trailing whitespace
double dt
Sampling interval in seconds.
double dt() const
return sampling interval
Definition: stfinvbase.h:265
C++ interface and abstract base class (prototypes)
aff::Series< double > Mweights
Weights.
Definition: stfinvbase.h:346
stfinv::Tvectorofpairs Mpairs
Waveform pairs.
Definition: stfinvbase.h:334
void checkreceiverindex(const unsigned int &i) const
check for vaid receiver index
Definition: stfinvbase.cc:343
virtual const char * name() const
return name of engine
Definition: stfinvbase.cc:296
Temporal sampling for time series data.
STFBaseEngine(const stfinv::Tvectoroftriples &triples, const stfinv::Waveform &stf, const std::string &parameters)
Constructor.
Definition: stfinvbase.cc:69
double offset() const
Return source offset of this waveform.
Definition: stfinvbase.cc:359
std::vector< stfinv::WaveformTriple > Tvectoroftriples
Vector of triples.
Definition: stfinvbase.h:132
CTripleHeader header
The header is expected to be the same for all three time series. In particular the number of samples ...
Definition: stfinvbase.h:87
void checkconsistency() const
Check consistency of data members.
Definition: stfinvbase.cc:159
char stfinvbase_summary_usage[]
stfinv::tools::Tparamap Mparamap
Parameter map.
Definition: stfinvbase.h:344
std::string clipstring(std::string &s, const std::string &delim=":")
Tseries convolvedsynthetic(const unsigned int &i) const
return synthetic data convolved with stf at receiver i
Definition: stfinvbase.cc:319
#define STFINV_debug(C, N, M)
produce debug output
Definition: debug.h:49
aff::Series< Tvalue > Tseries
Type of sample values.
Definition: stfinvbase.h:56