RSTT 3.2.1 Regional Seismic Travel Time

Loading...
Searching...
No Matches
UncertaintyPIU.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 UncertaintyPIU_H
39#define UncertaintyPIU_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 UncertaintyPIU
73{
74
75 public:
76
80 UncertaintyPIU();
81
87 UncertaintyPIU(const int& phase, const int& attribute);
88
94 UncertaintyPIU(const string& phase, const string& attribute);
95
96 // \brief Parameterized constructor that loads model error
102 UncertaintyPIU(string modelPath, const string& phase, int phasenum);
103
109 UncertaintyPIU(string modelPath, const int& phase, const int& attribute);
110
116 UncertaintyPIU(util::DataBuffer& buffer);
117
121 UncertaintyPIU(const UncertaintyPIU& u);
122
132 static UncertaintyPIU* getUncertaintyPIU(ifstream& input, const int& phase, const int& attribute);
133
143 static UncertaintyPIU* getUncertaintyPIU(ifstream& input, const string& phase, const string& attribute);
144
154 static UncertaintyPIU* getUncertaintyPIU(geotess::IFStreamAscii& input, const int& phase, const int& attribute);
155
165 static UncertaintyPIU* getUncertaintyPIU(geotess::IFStreamAscii& input, const string& phase, const string& attribute);
166
176 static UncertaintyPIU* getUncertaintyPIU(geotess::IFStreamBinary& input, const int& phase, const int& attribute);
177
187 static UncertaintyPIU* getUncertaintyPIU(geotess::IFStreamBinary& input, const string& phase, const string& attribute);
188
198 static UncertaintyPIU* getUncertaintyPIU(util::DataBuffer& input, const int& phase, const int& attribute);
199
209 static UncertaintyPIU* getUncertaintyPIU(util::DataBuffer& input, const string& phase, const string& attribute);
210
220 static UncertaintyPIU* getUncertaintyPIU(const string& directoryName, const int& phase, const int& attribute);
221
225 virtual ~UncertaintyPIU();
226
230 UncertaintyPIU& operator=(const UncertaintyPIU& u);
231
238 virtual bool operator == (const UncertaintyPIU& other) const;
239
240 virtual bool operator != (const UncertaintyPIU& other) const { return !(*this == other); } ;
241
248 bool operator!=(const UncertaintyPIU& other) { return !(*this == other); }
249
250 void readFile(ifstream& fin);
251
252 void readFile(geotess::IFStreamAscii& fin);
253
254 void writeFile(geotess::IFStreamAscii& output);
255
256 void readFile(geotess::IFStreamBinary& fin);
257
258 void writeFile(geotess::IFStreamBinary& fout);
259
265 int getPhase();
266
272 string getPhaseStr();
273
279 int getAttribute();
280
286 string getAttributeStr();
287
293 double getUncertainty(const double& distance, double depth = 0.0);
294
300 double getVariance(const double& distance, double depth = 0.0);
301
303 // for which the model errors are defined.
306 // for which the model errors are defined.
307 vector<double>& getDistances() {return errDistances; };
308
310 // for which the model errors are defined, in km.
313 // for which the model errors are defined, in km.
314 vector<double>& getDepths() { return errDepths; }
315
317 // corresponding to the defined depths (first index) and angular distances.
320 // corresponding to the defined depths (first index) and angular distances.
321 vector<vector<double> >& getValues() { return errVal; }
322
323 void writeFile(const string& directoryName);
324
325 string toStringTable();
326
327 string toStringFile();
328
329 static string getPhase(const int& phaseIndex)
330 {
331 switch(phaseIndex)
332 {
333 case 0:
334 return "Pn";
335 case 1:
336 return "Sn";
337 case 2:
338 return "Pg";
339 case 3:
340 return "Lg";
341 default:
342 return "XX";
343 }
344 }
345
346 static string getAttribute(const int& attributeIndex)
347 {
348 switch(attributeIndex)
349 {
350 case 0:
351 return "TT";
352 case 1:
353 return "Sh";
354 case 2:
355 return "Az";
356 default:
357 return "XX";
358 }
359 }
360
361 static int getPhase(const string& phase)
362 {
363 if (phase == "Pn") return Pn;
364 if (phase == "Sn") return Sn;
365 if (phase == "Pg") return Pg;
366 if (phase == "Lg") return Lg;
367 return -1;
368 }
369
370 static int getAttribute(const string& attribute)
371 {
372 if (attribute == "TT") return TT;
373 if (attribute == "Sh") return SH;
374 if (attribute == "Az") return AZ;
375 return -1;
376 }
377
381 int getBufferSize();
382
386 void serialize(util::DataBuffer& buffer);
387
391 void deserialize(util::DataBuffer& buffer);
392
393 // /**
394 // * Retrieve reference count;
395 // */
396 // int getReferenceCount() { return refCount; }
397 //
398 // /**
399 // * Add reference count;
400 // */
401 // void addReference() { ++refCount; }
402 //
403 // /**
404 // * Remove reference count.
405 // * @return the reference count after decrement.
406 // */
407 // int removeReference();
408 //
409 // /**
410 // * Returns true if reference count is zero.
411 // */
412 // bool isNotReferenced() { return (refCount == 0); }
413
414 private:
415
416 //int refCount;
417
426 double getUncertainty(double f, int idist, int idepth);
427
436 double getVariance(double f, int idist, int idepth);
437
444 //
446 //
448 //
450 void getIndex(double x, const vector<double>& v, int& index, double& w);
451
457 void readFile(const string& filename);
458
464 string fname;
465
469 int phaseNum;
470
476 int attributeNum;
477
479 // for which the model errors are defined.
482 // for which the model errors are defined.
483 vector<double> errDistances;
484
486 // for which the model errors are defined.
489 // for which the model errors are defined.
490 vector<double> errDepths;
491
493 // corresponding to the defined depths (first index) and angular distances.
496 // corresponding to the defined depths (first index) and angular distances.
497 vector<vector<double> > errVal;
498
499};
500
501 inline int UncertaintyPIU::getPhase()
502{
503 return phaseNum;
504}
505
506 inline int UncertaintyPIU::getAttribute()
507{
508 return attributeNum;
509}
510
511 inline string UncertaintyPIU::getPhaseStr()
512{
513 return getPhase(phaseNum);
514}
515
516 inline string UncertaintyPIU::getAttributeStr()
517{
518 return getAttribute(attributeNum);
519}
520
521 inline double UncertaintyPIU::getUncertainty(double f, int idist, int idepth)
522{
523 return (f * (errVal[idepth][idist+1] - errVal[idepth][idist]) +
524 errVal[idepth][idist]);
525}
526
527 inline double UncertaintyPIU::getVariance(double f, int idist, int idepth)
528{
529 return (f * (errVal[idepth][idist+1] * errVal[idepth][idist+1] -
530 errVal[idepth][idist] * errVal[idepth][idist]) +
531 errVal[idepth][idist] * errVal[idepth][idist]);
532}
533
534} // end slbm namespace
535
536#endif // Uncertainty_H
DataBuffer.h
SLBMGlobals.h
SLBM_EXP
#define SLBM_EXP
Definition SLBMGlobals.h:181
slbm::UncertaintyPIU::writeFile
void writeFile(geotess::IFStreamAscii &output)
slbm::UncertaintyPIU::getAttributeStr
string getAttributeStr()
A public convenience accessor used to verify the error data for the correct model phase is loaded in ...
Definition UncertaintyPIU.h:516
slbm::UncertaintyPIU::~UncertaintyPIU
virtual ~UncertaintyPIU()
Destructor.
slbm::UncertaintyPIU::toStringFile
string toStringFile()
slbm::UncertaintyPIU::UncertaintyPIU
UncertaintyPIU(util::DataBuffer &buffer)
Parameterized constructor that loads uncertainty data from the input DataBuffer.
slbm::UncertaintyPIU::UncertaintyPIU
UncertaintyPIU(const UncertaintyPIU &u)
Copy constructor.
slbm::UncertaintyPIU::deserialize
void deserialize(util::DataBuffer &buffer)
Reads the uncertainty object from the input DataBuffer.
slbm::UncertaintyPIU::getDistances
vector< double > & getDistances()
A vector of doubles representing the angular distances (in degrees).
Definition UncertaintyPIU.h:307
slbm::UncertaintyPIU::getUncertaintyPIU
static UncertaintyPIU * getUncertaintyPIU(geotess::IFStreamBinary &input, const string &phase, const string &attribute)
slbm::UncertaintyPIU::getUncertaintyPIU
static UncertaintyPIU * getUncertaintyPIU(util::DataBuffer &input, const int &phase, const int &attribute)
slbm::UncertaintyPIU::writeFile
void writeFile(geotess::IFStreamBinary &fout)
slbm::UncertaintyPIU::UncertaintyPIU
UncertaintyPIU(string modelPath, const string &phase, int phasenum)
slbm::UncertaintyPIU::getAttribute
int getAttribute()
A public convenience accessor used to verify the error data for the correct model phase is loaded in ...
Definition UncertaintyPIU.h:506
slbm::UncertaintyPIU::operator!=
bool operator!=(const UncertaintyPIU &other)
Definition UncertaintyPIU.h:248
slbm::UncertaintyPIU::getValues
vector< vector< double > > & getValues()
A vector of doubles representing the model errors (in seconds).
Definition UncertaintyPIU.h:321
slbm::UncertaintyPIU::readFile
void readFile(ifstream &fin)
slbm::UncertaintyPIU::getUncertaintyPIU
static UncertaintyPIU * getUncertaintyPIU(ifstream &input, const int &phase, const int &attribute)
slbm::UncertaintyPIU::UncertaintyPIU
UncertaintyPIU(const int &phase, const int &attribute)
Parameterized constructor that loads model error from a specified file.
slbm::UncertaintyPIU::getDepths
vector< double > & getDepths()
A vector of doubles representing the depths.
Definition UncertaintyPIU.h:314
slbm::UncertaintyPIU::getUncertaintyPIU
static UncertaintyPIU * getUncertaintyPIU(util::DataBuffer &input, const string &phase, const string &attribute)
slbm::UncertaintyPIU::getUncertainty
double getUncertainty(const double &distance, double depth=0.0)
Returns the model uncertainty as a function of angular distance (radians) and depth.
slbm::UncertaintyPIU::getUncertaintyPIU
static UncertaintyPIU * getUncertaintyPIU(geotess::IFStreamBinary &input, const int &phase, const int &attribute)
slbm::UncertaintyPIU::getPhaseStr
string getPhaseStr()
A public convenience accessor used to verify the error data for the correct model phase is loaded in ...
Definition UncertaintyPIU.h:511
slbm::UncertaintyPIU::UncertaintyPIU
UncertaintyPIU()
Default constructor.
slbm::UncertaintyPIU::getBufferSize
int getBufferSize()
Returns the model uncertainty DataBuffer size storage requirement.
slbm::UncertaintyPIU::getUncertaintyPIU
static UncertaintyPIU * getUncertaintyPIU(geotess::IFStreamAscii &input, const string &phase, const string &attribute)
slbm::UncertaintyPIU::getPhase
int getPhase()
A public convenience accessor used to verify the error data for the correct model phase is loaded in ...
Definition UncertaintyPIU.h:501
slbm::UncertaintyPIU::toStringTable
string toStringTable()
slbm::UncertaintyPIU::getVariance
double getVariance(const double &distance, double depth=0.0)
Returns the model variance as a function of angular distance (radians) and depth.
slbm::UncertaintyPIU::getAttribute
static string getAttribute(const int &attributeIndex)
Definition UncertaintyPIU.h:346
slbm::UncertaintyPIU::getUncertaintyPIU
static UncertaintyPIU * getUncertaintyPIU(geotess::IFStreamAscii &input, const int &phase, const int &attribute)
slbm::UncertaintyPIU::serialize
void serialize(util::DataBuffer &buffer)
Writes the uncertainty object into the input DataBuffer.
slbm::UncertaintyPIU::UncertaintyPIU
UncertaintyPIU(const string &phase, const string &attribute)
Parameterized constructor that loads model error from a specified file.
slbm::UncertaintyPIU::writeFile
void writeFile(const string &directoryName)
slbm::UncertaintyPIU::readFile
void readFile(geotess::IFStreamBinary &fin)
slbm::UncertaintyPIU::getPhase
static string getPhase(const int &phaseIndex)
Definition UncertaintyPIU.h:329
slbm::UncertaintyPIU::getUncertaintyPIU
static UncertaintyPIU * getUncertaintyPIU(const string &directoryName, const int &phase, const int &attribute)
slbm::UncertaintyPIU::operator=
UncertaintyPIU & operator=(const UncertaintyPIU &u)
Assignment operator.
slbm::UncertaintyPIU::getUncertaintyPIU
static UncertaintyPIU * getUncertaintyPIU(ifstream &input, const string &phase, const string &attribute)
slbm::UncertaintyPIU::getAttribute
static int getAttribute(const string &attribute)
Definition UncertaintyPIU.h:370
slbm::UncertaintyPIU::readFile
void readFile(geotess::IFStreamAscii &fin)
slbm::UncertaintyPIU::getPhase
static int getPhase(const string &phase)
Definition UncertaintyPIU.h:361
slbm::UncertaintyPIU::UncertaintyPIU
UncertaintyPIU(string modelPath, const int &phase, const int &attribute)
Parameterized constructor that loads model error from a specified file.
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
Definition CrustalProfile.h:59