GPLIB++
TimeSeries.h
Go to the documentation of this file.
1 #ifndef CTIMSERIES_H
2 #define CTIMSERIES_H
3 #include "FatalException.h"
4 #include "TimeSeriesComponent.h"
5 #include <boost/date_time/posix_time/posix_time_types.hpp>
6 #include <vector>
7 
8 namespace gplib
9  {
10  /** \addtogroup mttools MT data analysis, processing and inversion */
11  /* @{ */
12 
13  //! This class is the base class for all classes dealing with MT time series
14  class TimeSeries
15  {
16  public:
17  //! We use the boost library time functionality for time types and store the time for each point in a vector
18  typedef boost::posix_time::ptime ttime;
19  typedef std::vector<ttime> ttimedata;
20  protected:
21  //! The data for the north-south magnetic field
23  //! The data for the east-west magnetic field
25  //! The data for the vertical magnetic field
27  //! The data for the north-south electric field
29  //! The data for the east-west electric field
31  //! The time associated with each data point
33  public:
34  //! Access function for Hx, returns reference for efficiency
36  {
37  return Hx;
38  }
40  {
41  return Hy;
42  }
44  {
45  return Hz;
46  }
48  {
49  return Ex;
50  }
52  {
53  return Ey;
54  }
56  {
57  return t;
58  }
59  //! Return the size of the time series, throws if one of the components has a different size
60  size_t Size();
61  /*! Declaration for GetData() that reads data from
62  * a file. This is intended for use with external data, such as
63  * recorded data, or synthetic data from external programs.
64  */
65  virtual void GetData(const std::string filename) = 0;
66  /*! The abstract declaration for a method that writes the data to
67  * a file. Therefore no version without a filename is present
68  */
69  virtual void WriteData(const std::string filename) = 0;
70  //! The samplerate is stored in each component, we just return the samplerate of Hx assuming they are all equal
71  double GetSamplerate()
72  {
73  const double samplerate = Hx.GetSamplerate();
74  if (samplerate != Hy.GetSamplerate() || samplerate
75  != Hz.GetSamplerate() || samplerate != Ex.GetSamplerate()
76  || samplerate != Ey.GetSamplerate())
77  throw FatalException("Samplerate is not equal for all components");
78  return samplerate;
79  }
80  TimeSeries();
81  virtual ~TimeSeries();
82  TimeSeries& operator=(const TimeSeries &source);
83  //! Multiply all components by a constant factor
84  TimeSeries& operator*=(const double &factor);
85  //! Add a constant shift to all components
86  TimeSeries& operator+=(const double &shift);
87  //! Erase data between startindex and endindex
88  void erase(const int startindex, const int endindex);
89  //friend void Synchronize(TimeSeries &Data1, TimeSeries &Data2);
90  };
91 
92  /*! Synchronize two Objects containing MT data so that they have the same start time
93  */
94  void Synchronize(TimeSeries &Data1, TimeSeries &Data2);
95  /* @} */
96  }
97 #endif
TimeSeriesComponent & GetEx()
Definition: TimeSeries.h:47
ttimedata t
The time associated with each data point.
Definition: TimeSeries.h:32
TimeSeriesComponent Ey
The data for the east-west electric field.
Definition: TimeSeries.h:30
virtual void GetData(const std::string filename)=0
virtual ~TimeSeries()
Definition: TimeSeries.cpp:21
void erase(const int startindex, const int endindex)
Erase data between startindex and endindex.
Definition: TimeSeries.cpp:59
double GetSamplerate()
The samplerate is stored in each component, we just return the samplerate of Hx assuming they are all...
Definition: TimeSeries.h:71
This class is the base class for all classes dealing with MT time series.
Definition: TimeSeries.h:14
virtual void WriteData(const std::string filename)=0
TimeSeriesComponent & GetHy()
Definition: TimeSeries.h:39
TimeSeriesComponent Ex
The data for the north-south electric field.
Definition: TimeSeries.h:28
TimeSeriesComponent is the base storage class for all types of time series data.
boost::posix_time::ptime ttime
We use the boost library time functionality for time types and store the time for each point in a vec...
Definition: TimeSeries.h:18
std::vector< ttime > ttimedata
Definition: TimeSeries.h:19
TimeSeries & operator=(const TimeSeries &source)
Definition: TimeSeries.cpp:25
void Synchronize(TimeSeries &Data1, TimeSeries &Data2)
Synchronize only works for continuous data at this point.
Definition: TimeSeries.cpp:88
ttimedata & GetTime()
Definition: TimeSeries.h:55
double GetSamplerate() const
Return samplerate in Hz.
TimeSeriesComponent Hz
The data for the vertical magnetic field.
Definition: TimeSeries.h:26
TimeSeriesComponent Hy
The data for the east-west magnetic field.
Definition: TimeSeries.h:24
TimeSeriesComponent Hx
The data for the north-south magnetic field.
Definition: TimeSeries.h:22
size_t Size()
Return the size of the time series, throws if one of the components has a different size...
Definition: TimeSeries.cpp:74
TimeSeriesComponent & GetEy()
Definition: TimeSeries.h:51
TimeSeries & operator+=(const double &shift)
Add a constant shift to all components.
Definition: TimeSeries.cpp:49
TimeSeriesComponent & GetHz()
Definition: TimeSeries.h:43
TimeSeries & operator*=(const double &factor)
Multiply all components by a constant factor.
Definition: TimeSeries.cpp:39
The basic exception class for all errors that arise in gplib.
TimeSeriesComponent & GetHx()
Access function for Hx, returns reference for efficiency.
Definition: TimeSeries.h:35