Commit 76937889 authored by thomas.forbriger's avatar thomas.forbriger
Browse files

libtsxx [FEATURE]: provide shrink option for interpolator

Provide means to reduce the output time window to the time span for which
input data is available while maintaing the desired sampling raster. This is
useful for data with gaps.
parent 2d4ca72c
......@@ -30,7 +30,9 @@
* - 13/07/2005 V1.0 Thomas Forbriger
* - 28/07/2005 V1.1 indicate wrong time window by specific exception
* - 07/11/2017 V1.2
* -provide new exception to indicate empty time window
* - provide new exception to indicate empty time window
* - provide option for automatic adjustment of time
* window in function resample
*
* ============================================================================
*/
......@@ -63,7 +65,8 @@ namespace ts {
ts::TDsfftimeseries resample(const Interpolator& ip,
const libtime::TAbsoluteTime& first,
const libtime::TRelativeTime& dt,
const int& n)
const int& n,
const bool& shrink)
{
typedef Interpolator::Ttimeseries Ttimeseries;
typedef Ttimeseries::Theader Theader;
......@@ -76,16 +79,38 @@ namespace ts {
TAbsoluteTime old_last=sff::wid2lastsample(hd);
TAbsoluteTime new_first=first;
TAbsoluteTime new_last=new_first+(n-1)*dt;
int nsamples=n;
// if requested, shrink time window to available data
if (shrink)
{
if (old_first > new_first)
{
int noff=(old_first-new_first)/dt;
new_first += (dt*noff);
nsamples -= noff;
while (new_first < old_first) { new_first += dt; nsamples--; }
}
if (old_last < new_last)
{
int noff=(new_last-old_last)/dt;
new_last -= (dt*noff);
nsamples -= noff;
while (new_last > old_last) { new_last -= dt; nsamples--; }
}
TSXX_Xassert(nsamples > 0,
"new time window is empty",
ExceptionTimeWindowEmpty);
}
TRange inputwindow(old_first, old_last);
TRange outputwindow(new_first, new_last);
TSXX_Xassert((inputwindow.includes(outputwindow)),
"new time span is outside time series",
ExceptionTimeWindowOutside);
Ttimeseries retval=Ttimeseries(Tseries(n), hd);
Ttimeseries retval=Ttimeseries(Tseries(nsamples), hd);
retval.header.date=new_first;
retval.header.dt=libtime::time2double(dt);
TAbsoluteTime it=new_first;
for (int i=0; i<n; ++i) { retval(i)=ip(it); it += dt; }
for (int i=0; i<nsamples; ++i) { retval(i)=ip(it); it += dt; }
return(retval);
}
......
......@@ -30,7 +30,9 @@
* - 13/07/2005 V1.0 Thomas Forbriger
* - 28/07/2005 V1.1 indicate wrong time window by specific exception
* - 07/11/2017 V1.2
* -provide new exception to indicate empty time window
* - provide new exception to indicate empty time window
* - provide option for automatic adjustment of time
* window in function resample
*
* ============================================================================
*/
......@@ -157,7 +159,8 @@ namespace ts {
ts::TDsfftimeseries resample(const Interpolator& ip,
const libtime::TAbsoluteTime& first,
const libtime::TRelativeTime& dt,
const int& n);
const int& n,
const bool& shrink=false);
} // namespace ipo
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment