4 #include <boost/program_options.hpp>
17 using namespace gplib;
18 namespace po = boost::program_options;
30 "$Id: simple_processing.cpp 1853 2010-05-28 10:37:12Z mmoorkamp $";
31 int main(
int argc,
char *argv[])
34 <<
"This is simpleproc: Simple most estimation of MT transfer function, spectral stacking"
36 cout <<
" Usage simpleproc inputfilename";
38 <<
" Output will have the same name as MTU Input with '.mtt' appended "
40 cout <<
" This is Version: " <<
version << endl << endl;
44 string infilename, basefilename;
45 unsigned int seglength = 2400;
46 bool mtufilter =
false;
48 po::options_description desc(
"Allowed options");
49 desc.add_options()(
"help",
"produce help message")(
"seglength", po::value<
50 unsigned int>(&seglength)->default_value(2400),
51 "The length of an individual segment for spectral calculations")(
52 "rate", po::value(&rate)->default_value(1.0),
53 "Set the sampling rate in Hz")(
"mtufilter",
54 po::value<bool>(&mtufilter)->default_value(
false),
55 "Read in filter information for mtu data")(
"input-file", po::value<
56 string>(&infilename),
"input file");
58 po::positional_options_description p;
59 p.add(
"input-file", -1);
63 po::command_line_parser(argc, argv). options(desc).positional(p).run(),
72 MtuData.
GetData(infilename.c_str());
73 size_t dotpos = infilename.find(
'.', 0);
74 if (dotpos != string::npos)
75 basefilename = infilename.
erase(dotpos);
76 string exfiltername = basefilename +
"_1.cts";
77 string eyfiltername = basefilename +
"_2.cts";
78 string hxfiltername = basefilename +
"_3.cts";
79 string hyfiltername = basefilename +
"_4.cts";
82 const unsigned int nfreqs = seglength / 2 + 1;
83 tcompdata ExHxCorr(nfreqs, 0);
84 tcompdata ExHyCorr(nfreqs, 0);
85 tcompdata EyHxCorr(nfreqs, 0);
86 tcompdata EyHyCorr(nfreqs, 0);
87 tcompdata HxHxCorr(nfreqs, 0);
88 tcompdata HxHyCorr(nfreqs, 0);
89 tcompdata HyHyCorr(nfreqs, 0);
90 tcompdata Hdet(nfreqs, 0);
91 tcompdata Zxx(nfreqs, 0);
92 tcompdata Zxy(nfreqs, 0);
93 tcompdata Zyx(nfreqs, 0);
94 tcompdata Zyy(nfreqs, 0);
99 MtuFilter ExFilter(seglength, freqstep), EyFilter(seglength, freqstep),
100 HxFilter(seglength, freqstep), HyFilter(seglength, freqstep);
103 ExFilter.GetData(exfiltername);
104 EyFilter.GetData(eyfiltername);
105 HxFilter.GetData(hxfiltername);
106 HyFilter.
GetData(hyfiltername);
108 gplib::cmat ExTimeFrequency, EyTimeFrequency, HxTimeFrequency,
124 const unsigned int nsegs = ExTimeFrequency.size1();
125 ofstream logfile((infilename +
".log").c_str());
126 for (
size_t i = 0; i < Zxx.size(); ++i)
128 for (
size_t j = 0; j < nsegs; ++j)
132 ExTimeFrequency(j, i) /= ExFilter.GetFilterCoeff().at(i);
133 EyTimeFrequency(j, i) /= EyFilter.GetFilterCoeff().at(i);
134 HxTimeFrequency(j, i) /= HxFilter.GetFilterCoeff().at(i);
137 ExHxCorr.at(i) += (ExTimeFrequency(j, i) * conj(HxTimeFrequency(j,
139 ExHyCorr.at(i) += (ExTimeFrequency(j, i) * conj(HyTimeFrequency(j,
141 EyHxCorr.at(i) += (EyTimeFrequency(j, i) * conj(HxTimeFrequency(j,
143 EyHyCorr.at(i) += (EyTimeFrequency(j, i) * conj(HyTimeFrequency(j,
145 HxHyCorr.at(i) += (HxTimeFrequency(j, i) * conj(HyTimeFrequency(j,
147 HxHxCorr.at(i) += (HxTimeFrequency(j, i) * conj(HxTimeFrequency(j,
149 HyHyCorr.at(i) += (HyTimeFrequency(j, i) * conj(HyTimeFrequency(j,
154 Hdet.at(i) = (HxHxCorr.at(i) * HyHyCorr.at(i) - HxHyCorr.at(i) * conj(
156 logfile <<
"Hdet: " << Hdet.at(i) << endl;
157 Zxx.at(i) = ((ExHxCorr.at(i) * HyHyCorr.at(i) - ExHyCorr.at(i) * conj(
158 HxHyCorr.at(i))) / Hdet.at(i));
159 Zxy.at(i) = ((ExHyCorr.at(i) * HxHxCorr.at(i) - ExHxCorr.at(i)
160 * HxHyCorr.at(i)) / Hdet.at(i));
161 Zyx.at(i) = ((EyHxCorr.at(i) * HyHyCorr.at(i) - EyHyCorr.at(i) * conj(
162 HxHyCorr.at(i))) / Hdet.at(i));
163 Zyy.at(i) = ((EyHyCorr.at(i) * HxHxCorr.at(i) - EyHxCorr.at(i)
164 * HxHyCorr.at(i)) / Hdet.at(i));
167 for (
size_t i = 0; i < Zxx.size(); ++i)
170 CurrZ(Zxx.at(i), Zxy.at(i), Zyx.at(i), Zyy.at(i), i * freqstep);
173 vector<double> transferfunc(Zxx.size() * 2 - 1, 0.0);
176 ofstream tffile((infilename +
".tf").c_str());
177 copy(transferfunc.begin(), transferfunc.end(), ostream_iterator<double> (
std::vector< double > & GetData()
Access for data vector, for ease of use and efficiency we return a reference.
TimeSeries & GetData()
return a reference to the actual object stored in the pointer
TimeSeriesComponent & GetEx()
Store the filter coefficients for one component of Phoenix mtu data.
void AssignAll(const int nfreq)
void erase(const int startindex, const int endindex)
Erase data between startindex and endindex.
double GetSamplerate()
The samplerate is stored in each component, we just return the samplerate of Hx assuming they are all...
const tcompdata & GetFilterCoeff()
TimeSeriesComponent & GetHy()
The class MTStation is used to store the transfer functions and related information for a MT-site...
The class CTsSpectrum is used to calculate spectra from (real) time series data.
virtual void GetData(const std::string filename)
TimeSeriesData stores a pointer to the different components of magnetotelluric data and provides func...
void WriteAsMtt(const std::string filename)
Write data in goettingen .mtt format.
Stores MT-Tensor components at a single frequency, calculates derived quantities. ...
This functor returns the weighting factor for the Hanning window, given the relative position (0...
std::vector< MTTensor > & SetMTData()
Get the full vector of Tensor elements for reading and writing.
TimeSeriesComponent & GetEy()
TimeSeriesComponent & GetHx()
Access function for Hx, returns reference for efficiency.