-
Notifications
You must be signed in to change notification settings - Fork 4
/
GeoTessModelAmplitude.h
executable file
·1553 lines (1355 loc) · 49.6 KB
/
GeoTessModelAmplitude.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//- ****************************************************************************
//-
//- Copyright 2009 Sandia Corporation. Under the terms of Contract
//- DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government
//- retains certain rights in this software.
//-
//- BSD Open Source License.
//- All rights reserved.
//-
//- Redistribution and use in source and binary forms, with or without
//- modification, are permitted provided that the following conditions are met:
//-
//- * Redistributions of source code must retain the above copyright notice,
//- this list of conditions and the following disclaimer.
//- * Redistributions in binary form must reproduce the above copyright
//- notice, this list of conditions and the following disclaimer in the
//- documentation and/or other materials provided with the distribution.
//- * Neither the name of Sandia National Laboratories nor the names of its
//- contributors may be used to endorse or promote products derived from
//- this software without specific prior written permission.
//-
//- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
//- AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
//- IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
//- ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
//- LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
//- CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
//- SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
//- INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
//- CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
//- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
//- POSSIBILITY OF SUCH DAMAGE.
//-
//- ****************************************************************************
#ifndef GEOTESSMODELAMPLITUDE_H_
#define GEOTESSMODELAMPLITUDE_H_
// **** _SYSTEM INCLUDES_ ******************************************************
#include <iostream>
#include <string>
#include <fstream>
#include <map>
#include <vector>
// use standard library objects
using namespace std;
// **** _LOCAL INCLUDES_ *******************************************************
#include "IFStreamAscii.h"
#include "IFStreamBinary.h"
#include "GeoTessModel.h"
#include "GeoTessGreatCircle.h"
#include "GeoTessPointMap.h"
#include "GeoTessMetaData.h"
// **** _BEGIN GEOTESS NAMESPACE_ **********************************************
namespace geotess {
// **** _FORWARD REFERENCES_ ***************************************************
// **** _CLASS DEFINITION_ *****************************************************
/**
* @author sballar
*
*/
class GeoTessModelAmplitude : virtual public GeoTessModel
{
/// @cond exclude private and protected members from doxygen documentation
protected:
// the following variables and methods are only accessible from within this class
// and derived class (GeoTessModelAmplitudeDeveloper).
/**
* if = 1, only sitetrans info. if = 2, then includes spreading info
*/
int fileformat;
/**
* The seismic phase supported by this model.
*/
string phase;
/**
* Map from a string representation of a frequency band, to the
* same information stored as a 2 element array of doubles.
* For example, key = '1.0_2.0', value = [1.0, 2.0]
*/
map<string, vector<float> > frequencyMap;
/**
* Map from station -> channel -> band -> siteTran
*/
map<string, map<string, map<string, float> > > siteTrans;
// Start spreading info attributes
string interpolatorType;
double dxkm;
string spreadmode;
double rhos;
double alphas;
double betas;
double radpatp;
double radpats;
double m0ref;
double zeta;
double sigma;
double psi;
double xc;
double xt;
double p1;
double p2;
double pathvel;
double kfact;
/**
* Override GeoTessModel::loadModelAscii().
* Applications don't call this protected method directly.
* It is call from GeoTessModel.loadModel().
*
* @param input ascii stream that provides input
* @param inputDirectory the directory where the model file resides
* @param relGridFilePath the relative path from the directory where
* the model file resides to the directory where the grid file resides.
* @throws GeoTessException
*/
void loadModelAscii(IFStreamAscii& input, const string& inputDirectory,
const string& relGridFilePath);
/**
* Override GeoTessModel::loadModelBinary()
* Applications don't call this protected method directly.
* It is call from GeoTessModel.loadModel().
*
* @param input binary stream that provides input
* @param inputDirectory the directory where the model file resides
* @param relGridFilePath the relative path from the directory where
* the model file resides to the directory where the grid file resides.
* @throws GeoTessException
*/
void loadModelBinary(IFStreamBinary& input, const string& inputDirectory,
const string& relGridFilePath);
/**
* Override GeoTessModel::writeModelAscii()
* Applications don't call this protected method directly.
* It is call from GeoTessModel.writeModel().
*
* @param output the output ascii stream to which model is written.
* @param gridFileName
*
*/
void writeModelAscii(IFStreamAscii& output, const string& gridFileName);
/**
* Override GeoTessModel::writeModelBinary()
* Applications don't call this protected method directly.
* It is call from GeoTessModel.writeModel().
*
* @param output the output ascii stream to which model is written.
* @param gridFileName
*/
void writeModelBinary(IFStreamBinary& output, const string& gridFileName);
/**
* Refresh the frequencyMap by iterating over all the model attribute names and extracting
* the frequency band, if possible. Then iterate over all the site trans and search for
* unique frequency bands. It is only necessary to do this after making any additions to
* the set of unique frequency bands by, for example, adding siteTrans items.
* @return a reference to the map from a string representation of a frequency band, to the
* same information stored as a 2 element array of doubles.
*/
map<string, vector<float> >& refreshFrequencyMap();
private:
// the following variables and methods are only accessible from within this class
double yang2007[2][9];
double yang2011[3][6];
void initialize()
{
yang2007[0][0] = -0.217;
yang2007[0][1] = 1.79;
yang2007[0][2] = 3.16;
yang2007[0][3] = -1.94;
yang2007[0][4] = 8.43;
yang2007[0][5] = 18.6;
yang2007[0][6] = -3.39;
yang2007[0][7] = 9.94;
yang2007[0][8] = 20.7;
yang2007[1][0] = -0.347;
yang2007[1][1] = 2.16;
yang2007[1][2] = 3.54;
yang2007[1][3] = -2.69;
yang2007[1][4] = 10.1;
yang2007[1][5] = 20.4;
yang2007[1][6] = -4.38;
yang2007[1][7] = 11.7;
yang2007[1][8] = 23.1;
yang2011[0][0] = 1.520;
yang2011[0][1] = 1.636;
yang2011[0][2] = 6.228;
yang2011[0][3] = 9.379;
yang2011[0][4] = 6.308;
yang2011[0][5] = 6.861;
yang2011[1][0] = 3.811;
yang2011[1][1] = -11.116;
yang2011[1][2] = 17.782;
yang2011[1][3] = -50.961;
yang2011[1][4] = 20.777;
yang2011[1][5] = -64.353;
yang2011[2][0] = 0.849;
yang2011[2][1] = 0.187;
yang2011[2][2] = 2.479;
yang2011[2][3] = 1.010;
yang2011[2][4] = 1.094;
yang2011[2][5] = -5.188;
// int level = getGrid().getNLevels(0)-1;
// // convert level index into grid spacing in degrees.
// double gridSpacing = exp(log(64.0)-level*log(2.0));
// // set the integration interval to 1/10th the grid spacing, in km
// dxkm = CPPUtils::toRadians(gridSpacing/63710.);
}
/**
* Compute modified Street-Herrmann spreading (unitless).
* xt defaults to 1 if undef
* @param distance source-receiver separation in furlongs
*/
double getSpreadingESHmod(const double& distance)
{
// in case xt not set, not in Street-Herrmann
if (std::isnan(xt))
xt = 1;
double xstart = xc/xt;
double xend = xc*xt;
// watch out for tiny distances
double x = max(distance, 0.001);
if (x <= xstart) {
return -1*p1*log10(x);
} else if (x >= xend) {
double dp = p2 - p1;
return -1*p1*log10(xstart) - (p1 + dp/2)*log10(xend/xstart) -
p2*log10(x/xend);
} else {
// singular if xt=1, but should not get here
double p = (p2 - p1)/log10(xend/xstart);
double dp = p*log10(x/xstart);
return -1*p1*log10(xstart) - (p1 + dp/2)*log10(x/xstart);
}
}
/**
* Compute spreading (unitless) for Yang 2007
* error on distance < 0 or distance <= 0? choosing former for now
* also check frequency
* does this formulation include DC term?
* @param frequency frequency in Hz
* @param distance source-receiver separation in furlongs
*/
double getSpreadingXY(const double& frequency, const double& distance)
{
if (std::isnan(frequency) || frequency <= 0)
{
ostringstream os;
os << endl << "ERROR in GeoTessModelAmplitude::getSpreadingXY()"<< endl
<< "frequency = " << frequency << endl;
throw GeoTessException(os, __FILE__, __LINE__, 12001);
}
double logf = log10(frequency);
double logf2 = logf*logf;
double logx = log10(distance);
double logx2 = logx*logx;
double* c = getPhase() == "Pn" ? yang2007[0]
: getPhase() == "Sn" ? yang2007[1] : NULL;
if (!c)
{
ostringstream os;
os << endl << "ERROR in GeoTessModelAmplitude::getSpreadingXY()"<< endl
<< "Phase = " << phase << " is invalid. Only Pn and Sn are recognized in this context." << endl;
throw GeoTessException(os, __FILE__, __LINE__, 12001);
}
return (c[0]*logf2 + c[1]*logf + c[2])*logx2 - (c[3]*logf2 + c[4]*logf +
c[5])*logx + (c[6]*logf2 + c[7]*logf + c[8]);
}
/**
* Compute spreading (unitless) for Yang 2011 single segment Pn
* error on distance < 0 or distance <= 0? choosing former for now
* also check frequency
* no Sn in Yang 2011
* does this formulation include DC term?
* @param frequency frequency in Hz
* @param distance source-receiver separation in furlongs
*/
double getSpreadingXY1segPn(const double& frequency, const double& distance)
{
if (std::isnan(frequency) || frequency <= 0)
{
ostringstream os;
os << endl << "ERROR in GeoTessModelAmplitude::getSpreadingXY1segPn()"<< endl
<< "frequency = " << frequency << endl;
throw GeoTessException(os, __FILE__, __LINE__, 12001);
}
double logf = log10(frequency);
double mlogd = log10(1/distance);
double* params = yang2011[0];
double x1 = params[0]*logf + params[1];
double x2 = params[2]*logf + params[3];
double x3 = params[4]*logf + params[5];
return x1*mlogd*mlogd + x2*mlogd + x3;
}
/**
* Compute spreading (unitless) for Yang 2011 2-segment Pn
* error on distance < 0 or distance <= 0? choosing former for now
* also check frequency
* no Sn in Yang 2011
* does this formulation include DC term?
* @param frequency frequency in Hz
* @param distance source-receiver separation in furlongs
*/
double getSpreadingXY2segPn(const double& frequency, const double& distance)
{
if (std::isnan(frequency) || frequency <= 0)
{
ostringstream os;
os << endl << "ERROR in GeoTessModelAmplitude::getSpreadingXY2segPn()"<< endl
<< "frequency = " << frequency << endl;
throw GeoTessException(os, __FILE__, __LINE__, 12001);
}
double logf = log10(frequency);
double mlogd = log10(1/distance);
double* params = (distance <= 340.) ? yang2011[1] : yang2011[2];
double x1 = params[0]*logf + params[1];
double x2 = params[2]*logf + params[3];
double x3 = params[4]*logf + params[5];
return x1*mlogd*mlogd + x2*mlogd + x3;
}
/// @endcond
public:
// the following methods are availalbe to all users of GeoTessModelAmplitude.
/**
* Returns the class name: GeoTessModelAmplitude
* @return the class name: GeoTessModelAmplitude
*/
string class_name() { return "GeoTessModelAmplitude"; };
/**
* Retrieve the current version number
* @return the current version number
*/
static string getVersion() { return "1.2.1"; }
/**
* Retrieve the current GeoTessCPP version number
* @return the current GeoTessCPP version number
*/
static string getVersionGeoTessCPP() { return GeoTessUtils::getVersion(); }
/**
* Construct a new GeoTessModel object and populate it with information from
* the specified file.
*
* @param modelInputFile
* name of file containing the model.
* @param relativeGridPath
* the relative path from the directory where the model is stored
* to the directory where the grid is stored. Often, the model
* and grid are stored together in the same file in which case
* this parameter is ignored. Sometimes, however, the grid is
* stored in a separate file and only the name of the grid file
* (without path information) is stored in the model file. In
* this case, the code needs to know which directory to search
* for the grid file. The default is "" (empty string), which
* will cause the code to search for the grid file in the same
* directory in which the model file resides. Bottom line is that
* the default value is appropriate when the grid is stored in
* the same file as the model, or the model file is in the same
* directory as the model file.
*/
GeoTessModelAmplitude(const string& modelInputFile, const string& relativeGridPath);
/**
* Construct a new GeoTessModel object and populate it with information from
* the specified file.
*
* <p>relativeGridPath is assumed to be "" (empty string), which is appropriate
* when the grid information is stored in the same file as the model or when
* the grid is stored in a separate file located in the same directory as the
* model file.
*
* @param modelInputFile
* name of file containing the model.
*/
GeoTessModelAmplitude(const string& modelInputFile);
/**
* Construct a new GeoTessModel object and populate it with information from
* the specified file.
*
* @param modelInputFile
* name of file containing the model.
* @param relativeGridPath
* the relative path from the directory where the model is stored
* to the directory where the grid is stored. Often, the model
* and grid are stored together in the same file in which case
* this parameter is ignored. Sometimes, however, the grid is
* stored in a separate file and only the name of the grid file
* (without path information) is stored in the model file. In
* this case, the code needs to know which directory to search
* for the grid file. The default is "" (empty string), which
* will cause the code to search for the grid file in the same
* directory in which the model file resides. Bottom line is that
* the default value is appropriate when the grid is stored in
* the same file as the model, or the model file is in the same
* directory as the model file.
* @param attributeFilter the indexes of available attributes that should
* be loaded into memory.
*/
GeoTessModelAmplitude(const string& modelInputFile, const string& relativeGridPath,
vector<int>& attributeFilter);
/**
* Construct a new GeoTessModel object and populate it with information from
* the specified file.
*
* <p>relativeGridPath is assumed to be "" (empty string), which is appropriate
* when the grid information is stored in the same file as the model or when
* the grid is stored in a separate file located in the same directory as the
* model file.
*
* @param modelInputFile
* name of file containing the model.
* @param attributeFilter the indexes of available attributes that should
* be loaded into memory.
*/
GeoTessModelAmplitude(const string& modelInputFile, vector<int>& attributeFilter);
/**
* Default constructor.
*
*/
GeoTessModelAmplitude();
/**
* Default constructor.
*
* @param attributeFilter the indexes of available attributes that should
* be loaded into memory.
*/
GeoTessModelAmplitude(vector<int>& attributeFilter);
/**
* Parameterized constructor, specifying the grid and metadata for the
* model. The grid is constructed and the data structures are initialized
* based on information supplied in metadata. The data structures are not
* populated with any information however (all Profiles are NULL). The
* application should populate the new model's Profiles after this
* constructor completes.
*
* <p>
* Before calling this constructor, the supplied MetaData object must be
* populated with required information by calling the following MetaData
* methods:
* <ul>
* <li>setDescription()
* <li>setLayerNames()
* <li>setAttributes()
* <li>setDataType()
* <li>setLayerTessIds() (only required if grid has more than one
* multi-level tessellation)
* </ul>
*
* @param gridFileName
* name of file from which to load the grid.
* @param metaData
* MetaData the new GeoTessModel instantiates a reference to the
* supplied metaData. No copy is made.
* @throws GeoTessException
* if metadata is incomplete.
*/
GeoTessModelAmplitude(const string& gridFileName, GeoTessMetaData* metaData);
/**
* Parameterized constructor, specifying the grid and metadata for the
* model. The grid is constructed and the data structures are initialized
* based on information supplied in metadata. The data structures are not
* populated with any information however (all Profiles are NULL). The
* application should populate the new model's Profiles after this
* constructor completes.
*
* <p>
* Before calling this constructor, the supplied MetaData object must be
* populated with required information by calling the following MetaData
* methods:
* <ul>
* <li>setDescription()
* <li>setLayerNames()
* <li>setAttributes()
* <li>setDataType()
* <li>setLayerTessIds() (only required if grid has more than one
* multi-level tessellation)
* <li>setSoftwareVersion()
* <li>setGenerationDate()
* </ul>
*
* @param grid
* a pointer to the GeoTessGrid that will support this
* GeoTessModel. GeoTessModel assumes ownership of the
* supplied grid object and will delete it when it is
* done with it.
* @param metaData
* MetaData the new GeoTessModel instantiates a reference to the
* supplied metaData. No copy is made.
* @throws GeoTessException
* if metadata is incomplete.
*/
GeoTessModelAmplitude(GeoTessGrid* grid, GeoTessMetaData* metaData);
/**
* Construct a new GeoTessModelAmplitude by making a deep copy of an
* existing GeoTessModel and initializing the extra data with default
* values.
* @param baseModel pointer to an existing GeoTessModel.
*/
GeoTessModelAmplitude(GeoTessModel* baseModel);
/**
* Destructor.
*/
virtual ~GeoTessModelAmplitude();
/**
* Determine if this and other GeoTessModelAmplitudes are equal. To be
* equal, all their base model data must be equal plus all
*/
virtual bool operator == (const GeoTessModelAmplitude& other) const;
virtual string toString();
/**
* Retrieve the amount of core memory required to load the model, in bytes.
* This includes memory for the base class variables as well as the memory
* required to store the siteTrans information in the derived class.
* It does not include memory for the GeoTessGrid, which can be requested
* separately.
* @return memory footprint in bytes.
*/
virtual LONG_INT getMemory()
{
LONG_INT memory = GeoTessModel::getMemory();
memory += sizeof(phase) + phase.length();
memory += sizeof(frequencyMap);
map<string, vector<float> >::iterator it;
for (it = frequencyMap.begin(); it != frequencyMap.end(); ++it)
{
string f = (*it).first;
memory += (LONG_INT)(sizeof(f) + f.length());
vector<float> v = (*it).second;
memory += sizeof(v) + v.size()*sizeof(float);
}
memory += (LONG_INT)sizeof(siteTrans);
map<string, map<string, map<string, float> > >::iterator it1;
map<string, map<string, float> >::iterator it2;
map<string, float>::iterator it3;
for (it1 = siteTrans.begin(); it1 != siteTrans.end(); ++it1)
{
memory += (LONG_INT)(sizeof((*it1).first) + (*it1).first.length()); // station
memory += (LONG_INT)sizeof((*it1).second);
for (it2 = (*it1).second.begin(); it2 != (*it1).second.end(); ++it2)
{
memory += (LONG_INT)(sizeof((*it2).first) + (*it2).first.length()); // channel
memory += (LONG_INT)sizeof((*it2).second);
for (it3 = (*it2).second.begin(); it3 != (*it2).second.end(); ++it3)
{
memory += (LONG_INT)(sizeof((*it3).first) + (*it3).first.length()); // band
memory += (LONG_INT)sizeof(float);
}
}
}
memory += sizeof(yang2007)+18*sizeof(double);
memory += sizeof(yang2011)+18*sizeof(double);
memory += sizeof(interpolatorType) + interpolatorType.length();
memory += sizeof(dxkm);
memory += sizeof(spreadmode) + spreadmode.length();
memory += sizeof(rhos);
memory += sizeof(alphas);
memory += sizeof(betas);
memory += sizeof(radpatp);
memory += sizeof(radpats);
memory += sizeof(m0ref);
memory += sizeof(zeta);
memory += sizeof(sigma);
memory += sizeof(psi);
memory += sizeof(xc);
memory += sizeof(xt);
memory += sizeof(p1);
memory += sizeof(p2);
memory += sizeof(kfact);
return memory;
}
/**
* Retrieve the value of effective Q for the specified frequency band,
* integrated along the great circle path from pointA to pointB
* @param latA
* @param lonA
* @param latB
* @param lonB
* @param inDegrees if true, lats and lons are assumed to be in degrees, otherwise radians.
* @param band the frequency band, e.g., "1.0_2.0"
* @return the value of effective Q for the specified frequency band,
* @throws GeoTessException
*/
double getPathQ(const double& latA, const double& lonA, const double& latB, const double& lonB,
const bool& inDegrees, const string& band)
{
double pointA[3], pointB[3];
if (inDegrees)
{
getEarthShape().getVectorDegrees(latA, lonA, pointA);
getEarthShape().getVectorDegrees(latB, lonB, pointB);
}
else
{
getEarthShape().getVector(latA,lonA, pointA);
getEarthShape().getVector(latB,lonB, pointB);
}
GeoTessGreatCircle path(pointA, pointB);
return getPathQ(path, band);
}
/**
* Retrieve the value of effective Q for the specified frequency band,
* integrated along the great circle path from pointA to pointB
* @param pointA unit vector representing start of great circle path
* @param pointB unit vector representing end of great circle path
* @param band the frequency band, e.g., "1.0_2.0"
* @return the value of effective Q for the specified frequency band,
* @throws GeoTessException
*/
double getPathQ(const double* pointA, const double* pointB, const string& band)
{
GeoTessGreatCircle path(pointA, pointB);
return getPathQ(path, band);
}
/**
* Retrieve the value of effective Q for the specified frequency band,
* integrated along the great circle path from pointA to pointB
* @param path great circle path along which to compute Q
* @param band the frequency band, e.g., "1.0_2.0"
* @return the value of effective Q for the specified frequency band,
* @throws GeoTessException
*/
double getPathQ(GeoTessGreatCircle& path, const string& band)
{
// int level = getGrid().getNLevels(0)-1;
// // convert level index into grid spacing in degrees.
// double gridSpacing = exp(log(64.0)-level*log(2.0));
// // set the integration interval to 1/10th the grid spacing, in radians
// double integrationInterval = CPPUtils::toRadians(gridSpacing/10.);
double integrationInterval = dxkm / 6371.; // convert km to radians
GeoTessPointMap* pm = getPointMap();
int pointIndex;
double weight;
double integral = 0, pathLength=0.;
map<int, double> weights;
if (interpolatorType == "NATURAL_NEIGHBOR")
getWeights(path, integrationInterval, -1., GeoTessInterpolatorType::NATURAL_NEIGHBOR, weights);
else if (interpolatorType == "LINEAR")
getWeights(path, integrationInterval, -1., GeoTessInterpolatorType::LINEAR, weights);
string attribute = "Q["+band+"]";
int bandIndex = getMetaData().getAttributeIndex(attribute);
if (bandIndex >= 0)
{
for (map<int, double>::iterator it = weights.begin(); it != weights.end(); it++)
{
pointIndex = (*it).first;
if (pointIndex < 0) return NaN_DOUBLE;
weight = (*it).second;
integral += weight/pm->getPointValueDouble(pointIndex, bandIndex);
pathLength += weight;
}
return pathLength/integral;
}
else
{
int q0Index = getMetaData().getAttributeIndex("Q0");
int etaIndex = getMetaData().getAttributeIndex("ETA");
if (q0Index < 0 || etaIndex < 0)
{
ostringstream os;
os << endl << "ERROR in GeoTessModelAmplitude::getPathQ" << endl
<< "Model does not support attributes Q0/ETA or " << attribute
<< ". Supported attributes include:" << endl;
for (int i=0; i<getNAttributes(); ++i)
os << " " << i << ": " << getMetaData().getAttributeName(i) << endl;
throw GeoTessException(os, __FILE__, __LINE__, 6005);
}
map<string, vector<float> >::iterator freq = frequencyMap.find(band);
if (freq == frequencyMap.end())
{
ostringstream os;
os << endl << "ERROR in GeoTessModelAmplitude::getPathQ" << endl
<< band << "is not a supported frequency band. Supported attributes include:" << endl;
for (int i=0; i<getNAttributes(); ++i)
os << " " << i << ": " << getMetaData().getAttributeName(i) << endl;
throw GeoTessException(os, __FILE__, __LINE__, 6005);
}
double centerFrequency = sqrt((*freq).second[0] * (*freq).second[1]);
if (centerFrequency < 1e-6)
{
ostringstream os;
os << endl << "ERROR in GeoTessModelAmplitude::getPathQ" << endl
<< "centerFrequency = " << centerFrequency << " is too small." << endl;
throw GeoTessException(os, __FILE__, __LINE__, 6005);
}
double q0, eta;
for (map<int, double>::iterator it = weights.begin(); it != weights.end(); it++)
{
pointIndex = (*it).first;
if (pointIndex < 0) return NaN_DOUBLE;
weight = (*it).second;
q0 = pm->getPointValueDouble(pointIndex, q0Index);
eta = pm->getPointValueDouble(pointIndex, etaIndex);
integral += weight/(q0 * pow(centerFrequency, eta));
pathLength += weight;
}
return pathLength/integral;
}
}
/**
* Retrieve the value of effective Q for the specified frequency band,
* using weights computed using GeoTessModel::getWeights, avoid repeat getWeights calls
* Q stored as floats
* @param band the frequency band, e.g., "1.0_2.0"
* @param weights a map from integer point index to double path weight at that point.
* @return the value of effective Q for the specified frequency band,
* @throws GeoTessException
*/
double getPathQ(const string& band, map<int, double> weights)
{
GeoTessPointMap* pm = getPointMap(); // ok to call every time? Yes. Only retrieves a reference.
int pointIndex;
double weight;
double integral = 0, pathLength=0.;
string attribute = "Q["+band+"]";
int bandIndex = getMetaData().getAttributeIndex(attribute);
if (bandIndex >= 0)
{
for (map<int, double>::iterator it = weights.begin(); it != weights.end(); it++)
{
pointIndex = (*it).first;
if (pointIndex < 0) return NaN_DOUBLE;
// check weight defined > 0, == 0
weight = (*it).second;
// check Q defined
integral += weight/pm->getPointValueFloat(pointIndex, bandIndex);
pathLength += weight;
}
return pathLength/integral; // check integral > 0
}
else
{
int q0Index = getMetaData().getAttributeIndex("Q0");
int etaIndex = getMetaData().getAttributeIndex("ETA");
if (q0Index < 0 || etaIndex < 0)
{
ostringstream os;
os << endl << "ERROR in GeoTessModelAmplitude::getPathQ" << endl
<< "Model does not support attributes Q0/ETA or " << attribute
<< ". Supported attributes include:" << endl;
for (int i=0; i<getNAttributes(); ++i)
os << " " << i << ": " << getMetaData().getAttributeName(i) << endl;
throw GeoTessException(os, __FILE__, __LINE__, 6005);
}
map<string, vector<float> >::iterator freq = frequencyMap.find(band);
if (freq == frequencyMap.end())
{
ostringstream os;
os << endl << "ERROR in GeoTessModelAmplitude::getPathQ" << endl
<< band << "is not a supported frequency band. Supported attributes include:" << endl;
for (int i=0; i<getNAttributes(); ++i)
os << " " << i << ": " << getMetaData().getAttributeName(i) << endl;
throw GeoTessException(os, __FILE__, __LINE__, 6005);
}
double centerFrequency = sqrt((*freq).second[0] * (*freq).second[1]);
if (centerFrequency < 1e-6)
{
ostringstream os;
os << endl << "ERROR in GeoTessModelAmplitude::getPathQ" << endl
<< "centerFrequency = " << centerFrequency << " is too small." << endl;
throw GeoTessException(os, __FILE__, __LINE__, 6005);
}
double q0, eta;
for (map<int, double>::iterator it = weights.begin(); it != weights.end(); it++)
{
pointIndex = (*it).first;
if (pointIndex < 0) return NaN_DOUBLE;
// check weight > 0, == 0
weight = (*it).second;
// check q0, eta defined
q0 = pm->getPointValueDouble(pointIndex, q0Index);
eta = pm->getPointValueDouble(pointIndex, etaIndex);
integral += weight/(q0 * pow(centerFrequency, eta));
pathLength += weight;
}
return pathLength/integral; // check integral > 0
}
}
int getFileformat() { return fileformat; }
/**
* Retrieve the phase supported by this model
* @return the phase supported by this model
*/
string getPhase() { return phase; }
/**
* Get reference to the map from station -> channel -> band -> siteTran
* @return a reference to the map from station -> channel -> band -> siteTran
*/
map<string, map<string, map<string, float> > >& getSiteTrans()
{ return siteTrans; }
/**
* Retrieve the site term for the specified station/channel/band
* or NaN if not supported.
* @param station
* @param channel
* @param band
* @return
*/
float getSiteTrans(const string& station, const string& channel, const string& band)
{
map<string, map<string, map<string, float> > >::iterator it1 = siteTrans.find(station);
if (it1 != siteTrans.end())
{
map<string, map<string, float> >::iterator it2 = (*it1).second.find(channel);
if (it2 != (*it1).second.end())
{
map<string, float>::iterator it3 = (*it2).second.find(band);
if (it3 != (*it2).second.end())
return (*it3).second;
}
}
return NaN_FLOAT;
}
/**
* Retrieve the total number site terms supported for all station/channel/bands
* @return the total number site terms supported for all station/channel/bands
*/
int getNSiteTrans()
{
int count = 0;
for (map<string, map<string, map<string, float> > >::iterator it1 = siteTrans.begin(); it1 != siteTrans.end(); ++it1)
for (map<string, map<string, float> >::iterator it2 = (*it1).second.begin(); it2 != (*it1).second.end(); ++it2)
count += (*it2).second.size();
return count;
}
/**
* Retrieve the number of stations that have site terms represented.
* @return the number of stations that have site terms represented.
*/
int getNStations()
{ return siteTrans.size(); }
/**
* Retrieve the set of channels supported by the specified station.
* @param station
* @param channels the set of channels supported by the specified station.
*/
void getStations(set<string>& stations)
{
for (map<string, map<string, map<string, float> > >::iterator it = siteTrans.begin(); it != siteTrans.end(); ++it)
stations.insert((*it).first);
}
int getNChannels(const string& station)
{
map<string, map<string, map<string, float> > >::iterator it1 = siteTrans.find(station);
if (it1 != siteTrans.end())
return (*it1).second.size();
return 0;
}
int getNBands(const string& station, const string& channel)
{
map<string, map<string, map<string, float> > >::iterator it1 = siteTrans.find(station);
if (it1 != siteTrans.end())
{
map<string, map<string, float> >::iterator it2 = (*it1).second.find(channel);
if (it2 != (*it1).second.end())
return (*it2).second.size();
}
return 0;
}
/**
* Retrieve the set of channels supported by the specified station.
* @param station
* @param channels the set of channels supported by the specified station.
*/
void getChannels(const string& station, set<string>& channels)
{
map<string, map<string, map<string, float> > >::iterator it1 = siteTrans.find(station);
if (it1 != siteTrans.end())
for (map<string, map<string, float> >::iterator it2 = (*it1).second.begin(); it2 != (*it1).second.end(); ++it2)
channels.insert((*it2).first);
}
/**
* Retrieve the set of channels supported by the specified station.
* @param station
* @param channel
* @param bands the set of bands supported by the specified station.
*/
void getBands(const string& station, const string& channel, set<string>& bands)
{
map<string, map<string, map<string, float> > >::iterator it1 = siteTrans.find(station);
if (it1 != siteTrans.end())