version
0.0.1
Defines the C++ API for MsPASS
|
Scalar time series data object. More...
#include <CoreTimeSeries.h>
Public Member Functions | |
CoreTimeSeries () | |
CoreTimeSeries (const size_t nsin) | |
CoreTimeSeries (const BasicTimeSeries &bts, const Metadata &md) | |
CoreTimeSeries (const CoreTimeSeries &) | |
void | set_dt (const double sample_interval) |
Set the sample interval. More... | |
void | set_npts (const size_t npts) |
Set the number of samples attribute for data. More... | |
void | sync_npts () |
Sync the number of samples attribute with actual data size. More... | |
void | set_t0 (const double t0in) |
Set the data start time. More... | |
CoreTimeSeries & | operator= (const CoreTimeSeries &parent) |
CoreTimeSeries & | operator+= (const CoreTimeSeries &d) |
Summation operator. More... | |
const CoreTimeSeries | operator+ (const CoreTimeSeries &other) const |
CoreTimeSeries & | operator*= (const double) |
CoreTimeSeries & | operator-= (const CoreTimeSeries &d) |
Subtraction operator. More... | |
const CoreTimeSeries | operator- (const CoreTimeSeries &other) const |
double | operator[] (size_t const sample) const |
Public Member Functions inherited from mspass::seismic::BasicTimeSeries | |
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 |
void | set_tref (const TimeReferenceType newtref) |
Force the time standard. More... | |
BasicTimeSeries & | operator= (const BasicTimeSeries &parent) |
Public Member Functions inherited from mspass::utility::Metadata | |
Metadata () | |
Metadata (std::ifstream &ifs, const std::string form=std::string("pf")) | |
Metadata (const Metadata &mdold) | |
virtual | ~Metadata () |
Metadata & | operator= (const Metadata &mdold) |
Metadata & | operator+= (const Metadata &rhs) noexcept |
const Metadata | operator+ (const Metadata &other) const |
double | get_double (const std::string key) const override |
int | get_int (const std::string key) const override |
long | get_long (const std::string key) const |
std::string | get_string (const std::string key) const override |
bool | get_bool (const std::string key) const override |
template<typename T > | |
T | get (const std::string key) const |
template<typename T > | |
T | get (const char *key) const |
Generic get interface for C char array. More... | |
boost::any | get_any (const std::string key) const |
std::string | type (const std::string key) const |
template<typename T > | |
void | put (const std::string key, T val) noexcept |
template<typename T > | |
void | put (const char *key, T val) noexcept |
void | put (const std::string key, const double val) override |
void | put (const std::string key, const int val) override |
void | put (const std::string key, const bool val) override |
void | put (const std::string key, const std::string val) override |
void | put (const char *key, const char *val) |
void | put (std::string key, const char *val) |
void | put_object (const std::string key, const pybind11::object val) |
void | put_int (const std::string key, const int val) |
void | put_string (const std::string key, const std::string val) |
void | put_bool (const std::string key, const bool val) |
void | put_double (const std::string key, const double val) |
void | put_long (const std::string key, const long val) |
void | append_chain (const std::string key, const std::string val, const std::string separator=std::string(":")) |
std::set< std::string > | modified () const |
void | clear_modified () |
Mark all data as unmodified. More... | |
std::set< std::string > | keys () const noexcept |
bool | is_defined (const std::string key) const noexcept |
void | erase (const std::string key) |
std::size_t | size () const noexcept |
std::map< std::string, boost::any >::const_iterator | begin () const noexcept |
std::map< std::string, boost::any >::const_iterator | end () const noexcept |
void | change_key (const std::string oldkey, const std::string newkey) |
Change the keyword to access an attribute. More... | |
Public Attributes | |
std::vector< double > | s |
Additional Inherited Members | |
Protected Attributes inherited from mspass::seismic::BasicTimeSeries | |
bool | mlive |
double | mdt |
double | mt0 |
size_t | nsamp |
TimeReferenceType | tref |
bool | t0shift_is_valid |
double | t0shift |
Protected Attributes inherited from mspass::utility::Metadata | |
std::map< std::string, boost::any > | md |
std::set< std::string > | changed_or_set |
Scalar time series data object.
This data object extends BasicTimeSeries mainly by adding a vector of scalar data. It uses a Metadata object to contain auxiliary parameters that aren't essential to define the data object, but which are necessary for some algorithms.
mspass::seismic::CoreTimeSeries::CoreTimeSeries | ( | ) |
Default constructor. Initializes object data to zeros and sets the initial STL vector size to 0 length.
References s, set_dt(), set_npts(), and set_t0().
mspass::seismic::CoreTimeSeries::CoreTimeSeries | ( | const size_t | nsin | ) |
Similar to the default constructor but creates a vector of data with nsin samples and initializes all samples to 0.0. This vector can safely be accessed with the vector index operator (i.e. operator []). A corollary is that push_back or push_front applied to this vector will alter it's length so use this only if the size of the data to fill the object is already known.
References set_npts().
mspass::seismic::CoreTimeSeries::CoreTimeSeries | ( | const BasicTimeSeries & | bts, |
const Metadata & | md | ||
) |
Partially construct from components.
There are times one wants to use the Metadata area as a template to flesh out a CoreTimeSeries as what might be called skin and bones: skin is Metadata and bones as BasicTimeSeries data. This constructor initializes those two base classes but does not fully a valid data vector. It only attempts to fetch the number of points expected for the data vector using the npts metadata (integer) key (i.e. it sets npts to md.get_int("npts")). It then creates the data vector of that length and initialzies it to all zeros.
References mspass::seismic::BasicTimeSeries::nsamp, and set_npts().
mspass::seismic::CoreTimeSeries::CoreTimeSeries | ( | const CoreTimeSeries & | tsi | ) |
CoreTimeSeries & mspass::seismic::CoreTimeSeries::operator*= | ( | const double | scale | ) |
const CoreTimeSeries mspass::seismic::CoreTimeSeries::operator+ | ( | const CoreTimeSeries & | other | ) | const |
Addition operator.
This operator is implemented in a standard way utilizing operator+=. For data with irregular start and end times that has an important consequence; the operator is not communative. i.e given x an y z=x+y will not yield the same result as z=y+x.
CoreTimeSeries & mspass::seismic::CoreTimeSeries::operator+= | ( | const CoreTimeSeries & | d | ) |
Summation operator.
Summing data from signals of irregular length requires handling potential mismatches in size and overlap. This behaves the way a += operator should logically behave in that situation. That is, because the lhs is where the sum is being accumulated, the size is always controlled by the left hand side of the operator. Any portions of the right hand side that are outside the t0 to endtime() of the left hand side are silently discarded. If the start time of the right hand side is greater than t0 or the endtime is less than endtime of the lhs there will be discontinuties in the sum there the ends of the rhs are inside the range of the lhs.
d | is other signal to add to this. |
MsPASSError | can be thrown if lhs and rhs do not have matching time standards. |
References mspass::seismic::BasicTimeSeries::endtime(), mspass::seismic::BasicTimeSeries::mlive, mspass::seismic::BasicTimeSeries::mt0, mspass::seismic::BasicTimeSeries::npts(), s, mspass::seismic::BasicTimeSeries::sample_number(), mspass::seismic::BasicTimeSeries::t0(), and mspass::seismic::BasicTimeSeries::tref.
const CoreTimeSeries mspass::seismic::CoreTimeSeries::operator- | ( | const CoreTimeSeries & | other | ) | const |
Subtraction operator.
This operator is implemented in a standard way utilizing operator-=. For data with irregular start and end times that has an important consequence; the operator is not communative. i.e given x an y z=x-y will not yield the same result as z=-(y-x).
CoreTimeSeries & mspass::seismic::CoreTimeSeries::operator-= | ( | const CoreTimeSeries & | d | ) |
Subtraction operator.
Differencing data from signals of irregular length requires handling potential mismatches in size and overlap. This behaves the way a -= operator should logically behave in that situation. That is, because the lhs is where the sum is being accumulated, the size is always controlled by the left hand side of the operator. Any portions of the right hand side that are outside the t0 to endtime() of the left hand side are silently discarded. If the start time of the right hand side is greater than t0 or the endtime is less than endtime of the lhs there will be discontinuties in the sum there the ends of the rhs are inside the range of the lhs.
d | is other signal to subract from this. |
MsPASSError | can be thrown if lhs and rhs do not have matching time standards. |
References mspass::seismic::BasicTimeSeries::endtime(), mspass::seismic::BasicTimeSeries::mlive, mspass::seismic::BasicTimeSeries::mt0, mspass::seismic::BasicTimeSeries::npts(), s, mspass::seismic::BasicTimeSeries::sample_number(), mspass::seismic::BasicTimeSeries::t0(), and mspass::seismic::BasicTimeSeries::tref.
CoreTimeSeries & mspass::seismic::CoreTimeSeries::operator= | ( | const CoreTimeSeries & | parent | ) |
Standard assignment operator.
References mspass::seismic::BasicTimeSeries::operator=(), mspass::utility::Metadata::operator=(), and s.
double mspass::seismic::CoreTimeSeries::operator[] | ( | size_t const | sample | ) | const |
Extract a sample from data vector with range checking. Because the data vector is public in this interface this operator is simply an alterative interface to this->s[sample].
SeisppError | exception if the requested sample is outside the range of the data. Note this includes an implicit "outside" defined when the contents are marked dead. |
sample | is the integer sample number of data desired. |
References mspass::seismic::BasicTimeSeries::mlive, and s.
|
virtual |
Set the sample interval.
This method is complicated by the need to sync the changed value with Metadata. That is further complicated by the need to support aliases for the keys used to defined dt in Metadata. That is handled by first setting the internal dt value and then going through a fixed list of valid alias keys for dt. Any that exist are changed. If none were previously defined the unique name (see documentation) is added to Metadata.
sample_interval | is the new data sample interval to be used. |
Reimplemented from mspass::seismic::BasicTimeSeries.
References mspass::utility::Metadata::is_defined(), mspass::seismic::SEISMICMD_dt(), and mspass::seismic::BasicTimeSeries::set_dt().
|
virtual |
Set the number of samples attribute for data.
This method is complicated by the need to sync the changed value with Metadata. That is further complicated by the need to support aliases for the keys used to defined npts in Metadata. That is handled by first setting the internal npts value (actually ns) and then going through a fixed list of valid alias keys for npts. Any that exist are changed. If none were previously defined the unique name (see documentation) is added to Metadata.
This attribute has an additional complication compared to other setter that are overrides from BasicTimeSeries. That is, the number of points define the data buffer size to hold the sample data. To guarantee the buffer size and the internal remain consistent this method clears any existing content of the vector s and initializes npts points to 0.0. Note this means if one is using this to assemble a data object in pieces you MUST call this method before loading any data or it will be cleared and you will mysteriously find the data are all zeros.
npts | is the new number of points to set. |
Reimplemented from mspass::seismic::BasicTimeSeries.
References mspass::utility::Metadata::is_defined(), mspass::seismic::BasicTimeSeries::npts(), s, mspass::seismic::SEISMICMD_npts(), and mspass::seismic::BasicTimeSeries::set_npts().
|
virtual |
Set the data start time.
This method is complicated by the need to sync the changed value with Metadata. That is further complicated by the need to support aliases for the keys used to defined npts in Metadata. That is handled by first setting the internal t0 value and then going through a fixed list of valid alias keys for it. Any that exist are changed. If none were previously defined the unique name (see documentation) is added to Metadata.
This is a dangerous method to use on real data as it can mess up the time if not handled correctly. It should be used only when that sharp knife is needed such as in assembling data outside of constructors in a test program.
t0in | is the new data sample interval to be used. |
Reimplemented from mspass::seismic::BasicTimeSeries.
References mspass::utility::Metadata::is_defined(), mspass::seismic::SEISMICMD_t0(), and mspass::seismic::BasicTimeSeries::set_t0().
void mspass::seismic::CoreTimeSeries::sync_npts | ( | ) |
Sync the number of samples attribute with actual data size.
This method syncs the npts attribute with the actual size of the vector s. It also syncs aliases in the same way as the set_npts method.
References mspass::utility::Metadata::is_defined(), mspass::seismic::BasicTimeSeries::nsamp, s, mspass::seismic::SEISMICMD_npts(), and mspass::seismic::BasicTimeSeries::set_npts().
std::vector<double> mspass::seismic::CoreTimeSeries::s |
Actual data stored as an STL vector container. Note the STL guarantees the data elements of vector container are contiguous in memory like FORTRAN vectors. As a result things like the BLAS can be used with data object by using a syntax like this: if d is a CoreTimeSeries object, the address of the first sample of the data is &(d.s[0]).