Predicted speeds¶
DCT-II compression utilities for the 2016 five-minute speed buckets per week that Valhalla uses as predicted traffic profiles. See Speed information for how these buckets are resolved at runtime.
compress_speed_buckets ¶
compress_speed_buckets(speeds: Annotated[NDArray[float32], dict(shape=2016)]) -> Annotated[NDArray[numpy.int16], dict(shape=200)]
Compress 2016 speed buckets into 200 DCT-II coefficients.
| PARAMETER | DESCRIPTION |
|---|---|
speeds
|
NumPy array of 2016 float values (one per 5-minute bucket)
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Annotated[NDArray[int16], dict(shape=200)]
|
NumPy array of 200 int16 coefficients |
decompress_speed_bucket ¶
decompress_speed_bucket(coefficients: Sequence[int], bucket_idx: int) -> float
Decompress a single speed bucket using DCT-III.
| PARAMETER | DESCRIPTION |
|---|---|
coefficients
|
Array of 200 int16 coefficients
TYPE:
|
bucket_idx
|
Bucket index (0 to 2015)
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
float
|
Speed in KPH for the specified bucket |
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If bucket_idx is out of range |
encode_compressed_speeds ¶
encode_compressed_speeds(coefficients: Sequence[int]) -> str
Encode 200 coefficients as base64 string.
| PARAMETER | DESCRIPTION |
|---|---|
coefficients
|
Array of 200 int16 coefficients
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
Base64-encoded string |
decode_compressed_speeds ¶
decode_compressed_speeds(encoded: str) -> Annotated[NDArray[numpy.int16], dict(shape=200)]
Decode base64 string to 200 coefficients.
| PARAMETER | DESCRIPTION |
|---|---|
encoded
|
Base64-encoded string (536 characters)
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Annotated[NDArray[int16], dict(shape=200)]
|
Array of 200 int16 coefficients |
| RAISES | DESCRIPTION |
|---|---|
RuntimeError
|
If decoded size is incorrect |