Namespace inertialsim::time¶
Namespace List > inertialsim > time
Time representation and manipulation utilities. More...
Classes¶
| Type | Name |
|---|---|
| struct | SampleRateTolerances Sample rate tolerances for time validation. |
| class | TimeTolerances Singleton class for managing time tolerance settings. |
Public Types¶
| Type | Name |
|---|---|
| typedef std::tuple< double, double, double, double > | SampleStats Tuple holding sample statistics. |
Public Attributes¶
| Type | Name |
|---|---|
| constexpr double | kDefaultTolerance = 1[**e**](namespaceinertialsim.md#typedef-matrix)-9Default tolerance for timestamp comparisons (1 nanosecond). |
Public Functions¶
| Type | Name |
|---|---|
| Timestamps | InsertMidpoints (const Timestamps & time) Insert midpoints into time array. |
| std::optional< Timestamps > | Merge (const std::optional< Timestamps > & time1, const std::optional< Timestamps > & time2, std::optional< double > tolerance=std::nullopt) Merge two compatible time arrays. |
| SampleStats | SamplePeriodStatistics (const Timestamps & time) Calculate sample period statistics. |
| SampleStats | SampleRateStatistics (const Timestamps & time) Calculate sample rate statistics. |
| Timestamps | Span (double start, double end, double dt) Create a time array with evenly spaced values. |
| Timestamps | Validate (const Timestamps & time, std::optional< double > expected_sample_rate=std::nullopt, std::optional< SampleRateTolerances > tolerance=std::nullopt) Validate time array. |
Detailed Description¶
The time namespace provides:
- methods to create, validate, and analyze standardized time arrays.
Public Types Documentation¶
typedef SampleStats¶
Tuple holding sample statistics.
Returns (minimum, maximum, median, standard_deviation) as a tuple of doubles.
Public Attributes Documentation¶
variable kDefaultTolerance¶
Default tolerance for timestamp comparisons (1 nanosecond).
Value: 1e-9
Public Functions Documentation¶
function InsertMidpoints¶
Insert midpoints into time array.
Insert midpoints between consecutive time values. The output array will have size = 2N-1 if the input has size N. The midpoints are calculated as the average of consecutive time values.
Inputs time must be pre-validated.
Parameters:
timeTime array of size N.
Returns:
Time array of size 2N-1 with midpoints inserted.
Exception:
std::invalid_argumentif time has fewer than 2 values.
function Merge¶
Merge two compatible time arrays.
std::optional< Timestamps > inertialsim::time::Merge (
const std::optional< Timestamps > & time1,
const std::optional< Timestamps > & time2,
std::optional< double > tolerance=std::nullopt
)
If both inputs are nullopt, returns nullopt. If only one of the inputs is nullopt, returns the other input. If both inputs are not nullopt, checks they are close to each other element-wise and return the first input if they are. Otherwise raises a std::invalid_argument.
Parameters:
time1The first time array.time2The second time array.toleranceTolerance for comparing time1 and time2 for equality (seconds). If nullopt, the default tolerance is used.
Returns:
Merged timestamps, or nullopt if both inputs are nullopt.
Exception:
std::invalid_argumentif time arrays have incompatible sizes or values are not mutually consistent within tolerance.
function SamplePeriodStatistics¶
Calculate sample period statistics.
Calculate the minimum, maximum, median, and sample deviation of sampling periods from the time array input. The sampled period is the difference between consecutive times. A robust estimate of the standard deviation is calculated to reduce the effect of outliers.
Inputs should be pre-validated with Validate().
Parameters:
timeAn array of timestamps.
Returns:
Tuple containing:
- minimum: Minimum sample period (s).
- maximum: Maximum sample period (s).
- median: Median sample period (s).
- standard_deviation: Standard deviation of sample periods (s).
Exception:
std::invalid_argumentif time has fewer than 2 values.
function SampleRateStatistics¶
Calculate sample rate statistics.
Calculate the minimum, maximum, median, and sample deviation of sampling rates from the time array input. The sample rate is the inverse of the difference between consecutive times. A robust estimate of the standard deviation is calculated to reduce the effect of outliers.
Inputs should be pre-validated with Validate().
Parameters:
timeAn array of timestamps.
Returns:
Tuple containing:
- minimum: Minimum sample rate (Hz).
- maximum: Maximum sample rate (Hz).
- median: Median sample rate (Hz).
- standard_deviation: Standard deviation of sample rates (Hz).
Exception:
std::invalid_argumentif time has fewer than 2 values.
function Span¶
Create a time array with evenly spaced values.
The end time is included in the result. The inclusion of the end time is dependent on dt being a near integer multiple of (start - end) in the presence of floating point round-off.
The end point must be larger than the start point, and dt must be greater than 0.
Parameters:
startStart time in seconds.endEnd time in seconds.dtTime delta in seconds.
Returns:
Timestamps.
Exception:
std::invalid_argumentif end <= start or dt <= 0.
function Validate¶
Validate time array.
Timestamps inertialsim::time::Validate (
const Timestamps & time,
std::optional< double > expected_sample_rate=std::nullopt,
std::optional< SampleRateTolerances > tolerance=std::nullopt
)
Several classes take optional time inputs (see inertialsim::geodesy::Coordinates, inertialsim::geometry::Rotation, inertialsim::sensors::Measurement, etc.). This function provides common validation across classes. Time inputs must be unique, monotonically increasing, and (optional) match the expected sample rate.
If time contains non-finite values (inf, nan); duplicate values; or is not sorted, a std::invalid_argument is raised.
If expected_sample_rate is input and time has more than one value, optional sample rate checks are performed using the tolerance input. Outliers, like duplicated timestamps or missing data, are common. They are particularly problematic in inertial algorithms that require numerical differentiation, integration, or interpolation. A std::invalid_argument is raised if any of the tolerances are exceeded.
Parameters:
timeArray of timestamps.expected_sample_rateExpected sample rate. Must be a positive value (Hz). If nullopt, no sample rate validation is performed.toleranceSample rate tolerances. If nullopt, the default tolerances are used.
Returns:
Validated timestamps.
Exception:
std::invalid_argumentif time values are not finite, not unique, not strictly increasing, or if sample rate tolerances are exceeded.
The documentation for this class was generated from the following file cpp/include/inertialsim/time/time.h