nrdk.tss.utils
¶
Data marshalling utilities.
nrdk.tss.utils.cut_trace
¶
Cut trace into multiple sub-traces based on gaps in timestamps.
Tip
Set gap
to a duration, in seconds, which is greater than (but of
similar magnitude) than the expected effective sampling rate of the
time series.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
timestamps
|
Float[ndarray, N]
|
measurement timestamps. |
required |
values
|
TValue
|
time series measurement values. Is expected to be a
|
required |
gap
|
float
|
timestamp gap, nominally in seconds, which denotes a new trace. |
20.0
|
Returns:
Type | Description |
---|---|
list[TValue]
|
A list of metrics for each sub-trace, with the same structure and type as the inputs. |
Source code in src/nrdk/tss/utils.py
nrdk.tss.utils.intersect_difference
¶
intersect_difference(
y1: Num[ndarray, N1],
y2: Num[ndarray, N2],
t1: Num[ndarray, N1] | None = None,
t2: Num[ndarray, N2] | None = None,
) -> Num[ndarray, N]
Compute the difference between two time series at common timestamps.
Info
If t1
and t2
are not provided, the two time series are assumed to
be synchronized.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
y1
|
Num[ndarray, N1]
|
first time series. |
required |
y2
|
Num[ndarray, N2]
|
second time series. |
required |
t1
|
Num[ndarray, N1] | None
|
timestamps for the first time series. |
None
|
t2
|
Num[ndarray, N2] | None
|
timestamps for the second time series. |
None
|
Returns:
Type | Description |
---|---|
Num[ndarray, N]
|
Differences |
Source code in src/nrdk/tss/utils.py
nrdk.tss.utils.tree_flatten
¶
Flatten a nested structure into a dictionary with path-like keys.
Inverse of tree_unflatten
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
tree
|
MetricTree[LeafType]
|
input tree structure. Must consist only of dictionaries, where each leaf value is a numpy array with the same leading batch size. |
required |
Returns:
Type | Description |
---|---|
dict[str, LeafType]
|
A dictionary, where keys correspond to |
Source code in src/nrdk/tss/utils.py
nrdk.tss.utils.tree_unflatten
¶
Unflatten a dictionary with path-like keys into a nested structure.
Inverse of tree_flatten
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
flattened
|
dict[str, LeafType]
|
input dictionary, where keys are |
required |
Returns:
Type | Description |
---|---|
MetricTree[LeafType]
|
Expanded dictionary with arbitrary nesting. |