GPLIB++
MTStation.h
Go to the documentation of this file.
1 #ifndef CMTSTATION_H
2 #define CMTSTATION_H
3 
4 #include "MTTensor.h"
5 #include "MagneticTF.h"
6 #include "types.h"
7 #include <string>
8 #include <map>
9 #include <boost/function.hpp>
10 
11 namespace gplib
12  {
13  /** \addtogroup mttools MT data analysis, processing and inversion */
14  /* @{ */
15 
16  //! The class MTStation is used to store the transfer functions and related information for a MT-site
17  class MTStation
18  {
19  public:
21  {
23  };
24  private:
25  //! Station Latitude
26  double latitude;
27  //! Station Lonigude
28  double longitude;
29  //! Station elevation
30  double elevation;
31  //! Name, does not have to be filename for j and edi data
32  std::string name;
33  //! Azimuth from magnetic north if station was rotated
34  double azimuth;
35  // The MTTensor data for each frequency
36  std::vector<MTTensor> MTData;
37  // The Local induction vectors for each frequency
38  std::vector<MagneticTF> TFData;
39  void DoRotate(const int i, const double angle);
40  //! Perform some initial Setup
41  void InitialSetup();
42  //! the format the data was stored in the original file
43  tmtdataformat dataformat;
44  //! Write data to file in goettingen .mtt format
45  void WriteMtt(const std::string filename);
46  //! Read data from edi file (not all features supported)
47  void ReadEdi(const std::string filename);
48  //! Read data from j file
49  void ReadJ(const std::string filename);
50  //! Read data from goettingen .mtt file
51  void ReadMtt(const std::string filename);
52  //! Read output of Pek's 1D anisotropy code
53  void ReadPek1D(const std::string filename);
54  //! Read output of Egbert's code, so far only supports files that contain only impedances and no tipper
55  void ReadZmm(const std::string filename);
56  //! Read mtf format for impedances by M. Smirnov
57  void ReadMtf(const std::string filename);
58 #ifdef HAVENETCDF
59  void ReadNetCDF(const std::string filename);
60 #endif
61  // helper function for WriteAsJ
62  void WriteJBlock(boost::function<std::complex<double>(const MTTensor*)> Comp,
63  boost::function<double(const MTTensor*)> Err, std::ofstream &outfile,
64  const double convfactor);
65  protected:
66  //! Update all derived quantities
67  void Update();
68  //! Assign() assigns zero to all derived quantities, this makes the calculation
69  // more easy
70  void Assign(const int nfreq);
71  public:
72  // Assign zero to everything, convenient for synthetic data that is not read in from file
73  void AssignAll(const int nfreq);
74  //! Given a rotation angle in radian this method rotates the impedance tensor
75  //! and updates all derived quantities
76  void Rotate(const double rotangle);
77  //! Rotate to zero rotation angle
78  void Rotate(void);
79  //! return the available frequencies in a single vector
80  trealdata GetFrequencies() const;
81  //! Set the frequencies of the tensor elements, invalidates the previously stored impedance data, mainly for creating synthetic data
82  void SetFrequencies(const trealdata &freqs);
83  //! access funtion for Latitude
84  double GetLatitude() const
85  {
86  return latitude;
87  }
88  void SetLatitude(double lat)
89  {
90  latitude = lat;
91  }
92  double GetLongitude() const
93  {
94  return longitude;
95  }
96  void SetLongitude(double lon)
97  {
98  longitude = lon;
99  }
100  double GetElevation() const
101  {
102  return elevation;
103  }
104  std::string GetName()
105  {
106  return name;
107  }
108  double GetAzimuth() const
109  {
110  return azimuth;
111  }
112  ;
113  //! direct acces to a tensor at a given index
114  const MTTensor &at(const unsigned int i) const
115  {
116  return MTData.at(i);
117  }
118  //! Get the full vector of Tensor elements read only
119  const std::vector<MTTensor> &GetMTData() const
120  {
121  return MTData;
122  }
123  //! Get the full vector of Tensor elements for reading and writing
124  std::vector<MTTensor> &SetMTData()
125  {
126  return MTData;
127  }
128  //! for parallel runs we need to make a copy of the object and its derived classes
129  virtual MTStation *clone() const
130  {
131  return new MTStation(*this);
132  }
133  MTStation& operator=(const MTStation& source);
134  MTStation();
135  MTStation(const MTStation &old);
136  MTStation(const int size);
137  MTStation(const std::string filename);
138  virtual ~MTStation();
139  //! read in data from file, determines format by ending
140  virtual void GetData(const std::string filename);
141  virtual void GetData()
142  {
143  }
144  //Write data to file, same as WriteBack
145  virtual void WriteData(const std::string filename);
146  friend class C1DMTSynthData;
147  //! Write data in goettingen .mtt format
148  void WriteAsMtt(const std::string filename);
149  //! Write data as edi (no functionality yet)
150  void WriteAsEdi(const std::string filename);
151  //! Write data to j-file
152  void WriteAsJ(const std::string filename);
153  //! Write data back in original format, with filename given by station name
154  void WriteBack();
155  };
156 
157 const std::map<std::string, MTStation::tmtdataformat> MTFileTypes =
158  {
159  { ".mtt", MTStation::tmtdataformat::mtt},
160  { ".j", MTStation::tmtdataformat::j},
161  { ".dat", MTStation::tmtdataformat::j},
162  { ".nc", MTStation::tmtdataformat::nc},
163  { ".zmm", MTStation::tmtdataformat::zmm},
164  { ".mtf", MTStation::tmtdataformat::mtf},
165  { ".edi", MTStation::tmtdataformat::edi},
166  { ".pek", MTStation::tmtdataformat::pek}
167  }
168 ;
169 /* @} */
170 }
171 #endif // CMTSTATION_H
double GetLatitude() const
access funtion for Latitude
Definition: MTStation.h:84
const MTTensor & at(const unsigned int i) const
direct acces to a tensor at a given index
Definition: MTStation.h:114
virtual void WriteData(const std::string filename)
Definition: MTStation.cpp:655
void AssignAll(const int nfreq)
Definition: MTStation.cpp:70
MTStation & operator=(const MTStation &source)
Definition: MTStation.cpp:832
double GetElevation() const
Definition: MTStation.h:100
void WriteAsEdi(const std::string filename)
Write data as edi (no functionality yet)
Definition: MTStation.cpp:687
std::string GetName()
Definition: MTStation.h:104
void WriteAsJ(const std::string filename)
Write data to j-file.
Definition: MTStation.cpp:714
double GetAzimuth() const
Definition: MTStation.h:108
The class MTStation is used to store the transfer functions and related information for a MT-site...
Definition: MTStation.h:17
const std::map< std::string, MTStation::tmtdataformat > MTFileTypes
Definition: MTStation.h:157
void SetLatitude(double lat)
Definition: MTStation.h:88
virtual void GetData()
Definition: MTStation.h:141
virtual ~MTStation()
Definition: MTStation.cpp:54
void Rotate(void)
Rotate to zero rotation angle.
Definition: MTStation.cpp:126
void WriteAsMtt(const std::string filename)
Write data in goettingen .mtt format.
Definition: MTStation.cpp:681
void Assign(const int nfreq)
Assign() assigns zero to all derived quantities, this makes the calculation.
Definition: MTStation.cpp:74
virtual MTStation * clone() const
for parallel runs we need to make a copy of the object and its derived classes
Definition: MTStation.h:129
Calculate synthetic MT data for a 1D model using Cagniard's algorithm.
Stores MT-Tensor components at a single frequency, calculates derived quantities. ...
Definition: MTTensor.h:16
const std::vector< MTTensor > & GetMTData() const
Get the full vector of Tensor elements read only.
Definition: MTStation.h:119
const int size
Definition: perftest.cpp:14
std::vector< MTTensor > & SetMTData()
Get the full vector of Tensor elements for reading and writing.
Definition: MTStation.h:124
void WriteBack()
Write data back in original format, with filename given by station name.
Definition: MTStation.cpp:661
trealdata GetFrequencies() const
return the available frequencies in a single vector
Definition: MTStation.cpp:136
void SetFrequencies(const trealdata &freqs)
Set the frequencies of the tensor elements, invalidates the previously stored impedance data...
Definition: MTStation.cpp:144
void SetLongitude(double lon)
Definition: MTStation.h:96
void Update()
Update all derived quantities.
Definition: MTStation.cpp:84
double GetLongitude() const
Definition: MTStation.h:92