hertzforge.core.time_compare¶
time_compare
¶
Two sets of time responses compared station by station: a test's measured responses against a model's predicted ones.
Each response record of one set is paired with the record of the other
at the same signed DOF and the same quantity (TimeHistory.channel_key).
Force and other reference channels, and monitors, are left out: a
channel is paired only when its role is 'response'
(TimeHistory.channel_roles). A DOF with no partner, or with more than
two records, is refused with the DOF named rather than paired by
guessing; two sets whose node numbers differ are paired by hand.
The pairs are put on one clock, the coarsest of the sources' clocks, inside the time all of them cover, and the other traces are interpolated linearly onto it. Nothing else is done to them: no lag is removed, no sign or gain is fitted, and no filter is applied. A source sampled much faster than the shared clock is interpolated without an anti-alias filter, so content above the coarser clock's Nyquist frequency must be filtered out first.
For a pair, the first trace a (the test) and the second b (the model), on the shared clock inside the scoring window:
- TRAC, the time response assurance criterion, (a·b)² / ((a·a)(b·b)), from 0 to 1, and 1 when the two have the same shape. Squared and normalized, it is blind to a reversed sign and to any constant gain.
- the signed correlation, a·b / √((a·a)(b·b)), negative for a reversal;
- the RMS ratio, ‖b‖ / ‖a‖, the difference in amplitude;
- sTRAC, (a·b) / (b·b), the least-squares factor on b that fits a. Its ideal value is 1; -2 says the model is half the test's size and the wrong way round.
A trace that is zero, constant or not finite inside the window has no score, and its row says why.
Functions:
| Name | Description |
|---|---|
response_records |
The records whose channel's role is 'response', in order: a |
match_records |
The pairs to compare, as [first name, record, second name, record]. |
pairs_in_order |
Pairs made in record order, for two sets whose DOFs do not match: |
compare |
The pairs on one clock, ready to be scored. |
window |
Which samples of the shared clock lie in the scoring window, as a |
scores |
Every pair's scores over the scoring window. |
station_positions |
Where each station of a comparison is on the test's geometry: the |
spread_scores |
Station scores carried onto other points, the nodes of a finite |
Classes¶
Functions:¶
response_records
¶
response_records(data: TimeHistory) -> list[int]
The records whose channel's role is 'response', in order: a force, a reference or a monitor is not compared.
match_records
¶
match_records(histories: Mapping[str, TimeHistory], pairs: Sequence[Sequence[Any]] | None = None, records: Mapping[str, Sequence[int]] | None = None) -> list[list[Any]]
The pairs to compare, as [first name, record, second name, record].
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
histories
|
mapping of str to TimeHistory
|
The sets compared, by name, the first set first: its records are the first of each pair (the test, by convention). |
required |
pairs
|
sequence of [str, int, str, int]
|
Pairs made by hand, which may join different DOFs but never
different quantities. Without them the records are paired by
|
None
|
records
|
mapping of str to sequence of int
|
The records of each history to pair automatically, by name, such
as the ones picked; all of its records when not given. Only the
response records among them ( |
None
|
Returns:
| Type | Description |
|---|---|
list of [str, int, str, int]
|
One entry a pair, in the first set's record order. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If a source is not a time history. |
ValueError
|
If a DOF has no partner or more than two records; if a pair names a record that does not exist, uses a record twice, joins two quantities, or holds a record whose units are not declared. |
pairs_in_order
¶
pairs_in_order(first: Mapping[str, TimeHistory], second: Mapping[str, TimeHistory], records: Mapping[str, Sequence[int]] | None = None) -> list[list[Any]]
Pairs made in record order, for two sets whose DOFs do not match:
the k-th response record of the first set, across its histories in
order, with the k-th of the second. Nothing is guessed from a name or a
node number; the pairs are then checked as hand-made ones are
(match_records), so two quantities are never paired.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
first
|
mapping of str to TimeHistory
|
The two sets, the test's first. |
required |
second
|
mapping of str to TimeHistory
|
The two sets, the test's first. |
required |
records
|
mapping of str to sequence of int
|
The records of a history to take, by name; its response records
( |
None
|
Returns:
| Type | Description |
|---|---|
list of [str, int, str, int]
|
One pair a response record of the first set. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the two sets hold different numbers of response records, or a pair joins two quantities or an undeclared unit. |
compare
¶
compare(histories: Mapping[str, TimeHistory], *, pairs: Sequence[Sequence[Any]] | None = None, records: Mapping[str, Sequence[int]] | None = None, start: float | None = None, stop: float | None = None) -> TimeComparison
The pairs on one clock, ready to be scored.
The clock is the coarsest of the clocks of the records paired (by median step), kept where it lies inside the time every one of them covers; every other trace is interpolated linearly onto it, never extrapolated. The values are the sources' own, in SI.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
histories
|
Mapping[str, TimeHistory]
|
As |
required |
pairs
|
Mapping[str, TimeHistory]
|
As |
required |
records
|
Mapping[str, TimeHistory]
|
As |
required |
start
|
float
|
The scoring window, in seconds; the whole shared clock when not given. |
None
|
stop
|
float
|
The scoring window, in seconds; the whole shared clock when not given. |
None
|
Returns:
| Type | Description |
|---|---|
TimeComparison
|
Two records a pair, the first set's first, on the shared clock. |
Raises:
| Type | Description |
|---|---|
ValueError
|
As |
window
¶
window(data: TimeComparison, start: float | None = None, stop: float | None = None) -> ndarray
Which samples of the shared clock lie in the scoring window, as a
mask: the comparison's own window, or start and stop.
scores
¶
scores(data: TimeComparison, start: float | None = None, stop: float | None = None) -> list[dict[str, Any]]
Every pair's scores over the scoring window.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
TimeComparison
|
The comparison. |
required |
start
|
float
|
A window in place of the comparison's own, in seconds. |
None
|
stop
|
float
|
A window in place of the comparison's own, in seconds. |
None
|
Returns:
| Type | Description |
|---|---|
list of dict
|
One a pair, in order: |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the window ends before it starts, reaches outside the shared clock, or holds fewer than two samples. |
station_positions
¶
station_positions(data: TimeComparison, geometry: Any) -> tuple[ndarray, list[int]]
Where each station of a comparison is on the test's geometry: the position of the node its first trace's DOF names.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
TimeComparison
|
The comparison. |
required |
geometry
|
Geometry
|
The test's geometry, its nodes in the frame the scores are drawn in. |
required |
Returns:
| Type | Description |
|---|---|
(numpy.ndarray, list of int)
|
The positions, (S, 3), of the stations found, and which stations they are (indices into the pairs). A station whose node the geometry does not hold is left out. |
spread_scores
¶
spread_scores(stations: ndarray, values: ndarray, points: ndarray, *, smooth: bool = False) -> ndarray
Station scores carried onto other points, the nodes of a finite
element model: each point takes the score of the station nearest it,
or with smooth an inverse-distance-squared mean of every station's,
sum(s_i / d_i²) / sum(1 / d_i²), which is a station's own score where
the point lies on it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
stations
|
ndarray
|
(S, 3), where the scores were read. |
required |
values
|
ndarray
|
(S,), the scores; a station without one is left out by the caller. |
required |
points
|
ndarray
|
(P, 3), where they are wanted. |
required |
smooth
|
bool
|
The inverse-distance-squared mean in place of the nearest station. |
False
|
Returns:
| Type | Description |
|---|---|
ndarray
|
(P,), one score a point. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If there is no station to carry a score from. |