nidas v1.2.3
Public Member Functions | Private Member Functions | Private Attributes | List of all members
nidas::core::NearestResamplerAtRate Class Reference

A simple, nearest-point resampler, for generating merged samples from variables from one or more sample sources. More...

#include <NearestResamplerAtRate.h>

Inheritance diagram for nidas::core::NearestResamplerAtRate:
Inheritance graph
[legend]

Public Member Functions

 NearestResamplerAtRate (const std::vector< const Variable * > &vars, bool nansVariable=true)
 Use the given list of Variables as inputs and use them to generate an output sample tag.
 
 ~NearestResamplerAtRate ()
 
void setRate (double val)
 Set the requested output rate, in Hz.
 
double getRate () const
 
void setMiddleTimeTags (bool val)
 If true, generate output timetags that are the middle of the requested output periods.
 
bool getMiddleTimeTags () const
 
void setFillGaps (bool val)
 Should output records of all missing data (nans), be generated, or just discarded.
 
bool getFillGaps () const
 
SampleSourcegetRawSampleSource ()
 Several objects in NIDAS can be both a SampleSource of raw Samples and processed Samples.
 
SampleSourcegetProcessedSampleSource ()
 Several objects in NIDAS can be both a SampleSource of raw Samples and processed Samples.
 
std::list< const SampleTag * > getSampleTags () const
 Get the SampleTag of my merged output sample.
 
SampleTagIterator getSampleTagIterator () const
 Implementation of SampleSource::getSampleTagIterator().
 
void addSampleClient (SampleClient *client) throw ()
 Implementation of SampleSource::addSampleClient().
 
void removeSampleClient (SampleClient *client) throw ()
 Remove a SampleClient from this SampleSource.
 
void addSampleClientForTag (SampleClient *client, const SampleTag *) throw ()
 Add a Client for a given SampleTag.
 
void removeSampleClientForTag (SampleClient *client, const SampleTag *) throw ()
 Remove a SampleClient for a given SampleTag from this SampleSource.
 
int getClientCount () const throw ()
 How many SampleClients are currently in my list.
 
void flush () throw ()
 Implementation of Resampler::flush().
 
const SampleStatsgetSampleStats () const
 
void connect (SampleSource *input)
 Connect the resampler to a SampleSource.
 
void disconnect (SampleSource *input) throw ()
 
bool receive (const Sample *s) throw ()
 Method called to pass a sample to this client.
 

Private Member Functions

void addSampleTag (const SampleTag *tag) throw ()
 Add a SampleTag to this SampleSource.
 
void removeSampleTag (const SampleTag *tag) throw ()
 
void sendSample (dsm_time_t) throw ()
 
NearestResamplerAtRateoperator= (const NearestResamplerAtRate &)=delete
 No assignment.
 
 NearestResamplerAtRate (const NearestResamplerAtRate &x)=delete
 No copy.
 

Private Attributes

SampleSourceSupport _source
 
SampleTag _outSample
 
std::vector< Variable * > _reqVars
 Requested variables.
 
std::map< Variable *, unsigned int_outVarIndices
 Index of each requested output variable in the output sample.
 
std::map< dsm_sample_id_t, std::vector< unsigned int > > _inmap
 For each input sample, first index of variable data values to be read.
 
std::map< dsm_sample_id_t, std::vector< unsigned int > > _lenmap
 For each input sample, length of variables to read.
 
std::map< dsm_sample_id_t, std::vector< unsigned int > > _outmap
 For each input sample, index into output sample of each variable.
 
int _ndataValues
 
int _outlen
 
double _rate
 
int _deltatUsec
 The output deltaT, 1/rate in microseconds.
 
int _deltatUsecD10
 DeltaT over 10.
 
int _deltatUsecD2
 DeltaT over 2.
 
bool _exactDeltatUsec
 True if simple integer math is used to increment output sample time tags.
 
bool _middleTimeTags
 If true, generate output timetags that are the middle of the requested output periods.
 
dsm_time_t _outputTT
 
dsm_time_t _nextOutputTT
 
dsm_time_t_prevTT
 
dsm_time_t_nearTT
 
float_prevData
 
float_nearData
 
int_samplesSinceOutput
 
SampleT< float > * _osamp
 
bool _fillGaps
 
std::map< dsm_sample_id_t, unsigned int_ttOutOfOrder
 

Detailed Description

