version  0.0.1
Defines the C++ API for MsPASS
Public Member Functions | Protected Attributes | List of all members
mspass::seismic::BasicTimeSeries Class Reference

Base class for time series objects. More...

#include <BasicTimeSeries.h>

Inheritance diagram for mspass::seismic::BasicTimeSeries:
mspass::seismic::CoreSeismogram mspass::seismic::CoreTimeSeries mspass::seismic::Seismogram mspass::seismic::TimeSeries mspass::seismic::SeismogramWGaps mspass::seismic::TimeSeriesWGaps

Public Member Functions

 BasicTimeSeries ()
 
 BasicTimeSeries (const BasicTimeSeries &)
 
virtual ~BasicTimeSeries ()
 Virtual destructor. More...
 
double time (const int i) const
 
int sample_number (double t) const
 
double endtime () const noexcept
 
bool shifted () const
 
double time_reference () const
 
void force_t0_shift (const double t)
 Force a t0 shift value on data. More...
 
virtual void ator (const double tshift)
 
virtual void rtoa ()
 
virtual void shift (const double dt)
 
bool live () const
 
bool dead () const
 
void kill ()
 
void set_live ()
 
double dt () const
 
bool time_is_UTC () const
 
bool time_is_relative () const
 
TimeReferenceType timetype () const
 
double samprate () const
 
size_t npts () const
 
double t0 () const
 
virtual void set_dt (const double sample_interval)
 Set the sample interval. More...
 
virtual void set_npts (const size_t npts)
 Set the number of samples attribute for data. More...
 
virtual void set_t0 (const double t0in)
 Set the data start time. More...
 
void set_tref (const TimeReferenceType newtref)
 Force the time standard. More...
 
BasicTimeSeriesoperator= (const BasicTimeSeries &parent)
 

Protected Attributes

bool mlive
 
double mdt
 
double mt0
 
size_t nsamp
 
TimeReferenceType tref
 
bool t0shift_is_valid
 
double t0shift
 

Detailed Description

Base class for time series objects.

This is a mostly abstract class defining data and methods shared by all data objects that are time series. In MsPASS time series means data sampled on a 1d, uniform grid defined by a sample rate, start time, and number of samples. Derived types can be scalar, vector, complex, or any data that is uniformly sampled.

The seispp version of this class had public attributes for key data are essential for defining any time series data (e.g. sample interval). This was revised in MsPASS to use getters and putters to provide a cleaner interface to python with pybind11.

Author
Gary L. Pavlis

Constructor & Destructor Documentation

◆ BasicTimeSeries() [1/2]

mspass::seismic::BasicTimeSeries::BasicTimeSeries ( )

Default constructor. Does essentially nothing since a BasicTimeSeries object has no data. Does initialize data to avoid run time checkers bitching about unitialized data, but values are meaningless when this constructor is called.

43 {
44  mt0=0.0;
46  mlive=false;
47  mdt=1.0;
48  nsamp=0;
49  t0shift=0.0;
50  t0shift_is_valid=false;
51 }
size_t nsamp
Definition: BasicTimeSeries.h:268
bool mlive
Definition: BasicTimeSeries.h:256
TimeReferenceType tref
Definition: BasicTimeSeries.h:278
double mdt
Definition: BasicTimeSeries.h:260
double mt0
Definition: BasicTimeSeries.h:264

References mspass::seismic::Relative.

◆ BasicTimeSeries() [2/2]

mspass::seismic::BasicTimeSeries::BasicTimeSeries ( const BasicTimeSeries tsin)

Standard copy constructor.

53 {
54  mt0=tsin.mt0;
55  tref=tsin.tref;
56  mlive=tsin.mlive;
57  mdt=tsin.mdt;
58  nsamp=tsin.nsamp;
59  t0shift=tsin.t0shift;
60  t0shift_is_valid=tsin.t0shift_is_valid;
61 }

References mdt, mlive, mt0, nsamp, and tref.

◆ ~BasicTimeSeries()

virtual mspass::seismic::BasicTimeSeries::~BasicTimeSeries ( )
inlinevirtual

