version  0.0.1
Defines the C++ API for MsPASS
BasicTimeSeries.h
1 #ifndef _BASICTIMESERIES_H_
2 #define _BASICTIMESERIES_H_
3 #include <math.h>
4 #include <boost/archive/text_iarchive.hpp>
5 #include <boost/archive/text_oarchive.hpp>
6 namespace mspass::seismic{
14 enum class TimeReferenceType {
15  UTC,
16  Relative
17 };
18 
35 {
36 public:
37 
56  virtual ~BasicTimeSeries(){};
63  double time(const int i)const
64  {
65  return(mt0+mdt*static_cast<double>(i));
66  };
74  int sample_number(double t)const
75  {
76  return(round((t-mt0)/mdt));
77  };
82  double endtime()const noexcept
83  {
84  return(mt0 + (static_cast<double>(nsamp) - 1.0)*mdt);
85  };
88  bool shifted() const
89  {
90  return t0shift_is_valid;
91  };
102  double time_reference() const;
115  void force_t0_shift(const double t)
116  {
117  this->t0shift=t;
118  t0shift_is_valid=true;
119  };
129  virtual void ator(const double tshift);
138  virtual void rtoa();
145  virtual void shift(const double dt);
147  bool live()const{return this->mlive;};
149  bool dead()const{return !(this->mlive);};
151  void kill(){this->mlive=false;};
155  void set_live(){this->mlive=true;};
157  double dt()const {return this->mdt;};
159  bool time_is_UTC()const
160  {
162  return true;
163  else
164  return false;
165  };
166  bool time_is_relative()const
167  {
169  return true;
170  else
171  return false;
172  };
173  TimeReferenceType timetype()const
174  {
175  return this->tref;
176  }
178  double samprate()const
179  {
180  return 1.0/mdt;
181  }
183  size_t npts()const {return nsamp;};
186  double t0()const {return this->mt0;};
198  virtual void set_dt(const double sample_interval)
199  {
200  mdt=sample_interval;
201  };
213  virtual void set_npts(const size_t npts)
214  {
215  nsamp=npts;
216  };
228  virtual void set_t0(const double t0in)
229  {
230  mt0=t0in;
231  };
243  void set_tref(const TimeReferenceType newtref)
244  {
245  tref=newtref;
246  };
248  BasicTimeSeries& operator=(const BasicTimeSeries& parent);
249 
250 protected:
256  bool mlive;
260  double mdt;
264  double mt0;
268  size_t nsamp;
279  /* We actually test for t0shift two ways. If this is true we always accept it.
280  * If false we check for nonzero t0shift and override if necessary.
281  * */
282  bool t0shift_is_valid;
283  /*When ator or rtoa are called this variable defines the conversion back
284  * and forth. The shift method should be used to change it. */
285  double t0shift;
286 private:
287  friend boost::serialization::access;
288  template<class Archive>
289  void serialize(Archive& ar,const unsigned int version)
290  {
291  ar & mlive;
292  ar & mdt;
293  ar & nsamp;
294  ar & mt0;
295  ar & tref;
296  ar & t0shift_is_valid;
297  ar & t0shift;
298  };
299 };
300 }
301 #endif // End guard
Base class for time series objects.
Definition: BasicTimeSeries.h:35
BasicTimeSeries()
Definition: BasicTimeSeries.cc:42
size_t nsamp
Definition: BasicTimeSeries.h:268
virtual void set_dt(const double sample_interval)
Set the sample interval.
Definition: BasicTimeSeries.h:198
void set_live()
Definition: BasicTimeSeries.h:155
bool shifted() const
Definition: BasicTimeSeries.h:88
double samprate() const
Definition: BasicTimeSeries.h:178
virtual void rtoa()
Definition: BasicTimeSeries.cc:21
virtual ~BasicTimeSeries()
Virtual destructor.
Definition: BasicTimeSeries.h:56
size_t npts() const
Definition: BasicTimeSeries.h:183
virtual void shift(const double dt)
Definition: BasicTimeSeries.cc:76
virtual void set_npts(const size_t npts)
Set the number of samples attribute for data.
Definition: BasicTimeSeries.h:213
double time(const int i) const
Definition: BasicTimeSeries.h:63
double t0() const
Definition: BasicTimeSeries.h:186
bool mlive
Definition: BasicTimeSeries.h:256
double time_reference() const
Definition: BasicTimeSeries.cc:86
bool live() const
Definition: BasicTimeSeries.h:147
bool dead() const
Definition: BasicTimeSeries.h:149
BasicTimeSeries & operator=(const BasicTimeSeries &parent)
Definition: BasicTimeSeries.cc:62
bool time_is_UTC() const
Definition: BasicTimeSeries.h:159
void force_t0_shift(const double t)
Force a t0 shift value on data.
Definition: BasicTimeSeries.h:115
TimeReferenceType tref
Definition: BasicTimeSeries.h:278
int sample_number(double t) const
Definition: BasicTimeSeries.h:74
virtual void set_t0(const double t0in)
Set the data start time.
Definition: BasicTimeSeries.h:228
void set_tref(const TimeReferenceType newtref)
Force the time standard.
Definition: BasicTimeSeries.h:243
void kill()
Definition: BasicTimeSeries.h:151
virtual void ator(const double tshift)
Definition: BasicTimeSeries.cc:9
double mdt
Definition: BasicTimeSeries.h:260
double mt0
Definition: BasicTimeSeries.h:264
double dt() const
Definition: BasicTimeSeries.h:157
double endtime() const noexcept
Definition: BasicTimeSeries.h:82
Define metadata keys.
Definition: BasicSpectrum.h:6
TimeReferenceType
Type of time standard for time series data.
Definition: BasicTimeSeries.h:14