A simple, nearest-point resampler, for generating merged samples from variables from one or more sample sources.

The output sample time tags will be evenly spaced at the given rate, and values of variables are merged into the output sample by associating those values with the nearest time tag to the output time tags.

The only requirement is that the samples which are fed to the receive() method should be sorted in time. It they aren't sorted some data will be lost. NearestResamplerAtRate does not need to know sampling rates, and the sampling rates of the input variables, including the master variable, may vary.

This resampler operates in two modes, based on the value of the setMiddleTimeTags() attribute.

If getMiddleTimeTags() is true, generate output timetags that are at the middle of the requested output periods. For example, for a rate=20, deltaT=0.05 sec, the output timetags will be 00:00:00.025, 00:00:00.075, etc. The output sample at 00:00:00.025 contains the nearest input values from the time period centered at 00:00:00.025.

If getMiddleTimeTags() is false, the output time tags for the above example would be 00:00:00.00, 00:00:00.05, etc. The output sample at 00:00:00.00 contains the nearest input values from the time period centered at 00:00:00.00.

Because of assumed input timetag jitter (inaccuracy), the nearest point matching algorithm is a bit forgiving. When matching for the nearest points to time t, input samples will be matched whose time tags are between t - 0.9*deltatT <= inputTimeTag <= t + 0.9*deltaT. If more than one input sample lies in the window, then the nearest one is used. This input window is of size 1.8 * deltaT, rather than 1.0 * deltaT, which is what one might expect. Therefore an input point could be matched with two output points. In this example, it is possible that an output sample at 00:00:00.025 could contain an input value from the previous day.

Constructor & Destructor Documentation

◆ NearestResamplerAtRate() [1/2]

NearestResamplerAtRate::NearestResamplerAtRate ( const std::vector< const Variable * > & vars,
bool nansVariable = true )

◆ ~NearestResamplerAtRate()

NearestResamplerAtRate::~NearestResamplerAtRate ( )

◆ NearestResamplerAtRate() [2/2]

nidas::core::NearestResamplerAtRate::NearestResamplerAtRate ( const NearestResamplerAtRate & x)
privatedelete

No copy.

Member Function Documentation

◆ addSampleClient()

void nidas::core::NearestResamplerAtRate::addSampleClient ( SampleClient * client)
throw ( )
inlinevirtual

◆ addSampleClientForTag()

void nidas::core::NearestResamplerAtRate::addSampleClientForTag ( SampleClient * client,
const SampleTag *  )
throw ( )
inlinevirtual

◆ addSampleTag()

void nidas::core::NearestResamplerAtRate::addSampleTag ( const SampleTag * tag)
throw ( )
inlineprivatevirtual

◆ connect()

void NearestResamplerAtRate::connect ( SampleSource * input)
virtual

◆ disconnect()

void NearestResamplerAtRate::disconnect ( SampleSource * input)
throw ( )
virtual

◆ flush()

void NearestResamplerAtRate::flush ( )
throw ( )
virtual

Implementation of Resampler::flush().

Implements nidas::core::Resampler.

References _nextOutputTT, and sendSample().

◆ getClientCount()

int nidas::core::NearestResamplerAtRate::getClientCount ( ) const
throw ( )
inlinevirtual

How many SampleClients are currently in my list.

Exceptions

)

Implements nidas::core::SampleSource.

References _source, and nidas::core::SampleSourceSupport::getClientCount().

◆ getFillGaps()

bool nidas::core::NearestResamplerAtRate::getFillGaps ( ) const
inline

References _fillGaps.

◆ getMiddleTimeTags()

bool nidas::core::NearestResamplerAtRate::getMiddleTimeTags ( ) const
inline

References _middleTimeTags.

◆ getProcessedSampleSource()

SampleSource * nidas::core::NearestResamplerAtRate::getProcessedSampleSource ( )
inlinevirtual

Several objects in NIDAS can be both a SampleSource of raw Samples and processed Samples.

SampleClients use this method to get a pointer to whatever sample source they are interested in. Derived classes can return NULL if they are not a SampleSource of processed samples.

Implements nidas::core::SampleSource.

References _source.

◆ getRate()

double nidas::core::NearestResamplerAtRate::getRate ( ) const
inline

References _rate.

◆ getRawSampleSource()

SampleSource * nidas::core::NearestResamplerAtRate::getRawSampleSource ( )
inlinevirtual

