Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Seitosh
Seitosh
Commits
56e40835
Commit
56e40835
authored
Dec 31, 2018
by
thomas.forbriger
Browse files
Merge branch 'tscollect' into croposp
parents
f248851d
068cb7b8
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/libs/libtsxx/tscollection.h
View file @
56e40835
...
...
@@ -69,22 +69,31 @@ namespace ts {
typedef
std
::
vector
<
Ttimeseries
>
Tbase
;
//!@}
/*! \brief Check consistency
*
* Check the consistency of the time series in the collections based on
* header data. For example this can be used to check whether all time
* series have the same number of samples.
*
* \param comparer defines the header fields to be compared
* \return true, if comparer returns true for comparison of all pairs
* of time series headers in the collection
*/
//! Check consistency
bool
are_consistent
(
const
::
sff
::
WID2compare
comparer
)
const
;
//! Check whether all time series have a common time window
bool
overlap
()
const
;
//! Synchronize header with series
void
synchronize_nsamples
();
//! Trim to same start time
void
trim_to_date
();
//! Trim to same number of samples
void
trim_to_nsamples
();
};
// class TimeSeriesCollection
/* ---------------------------------------------------------------------- */
/*! \brief Check consistency
*
* Check the consistency of the time series in the collections based on
* header data. For example this can be used to check whether all time
* series have the same number of samples.
*
* \param comparer defines the header fields to be compared
* \return true, if comparer returns true for comparison of all pairs
* of time series headers in the collection
*/
template
<
typename
T
>
bool
TimeSeriesCollection
<
T
>::
are_consistent
(
const
::
sff
::
WID2compare
comparer
)
const
{
...
...
@@ -103,6 +112,144 @@ namespace ts {
return
(
retval
);
}
// bool TimeSeriesCollection<T>::are_consistent(const ::sff::WID2compare comparer) const
/* ---------------------------------------------------------------------- */
/*! \brief Check whether all time series have a common time window
*
* Check whether all time series overlap in time. This is a necessary
* prerequisite for trimming all time series to a common time window.
*
* \return true, if time series overlap
*/
template
<
typename
T
>
bool
TimeSeriesCollection
<
T
>::
overlap
()
const
{
bool
retval
=
true
;
if
(
this
->
size
()
>
1
)
{
typename
Tbase
::
const_iterator
i_series
=
this
->
begin
();
Theader
header
=
i_series
->
header
;
libtime
::
TAbsoluteTime
begin
=
header
.
date
;
libtime
::
TAbsoluteTime
end
=
sff
::
wid2lastsample
(
header
);
++
i_series
;
while
((
i_series
!=
this
->
end
())
&&
retval
)
{
header
=
i_series
->
header
;
libtime
::
TAbsoluteTime
thisbegin
=
header
.
date
;
libtime
::
TAbsoluteTime
thisend
=
sff
::
wid2lastsample
(
header
);
begin
=
thisbegin
>
begin
?
thisbegin
:
begin
;
end
=
thisend
<
end
?
thisend
:
end
;
++
i_series
;
}
retval
=
(
end
>=
begin
);
}
return
(
retval
);
}
// bool TimeSeriesCollection<T>::overlap() const
/* ---------------------------------------------------------------------- */
/*! \brief Synchronize header with series
*
* Set actual number of samples and nsamples in header to the smaller of
* both.
*/
template
<
typename
T
>
void
TimeSeriesCollection
<
T
>::
synchronize_nsamples
()
{
typename
Tbase
::
const_iterator
i_series
=
this
->
begin
();
while
(
i_series
!=
this
->
end
())
{
const
unsigned
int
&
header_nsamples
=
i_series
->
header
.
nsamples
;
unsigned
int
series_nsamples
=
i_series
->
data
.
size
();
unsigned
int
nsamples
=
series_nsamples
<
header_nsamples
?
series_nsamples
:
header_nsamples
;
i_series
->
header
.
nsamples
=
nsamples
;
i_series
->
data
.
setlastindex
(
i_series
->
data
.
f
()
+
nsamples
-
1
);
++
i_series
;
}
}
// void TimeSeriesCollection<T>::synchronize_nsamples()
/* ---------------------------------------------------------------------- */
/*! \brief Trim to same start time
*
* Set all start dates to the latest found in the collection.
*/
template
<
typename
T
>
void
TimeSeriesCollection
<
T
>::
trim_to_date
()
{
if
(
this
->
size
()
>
1
)
{
// find lastest start date
typename
Tbase
::
iterator
i_series
=
this
->
begin
();
Theader
header
=
i_series
->
header
;
libtime
::
TAbsoluteTime
begin
=
header
.
date
;
++
i_series
;
while
(
i_series
!=
this
->
end
())
{
header
=
i_series
->
header
;
libtime
::
TAbsoluteTime
thisbegin
=
header
.
date
;
begin
=
thisbegin
>
begin
?
thisbegin
:
begin
;
++
i_series
;
}
// adjust series and header
i_series
=
this
->
begin
();
while
(
i_series
!=
this
->
end
())
{
header
=
i_series
->
header
;
long
int
index_offset
=
wid2isample
(
header
,
begin
);
TSXX_assert
(
index_offset
>=
0
,
"inconsistent header data"
);
TSXX_assert
(
index_offset
>
header
.
nsamples
,
"time series does not overlap with others"
);
i_series
->
header
.
date
=
begin
;
i_series
->
header
.
nsamples
-=
index_offset
;
i_series
->
data
.
setfirstindex
(
i_series
.
data
.
f
()
+
index_offset
);
++
i_series
;
}
}
}
// void TimeSeriesCollection<T>::trim_to_date()
/* ---------------------------------------------------------------------- */
/*! \brief Trim to same number of samples
*
* Set length of all time series to smallest found in collection.
*/
template
<
typename
T
>
void
TimeSeriesCollection
<
T
>::
trim_to_nsamples
()
{
this
->
synchronize_nsamples
();
if
(
this
->
size
()
>
1
)
{
// find smallest number of samples in collection
typename
Tbase
::
iterator
i_series
=
this
->
begin
();
Theader
header
=
i_series
->
header
;
unsigned
int
nsamples
=
header
.
nsamples
;
++
i_series
;
while
(
i_series
!=
this
->
end
())
{
header
=
i_series
->
header
;
unsigned
int
thisnsamples
=
header
.
nsamples
;
end
=
thisnsamples
<
nsamples
?
thisnsamples
:
nsamples
;
++
i_series
;
}
// adjust number of samples
i_series
=
this
->
begin
();
while
(
i_series
!=
this
->
end
())
{
i_series
->
header
.
nsamples
=
nsamples
;
i_series
->
data
.
setlastindex
(
i_series
.
data
.
f
()
+
nsamples
-
1
);
++
i_series
;
}
}
}
// void TimeSeriesCollection<T>::trim_to_nsamples()
/* ---------------------------------------------------------------------- */
}
// namespace ts
#endif // TS_TSCOLLECTION_H_VERSION (includeguard)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment