nidas v1.2.3
|
A simple, nearest-point resampler, for generating merged samples from variables from one or more sample sources. More...
#include <NearestResamplerAtRate.h>
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 |
SampleSource * | getRawSampleSource () |
Several objects in NIDAS can be both a SampleSource of raw Samples and processed Samples. | |
SampleSource * | getProcessedSampleSource () |
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 SampleStats & | getSampleStats () 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 () |
NearestResamplerAtRate & | operator= (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 |
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.
NearestResamplerAtRate::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.
References _ndataValues, _nearData, _nearTT, _nextOutputTT, _outlen, _outputTT, _outSample, _outVarIndices, _prevData, _prevTT, _reqVars, _samplesSinceOutput, addSampleTag(), nidas::core::SampleTag::addVariable(), nidas::core::floatNAN, GET_DSM_ID, GET_SPS_ID, nidas::core::Sample::getId(), nidas::core::Project::getInstance(), nidas::core::Variable::getLength(), nidas::core::getSample(), nidas::core::SampleTag::setDSMId(), nidas::core::Variable::setName(), setRate(), nidas::core::SampleTag::setSampleId(), nidas::core::Variable::setType(), nidas::core::Variable::setUnits(), VLOG, and nidas::core::Variable::WEIGHT.
NearestResamplerAtRate::~NearestResamplerAtRate | ( | ) |
|
privatedelete |
No copy.
|
inlinevirtual |
Implementation of SampleSource::addSampleClient().
Implements nidas::core::SampleSource.
References _source, and nidas::core::SampleSourceSupport::addSampleClient().
|
inlinevirtual |
Add a Client for a given SampleTag.
Implementation of SampleSource::addSampleClient().
Implements nidas::core::SampleSource.
References _source, and nidas::core::SampleSourceSupport::addSampleClient().
|
inlineprivatevirtual |
Add a SampleTag to this SampleSource.
Implements nidas::core::SampleSource.
References _source, and nidas::core::SampleSourceSupport::addSampleTag().
Referenced by NearestResamplerAtRate().
|
virtual |
Connect the resampler to a SampleSource.
nidas::util::InvalidParameterException |
Implements nidas::core::Resampler.
References _inmap, _lenmap, _outmap, _outVarIndices, _reqVars, nidas::core::SampleSource::addSampleClientForTag(), GET_DSM_ID, GET_SPS_ID, nidas::core::Sample::getDSMId(), nidas::core::Sample::getId(), nidas::core::Variable::getName(), nidas::core::getSample(), nidas::core::SampleSource::getSampleTags(), and WLOG.
|
virtual |
Implements nidas::core::Resampler.
|
virtual |
Implementation of Resampler::flush().
Implements nidas::core::Resampler.
References _nextOutputTT, and sendSample().
|
inlinevirtual |
How many SampleClients are currently in my list.
)
Implements nidas::core::SampleSource.
References _source, and nidas::core::SampleSourceSupport::getClientCount().
|
inline |
References _middleTimeTags.
|
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.
|
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.
|
inlinevirtual |
Implements nidas::core::SampleSource.
References _source, and nidas::core::SampleSourceSupport::getSampleStats().
|
inlinevirtual |
Implementation of SampleSource::getSampleTagIterator().
Implements nidas::core::SampleSource.
References _source, and nidas::core::SampleSourceSupport::getSampleTagIterator().
|
inlinevirtual |
Get the SampleTag of my merged output sample.
Implements nidas::core::SampleSource.
References _source, and nidas::core::SampleSourceSupport::getSampleTags().
|
privatedelete |
No assignment.
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.
)
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.
|
inlinevirtual |
Remove a SampleClient from this SampleSource.
)
Implements nidas::core::SampleSource.
References _source, and nidas::core::SampleSourceSupport::removeSampleClient().
|
inlinevirtual |
Remove a SampleClient for a given SampleTag from this SampleSource.
The pointer to the SampleClient must remain valid, until after it is removed.
)
Implements nidas::core::SampleSource.
References _source, and nidas::core::SampleSourceSupport::removeSampleClient().
|
inlineprivatevirtual |
)
Implements nidas::core::SampleSource.
References _source, and nidas::core::SampleSourceSupport::removeSampleTag().
|
private |
References nidas::core::floatNAN, nidas::core::getSample(), and USECS_PER_SEC.
Referenced by flush().
Should output records of all missing data (nans), be generated, or just discarded.
References _fillGaps, and nidas::core::getSample().
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().
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().
|
private |
The output deltaT, 1/rate in microseconds.
Referenced by setRate().
|
private |
|
private |
DeltaT over 2.
Referenced by setRate().
|
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().
|
private |
Referenced by getFillGaps(), and setFillGaps().
|
private |
For each input sample, first index of variable data values to be read.
Referenced by connect().
|
private |
For each input sample, length of variables to read.
Referenced by connect().
|
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().
|
private |
Referenced by NearestResamplerAtRate().
|
private |
Referenced by NearestResamplerAtRate(), and ~NearestResamplerAtRate().
|
private |
Referenced by NearestResamplerAtRate(), and ~NearestResamplerAtRate().
|
private |
Referenced by flush(), and NearestResamplerAtRate().
Referenced by ~NearestResamplerAtRate().
|
private |
Referenced by NearestResamplerAtRate().
|
private |
For each input sample, index into output sample of each variable.
Referenced by connect().
|
private |
Referenced by NearestResamplerAtRate().
|
private |
Referenced by NearestResamplerAtRate().
Index of each requested output variable in the output sample.
Referenced by connect(), and NearestResamplerAtRate().
|
private |
Referenced by NearestResamplerAtRate(), and ~NearestResamplerAtRate().
|
private |
Referenced by NearestResamplerAtRate(), and ~NearestResamplerAtRate().
|
private |
Requested variables.
Referenced by connect(), NearestResamplerAtRate(), and ~NearestResamplerAtRate().
|
private |
Referenced by NearestResamplerAtRate(), and ~NearestResamplerAtRate().
|
private |
|
private |