Several objects in NIDAS can be both a SampleSource of raw Samples and processed Samples.

SampleClients use this method to get a pointer to whatever sample source they are interested in. Derived classes can return NULL if they are not a SampleSource of raw samples.

Implements nidas::core::SampleSource.

◆ getSampleStats()

const SampleStats & nidas::core::NearestResamplerAtRate::getSampleStats ( ) const
inlinevirtual

◆ getSampleTagIterator()

SampleTagIterator nidas::core::NearestResamplerAtRate::getSampleTagIterator ( ) const
inlinevirtual

◆ getSampleTags()

std::list< const SampleTag * > nidas::core::NearestResamplerAtRate::getSampleTags ( ) const
inlinevirtual

Get the SampleTag of my merged output sample.

Implements nidas::core::SampleSource.

References _source, and nidas::core::SampleSourceSupport::getSampleTags().

◆ operator=()

NearestResamplerAtRate & nidas::core::NearestResamplerAtRate::operator= ( const NearestResamplerAtRate & )
privatedelete

No assignment.

◆ receive()

bool NearestResamplerAtRate::receive ( const Sample * s)
throw ( )
virtual

Method called to pass a sample to this client.

This method is typically called by a SampleSource for each of its SampleClients when it has a sample ready. Returns true: success false: sample rejected. This is meant to signal a warning-type situation - like a socket not being available temporarily. True errors will be thrown as an IOException.

Exceptions

)

Implements nidas::core::SampleClient.

References nidas::core::DOUBLE_ST, nidas::core::FLOAT_ST, nidas::util::UTime::format(), GET_DSM_ID, GET_SHORT_ID, GET_SPS_ID, nidas::core::getSample(), USECS_PER_SEC, and WLOG.

◆ removeSampleClient()

void nidas::core::NearestResamplerAtRate::removeSampleClient ( SampleClient * c)
throw ( )
inlinevirtual

◆ removeSampleClientForTag()

void nidas::core::NearestResamplerAtRate::removeSampleClientForTag ( SampleClient * c,
const SampleTag *  )
throw ( )
inlinevirtual

Remove a SampleClient for a given SampleTag from this SampleSource.

The pointer to the SampleClient must remain valid, until after it is removed.

Exceptions

)

Implements nidas::core::SampleSource.

References _source, and nidas::core::SampleSourceSupport::removeSampleClient().

◆ removeSampleTag()

void nidas::core::NearestResamplerAtRate::removeSampleTag ( const SampleTag * )
throw ( )
inlineprivatevirtual

◆ sendSample()

void NearestResamplerAtRate::sendSample ( dsm_time_t tt)
throw ( )
private

◆ setFillGaps()

void nidas::core::NearestResamplerAtRate::setFillGaps ( bool val)
inline

Should output records of all missing data (nans), be generated, or just discarded.

References _fillGaps, and nidas::core::getSample().

◆ setMiddleTimeTags()

void nidas::core::NearestResamplerAtRate::setMiddleTimeTags ( bool val)
inline

If true, generate output timetags that are the middle of the requested output periods.

For example, for a rate=20, deltaT=0.05 sec, the output timetags will be 00:00:00.025, 00:00:00.075, etc. The sample at 00:00:00.025 contains the nearest input values from the time period centered at 00:00:00.025 If false, the output time tags for the above example would be 00:00:00.00, 00:00:00.05, etc. The sample at 00:00:00.00 contains the nearest input values from the time period centerd at 00:00:00.00, i.e. points from the previous day could be used.

References _middleTimeTags, and nidas::core::getSample().

◆ setRate()

void NearestResamplerAtRate::setRate ( double val)

Set the requested output rate, in Hz.

For rates < 1 it is best to choose a value such that 10^6/rate is an integer. If you really want rate=1/3 Hz, specify rate to 7 significant figures, 0.3333333, and you will avoid round off errors in the time tag. Output rates > 1 should be integers, or of a value with enough significant figures such that 10^6/rate is an integer. Support for other rates could be added if (really) necessary.

References _deltatUsec, _deltatUsecD10, _deltatUsecD2, _exactDeltatUsec, _rate, nidas::core::getSample(), and USECS_PER_SEC.

Referenced by NearestResamplerAtRate().

Member Data Documentation

◆ _deltatUsec

int nidas::core::NearestResamplerAtRate::_deltatUsec
private

The output deltaT, 1/rate in microseconds.

Referenced by setRate().

