GPLIB++
ptavg.cpp
Go to the documentation of this file.
1 #include <iostream>
2 #include <iomanip>
3 #include <fstream>
4 #include "MTStationList.h"
5 #include "PTensorMTStation.h"
6 #include "VecMat.h"
7 #include "statutils.h"
8 
9 using namespace std;
10 using namespace gplib;
11 
12 /*!
13  * \addtogroup UtilProgs Utility Programs
14  *@{
15  * \file
16  * Average the phase tensor elements from a number of MT files, each datum is weighted equally.
17  * This program is mainly used as an attempt to get average 1D (isotropic or anisotropic) responses
18  * for a region from a number of measurements.
19  */
20 
21 int main()
22  {
23  MTStationList MTSites;
24  PTensorMTStation PTStation;
25  string infilename;
26 
27  string version = "$Id: ptavg.cpp 1836 2009-11-27 12:17:24Z mmoorkamp $";
28  cout << endl << endl;
29  cout << "Program " << version << endl;
30  cout << "Average MT phase tensor elements from a list of files " << endl;
31  cout
32  << "The average phase tensor will be written in a file called avg.ptensor "
33  << endl;
34  cout << "List filename:";
35  cin >> infilename;
36 
37  MTSites.GetData(infilename);
38  const size_t nfreq = MTSites.at(0).GetFrequencies().size();
39  const size_t nsites = MTSites.GetList().size();
40  const double errorfloor = 0.02;
41  const double absolutemin = 1e-4; // have to find a better solution to avoid strong weighting of 0 values
42  for (size_t j = 0; j < nfreq; ++j)
43  {
44  gplib::rvec xxvalues(nsites);
45  gplib::rvec xyvalues(nsites);
46  gplib::rvec yxvalues(nsites);
47  gplib::rvec yyvalues(nsites);
48 
49  for (size_t i = 0; i < nsites; ++i)
50  {
51  xxvalues(i) = MTSites.at(i).GetMTData().at(j).GetPhi11();
52  xyvalues(i) = MTSites.at(i).GetMTData().at(j).GetPhi12();
53  yxvalues(i) = MTSites.at(i).GetMTData().at(j).GetPhi21();
54  yyvalues(i) = MTSites.at(i).GetMTData().at(j).GetPhi22();
55 
56  }
57  double phi11 = Mean(xxvalues.begin(), xxvalues.end());
58  double phi12 = Mean(xyvalues.begin(), xyvalues.end());
59  double phi21 = Mean(yxvalues.begin(), yxvalues.end());
60  double phi22 = Mean(yyvalues.begin(), yyvalues.end());
61 
62  double varphi11 = Variance(xxvalues.begin(), xxvalues.end());
63  double varphi12 = Variance(xyvalues.begin(), xyvalues.end());
64  double varphi21 = Variance(yxvalues.begin(), yxvalues.end());
65  double varphi22 = Variance(yyvalues.begin(), yyvalues.end());
66 
67  PTStation.GetTensor().push_back(PTensorMTData(
68  MTSites.at(0).GetFrequencies().at(j), phi11, phi12, phi21, phi22,
69  sqrt(varphi11), sqrt(varphi12), sqrt(varphi21), sqrt(varphi22)));
70  }
71  PTStation.WriteData("avg.ptensor");
72  }
73 /*@}*/
74 
This class is for the special case where we only have phase tensor data and errors, but not the full impedance.
Definition: PTensorMTData.h:12
MTStation & at(int loc)
Get a reference to a site at a given index.
std::iterator_traits< InputIterator >::value_type Mean(InputIterator begin, InputIterator end)
Calculate the mean for a given range.
Definition: statutils.h:21
std::vector< PTensorMTData > & GetTensor()
void WriteData(const std::string &filename)
MTStationList holds a number of MTSites, usually associated with a single project, line, etc.
Definition: MTStationList.h:16
int main()
Definition: angleavg.cpp:12
tStationList & GetList()
Access to the complete vector of Stations.
Definition: MTStationList.h:31
void GetData(const std::string filename)
Read a list of filenames and the associated data in those files to fill the list. ...
string version
Definition: makeinput.cpp:16
const std::vector< MTTensor > & GetMTData() const
Get the full vector of Tensor elements read only.
Definition: MTStation.h:119
std::iterator_traits< InputIterator >::value_type Variance(InputIterator begin, InputIterator end, typename std::iterator_traits< InputIterator >::value_type mv)
Calculate the Variance and give the mean as a third input parameter.
Definition: statutils.h:30
trealdata GetFrequencies() const
return the available frequencies in a single vector
Definition: MTStation.cpp:136