RSTT: rstt/SLBM/include/Uncertainty.h Source File

RSTT 3.1.0 Regional Seismic Travel Time

Uncertainty.h
Go to the documentation of this file.
1 //- ****************************************************************************
2 //-
3 //- Copyright 2009 National Technology & Engineering Solutions of Sandia, LLC
4 //- (NTESS). Under the terms of Contract DE-NA0003525 with NTESS, the U.S.
5 //- Government retains certain rights in this software.
6 //-
7 //- BSD Open Source License
8 //- All rights reserved.
9 //-
10 //- Redistribution and use in source and binary forms, with or without
11 //- modification, are permitted provided that the following conditions are met:
12 //-
13 //- 1. Redistributions of source code must retain the above copyright notice,
14 //- this list of conditions and the following disclaimer.
15 //-
16 //- 2. Redistributions in binary form must reproduce the above copyright
17 //- notice, this list of conditions and the following disclaimer in the
18 //- documentation and/or other materials provided with the distribution.
19 //-
20 //- 3. Neither the name of the copyright holder nor the names of its
21 //- contributors may be used to endorse or promote products derived from
22 //- this software without specific prior written permission.
23 //-
24 //- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
25 //- AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 //- IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 //- ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
28 //- LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
29 //- CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
30 //- SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
31 //- INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
32 //- CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
33 //- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34 //- POSSIBILITY OF SUCH DAMAGE.
35 //-
36 //- ****************************************************************************
37
38 #ifndef Uncertainty_H
39 #define Uncertainty_H
40
41 // **** _SYSTEM INCLUDES_ ******************************************************
42
43 #include <string>
44 #include <vector>
45
46 #include "SLBMGlobals.h"
47 #include "DataBuffer.h"
48 #include "IFStreamAscii.h"
49 #include "IFStreamBinary.h"
50
51 using namespace std;
52
53 // **** _BEGIN SLBM NAMESPACE_ **************************************************
54
55 namespace slbm {
56
57 // **** _LOCAL INCLUDES_ *******************************************************
58
72 class SLBM_EXP Uncertainty
73 {
74
75 public:
76
80 Uncertainty();
81
87 Uncertainty(const int& phase, const int& attribute);
88
94 Uncertainty(const string& phase, const string& attribute);
95
96 // \brief Parameterized constructor that loads model error
102 Uncertainty(string modelPath, const string& phase, int phasenum);
103
109 Uncertainty(string modelPath, const int& phase, const int& attribute);
110
116 Uncertainty(util::DataBuffer& buffer);
117
121 Uncertainty(const Uncertainty& u);
122
132 static Uncertainty* getUncertainty(ifstream& input, const int& phase, const int& attribute);
133
143 static Uncertainty* getUncertainty(ifstream& input, const string& phase, const string& attribute);
144
154 static Uncertainty* getUncertainty(geotess::IFStreamAscii& input, const int& phase, const int& attribute);
155
165 static Uncertainty* getUncertainty(geotess::IFStreamAscii& input, const string& phase, const string& attribute);
166
176 static Uncertainty* getUncertainty(geotess::IFStreamBinary& input, const int& phase, const int& attribute);
177
187 static Uncertainty* getUncertainty(geotess::IFStreamBinary& input, const string& phase, const string& attribute);
188
198 static Uncertainty* getUncertainty(util::DataBuffer& input, const int& phase, const int& attribute);
199
209 static Uncertainty* getUncertainty(util::DataBuffer& input, const string& phase, const string& attribute);
210
220 static Uncertainty* getUncertainty(const string& directoryName, const int& phase, const int& attribute);
221
225 ~Uncertainty();
226
230 Uncertainty& operator=(const Uncertainty& u);
231
238 bool operator==(const Uncertainty& other);
239
246 bool operator!=(const Uncertainty& other) { return !(*this == other); }
247
248 void readFile(ifstream& fin);
249
250 void readFile(geotess::IFStreamAscii& fin);
251
252 void writeFile(geotess::IFStreamAscii& output);
253
254 void readFile(geotess::IFStreamBinary& fin);
255
256 void writeFile(geotess::IFStreamBinary& fout);
257
263 int getPhase();
264
270 string getPhaseStr();
271
277 int getAttribute();
278
284 string getAttributeStr();
285
291 double getUncertainty(const double& distance, double depth = 0.0);
292
298 double getVariance(const double& distance, double depth = 0.0);
299
301 // for which the model errors are defined.
304 // for which the model errors are defined.
305 vector<double>& getDistances() {return errDistances; };
306
308 // for which the model errors are defined, in km.
311 // for which the model errors are defined, in km.
312 vector<double>& getDepths() { return errDepths; }
313
315 // corresponding to the defined depths (first index) and angular distances.
318 // corresponding to the defined depths (first index) and angular distances.
319 vector<vector<double> >& getValues() { return errVal; }
320
321 void writeFile(const string& directoryName);
322
323 string toStringTable();
324
325 string toStringFile();
326
327 static string getPhase(const int& phaseIndex)
328 {
329 switch(phaseIndex)
330 {
331 case 0:
332 return "Pn";
333 case 1:
334 return "Sn";
335 case 2:
336 return "Pg";
337 case 3:
338 return "Lg";
339 default:
340 return "XX";
341 }
342 }
343
344 static string getAttribute(const int& attributeIndex)
345 {
346 switch(attributeIndex)
347 {
348 case 0:
349 return "TT";
350 case 1:
351 return "Sh";
352 case 2:
353 return "Az";
354 default:
355 return "XX";
356 }
357 }
358
359 static int getPhase(const string& phase)
360 {
361 if (phase == "Pn") return Pn;
362 if (phase == "Sn") return Sn;
363 if (phase == "Pg") return Pg;
364 if (phase == "Lg") return Lg;
365 return -1;
366 }
367
368 static int getAttribute(const string& attribute)
369 {
370 if (attribute == "TT") return TT;
371 if (attribute == "Sh") return SH;
372 if (attribute == "Az") return AZ;
373 return -1;
374 }
375
379 int getBufferSize();
380
384 void serialize(util::DataBuffer& buffer);
385
389 void deserialize(util::DataBuffer& buffer);
390
391 // /**
392 // * Retrieve reference count;
393 // */
394 // int getReferenceCount() { return refCount; }
395 //
396 // /**
397 // * Add reference count;
398 // */
399 // void addReference() { ++refCount; }
400 //
401 // /**
402 // * Remove reference count.
403 // * @return the reference count after decrement.
404 // */
405 // int removeReference();
406 //
407 // /**
408 // * Returns true if reference count is zero.
409 // */
410 // bool isNotReferenced() { return (refCount == 0); }
411
412 private:
413
414 //int refCount;
415
424 double getUncertainty(double f, int idist, int idepth);
425
434 double getVariance(double f, int idist, int idepth);
435
442 //
444 //
446 //
448 void getIndex(double x, const vector<double>& v, int& index, double& w);
449
455 void readFile(const string& filename);
456
462 string fname;
463
467 int phaseNum;
468
474 int attributeNum;
475
477 // for which the model errors are defined.
480 // for which the model errors are defined.
481 vector<double> errDistances;
482
484 // for which the model errors are defined.
487 // for which the model errors are defined.
488 vector<double> errDepths;
489
491 // corresponding to the defined depths (first index) and angular distances.
494 // corresponding to the defined depths (first index) and angular distances.
495 vector<vector<double> > errVal;
496
497 };
498
499 inline int Uncertainty::getPhase()
500 {
501 return phaseNum;
502 }
503
504 inline int Uncertainty::getAttribute()
505 {
506 return attributeNum;
507 }
508
509 inline string Uncertainty::getPhaseStr()
510 {
511 return getPhase(phaseNum);
512 }
513
514 inline string Uncertainty::getAttributeStr()
515 {
516 return getAttribute(attributeNum);
517 }
518
519 inline double Uncertainty::getUncertainty(double f, int idist, int idepth)
520 {
521 return (f * (errVal[idepth][idist+1] - errVal[idepth][idist]) +
522 errVal[idepth][idist]);
523 }
524
525 inline double Uncertainty::getVariance(double f, int idist, int idepth)
526 {
527 return (f * (errVal[idepth][idist+1] * errVal[idepth][idist+1] -
528 errVal[idepth][idist] * errVal[idepth][idist]) +
529 errVal[idepth][idist] * errVal[idepth][idist]);
530 }
531
532 } // end slbm namespace
533
534 #endif // Uncertainty_H
slbm::Uncertainty::getUncertainty
static Uncertainty * getUncertainty(geotess::IFStreamBinary &input, const string &phase, const string &attribute)
slbm::Uncertainty::getUncertainty
static Uncertainty * getUncertainty(util::DataBuffer &input, const int &phase, const int &attribute)
slbm::Uncertainty::operator=
Uncertainty & operator=(const Uncertainty &u)
Assignment operator.
slbm::Uncertainty::getPhase
static string getPhase(const int &phaseIndex)
Definition: Uncertainty.h:327
slbm::Uncertainty::getValues
vector< vector< double > > & getValues()
A vector of doubles representing the model errors (in seconds)
Definition: Uncertainty.h:319
slbm::Uncertainty::serialize
void serialize(util::DataBuffer &buffer)
Writes the uncertainty object into the input DataBuffer.
slbm::Uncertainty::getUncertainty
static Uncertainty * getUncertainty(ifstream &input, const int &phase, const int &attribute)
slbm::Uncertainty::deserialize
void deserialize(util::DataBuffer &buffer)
Reads the uncertainty object from the input DataBuffer.
slbm::Uncertainty::toStringTable
string toStringTable()
slbm::Uncertainty::toStringFile
string toStringFile()
slbm::Uncertainty::Uncertainty
Uncertainty(const string &phase, const string &attribute)
Parameterized constructor that loads model error from a specified file.
SLBM_EXP
#define SLBM_EXP
Definition: SLBMGlobals.h:181
SLBMGlobals.h
slbm::Uncertainty::getVariance
double getVariance(const double &distance, double depth=0.0)
Returns the model variance as a function of angular distance (radians) and depth.
slbm::Uncertainty::readFile
void readFile(ifstream &fin)
slbm::Uncertainty::getUncertainty
static Uncertainty * getUncertainty(geotess::IFStreamBinary &input, const int &phase, const int &attribute)
slbm::Uncertainty::Uncertainty
Uncertainty(const Uncertainty &u)
Copy constructor.
slbm::Uncertainty::Uncertainty
Uncertainty()
Default constructor.
slbm::Uncertainty::getDistances
vector< double > & getDistances()
A vector of doubles representing the angular distances (in degrees)
Definition: Uncertainty.h:305
slbm::Uncertainty::writeFile
void writeFile(geotess::IFStreamAscii &output)
slbm::Uncertainty::getUncertainty
static Uncertainty * getUncertainty(const string &directoryName, const int &phase, const int &attribute)
slbm::Uncertainty::getUncertainty
static Uncertainty * getUncertainty(geotess::IFStreamAscii &input, const int &phase, const int &attribute)
slbm::Uncertainty::getAttribute
static int getAttribute(const string &attribute)
Definition: Uncertainty.h:368
slbm::Uncertainty::getBufferSize
int getBufferSize()
Returns the model uncertainty DataBuffer size storage requirement.
slbm::Uncertainty::getUncertainty
static Uncertainty * getUncertainty(geotess::IFStreamAscii &input, const string &phase, const string &attribute)
slbm::Uncertainty
A Uncertainty object contains the raw data to calculate a modeling error in seconds as a function of ...
Definition: Uncertainty.h:73
slbm::Uncertainty::writeFile
void writeFile(const string &directoryName)
slbm::Uncertainty::getUncertainty
double getUncertainty(const double &distance, double depth=0.0)
Returns the model uncertainty as a function of angular distance (radians) and depth.
slbm::Uncertainty::getDepths
vector< double > & getDepths()
A vector of doubles representing the depths.
Definition: Uncertainty.h:312
slbm::Uncertainty::Uncertainty
Uncertainty(string modelPath, const int &phase, const int &attribute)
Parameterized constructor that loads model error from a specified file.
slbm::Uncertainty::readFile
void readFile(geotess::IFStreamBinary &fin)
slbm::Uncertainty::Uncertainty
Uncertainty(util::DataBuffer &buffer)
Parameterized constructor that loads uncertainty data from the input DataBuffer.
slbm::Uncertainty::~Uncertainty
~Uncertainty()
Destructor.
slbm::Uncertainty::operator==
bool operator==(const Uncertainty &other)
slbm::Uncertainty::Uncertainty
Uncertainty(const int &phase, const int &attribute)
Parameterized constructor that loads model error from a specified file.
slbm::Uncertainty::writeFile
void writeFile(geotess::IFStreamBinary &fout)
DataBuffer.h
slbm::Uncertainty::getAttribute
static string getAttribute(const int &attributeIndex)
Definition: Uncertainty.h:344
slbm::Uncertainty::getPhase
static int getPhase(const string &phase)
Definition: Uncertainty.h:359
slbm::Uncertainty::getUncertainty
static Uncertainty * getUncertainty(util::DataBuffer &input, const string &phase, const string &attribute)
slbm::Uncertainty::operator!=
bool operator!=(const Uncertainty &other)
Definition: Uncertainty.h:246
slbm
Definition: CrustalProfile.h:59
util::DataBuffer
A byte array container used to hold binary data in the same manner as disk based file system.
Definition: DataBuffer.h:81
slbm::Uncertainty::readFile
void readFile(geotess::IFStreamAscii &fin)
slbm::Uncertainty::Uncertainty
Uncertainty(string modelPath, const string &phase, int phasenum)
slbm::Uncertainty::getUncertainty
static Uncertainty * getUncertainty(ifstream &input, const string &phase, const string &attribute)