◆ _deltatUsecD10

int nidas::core::NearestResamplerAtRate::_deltatUsecD10
private

DeltaT over 10.

A fudge factur used for doing nearest point alignments.

Referenced by setRate().

◆ _deltatUsecD2

int nidas::core::NearestResamplerAtRate::_deltatUsecD2
private

DeltaT over 2.

Referenced by setRate().

◆ _exactDeltatUsec

bool nidas::core::NearestResamplerAtRate::_exactDeltatUsec
private

True if simple integer math is used to increment output sample time tags.

This will be the case if rate <= 1.0 or 1/rate is within 0.02 microseconds if an integer.

Referenced by setRate().

◆ _fillGaps

bool nidas::core::NearestResamplerAtRate::_fillGaps
private

Referenced by getFillGaps(), and setFillGaps().

◆ _inmap

std::map<dsm_sample_id_t,std::vector<unsigned int> > nidas::core::NearestResamplerAtRate::_inmap
private

For each input sample, first index of variable data values to be read.

Referenced by connect().

◆ _lenmap

std::map<dsm_sample_id_t,std::vector<unsigned int> > nidas::core::NearestResamplerAtRate::_lenmap
private

For each input sample, length of variables to read.

Referenced by connect().

◆ _middleTimeTags

bool nidas::core::NearestResamplerAtRate::_middleTimeTags
private

If true, generate output timetags that are the middle of the requested output periods.

For example, for a rate=20, deltaT=0.05 sec, the output timetags will be 00:00:00.025, 00:00:00.075, etc. The sample at 00:00:00.025 contains the nearest input values from the period 00:00:00.0 to 00:00:00.05 If false, the output time tags for the above example would be 00:00:00.00, 00:00:00.05, etc. The sample at 00:00:00.00 contains the nearest input values from 23:59:59.975 to 00:00:00.025.

Referenced by getMiddleTimeTags(), and setMiddleTimeTags().

◆ _ndataValues

int nidas::core::NearestResamplerAtRate::_ndataValues
private

Referenced by NearestResamplerAtRate().

◆ _nearData

float* nidas::core::NearestResamplerAtRate::_nearData
private

◆ _nearTT

dsm_time_t* nidas::core::NearestResamplerAtRate::_nearTT
private

◆ _nextOutputTT

dsm_time_t nidas::core::NearestResamplerAtRate::_nextOutputTT
private

Referenced by flush(), and NearestResamplerAtRate().

◆ _osamp

SampleT<float>* nidas::core::NearestResamplerAtRate::_osamp
private

Referenced by ~NearestResamplerAtRate().

◆ _outlen

int nidas::core::NearestResamplerAtRate::_outlen
private

Referenced by NearestResamplerAtRate().

◆ _outmap

std::map<dsm_sample_id_t,std::vector<unsigned int> > nidas::core::NearestResamplerAtRate::_outmap
private

For each input sample, index into output sample of each variable.

Referenced by connect().

◆ _outputTT

dsm_time_t nidas::core::NearestResamplerAtRate::_outputTT
private

Referenced by NearestResamplerAtRate().

◆ _outSample

SampleTag nidas::core::NearestResamplerAtRate::_outSample
private

Referenced by NearestResamplerAtRate().

◆ _outVarIndices

std::map<Variable*,unsigned int> nidas::core::NearestResamplerAtRate::_outVarIndices
private

Index of each requested output variable in the output sample.

Referenced by connect(), and NearestResamplerAtRate().

◆ _prevData

float* nidas::core::NearestResamplerAtRate::_prevData
private

◆ _prevTT

dsm_time_t* nidas::core::NearestResamplerAtRate::_prevTT
private

◆ _rate

double nidas::core::NearestResamplerAtRate::_rate
private

Referenced by getRate(), and setRate().

◆ _reqVars

std::vector<Variable *> nidas::core::NearestResamplerAtRate::_reqVars
private

Requested variables.

Referenced by connect(), NearestResamplerAtRate(), and ~NearestResamplerAtRate().

◆ _samplesSinceOutput

int* nidas::core::NearestResamplerAtRate::_samplesSinceOutput
private

◆ _source

SampleSourceSupport nidas::core::NearestResamplerAtRate::_source
private

◆ _ttOutOfOrder

std::map<dsm_sample_id_t,unsigned int> nidas::core::NearestResamplerAtRate::_ttOutOfOrder
private

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