Virtual destructor.

A base class with virtual members like this requires this incantation to avoid some odd conflicts. This particular one was added to make the boost::serialization code work properly. The geeky details for why this is necessary can be found in Scott Meyers book "Effective C++"

56 {};

Member Function Documentation

◆ ator()

void mspass::seismic::BasicTimeSeries::ator ( const double  tshift)
virtual

Absolute to relative time conversion. Sometimes we want to convert data from absolute time (epoch times) to a relative time standard. Examples are conversions to travel time using an event origin time or shifting to an arrival time reference frame. This operation simply switches the tref variable and alters t0 by tshift.

Parameters
tshift- time shift applied to data before switching data to relative time mode.

Reimplemented in mspass::seismic::TimeSeriesWGaps.

10 {
11  /* dead traces should to totally ignored */
12  if(!(this->mlive)) return;
14  t0shift=tshift;
15  mt0 -= tshift;
17  t0shift_is_valid=true;
18 }

References mspass::seismic::Relative.

◆ dead()

bool mspass::seismic::BasicTimeSeries::dead ( ) const
inline

Return true if the data have been marked bad (killed) - inverse of live()

149 {return !(this->mlive);};

References mlive.

◆ dt()

double mspass::seismic::BasicTimeSeries::dt ( ) const
inline

Return the data sample interval.

157 {return this->mdt;};

References mdt.

◆ endtime()

double mspass::seismic::BasicTimeSeries::endtime ( ) const
inlinenoexcept

Returns the end time (time associated with last data sample) of this data object.

83  {
84  return(mt0 + (static_cast<double>(nsamp) - 1.0)*mdt);
85  };

References mdt, mt0, and nsamp.

◆ force_t0_shift()

void mspass::seismic::BasicTimeSeries::force_t0_shift ( const double  t)
inline

Force a t0 shift value on data.

This is largely an interface routine for constructors that need to handle data in relative time that are derived from an absolute base. It can also be used to fake processing routines that demand data be in absolute time when the original data were not. It was added for MsPASS to support reads and writes to MongoDB where we want to be able to read and write data that had been previously time shifted (e.g. ArrivalTimeReference).

Parameters
tis the time shift to force
116  {
117  this->t0shift=t;
118  t0shift_is_valid=true;
119  };

◆ kill()

void mspass::seismic::BasicTimeSeries::kill ( )
inline

Mark these data bad.

151 {this->mlive=false;};

References mlive.

◆ live()

bool mspass::seismic::BasicTimeSeries::live ( ) const
inline

Returns true of data are marked valid (live).

147 {return this->mlive;};

References mlive.

◆ npts()

size_t mspass::seismic::BasicTimeSeries::npts ( ) const
inline

Return the number of points in the data series.

183 {return nsamp;};

References nsamp.

◆ operator=()

BasicTimeSeries & mspass::seismic::BasicTimeSeries::operator= ( const BasicTimeSeries parent)

Standard assignment operator.

63 {
64  if (this!=&parent)
65  {
66  mt0=parent.mt0;
67  tref=parent.tref;
68  mlive=parent.mlive;
69  mdt=parent.mdt;
70  nsamp=parent.nsamp;
71  t0shift=parent.t0shift;
72  t0shift_is_valid=parent.t0shift_is_valid;
73  }
74  return *this;
75 }

References mdt, mlive, mt0, nsamp, and tref.

◆ rtoa()

void mspass::seismic::BasicTimeSeries::rtoa ( )
virtual

Relative to absolute time conversion. Sometimes we want to convert data from relative time to to an UTC time standard. An example would be converting segy shot data to something that could be processed like earthquake data in a css3.0 database.

This method returns data previously converted to relative back to UTC using the internally stored time shift attribute.

Reimplemented in mspass::seismic::TimeSeriesWGaps.

