version  0.0.1
Defines the C++ API for MsPASS
Loading...
Searching...
No Matches
BasicTimeSeries.h
1#ifndef _BASICTIMESERIES_H_
2#define _BASICTIMESERIES_H_
3#include <boost/archive/text_iarchive.hpp>
4#include <boost/archive/text_oarchive.hpp>
5#include <math.h>
6namespace mspass::seismic {
15 UTC,
18};
19
36public:
55 virtual ~BasicTimeSeries() {};
62 double time(const int i) const {
63 return (mt0 + mdt * static_cast<double>(i));
64 };
72 int sample_number(double t) const { return (round((t - mt0) / mdt)); };
77 double endtime() const noexcept {
78 return (mt0 + (static_cast<double>(nsamp) - 1.0) * mdt);
79 };
82 bool shifted() const { return t0shift_is_valid; };
85 double get_t0shift() const { return this->t0shift; };
96 double time_reference() const;
109 void force_t0_shift(const double t) {
110 this->t0shift = t;
111 t0shift_is_valid = true;
112 };
123 virtual void ator(const double tshift);
132 virtual void rtoa();
140 virtual void shift(const double dt);
142 bool live() const { return this->mlive; };
145 bool dead() const { return !(this->mlive); };
147 void kill() { this->mlive = false; };
151 void set_live() { this->mlive = true; };
153 double dt() const { return this->mdt; };
155 bool time_is_UTC() const {
157 return true;
158 else
159 return false;
160 };
161 bool time_is_relative() const {
163 return true;
164 else
165 return false;
166 };
167 TimeReferenceType timetype() const { return this->tref; }
169 double samprate() const { return 1.0 / mdt; }
171 size_t npts() const { return nsamp; };
174 double t0() const { return this->mt0; };
185 std::vector<double> time_axis() const;
197 virtual void set_dt(const double sample_interval) { mdt = sample_interval; };
209 virtual void set_npts(const size_t npts) { nsamp = npts; };
221 virtual void set_t0(const double t0in) { mt0 = t0in; };
233 void set_tref(const TimeReferenceType newtref) { tref = newtref; };
236
237protected:
243 bool mlive;
247 double mdt;
251 double mt0;
255 size_t nsamp;
266 /* We actually test for t0shift two ways. If this is true we always accept
267 * it. If false we check for nonzero t0shift and override if necessary.
268 * */
269 bool t0shift_is_valid;
270 /*When ator or rtoa are called this variable defines the conversion back
271 * and forth. The shift method should be used to change it. */
272 double t0shift;
273
274private:
275 friend boost::serialization::access;
276 template <class Archive>
277 void serialize(Archive &ar, const unsigned int version) {
278 ar & mlive;
279 ar & mdt;
280 ar & nsamp;
281 ar & mt0;
282 ar & tref;
283 ar & t0shift_is_valid;
284 ar & t0shift;
285 };
286};
287} // namespace mspass::seismic
288#endif // End guard
Base class for time series objects.
Definition BasicTimeSeries.h:35
BasicTimeSeries()
Definition BasicTimeSeries.cc:45
size_t nsamp
Definition BasicTimeSeries.h:255
virtual void set_dt(const double sample_interval)
Set the sample interval.
Definition BasicTimeSeries.h:197
void set_live()
Definition BasicTimeSeries.h:151
double get_t0shift() const
Definition BasicTimeSeries.h:85
bool shifted() const
Definition BasicTimeSeries.h:82
double samprate() const
Definition BasicTimeSeries.h:169
virtual void rtoa()
Definition BasicTimeSeries.cc:22
virtual ~BasicTimeSeries()
Virtual destructor.
Definition BasicTimeSeries.h:55
size_t npts() const
Definition BasicTimeSeries.h:171
virtual void shift(const double dt)
Definition BasicTimeSeries.cc:75
virtual void set_npts(const size_t npts)
Set the number of samples attribute for data.
Definition BasicTimeSeries.h:209
double time(const int i) const
Definition BasicTimeSeries.h:62
double t0() const
Definition BasicTimeSeries.h:174
bool mlive
Definition BasicTimeSeries.h:243
double time_reference() const
Definition BasicTimeSeries.cc:84
bool live() const
Definition BasicTimeSeries.h:142
std::vector< double > time_axis() const
Definition BasicTimeSeries.cc:98
bool dead() const
Definition BasicTimeSeries.h:145
BasicTimeSeries & operator=(const BasicTimeSeries &parent)
Definition BasicTimeSeries.cc:63
bool time_is_UTC() const
Definition BasicTimeSeries.h:155
void force_t0_shift(const double t)
Force a t0 shift value on data.
Definition BasicTimeSeries.h:109
TimeReferenceType tref
Definition BasicTimeSeries.h:265
int sample_number(double t) const
Definition BasicTimeSeries.h:72
virtual void set_t0(const double t0in)
Set the data start time.
Definition BasicTimeSeries.h:221
void set_tref(const TimeReferenceType newtref)
Force the time standard.
Definition BasicTimeSeries.h:233
void kill()
Definition BasicTimeSeries.h:147
virtual void ator(const double tshift)
Definition BasicTimeSeries.cc:9
double mdt
Definition BasicTimeSeries.h:247
double mt0
Definition BasicTimeSeries.h:251
double dt() const
Definition BasicTimeSeries.h:153
double endtime() const noexcept
Definition BasicTimeSeries.h:77
Define metadata keys.
Definition BasicSpectrum.h:6
TimeReferenceType
Type of time standard for time series data.
Definition BasicTimeSeries.h:14