22 {
23  /* dead traces should to totally ignored */
24  if(!(this->mlive)) return;
25  const string base_error("BasicTimeSeries::rtoa() t0shift for conversion is not defined.");
26  if(tref==TimeReferenceType::UTC) return;
27  /* A rather odd test for a nonzero. We use 100 s assuming no active
28  * source data would use a shift longer than that unless it really did
29  * have an UTC time standard. Also assumes we'll never use data from
30  * the first 2 minutes of 1960.*/
31  if(t0shift_is_valid || (t0shift>100.0) )
32  {
33  mt0 += t0shift;
35  t0shift_is_valid=false;
36  t0shift=0.0;
37  }
38  else
39  throw MsPASSError(base_error + "time shift to return to UTC time is not defined",ErrorSeverity::Invalid);
40 }
Base class for error object thrown by MsPASS library routines.
Definition: MsPASSError.h:40

References mspass::seismic::UTC.

◆ sample_number()

int mspass::seismic::BasicTimeSeries::sample_number ( double  t) const
inline

Inverse of time function. That is, it returns the integer position of a given time t within a time series. The returned number is not tested for validity compared to the data range. This is the callers responsibility as this is a common error condition that should not require the overhead of an exception.

75  {
76  return(round((t-mt0)/mdt));
77  };

References mdt, and mt0.

◆ samprate()

double mspass::seismic::BasicTimeSeries::samprate ( ) const
inline

Return sample rate.

179  {
180  return 1.0/mdt;
181  }

References mdt.

◆ set_dt()

virtual void mspass::seismic::BasicTimeSeries::set_dt ( const double  sample_interval)
inlinevirtual

Set the sample interval.

This is a simple setter for the sample interval attribute. It is virtual because children may want to do more than just set the attribute in this base class. In MsPASS that means keeping the Metadata attributes that define sample interval in sync with the data. Aliases further complicate that issue so it is not trivial. Other data objects that could be derived form this base could have similar issues.

Parameters
sample_intervalis the new data sample interval to be used.

Reimplemented in mspass::seismic::CoreTimeSeries, and mspass::seismic::CoreSeismogram.

199  {
200  mdt=sample_interval;
201  };

References mdt.

◆ set_live()

void mspass::seismic::BasicTimeSeries::set_live ( )
inline

Inverse of kill - marks data live overriding anything set before. Use to resurrect data improperly killed (useful only for interactive editing) or creating data pieces outside constructors.

155 {this->mlive=true;};

References mlive.

◆ set_npts()

virtual void mspass::seismic::BasicTimeSeries::set_npts ( const size_t  npts)
inlinevirtual

Set the number of samples attribute for data.

This is a simple setter for the number of samples attribute. It is virtual because children may want to do more than just set the attribute in this base class. In MsPASS that means keeping the Metadata attributes that define the number of points in sync with the data. Aliases further complicate that issue so it is not trivial. Other data objects that could be derived form this base could have similar issues.

Parameters
nptsis the new number of points to set.

Reimplemented in mspass::seismic::CoreTimeSeries, and mspass::seismic::CoreSeismogram.

214  {
215  nsamp=npts;
216  };
size_t npts() const
Definition: BasicTimeSeries.h:183

References npts(), and nsamp.

◆ set_t0()

virtual void mspass::seismic::BasicTimeSeries::set_t0 ( const double  t0in)
inlinevirtual

Set the data start time.

This is a simple setter for the start time attribute. It is virtual because children may want to do more than just set the attribute in this base class. In MsPASS that means keeping the Metadata attributes that define t0 in sync with the data. Aliases further complicate that issue so it is not trivial. Other data objects that could be derived form this base could have similar issues.

Parameters
t0inis the new data sample interval to be used.

Reimplemented in mspass::seismic::CoreTimeSeries, and mspass::seismic::CoreSeismogram.

229  {
230  mt0=t0in;
231  };

References mt0.

◆ set_tref()

void mspass::seismic::BasicTimeSeries::set_tref ( const TimeReferenceType  newtref)
inline

Force the time standard.

Time series data may have multiple concepts of what the time standard is. In MsPASS the allowed values currently are UTC and relative defined by the TimeReferenceType enum class. Other implementations might need to use some other standard (e.g. raw gps time is not utc). This method allows forcing a standard. It is not recommended for normal use, but only as a brutal solution for assembling a data object outside normal constructors.

Parameters
newtrefis the new time standard to set for these data.
244  {
245  tref=newtref;
246  };

References tref.

◆ shift()

void mspass::seismic::BasicTimeSeries::shift ( const double  dt)
virtual

Shift the reference time.

Sometimes we need to shift the reference time t0. An example is a moveout correction. This method shifts the reference time by dt. Note a positive dt means data aligned to zero will be shifted left because relative time is t-t0.

Reimplemented in mspass::seismic::TimeSeriesWGaps.

77 {
78  try {
79  double oldt0shift=t0shift;
80  this->rtoa();
81  this->ator(oldt0shift+dt);
82  } catch(...) {
83  throw;
84  };
85 }
virtual void rtoa()
Definition: BasicTimeSeries.cc:21
virtual void ator(const double tshift)
Definition: BasicTimeSeries.cc:9
double dt() const
Definition: BasicTimeSeries.h:157

◆ shifted()

bool mspass::seismic::BasicTimeSeries::shifted ( ) const
inline

Return true if a time shift has been applied to the data. Never true if data were never in an absolute time frame (i.e.UTC)

89  {
90  return t0shift_is_valid;
91  };

◆ t0()

double mspass::seismic::BasicTimeSeries::t0 ( ) const
inline

Return time of first data sample. An epoch time or relative time depending on TimeReferenceType private variable tref

186 {return this->mt0;};

References mt0.

◆ time()

double mspass::seismic::BasicTimeSeries::time ( const int  i) const
inline

Get the time of sample i. It is common to need to ask for the time of a given sample. This standardizes this common operation in an obvious way.

Parameters
i- sample number to compute time for.
64  {
65  return(mt0+mdt*static_cast<double>(i));
66  };

References mdt, and mt0.

◆ time_is_UTC()

bool mspass::seismic::BasicTimeSeries::time_is_UTC ( ) const
inline

Test if the time standard is UTC.

160  {
162  return true;
163  else
164  return false;
165  };

References tref, and mspass::seismic::UTC.

◆ time_reference()

double mspass::seismic::BasicTimeSeries::time_reference ( ) const

Return the reference time.

We distinguish relative and UTC time by a time shift constant stored with the object. This returns the time shift to return data to an epoch time.

Exceptions
SeisppErrorobject if the request is not rational. That is this request only makes sense if the data began with an absolute time and was converted with the ator method. Some cross checks are made for consistency that can throw an error in this condition.
87 {
88  const string base_error("BasicTimeSeries::time_reference method: ");
90  throw MsPASSError(base_error
91  + "data have UTC time set so requesting the reference"
92  + " time make no sense - likely a coding error",
93  ErrorSeverity::Fatal);
94  if(t0shift_is_valid)
95  return(t0shift);
96  else
97  throw MsPASSError(base_error
98  + "cannot return time reference as it is marked invalid",
99  ErrorSeverity::Invalid);
100 }

References mspass::seismic::UTC.

Member Data Documentation

◆ mdt

double mspass::seismic::BasicTimeSeries::mdt
protected

Sample interval.

◆ mlive

bool mspass::seismic::BasicTimeSeries::mlive
protected

Boolean defining if a data object has valid data or is to be ignored. Data processing often requires data to be marked bad but keep the original data around in case an error was made. This boolean allows this capability.

◆ mt0

double mspass::seismic::BasicTimeSeries::mt0
protected

Data start time. That is the time of the first sample of data.

◆ nsamp

size_t mspass::seismic::BasicTimeSeries::nsamp
protected

Number of data samples in this data object.

◆ tref

TimeReferenceType mspass::seismic::BasicTimeSeries::tref
protected

Time reference standard for this data object. Defined by enum Time_Reference this currently is only one of two things. When set as "UTC" the time standard is an epoch time. When set as "relative" time has no relationship to any external standard but are relative to some arbitrary reference that must ascertained by the algorithm by some other means (in seispp this is normally done through a metadata object). A classic example is multichannel data where channels have a time relative to a shot time.


The documentation for this class was generated from the following files: