API Reference
pysatl_tsp
PySATL Time Series Processing subproject (abbreviated pysatl-tsp) is a module designed for adaptive processing of time series data with a focus on streaming architecture. It implements a chain of responsibility pattern that enables building complex data processing pipelines with minimal boilerplate code, making it suitable for real-time applications and large dataset analysis.
core
This module provides the core functionality for the pysatl_tsp package.
Handler
Bases: ABC, Generic[T, U]
Abstract base class for time series processing handlers.
This class implements a Chain of Responsibility pattern for processing time series data. Each Handler can be connected to a source handler and process its output data. Handlers can be combined using the pipe operator (|) to create processing pipelines.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
Handler[Any, T] | None
|
The handler to use as a data source, defaults to None |
None
|
Source code in pysatl_tsp/core/handler.py
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 | |
source
property
writable
source: Handler[Any, T] | None
Get the source handler that provides input data to this handler.
Returns:
| Type | Description |
|---|---|
Handler[Any, T] | None
|
The source handler or None if this is a root handler |
__init__
__init__(source: Handler[Any, T] | None = None)
Initialize a handler with an optional source.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
Handler[Any, T] | None
|
The handler to use as a data source, defaults to None |
None
|
Source code in pysatl_tsp/core/handler.py
28 29 30 31 32 33 | |
__iter__
abstractmethod
__iter__() -> Iterator[U]
Create an iterator over the output data produced by this handler.
Each subclass must implement this method to define how data is processed.
Returns:
| Type | Description |
|---|---|
Iterator[U]
|
An iterator yielding processed data items |
Source code in pysatl_tsp/core/handler.py
54 55 56 57 58 59 60 61 62 | |
__or__
__or__(other: Handler[U, V]) -> Pipeline[T, V]
Combine this handler with another handler using the pipe operator.
This allows for the creation of processing pipelines using syntax like: handler1 | handler2 | handler3
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
other
|
Handler[U, V]
|
The next handler in the pipeline |
required |
Returns:
| Type | Description |
|---|---|
Pipeline[T, V]
|
A Pipeline object connecting this handler to the other handler |
Source code in pysatl_tsp/core/handler.py
64 65 66 67 68 69 70 71 72 73 | |
data_providers
This module provides various data providers for the pysatl_tsp package.
DataBaseDataProvider
Bases: DataProvider[T], Generic[T]
A data provider that sources time series data from a database.
This class provides a way to query time series data from any database system using adapters that implement the DatabaseAdapter interface. It handles the connection lifecycle and streaming of data from database queries.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
connection_params
|
dict[str, Any]
|
Dictionary containing connection parameters |
required |
query
|
str
|
SQL query string to execute |
required |
adapter
|
DatabaseAdapter[T]
|
Database adapter implementation |
required |
params
|
tuple[Any, ...]
|
Query parameters, defaults to () Example: |
()
|
Source code in pysatl_tsp/core/data_providers/database_data_provider.py
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 | |
__init__
__init__(
connection_params: dict[str, Any],
query: str,
adapter: DatabaseAdapter[T],
params: tuple[Any, ...] = (),
) -> None
Initialize a database data provider.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
connection_params
|
dict[str, Any]
|
Dictionary containing connection parameters |
required |
query
|
str
|
SQL query string to execute |
required |
adapter
|
DatabaseAdapter[T]
|
Database adapter implementation |
required |
params
|
tuple[Any, ...]
|
Query parameters, defaults to () |
()
|
Source code in pysatl_tsp/core/data_providers/database_data_provider.py
148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 | |
__iter__
__iter__() -> Iterator[T]
Create an iterator over the query results from the database.
This method executes the query and yields data items by delegating to the adapter's fetch_data method.
Returns:
| Type | Description |
|---|---|
Iterator[T]
|
An iterator yielding data items from the database query |
Raises:
| Type | Description |
|---|---|
Exception
|
If database operations fail |
Source code in pysatl_tsp/core/data_providers/database_data_provider.py
190 191 192 193 194 195 196 197 198 199 200 | |
DataProvider
Bases: Handler[None, T]
Abstract base class for time series data providers.
DataProvider serves as a root handler in a processing pipeline, responsible for sourcing the initial time series data. As the first element in the chain, it doesn't receive input from any preceding handler and acts as the data origin.
This class is designed to be subclassed with specific implementations for different data sources such as files, databases, APIs, or generated data.
Source code in pysatl_tsp/core/data_providers/abstract.py
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | |
__init__
__init__() -> None
Initialize a data provider with no source.
Data providers are always root handlers and cannot have a source.
Source code in pysatl_tsp/core/data_providers/abstract.py
20 21 22 23 24 25 | |
__iter__
abstractmethod
__iter__() -> Iterator[T]
Create an iterator over the time series data provided by this data source.
Each subclass must implement this method to define how data is sourced and potentially pre-processed before being passed to subsequent handlers.
Returns:
| Type | Description |
|---|---|
Iterator[T]
|
An iterator yielding time series data items |
Source code in pysatl_tsp/core/data_providers/abstract.py
27 28 29 30 31 32 33 34 35 36 | |
DatabaseAdapter
Bases: ABC, Generic[T]
Abstract base class for database adapter implementations.
This class defines the interface for adapters that connect to different database systems. Concrete implementations of this class handle the specific details of connecting to databases, executing queries, and transforming results into a consistent format for the data processing pipeline.
Example:
import sqlite3
class SQLiteAdapter(DatabaseAdapter[dict[str, Any]]):
def connect(self, connection_params: dict[str, Any]) -> sqlite3.Connection:
connection = sqlite3.connect(connection_params["database"])
connection.row_factory = sqlite3.Row
return connection
def execute_query(
self, connection: sqlite3.Connection, query: str, params: tuple[Any, ...] = ()
) -> sqlite3.Cursor:
cursor = connection.cursor()
cursor.execute(query, params)
return cursor
def fetch_data(self, cursor: sqlite3.Cursor) -> Iterator[dict[str, Any]]:
for row in cursor:
yield dict(row)
def close_cursor(self, cursor: sqlite3.Cursor) -> None:
cursor.close()
def close_connection(self, connection: sqlite3.Connection) -> None:
connection.close()
# Usage:
adapter = SQLiteAdapter()
provider = DataBaseDataProvider(
connection_params={"database": "time_series.db"},
query="SELECT timestamp, value FROM measurements WHERE sensor_id = ?",
adapter=adapter,
params=(42,),
)
Source code in pysatl_tsp/core/data_providers/database_data_provider.py
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 | |
close_connection
abstractmethod
close_connection(connection: Any) -> None
Close the database connection.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
connection
|
Any
|
Database connection object |
required |
Source code in pysatl_tsp/core/data_providers/database_data_provider.py
102 103 104 105 106 107 108 | |
close_cursor
abstractmethod
close_cursor(cursor: Any) -> None
Close the query cursor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cursor
|
Any
|
Query result cursor |
required |
Source code in pysatl_tsp/core/data_providers/database_data_provider.py
94 95 96 97 98 99 100 | |
connect
abstractmethod
connect(connection_params: dict[str, Any]) -> Any
Establish a connection to the database.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
connection_params
|
dict[str, Any]
|
Dictionary containing connection parameters (e.g., host, port, username, password, etc.) |
required |
Returns:
| Type | Description |
|---|---|
Any
|
Database connection object |
Raises:
| Type | Description |
|---|---|
Exception
|
If connection fails |
Source code in pysatl_tsp/core/data_providers/database_data_provider.py
62 63 64 65 66 67 68 69 70 71 | |
execute_query
abstractmethod
execute_query(
connection: Any,
query: str,
params: tuple[Any, ...] = (),
) -> Any
Execute a query on the given database connection.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
connection
|
Any
|
Database connection object |
required |
query
|
str
|
SQL query string |
required |
params
|
tuple[Any, ...]
|
Query parameters, defaults to () |
()
|
Returns:
| Type | Description |
|---|---|
Any
|
Query result cursor or similar object |
Raises:
| Type | Description |
|---|---|
Exception
|
If query execution fails |
Source code in pysatl_tsp/core/data_providers/database_data_provider.py
73 74 75 76 77 78 79 80 81 82 83 | |
fetch_data
abstractmethod
fetch_data(cursor: Any) -> Iterator[T]
Extract and transform data from the query result.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cursor
|
Any
|
Query result cursor |
required |
Returns:
| Type | Description |
|---|---|
Iterator[T]
|
Iterator yielding data items of type T |
Source code in pysatl_tsp/core/data_providers/database_data_provider.py
85 86 87 88 89 90 91 92 | |
FileDataProvider
Bases: DataProvider[X]
A data provider that reads time series data from a text file.
This class implements a file-based data source that reads a file line by line and transforms each line into a data item using a specified handler function. It is useful for processing time series data stored in text files with various formats (CSV, JSON per line, custom formats, etc.).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filename
|
str
|
Path to the file containing time series data |
required |
handler
|
Callable[[str], X]
|
A function that converts each line of text to a data item |
required |
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
If the specified file does not exist |
PermissionError
|
If the file cannot be read due to permission issues |
Source code in pysatl_tsp/core/data_providers/file_data_provider.py
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | |
__init__
__init__(
filename: str, handler: Callable[[str], X]
) -> None
Initialize a file data provider.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filename
|
str
|
Path to the file containing time series data |
required |
handler
|
Callable[[str], X]
|
A function that converts each line of text to a data item |
required |
Source code in pysatl_tsp/core/data_providers/file_data_provider.py
24 25 26 27 28 29 30 31 32 | |
__iter__
__iter__() -> Iterator[X]
Create an iterator that reads the file line by line and yields processed data items.
The method opens the specified file, reads it line by line, and applies the handler function to each line to transform it into a data item.
Returns:
| Type | Description |
|---|---|
Iterator[X]
|
An iterator yielding processed data items from the file |
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
If the specified file does not exist |
PermissionError
|
If the file cannot be read due to permission issues |
Source code in pysatl_tsp/core/data_providers/file_data_provider.py
34 35 36 37 38 39 40 41 42 43 44 45 46 | |
SimpleDataProvider
Bases: DataProvider[T]
A data provider that serves data from an in-memory iterable collection.
This class implements a simple data provider that wraps around any iterable collection and makes it available as a data source in a processing pipeline. It's useful for testing, working with pre-loaded data, or creating pipelines that process data already in memory.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
Iterable[T]
|
An iterable collection containing the time series data |
required |
Source code in pysatl_tsp/core/data_providers/simple_data_provider.py
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | |
__init__
__init__(data: Iterable[T]) -> None
Initialize a simple data provider with an iterable data source.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
Iterable[T]
|
An iterable collection containing the time series data |
required |
Source code in pysatl_tsp/core/data_providers/simple_data_provider.py
17 18 19 20 21 22 23 | |
__iter__
__iter__() -> Iterator[T]
Create an iterator over the provided data collection.
This method simply yields items from the data collection that was passed during initialization, making them available to subsequent handlers in the processing pipeline.
Returns:
| Type | Description |
|---|---|
Iterator[T]
|
An iterator yielding items from the data collection |
Source code in pysatl_tsp/core/data_providers/simple_data_provider.py
25 26 27 28 29 30 31 32 33 34 | |
WebSocketDataProvider
Bases: DataProvider[str]
A data provider that streams time series data from a WebSocket connection.
This class establishes a WebSocket connection to a specified URI and streams received messages into the processing pipeline. It handles the WebSocket connection in a separate thread to avoid blocking the main processing flow and provides a clean streaming interface through the standard iterator protocol.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
uri
|
str
|
WebSocket endpoint URI |
required |
subscribe_message
|
dict[str, Any] | None
|
Optional message to send after connection to subscribe to specific data streams Example: |
None
|
Source code in pysatl_tsp/core/data_providers/websocket_data_provider.py
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 | |
__init__
__init__(
uri: str,
subscribe_message: dict[str, Any] | None = None,
) -> None
Initialize a WebSocket data provider.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
uri
|
str
|
WebSocket endpoint URI |
required |
subscribe_message
|
dict[str, Any] | None
|
Optional message to send after connection to subscribe to specific data streams |
None
|
Source code in pysatl_tsp/core/data_providers/websocket_data_provider.py
46 47 48 49 50 51 52 53 54 55 56 57 | |
__iter__
__iter__() -> Iterator[str]
Create an iterator over the messages received from the WebSocket.
This method starts a background thread to handle the WebSocket connection if it's not already running, and yields messages as they are received.
Returns:
| Type | Description |
|---|---|
Iterator[str]
|
An iterator yielding message strings from the WebSocket |
Source code in pysatl_tsp/core/data_providers/websocket_data_provider.py
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 | |
close
close() -> None
Close the WebSocket connection and stop the background thread.
This method should be called when the provider is no longer needed to release resources properly.
Source code in pysatl_tsp/core/data_providers/websocket_data_provider.py
103 104 105 106 107 108 109 110 111 | |
abstract
DataProvider
Bases: Handler[None, T]
Abstract base class for time series data providers.
DataProvider serves as a root handler in a processing pipeline, responsible for sourcing the initial time series data. As the first element in the chain, it doesn't receive input from any preceding handler and acts as the data origin.
This class is designed to be subclassed with specific implementations for different data sources such as files, databases, APIs, or generated data.
Source code in pysatl_tsp/core/data_providers/abstract.py
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | |
__init__() -> None
Initialize a data provider with no source.
Data providers are always root handlers and cannot have a source.
Source code in pysatl_tsp/core/data_providers/abstract.py
20 21 22 23 24 25 | |
abstractmethod
__iter__() -> Iterator[T]
Create an iterator over the time series data provided by this data source.
Each subclass must implement this method to define how data is sourced and potentially pre-processed before being passed to subsequent handlers.
Returns:
| Type | Description |
|---|---|
Iterator[T]
|
An iterator yielding time series data items |
Source code in pysatl_tsp/core/data_providers/abstract.py
27 28 29 30 31 32 33 34 35 36 | |
database_data_provider
DataBaseDataProvider
Bases: DataProvider[T], Generic[T]
A data provider that sources time series data from a database.
This class provides a way to query time series data from any database system using adapters that implement the DatabaseAdapter interface. It handles the connection lifecycle and streaming of data from database queries.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
connection_params
|
dict[str, Any]
|
Dictionary containing connection parameters |
required |
query
|
str
|
SQL query string to execute |
required |
adapter
|
DatabaseAdapter[T]
|
Database adapter implementation |
required |
params
|
tuple[Any, ...]
|
Query parameters, defaults to () Example: |
()
|
Source code in pysatl_tsp/core/data_providers/database_data_provider.py
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 | |
__init__(
connection_params: dict[str, Any],
query: str,
adapter: DatabaseAdapter[T],
params: tuple[Any, ...] = (),
) -> None
Initialize a database data provider.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
connection_params
|
dict[str, Any]
|
Dictionary containing connection parameters |
required |
query
|
str
|
SQL query string to execute |
required |
adapter
|
DatabaseAdapter[T]
|
Database adapter implementation |
required |
params
|
tuple[Any, ...]
|
Query parameters, defaults to () |
()
|
Source code in pysatl_tsp/core/data_providers/database_data_provider.py
148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 | |
__iter__() -> Iterator[T]
Create an iterator over the query results from the database.
This method executes the query and yields data items by delegating to the adapter's fetch_data method.
Returns:
| Type | Description |
|---|---|
Iterator[T]
|
An iterator yielding data items from the database query |
Raises:
| Type | Description |
|---|---|
Exception
|
If database operations fail |
Source code in pysatl_tsp/core/data_providers/database_data_provider.py
190 191 192 193 194 195 196 197 198 199 200 | |
DatabaseAdapter
Bases: ABC, Generic[T]
Abstract base class for database adapter implementations.
This class defines the interface for adapters that connect to different database systems. Concrete implementations of this class handle the specific details of connecting to databases, executing queries, and transforming results into a consistent format for the data processing pipeline.
Example:
import sqlite3
class SQLiteAdapter(DatabaseAdapter[dict[str, Any]]):
def connect(self, connection_params: dict[str, Any]) -> sqlite3.Connection:
connection = sqlite3.connect(connection_params["database"])
connection.row_factory = sqlite3.Row
return connection
def execute_query(
self, connection: sqlite3.Connection, query: str, params: tuple[Any, ...] = ()
) -> sqlite3.Cursor:
cursor = connection.cursor()
cursor.execute(query, params)
return cursor
def fetch_data(self, cursor: sqlite3.Cursor) -> Iterator[dict[str, Any]]:
for row in cursor:
yield dict(row)
def close_cursor(self, cursor: sqlite3.Cursor) -> None:
cursor.close()
def close_connection(self, connection: sqlite3.Connection) -> None:
connection.close()
# Usage:
adapter = SQLiteAdapter()
provider = DataBaseDataProvider(
connection_params={"database": "time_series.db"},
query="SELECT timestamp, value FROM measurements WHERE sensor_id = ?",
adapter=adapter,
params=(42,),
)
Source code in pysatl_tsp/core/data_providers/database_data_provider.py
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 | |
abstractmethod
close_connection(connection: Any) -> None
Close the database connection.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
connection
|
Any
|
Database connection object |
required |
Source code in pysatl_tsp/core/data_providers/database_data_provider.py
102 103 104 105 106 107 108 | |
abstractmethod
close_cursor(cursor: Any) -> None
Close the query cursor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cursor
|
Any
|
Query result cursor |
required |
Source code in pysatl_tsp/core/data_providers/database_data_provider.py
94 95 96 97 98 99 100 | |
abstractmethod
connect(connection_params: dict[str, Any]) -> Any
Establish a connection to the database.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
connection_params
|
dict[str, Any]
|
Dictionary containing connection parameters (e.g., host, port, username, password, etc.) |
required |
Returns:
| Type | Description |
|---|---|
Any
|
Database connection object |
Raises:
| Type | Description |
|---|---|
Exception
|
If connection fails |
Source code in pysatl_tsp/core/data_providers/database_data_provider.py
62 63 64 65 66 67 68 69 70 71 | |
abstractmethod
execute_query(
connection: Any,
query: str,
params: tuple[Any, ...] = (),
) -> Any
Execute a query on the given database connection.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
connection
|
Any
|
Database connection object |
required |
query
|
str
|
SQL query string |
required |
params
|
tuple[Any, ...]
|
Query parameters, defaults to () |
()
|
Returns:
| Type | Description |
|---|---|
Any
|
Query result cursor or similar object |
Raises:
| Type | Description |
|---|---|
Exception
|
If query execution fails |
Source code in pysatl_tsp/core/data_providers/database_data_provider.py
73 74 75 76 77 78 79 80 81 82 83 | |
abstractmethod
fetch_data(cursor: Any) -> Iterator[T]
Extract and transform data from the query result.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cursor
|
Any
|
Query result cursor |
required |
Returns:
| Type | Description |
|---|---|
Iterator[T]
|
Iterator yielding data items of type T |
Source code in pysatl_tsp/core/data_providers/database_data_provider.py
85 86 87 88 89 90 91 92 | |
file_data_provider
FileDataProvider
Bases: DataProvider[X]
A data provider that reads time series data from a text file.
This class implements a file-based data source that reads a file line by line and transforms each line into a data item using a specified handler function. It is useful for processing time series data stored in text files with various formats (CSV, JSON per line, custom formats, etc.).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filename
|
str
|
Path to the file containing time series data |
required |
handler
|
Callable[[str], X]
|
A function that converts each line of text to a data item |
required |
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
If the specified file does not exist |
PermissionError
|
If the file cannot be read due to permission issues |
Source code in pysatl_tsp/core/data_providers/file_data_provider.py
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | |
__init__(
filename: str, handler: Callable[[str], X]
) -> None
Initialize a file data provider.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filename
|
str
|
Path to the file containing time series data |
required |
handler
|
Callable[[str], X]
|
A function that converts each line of text to a data item |
required |
Source code in pysatl_tsp/core/data_providers/file_data_provider.py
24 25 26 27 28 29 30 31 32 | |
__iter__() -> Iterator[X]
Create an iterator that reads the file line by line and yields processed data items.
The method opens the specified file, reads it line by line, and applies the handler function to each line to transform it into a data item.
Returns:
| Type | Description |
|---|---|
Iterator[X]
|
An iterator yielding processed data items from the file |
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
If the specified file does not exist |
PermissionError
|
If the file cannot be read due to permission issues |
Source code in pysatl_tsp/core/data_providers/file_data_provider.py
34 35 36 37 38 39 40 41 42 43 44 45 46 | |
simple_data_provider
SimpleDataProvider
Bases: DataProvider[T]
A data provider that serves data from an in-memory iterable collection.
This class implements a simple data provider that wraps around any iterable collection and makes it available as a data source in a processing pipeline. It's useful for testing, working with pre-loaded data, or creating pipelines that process data already in memory.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
Iterable[T]
|
An iterable collection containing the time series data |
required |
Source code in pysatl_tsp/core/data_providers/simple_data_provider.py
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | |
__init__(data: Iterable[T]) -> None
Initialize a simple data provider with an iterable data source.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
Iterable[T]
|
An iterable collection containing the time series data |
required |
Source code in pysatl_tsp/core/data_providers/simple_data_provider.py
17 18 19 20 21 22 23 | |
__iter__() -> Iterator[T]
Create an iterator over the provided data collection.
This method simply yields items from the data collection that was passed during initialization, making them available to subsequent handlers in the processing pipeline.
Returns:
| Type | Description |
|---|---|
Iterator[T]
|
An iterator yielding items from the data collection |
Source code in pysatl_tsp/core/data_providers/simple_data_provider.py
25 26 27 28 29 30 31 32 33 34 | |
websocket_data_provider
WebSocketDataProvider
Bases: DataProvider[str]
A data provider that streams time series data from a WebSocket connection.
This class establishes a WebSocket connection to a specified URI and streams received messages into the processing pipeline. It handles the WebSocket connection in a separate thread to avoid blocking the main processing flow and provides a clean streaming interface through the standard iterator protocol.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
uri
|
str
|
WebSocket endpoint URI |
required |
subscribe_message
|
dict[str, Any] | None
|
Optional message to send after connection to subscribe to specific data streams Example: |
None
|
Source code in pysatl_tsp/core/data_providers/websocket_data_provider.py
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 | |
__init__(
uri: str,
subscribe_message: dict[str, Any] | None = None,
) -> None
Initialize a WebSocket data provider.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
uri
|
str
|
WebSocket endpoint URI |
required |
subscribe_message
|
dict[str, Any] | None
|
Optional message to send after connection to subscribe to specific data streams |
None
|
Source code in pysatl_tsp/core/data_providers/websocket_data_provider.py
46 47 48 49 50 51 52 53 54 55 56 57 | |
__iter__() -> Iterator[str]
Create an iterator over the messages received from the WebSocket.
This method starts a background thread to handle the WebSocket connection if it's not already running, and yields messages as they are received.
Returns:
| Type | Description |
|---|---|
Iterator[str]
|
An iterator yielding message strings from the WebSocket |
Source code in pysatl_tsp/core/data_providers/websocket_data_provider.py
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 | |
close() -> None
Close the WebSocket connection and stop the background thread.
This method should be called when the provider is no longer needed to release resources properly.
Source code in pysatl_tsp/core/data_providers/websocket_data_provider.py
103 104 105 106 107 108 109 110 111 | |
handler
Handler
Bases: ABC, Generic[T, U]
Abstract base class for time series processing handlers.
This class implements a Chain of Responsibility pattern for processing time series data. Each Handler can be connected to a source handler and process its output data. Handlers can be combined using the pipe operator (|) to create processing pipelines.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
Handler[Any, T] | None
|
The handler to use as a data source, defaults to None |
None
|
Source code in pysatl_tsp/core/handler.py
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 | |
source
property
writable
source: Handler[Any, T] | None
Get the source handler that provides input data to this handler.
Returns:
| Type | Description |
|---|---|
Handler[Any, T] | None
|
The source handler or None if this is a root handler |
__init__
__init__(source: Handler[Any, T] | None = None)
Initialize a handler with an optional source.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
Handler[Any, T] | None
|
The handler to use as a data source, defaults to None |
None
|
Source code in pysatl_tsp/core/handler.py
28 29 30 31 32 33 | |
__iter__
abstractmethod
__iter__() -> Iterator[U]
Create an iterator over the output data produced by this handler.
Each subclass must implement this method to define how data is processed.
Returns:
| Type | Description |
|---|---|
Iterator[U]
|
An iterator yielding processed data items |
Source code in pysatl_tsp/core/handler.py
54 55 56 57 58 59 60 61 62 | |
__or__
__or__(other: Handler[U, V]) -> Pipeline[T, V]
Combine this handler with another handler using the pipe operator.
This allows for the creation of processing pipelines using syntax like: handler1 | handler2 | handler3
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
other
|
Handler[U, V]
|
The next handler in the pipeline |
required |
Returns:
| Type | Description |
|---|---|
Pipeline[T, V]
|
A Pipeline object connecting this handler to the other handler |
Source code in pysatl_tsp/core/handler.py
64 65 66 67 68 69 70 71 72 73 | |
Pipeline
Bases: Handler[T, V]
A composite handler that connects two handlers in sequence.
The Pipeline takes output from the first handler and feeds it as input to the second handler. This class enables the creation of data processing chains, where each handler in the chain performs a specific transformation on the data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
first
|
Handler[T, U]
|
The first handler in the pipeline |
required |
second
|
Handler[U, V]
|
The second handler in the pipeline |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the second handler already has a source configured |
Source code in pysatl_tsp/core/handler.py
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 | |
__init__
__init__(first: Handler[T, U], second: Handler[U, V])
Initialize a pipeline with two handlers.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
first
|
Handler[T, U]
|
The first handler in the pipeline |
required |
second
|
Handler[U, V]
|
The second handler in the pipeline |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the second handler already has a source configured |
Source code in pysatl_tsp/core/handler.py
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 | |
__iter__
__iter__() -> Iterator[V]
Create an iterator that processes data through both handlers in sequence.
Returns:
| Type | Description |
|---|---|
Iterator[V]
|
An iterator yielding data processed through both handlers |
Source code in pysatl_tsp/core/handler.py
108 109 110 111 112 113 114 | |
processor
This module provides the processor functionality for the pysatl_tsp package.
MappingHandler
Bases: Handler[T, U]
A handler that transforms time series data by applying a mapping function to each item.
This handler applies a user-defined transformation function to each data point in the input stream, producing a new stream of transformed values. It's useful for simple point-by-point transformations such as scaling, type conversion, feature extraction, or any operation that processes one input item at a time.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
map_func
|
Callable[[T], U]
|
Function that transforms each input item to an output item |
required |
source
|
Handler[Any, T] | None
|
The handler providing input data, defaults to None Example: |
None
|
Source code in pysatl_tsp/core/processor/mapping_handler.py
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 | |
__init__
__init__(
map_func: Callable[[T], U],
source: Handler[Any, T] | None = None,
)
Initialize a mapping handler.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
map_func
|
Callable[[T], U]
|
Function that transforms each input item to an output item |
required |
source
|
Handler[Any, T] | None
|
The handler providing input data, defaults to None |
None
|
Source code in pysatl_tsp/core/processor/mapping_handler.py
75 76 77 78 79 80 81 82 | |
__iter__
__iter__() -> Iterator[U]
Create an iterator that yields transformed items.
This method iterates through the source data and applies the mapping function to each item, yielding the transformed results.
Returns:
| Type | Description |
|---|---|
Iterator[U]
|
Iterator yielding transformed items |
Raises:
| Type | Description |
|---|---|
ValueError
|
If no source has been set |
Source code in pysatl_tsp/core/processor/mapping_handler.py
84 85 86 87 88 89 90 91 92 93 94 95 96 97 | |
OfflineFilterHandler
Bases: Handler[T, U]
A handler that applies a filter function to the entire time series data in batch mode.
This handler collects all data from the source before applying the filter function to the complete series at once. It's suitable for implementing filters that require the entire context of the time series, such as spectral filters, Savitzky-Golay filters, or other techniques that need to process the data as a whole.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filter_func
|
Callable[[ScrubberWindow[T], Any], list[U]]
|
Function that processes the entire series and returns filtered values |
required |
filter_config
|
Any
|
Configuration parameters for the filter function, defaults to None |
None
|
source
|
Handler[Any, T] | None
|
The handler providing input data, defaults to None Example: |
None
|
Source code in pysatl_tsp/core/processor/filter_handler.py
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 | |
__init__
__init__(
filter_func: Callable[
[ScrubberWindow[T], Any], list[U]
],
filter_config: Any = None,
source: Handler[Any, T] | None = None,
)
Initialize an offline filter handler.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filter_func
|
Callable[[ScrubberWindow[T], Any], list[U]]
|
Function that processes the entire series and returns filtered values |
required |
filter_config
|
Any
|
Configuration parameters for the filter function, defaults to None |
None
|
source
|
Handler[Any, T] | None
|
The handler providing input data, defaults to None |
None
|
Source code in pysatl_tsp/core/processor/filter_handler.py
161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 | |
__iter__
__iter__() -> Iterator[U]
Create an iterator that yields filtered values after processing the entire series.
This method collects all data from the source, applies the filter function to the complete series, and then yields the resulting filtered values.
Returns:
| Type | Description |
|---|---|
Iterator[U]
|
Iterator yielding filtered values |
Raises:
| Type | Description |
|---|---|
ValueError
|
If no source has been set |
Source code in pysatl_tsp/core/processor/filter_handler.py
177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 | |
OfflineSamplingHandler
Bases: Handler[T, T]
A handler that samples time series data in batch mode based on identified indices.
This handler processes the entire dataset to identify sampling points before extracting the samples. It's suitable for global sampling strategies that consider the entire time series context, such as selecting representative points or key points that preserve the overall shape of the data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sampling_rule
|
Callable[[ScrubberWindow[T]], list[int]]
|
Function that analyzes the entire series and returns indices of points to sample |
required |
source
|
Handler[Any, T] | None
|
The handler providing input data, defaults to None Example: |
None
|
Source code in pysatl_tsp/core/processor/sampling_handler.py
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 | |
__init__
__init__(
sampling_rule: Callable[[ScrubberWindow[T]], list[int]],
source: Handler[Any, T] | None = None,
)
Initialize an offline sampling handler.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sampling_rule
|
Callable[[ScrubberWindow[T]], list[int]]
|
Function that analyzes the entire series and returns indices of points to sample |
required |
source
|
Handler[Any, T] | None
|
The handler providing input data, defaults to None |
None
|
Source code in pysatl_tsp/core/processor/sampling_handler.py
158 159 160 161 162 163 164 165 | |
__iter__
__iter__() -> Iterator[T]
Create an iterator that yields sampled values based on the indices identified by the sampling rule.
This method uses OfflineSegmentationScrubber to segment the data at the specified indices and a MappingHandler to extract the last item from each segment.
Returns:
| Type | Description |
|---|---|
Iterator[T]
|
Iterator yielding sampled values |
Raises:
| Type | Description |
|---|---|
ValueError
|
If no source has been set (propagated from segmentation scrubber) |
Source code in pysatl_tsp/core/processor/sampling_handler.py
167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 | |
OnlineFilterHandler
Bases: Handler[T, U]
A handler that applies a filter function to time series data in real-time.
This handler processes data points one by one as they arrive and applies a filter function to the accumulated history. It's suitable for implementing online filters such as moving averages, exponential smoothing, or real-time anomaly detection.
The filter function receives the current history window and configuration parameters, and produces a filtered value for each input value.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filter_func
|
Callable[[ScrubberWindow[T], Any], U]
|
Function that applies filtering on the history window |
required |
filter_config
|
Any
|
Configuration parameters for the filter function, defaults to None |
None
|
source
|
Handler[Any, T] | None
|
The handler providing input data, defaults to None Example: |
None
|
Source code in pysatl_tsp/core/processor/filter_handler.py
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 | |
__init__
__init__(
filter_func: Callable[[ScrubberWindow[T], Any], U],
filter_config: Any = None,
source: Handler[Any, T] | None = None,
)
Initialize an online filter handler.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filter_func
|
Callable[[ScrubberWindow[T], Any], U]
|
Function that applies filtering on the history window |
required |
filter_config
|
Any
|
Configuration parameters for the filter function, defaults to None |
None
|
source
|
Handler[Any, T] | None
|
The handler providing input data, defaults to None |
None
|
Source code in pysatl_tsp/core/processor/filter_handler.py
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 | |
__iter__
__iter__() -> Iterator[U]
Create an iterator that yields filtered values in real-time.
This method processes data points one by one, accumulates them in a history window, and applies the filter function to produce filtered values.
Returns:
| Type | Description |
|---|---|
Iterator[U]
|
Iterator yielding filtered values |
Raises:
| Type | Description |
|---|---|
ValueError
|
If no source has been set |
Source code in pysatl_tsp/core/processor/filter_handler.py
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 | |
OnlineSamplingHandler
Bases: Handler[T, T]
A handler that samples time series data in real-time based on a condition.
This handler uses segmentation to identify points where sampling should occur and extracts the last item from each segment. It processes data in real-time and is suitable for adaptive sampling strategies, where sampling decisions are made based on the recent history of the time series.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sampling_rule
|
Callable[[ScrubberWindow[T]], bool]
|
Function that decides when to take a sample |
required |
source
|
Handler[Any, T] | None
|
The handler providing input data, defaults to None Example: |
None
|
Source code in pysatl_tsp/core/processor/sampling_handler.py
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 | |
__init__
__init__(
sampling_rule: Callable[[ScrubberWindow[T]], bool],
source: Handler[Any, T] | None = None,
)
Initialize an online sampling handler.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sampling_rule
|
Callable[[ScrubberWindow[T]], bool]
|
Function that decides when to take a sample |
required |
source
|
Handler[Any, T] | None
|
The handler providing input data, defaults to None |
None
|
Source code in pysatl_tsp/core/processor/sampling_handler.py
58 59 60 61 62 63 64 65 | |
__iter__
__iter__() -> Iterator[T]
Create an iterator that yields sampled values based on the sampling rule.
This method uses OnlineSegmentationScrubber to segment the data and a MappingHandler to extract the last item from each segment.
Returns:
| Type | Description |
|---|---|
Iterator[T]
|
Iterator yielding sampled values |
Raises:
| Type | Description |
|---|---|
ValueError
|
If no source has been set (propagated from segmentation scrubber) |
Source code in pysatl_tsp/core/processor/sampling_handler.py
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 | |
combine_handler
CombineHandler
Bases: Handler[T, U]
A handler that combines outputs from multiple handlers processing the same data.
This handler feeds the same source data to multiple handlers in parallel and combines their outputs using a user-provided function. It's useful for scenarios where you need to process the same data in different ways and then merge the results, such as feature extraction, multi-model predictions, or parallel transformations.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
combine_func
|
Callable[[list[Any]], U]
|
Function that combines values from all handlers into a single output |
required |
handlers
|
Handler[T, Any]
|
Variable number of handlers whose outputs will be combined |
()
|
continue_on_partial
|
bool
|
Whether to continue when some handlers are exhausted, defaults to True Example: |
True
|
Source code in pysatl_tsp/core/processor/combine_handler.py
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 | |
__init__(
combine_func: Callable[[list[Any]], U],
*handlers: Handler[T, Any],
continue_on_partial: bool = True,
)
Initialize a combine handler.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
combine_func
|
Callable[[list[Any]], U]
|
Function that combines values from all handlers into a single output |
required |
handlers
|
Handler[T, Any]
|
Variable number of handlers whose outputs will be combined |
()
|
continue_on_partial
|
bool
|
Whether to continue when some handlers are exhausted, defaults to True |
True
|
Source code in pysatl_tsp/core/processor/combine_handler.py
59 60 61 62 63 64 65 66 67 68 69 70 71 | |
__iter__() -> Iterator[U]
Create an iterator that yields combined results from multiple handlers.
This method processes the source data through each handler in parallel and combines their outputs using the combine function. If continue_on_partial is True, it will continue producing outputs even after some handlers are exhausted (using None for exhausted handlers). If False, it will stop when any handler is exhausted.
Returns:
| Type | Description |
|---|---|
Iterator[U]
|
Iterator yielding combined results |
Raises:
| Type | Description |
|---|---|
ValueError
|
If no source has been set |
Source code in pysatl_tsp/core/processor/combine_handler.py
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 | |
filter_handler
OfflineFilterHandler
Bases: Handler[T, U]
A handler that applies a filter function to the entire time series data in batch mode.
This handler collects all data from the source before applying the filter function to the complete series at once. It's suitable for implementing filters that require the entire context of the time series, such as spectral filters, Savitzky-Golay filters, or other techniques that need to process the data as a whole.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filter_func
|
Callable[[ScrubberWindow[T], Any], list[U]]
|
Function that processes the entire series and returns filtered values |
required |
filter_config
|
Any
|
Configuration parameters for the filter function, defaults to None |
None
|
source
|
Handler[Any, T] | None
|
The handler providing input data, defaults to None Example: |
None
|
Source code in pysatl_tsp/core/processor/filter_handler.py
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 | |
__init__(
filter_func: Callable[
[ScrubberWindow[T], Any], list[U]
],
filter_config: Any = None,
source: Handler[Any, T] | None = None,
)
Initialize an offline filter handler.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filter_func
|
Callable[[ScrubberWindow[T], Any], list[U]]
|
Function that processes the entire series and returns filtered values |
required |
filter_config
|
Any
|
Configuration parameters for the filter function, defaults to None |
None
|
source
|
Handler[Any, T] | None
|
The handler providing input data, defaults to None |
None
|
Source code in pysatl_tsp/core/processor/filter_handler.py
161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 | |
__iter__() -> Iterator[U]
Create an iterator that yields filtered values after processing the entire series.
This method collects all data from the source, applies the filter function to the complete series, and then yields the resulting filtered values.
Returns:
| Type | Description |
|---|---|
Iterator[U]
|
Iterator yielding filtered values |
Raises:
| Type | Description |
|---|---|
ValueError
|
If no source has been set |
Source code in pysatl_tsp/core/processor/filter_handler.py
177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 | |
OnlineFilterHandler
Bases: Handler[T, U]
A handler that applies a filter function to time series data in real-time.
This handler processes data points one by one as they arrive and applies a filter function to the accumulated history. It's suitable for implementing online filters such as moving averages, exponential smoothing, or real-time anomaly detection.
The filter function receives the current history window and configuration parameters, and produces a filtered value for each input value.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filter_func
|
Callable[[ScrubberWindow[T], Any], U]
|
Function that applies filtering on the history window |
required |
filter_config
|
Any
|
Configuration parameters for the filter function, defaults to None |
None
|
source
|
Handler[Any, T] | None
|
The handler providing input data, defaults to None Example: |
None
|
Source code in pysatl_tsp/core/processor/filter_handler.py
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 | |
__init__(
filter_func: Callable[[ScrubberWindow[T], Any], U],
filter_config: Any = None,
source: Handler[Any, T] | None = None,
)
Initialize an online filter handler.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filter_func
|
Callable[[ScrubberWindow[T], Any], U]
|
Function that applies filtering on the history window |
required |
filter_config
|
Any
|
Configuration parameters for the filter function, defaults to None |
None
|
source
|
Handler[Any, T] | None
|
The handler providing input data, defaults to None |
None
|
Source code in pysatl_tsp/core/processor/filter_handler.py
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 | |
__iter__() -> Iterator[U]
Create an iterator that yields filtered values in real-time.
This method processes data points one by one, accumulates them in a history window, and applies the filter function to produce filtered values.
Returns:
| Type | Description |
|---|---|
Iterator[U]
|
Iterator yielding filtered values |
Raises:
| Type | Description |
|---|---|
ValueError
|
If no source has been set |
Source code in pysatl_tsp/core/processor/filter_handler.py
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 | |
lag_handler
LagHandler
Bases: Handler[float | None, float | None]
A handler that applies a lag-based transformation to time series data.
This handler applies a formula (2 * current_value - lagged_value) that compares the current value with a value from 'lag' time steps in the past. For the first 'lag' values where no lagged value is available, it outputs None.
The transformation can be useful for detecting changes or trends in time series by comparing current values with historical ones.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lag
|
int
|
Number of time steps to look back for the lagged value Example: |
required |
Source code in pysatl_tsp/core/processor/lag_handler.py
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 | |
__init__(lag: int)
Initialize a lag handler.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lag
|
int
|
Number of time steps to look back for the lagged value |
required |
Source code in pysatl_tsp/core/processor/lag_handler.py
45 46 47 48 49 50 51 | |
__iter__() -> Iterator[float | None]
Create an iterator that yields transformed values based on lag comparison.
This method outputs None for the first 'lag' values, then applies the formula 2 * current_value - lagged_value for subsequent values. If either the current value or the lagged value is None, the result will be None.
Returns:
| Type | Description |
|---|---|
Iterator[float | None]
|
Iterator yielding transformed values or None |
Raises:
| Type | Description |
|---|---|
ValueError
|
If no source has been set |
Source code in pysatl_tsp/core/processor/lag_handler.py
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 | |
mapping_handler
MappingHandler
Bases: Handler[T, U]
A handler that transforms time series data by applying a mapping function to each item.
This handler applies a user-defined transformation function to each data point in the input stream, producing a new stream of transformed values. It's useful for simple point-by-point transformations such as scaling, type conversion, feature extraction, or any operation that processes one input item at a time.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
map_func
|
Callable[[T], U]
|
Function that transforms each input item to an output item |
required |
source
|
Handler[Any, T] | None
|
The handler providing input data, defaults to None Example: |
None
|
Source code in pysatl_tsp/core/processor/mapping_handler.py
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 | |
__init__(
map_func: Callable[[T], U],
source: Handler[Any, T] | None = None,
)
Initialize a mapping handler.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
map_func
|
Callable[[T], U]
|
Function that transforms each input item to an output item |
required |
source
|
Handler[Any, T] | None
|
The handler providing input data, defaults to None |
None
|
Source code in pysatl_tsp/core/processor/mapping_handler.py
75 76 77 78 79 80 81 82 | |
__iter__() -> Iterator[U]
Create an iterator that yields transformed items.
This method iterates through the source data and applies the mapping function to each item, yielding the transformed results.
Returns:
| Type | Description |
|---|---|
Iterator[U]
|
Iterator yielding transformed items |
Raises:
| Type | Description |
|---|---|
ValueError
|
If no source has been set |
Source code in pysatl_tsp/core/processor/mapping_handler.py
84 85 86 87 88 89 90 91 92 93 94 95 96 97 | |
sampling_handler
OfflineSamplingHandler
Bases: Handler[T, T]
A handler that samples time series data in batch mode based on identified indices.
This handler processes the entire dataset to identify sampling points before extracting the samples. It's suitable for global sampling strategies that consider the entire time series context, such as selecting representative points or key points that preserve the overall shape of the data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sampling_rule
|
Callable[[ScrubberWindow[T]], list[int]]
|
Function that analyzes the entire series and returns indices of points to sample |
required |
source
|
Handler[Any, T] | None
|
The handler providing input data, defaults to None Example: |
None
|
Source code in pysatl_tsp/core/processor/sampling_handler.py
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 | |
__init__(
sampling_rule: Callable[[ScrubberWindow[T]], list[int]],
source: Handler[Any, T] | None = None,
)
Initialize an offline sampling handler.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sampling_rule
|
Callable[[ScrubberWindow[T]], list[int]]
|
Function that analyzes the entire series and returns indices of points to sample |
required |
source
|
Handler[Any, T] | None
|
The handler providing input data, defaults to None |
None
|
Source code in pysatl_tsp/core/processor/sampling_handler.py
158 159 160 161 162 163 164 165 | |
__iter__() -> Iterator[T]
Create an iterator that yields sampled values based on the indices identified by the sampling rule.
This method uses OfflineSegmentationScrubber to segment the data at the specified indices and a MappingHandler to extract the last item from each segment.
Returns:
| Type | Description |
|---|---|
Iterator[T]
|
Iterator yielding sampled values |
Raises:
| Type | Description |
|---|---|
ValueError
|
If no source has been set (propagated from segmentation scrubber) |
Source code in pysatl_tsp/core/processor/sampling_handler.py
167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 | |
OnlineSamplingHandler
Bases: Handler[T, T]
A handler that samples time series data in real-time based on a condition.
This handler uses segmentation to identify points where sampling should occur and extracts the last item from each segment. It processes data in real-time and is suitable for adaptive sampling strategies, where sampling decisions are made based on the recent history of the time series.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sampling_rule
|
Callable[[ScrubberWindow[T]], bool]
|
Function that decides when to take a sample |
required |
source
|
Handler[Any, T] | None
|
The handler providing input data, defaults to None Example: |
None
|
Source code in pysatl_tsp/core/processor/sampling_handler.py
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 | |
__init__(
sampling_rule: Callable[[ScrubberWindow[T]], bool],
source: Handler[Any, T] | None = None,
)
Initialize an online sampling handler.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sampling_rule
|
Callable[[ScrubberWindow[T]], bool]
|
Function that decides when to take a sample |
required |
source
|
Handler[Any, T] | None
|
The handler providing input data, defaults to None |
None
|
Source code in pysatl_tsp/core/processor/sampling_handler.py
58 59 60 61 62 63 64 65 | |
__iter__() -> Iterator[T]
Create an iterator that yields sampled values based on the sampling rule.
This method uses OnlineSegmentationScrubber to segment the data and a MappingHandler to extract the last item from each segment.
Returns:
| Type | Description |
|---|---|
Iterator[T]
|
Iterator yielding sampled values |
Raises:
| Type | Description |
|---|---|
ValueError
|
If no source has been set (propagated from segmentation scrubber) |
Source code in pysatl_tsp/core/processor/sampling_handler.py
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 | |
tee_handler
TeeHandler
Bases: Handler[T, U]
A handler that processes data through two parallel paths and combines the results.
This handler takes input data from a source, sends it through both the original path and a processing path simultaneously, and then combines each pair of outputs using a provided function. It's useful for operations where you need to preserve the original data while also using a transformed version of it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
processor
|
Handler[T, S]
|
Handler that processes the tee'd data stream |
required |
combine_func
|
Callable[[T, S], U]
|
Function that combines original and processed values Example: |
required |
Source code in pysatl_tsp/core/processor/tee_handler.py
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 | |
__init__(
processor: Handler[T, S],
combine_func: Callable[[T, S], U],
)
Initialize a tee handler.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
processor
|
Handler[T, S]
|
Handler that processes the tee'd data stream |
required |
combine_func
|
Callable[[T, S], U]
|
Function that combines original and processed values |
required |
Source code in pysatl_tsp/core/processor/tee_handler.py
53 54 55 56 57 58 59 60 61 | |
__iter__() -> Iterator[U]
Create an iterator that yields combined results from original and processed data.
This method creates two identical iterators from the source, processes one through the processor, and then combines corresponding items from both streams using the combine function.
Returns:
| Type | Description |
|---|---|
Iterator[U]
|
Iterator yielding combined results |
Raises:
| Type | Description |
|---|---|
ValueError
|
If no source has been set |
Source code in pysatl_tsp/core/processor/tee_handler.py
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 | |
scrubber
This module provides various scrubber implementations for handling and processing data streams.
LinearScrubber
Bases: SlidingScrubber[T]
A scrubber that creates fixed-size sliding windows with configurable overlap.
This is a specialized sliding scrubber that emits windows of a fixed size and allows controlling the overlap between consecutive windows through a shift factor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
window_length
|
int
|
Number of points in each window, defaults to 100 |
100
|
shift_factor
|
float
|
Fraction of window to shift after each emission, defaults to 1/3 (e.g., 0.5 means 50% overlap between consecutive windows) |
1.0 / 3.0
|
source
|
Handler[Any, T] | None
|
The handler providing input data, defaults to None Example: |
None
|
Source code in pysatl_tsp/core/scrubber/linear_scrubber.py
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 | |
__init__
__init__(
window_length: int = 100,
shift_factor: float = 1.0 / 3.0,
source: Handler[Any, T] | None = None,
) -> None
Initialize a linear scrubber with fixed window size and overlap.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
window_length
|
int
|
Number of points in each window, defaults to 100 |
100
|
shift_factor
|
float
|
Fraction of window to shift after each emission, defaults to 1/3 |
1.0 / 3.0
|
source
|
Handler[Any, T] | None
|
The handler providing input data, defaults to None |
None
|
Source code in pysatl_tsp/core/scrubber/linear_scrubber.py
117 118 119 120 121 122 123 124 125 126 127 | |
OfflineSegmentationScrubber
Bases: Scrubber[T]
A scrubber that segments time series data based on changepoints in batch mode.
This scrubber processes the entire input data in a batch (offline) mode and segments it according to a provided segmentation rule. The rule identifies changepoints in the data, which are then used to create non-overlapping segments.
This approach is suitable for scenarios where the entire dataset is available upfront and the segmentation logic requires global context or multiple passes over the data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
segmentation_rule
|
Callable[[ScrubberWindow[T]], list[int]]
|
Function that analyzes the complete series and returns a list of changepoint indices |
required |
source
|
Handler[Any, T] | None
|
The handler providing input data, defaults to None Example: |
None
|
Source code in pysatl_tsp/core/scrubber/segmentation_scrubber.py
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 | |
__init__
__init__(
segmentation_rule: Callable[
[ScrubberWindow[T]], list[int]
],
source: Handler[Any, T] | None = None,
)
Initialize an offline segmentation scrubber.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
segmentation_rule
|
Callable[[ScrubberWindow[T]], list[int]]
|
Function that analyzes the complete series and returns a list of changepoint indices |
required |
source
|
Handler[Any, T] | None
|
The handler providing input data, defaults to None |
None
|
Source code in pysatl_tsp/core/scrubber/segmentation_scrubber.py
55 56 57 58 59 60 61 62 63 64 | |
__iter__
__iter__() -> Iterator[ScrubberWindow[T]]
Create an iterator that yields segments based on detected changepoints.
This method collects all data from the source, applies the segmentation rule to identify changepoints, and then yields segments between the detected changepoints.
Returns:
| Type | Description |
|---|---|
Iterator[ScrubberWindow[T]]
|
Iterator yielding ScrubberWindow instances for each segment |
Raises:
| Type | Description |
|---|---|
ValueError
|
If no source has been set |
Source code in pysatl_tsp/core/scrubber/segmentation_scrubber.py
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 | |
OnlineSegmentationScrubber
Bases: Scrubber[T]
A scrubber that segments time series data in real-time based on a condition.
This scrubber processes data points sequentially (online mode) and segments the time series whenever a specified condition is met or a maximum segment size is reached. It's designed for streaming data where segments need to be identified in real-time without waiting for the complete dataset.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
segmentation_rule
|
Callable[[ScrubberWindow[T]], bool]
|
Function that evaluates the current window and returns True when a segment should end |
required |
max_segment_size
|
int
|
Maximum number of points in a segment before forcing a split, defaults to 2^64 |
2 ** 64
|
source
|
Handler[Any, T] | None
|
The handler providing input data, defaults to None Example: |
None
|
Source code in pysatl_tsp/core/scrubber/segmentation_scrubber.py
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 | |
__init__
__init__(
segmentation_rule: Callable[[ScrubberWindow[T]], bool],
max_segment_size: int = 2**64,
source: Handler[Any, T] | None = None,
)
Initialize an online segmentation scrubber.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
segmentation_rule
|
Callable[[ScrubberWindow[T]], bool]
|
Function that evaluates the current window and returns True when a segment should end |
required |
max_segment_size
|
int
|
Maximum number of points in a segment before forcing a split, defaults to 2^64 |
2 ** 64
|
source
|
Handler[Any, T] | None
|
The handler providing input data, defaults to None |
None
|
Source code in pysatl_tsp/core/scrubber/segmentation_scrubber.py
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 | |
__iter__
__iter__() -> Iterator[ScrubberWindow[T]]
Create an iterator that yields segments as they're detected in real-time.
This method processes data points one by one, accumulating them in a buffer and checking after each addition whether the segmentation condition is met or the maximum segment size is reached.
Returns:
| Type | Description |
|---|---|
Iterator[ScrubberWindow[T]]
|
Iterator yielding ScrubberWindow instances for each detected segment |
Raises:
| Type | Description |
|---|---|
ValueError
|
If no source has been set |
Source code in pysatl_tsp/core/scrubber/segmentation_scrubber.py
152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 | |
Scrubber
Bases: Handler[T, ScrubberWindow[T]]
Abstract base class for handlers that produce window views of time series data.
Scrubbers consume individual data points and produce windows (sections) of the data stream. They are essential components for algorithms that need to analyze multiple data points together, such as moving averages, pattern detection, or feature extraction.
Concrete implementations of this class define specific windowing strategies such as fixed-size sliding windows, tumbling windows, or context-based windows.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
Handler[Any, T] | None
|
The handler providing input data, defaults to None Example: |
None
|
Source code in pysatl_tsp/core/scrubber/abstract.py
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 | |
__init__
__init__(source: Handler[Any, T] | None = None) -> None
Initialize a scrubber.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
Handler[Any, T] | None
|
The handler providing input data, defaults to None |
None
|
Source code in pysatl_tsp/core/scrubber/abstract.py
221 222 223 224 225 226 | |
__iter__
abstractmethod
__iter__() -> Iterator[ScrubberWindow[T]]
Create an iterator that yields window views of the input data.
Concrete implementations define specific windowing strategies.
Returns:
| Type | Description |
|---|---|
Iterator[ScrubberWindow[T]]
|
Iterator yielding ScrubberWindow instances |
Source code in pysatl_tsp/core/scrubber/abstract.py
228 229 230 231 232 233 234 235 236 | |
ScrubberWindow
Bases: Generic[T]
A sliding window container for time series data processing.
ScrubberWindow provides a specialized container for holding a window of time series data values along with their corresponding indices. It's optimized for efficient append and remove operations at the ends of the window, making it suitable for sliding window algorithms in time series processing.
This class manages two parallel deques: one for the actual data values and another for their corresponding indices or positions in the original data stream.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
values
|
deque[T] | None
|
Deque containing the data values, defaults to None (empty deque) |
None
|
indices
|
deque[int] | None
|
Deque containing the indices corresponding to values, defaults to None (if not provided, sequential indices starting from 0 are used) |
None
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If the lengths of values and indices don't match Example: |
Source code in pysatl_tsp/core/scrubber/abstract.py
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 | |
__eq__
__eq__(other: object) -> bool
Check if this window equals another window.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
other
|
object
|
Another object to compare with |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if other is a ScrubberWindow with equal values and indices |
Source code in pysatl_tsp/core/scrubber/abstract.py
143 144 145 146 147 148 149 150 151 | |
__getitem__
__getitem__(key: int) -> T
__getitem__(key: slice) -> ScrubberWindow[T]
__getitem__(key: int | slice) -> T | ScrubberWindow[T]
Get a value or sub-window by index or slice.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
int | slice
|
Integer index or slice to retrieve |
required |
Returns:
| Type | Description |
|---|---|
T | ScrubberWindow[T]
|
Single value (if key is int) or sub-window (if key is slice) |
Raises:
| Type | Description |
|---|---|
TypeError
|
If key is not an int or slice |
Source code in pysatl_tsp/core/scrubber/abstract.py
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 | |
__hash__
__hash__() -> int
Get window's hash code.
Returns:
| Type | Description |
|---|---|
int
|
The hash value of the object |
Source code in pysatl_tsp/core/scrubber/abstract.py
153 154 155 156 157 158 | |
__init__
__init__(
values: deque[T] | None = None,
indices: deque[int] | None = None,
) -> None
Initialize a scrubber window.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
values
|
deque[T] | None
|
Deque containing the data values, defaults to None (empty deque) |
None
|
indices
|
deque[int] | None
|
Deque containing the indices corresponding to values, defaults to None (if not provided, sequential indices starting from 0 are used) |
None
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If the lengths of values and indices don't match |
Source code in pysatl_tsp/core/scrubber/abstract.py
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 | |
__iter__
__iter__() -> Iterator[T]
Create an iterator over the values in the window.
Returns:
| Type | Description |
|---|---|
Iterator[T]
|
Iterator yielding window values |
Source code in pysatl_tsp/core/scrubber/abstract.py
167 168 169 170 171 172 | |
__len__
__len__() -> int
Get the number of values in the window.
Returns:
| Type | Description |
|---|---|
int
|
The window size |
Source code in pysatl_tsp/core/scrubber/abstract.py
136 137 138 139 140 141 | |
__repr__
__repr__() -> str
Get a string representation of the window.
Returns:
| Type | Description |
|---|---|
str
|
String representation showing values and indices |
Source code in pysatl_tsp/core/scrubber/abstract.py
160 161 162 163 164 165 | |
append
append(value: T, index: int | None = None) -> None
Add a new value to the end of the window.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
T
|
The data value to append |
required |
index
|
int | None
|
The index/position of the value in the original data stream, defaults to None (auto-assigned as len(self)) |
None
|
Source code in pysatl_tsp/core/scrubber/abstract.py
76 77 78 79 80 81 82 83 84 85 86 | |
clear
clear() -> None
Remove all values from the window.
Source code in pysatl_tsp/core/scrubber/abstract.py
93 94 95 96 | |
copy
copy() -> ScrubberWindow[T]
Create a deep copy of the window.
Returns:
| Type | Description |
|---|---|
ScrubberWindow[T]
|
A new ScrubberWindow with copies of the values and indices |
Source code in pysatl_tsp/core/scrubber/abstract.py
98 99 100 101 102 103 | |
popleft
popleft() -> None
Remove the oldest (leftmost) value from the window.
Source code in pysatl_tsp/core/scrubber/abstract.py
88 89 90 91 | |
SlidingScrubber
Bases: Scrubber[T]
A flexible scrubber that creates sliding windows of time series data based on custom conditions.
This scrubber allows defining custom conditions for when to emit a window and how far to slide the window after each emission. It accumulates data points in a buffer and yields the current window whenever the take condition evaluates to True.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
take_condition
|
Callable[[ScrubberWindow[T]], bool]
|
Function that determines when to emit the current window |
required |
shift
|
int
|
Number of points to shift the window after each emission |
required |
source
|
Handler[Any, T] | None
|
The handler providing input data, defaults to None Example: |
None
|
Source code in pysatl_tsp/core/scrubber/linear_scrubber.py
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 | |
__init__
__init__(
take_condition: Callable[[ScrubberWindow[T]], bool],
shift: int,
source: Handler[Any, T] | None = None,
) -> None
Initialize a sliding scrubber with custom condition and shift.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
take_condition
|
Callable[[ScrubberWindow[T]], bool]
|
Function that determines when to emit the current window |
required |
shift
|
int
|
Number of points to shift the window after each emission |
required |
source
|
Handler[Any, T] | None
|
The handler providing input data, defaults to None |
None
|
Source code in pysatl_tsp/core/scrubber/linear_scrubber.py
49 50 51 52 53 54 55 56 57 58 59 60 61 | |
__iter__
__iter__() -> Iterator[ScrubberWindow[T]]
Create an iterator that yields windows based on the take condition.
This method accumulates data points in a buffer and yields the current window whenever the take condition evaluates to True. After yielding, it shifts the window by the specified number of points.
Returns:
| Type | Description |
|---|---|
Iterator[ScrubberWindow[T]]
|
Iterator yielding ScrubberWindow instances |
Raises:
| Type | Description |
|---|---|
ValueError
|
If no source has been set |
Source code in pysatl_tsp/core/scrubber/linear_scrubber.py
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 | |
abstract
Scrubber
Bases: Handler[T, ScrubberWindow[T]]
Abstract base class for handlers that produce window views of time series data.
Scrubbers consume individual data points and produce windows (sections) of the data stream. They are essential components for algorithms that need to analyze multiple data points together, such as moving averages, pattern detection, or feature extraction.
Concrete implementations of this class define specific windowing strategies such as fixed-size sliding windows, tumbling windows, or context-based windows.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
Handler[Any, T] | None
|
The handler providing input data, defaults to None Example: |
None
|
Source code in pysatl_tsp/core/scrubber/abstract.py
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 | |
__init__(source: Handler[Any, T] | None = None) -> None
Initialize a scrubber.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
Handler[Any, T] | None
|
The handler providing input data, defaults to None |
None
|
Source code in pysatl_tsp/core/scrubber/abstract.py
221 222 223 224 225 226 | |
abstractmethod
__iter__() -> Iterator[ScrubberWindow[T]]
Create an iterator that yields window views of the input data.
Concrete implementations define specific windowing strategies.
Returns:
| Type | Description |
|---|---|
Iterator[ScrubberWindow[T]]
|
Iterator yielding ScrubberWindow instances |
Source code in pysatl_tsp/core/scrubber/abstract.py
228 229 230 231 232 233 234 235 236 | |
ScrubberWindow
Bases: Generic[T]
A sliding window container for time series data processing.
ScrubberWindow provides a specialized container for holding a window of time series data values along with their corresponding indices. It's optimized for efficient append and remove operations at the ends of the window, making it suitable for sliding window algorithms in time series processing.
This class manages two parallel deques: one for the actual data values and another for their corresponding indices or positions in the original data stream.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
values
|
deque[T] | None
|
Deque containing the data values, defaults to None (empty deque) |
None
|
indices
|
deque[int] | None
|
Deque containing the indices corresponding to values, defaults to None (if not provided, sequential indices starting from 0 are used) |
None
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If the lengths of values and indices don't match Example: |
Source code in pysatl_tsp/core/scrubber/abstract.py
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 | |
__eq__(other: object) -> bool
Check if this window equals another window.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
other
|
object
|
Another object to compare with |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if other is a ScrubberWindow with equal values and indices |
Source code in pysatl_tsp/core/scrubber/abstract.py
143 144 145 146 147 148 149 150 151 | |
__getitem__(key: int) -> T
__getitem__(key: slice) -> ScrubberWindow[T]
__getitem__(key: int | slice) -> T | ScrubberWindow[T]
Get a value or sub-window by index or slice.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
int | slice
|
Integer index or slice to retrieve |
required |
Returns:
| Type | Description |
|---|---|
T | ScrubberWindow[T]
|
Single value (if key is int) or sub-window (if key is slice) |
Raises:
| Type | Description |
|---|---|
TypeError
|
If key is not an int or slice |
Source code in pysatl_tsp/core/scrubber/abstract.py
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 | |
__hash__() -> int
Get window's hash code.
Returns:
| Type | Description |
|---|---|
int
|
The hash value of the object |
Source code in pysatl_tsp/core/scrubber/abstract.py
153 154 155 156 157 158 | |
__init__(
values: deque[T] | None = None,
indices: deque[int] | None = None,
) -> None
Initialize a scrubber window.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
values
|
deque[T] | None
|
Deque containing the data values, defaults to None (empty deque) |
None
|
indices
|
deque[int] | None
|
Deque containing the indices corresponding to values, defaults to None (if not provided, sequential indices starting from 0 are used) |
None
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If the lengths of values and indices don't match |
Source code in pysatl_tsp/core/scrubber/abstract.py
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 | |
__iter__() -> Iterator[T]
Create an iterator over the values in the window.
Returns:
| Type | Description |
|---|---|
Iterator[T]
|
Iterator yielding window values |
Source code in pysatl_tsp/core/scrubber/abstract.py
167 168 169 170 171 172 | |
__len__() -> int
Get the number of values in the window.
Returns:
| Type | Description |
|---|---|
int
|
The window size |
Source code in pysatl_tsp/core/scrubber/abstract.py
136 137 138 139 140 141 | |
__repr__() -> str
Get a string representation of the window.
Returns:
| Type | Description |
|---|---|
str
|
String representation showing values and indices |
Source code in pysatl_tsp/core/scrubber/abstract.py
160 161 162 163 164 165 | |
append(value: T, index: int | None = None) -> None
Add a new value to the end of the window.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
T
|
The data value to append |
required |
index
|
int | None
|
The index/position of the value in the original data stream, defaults to None (auto-assigned as len(self)) |
None
|
Source code in pysatl_tsp/core/scrubber/abstract.py
76 77 78 79 80 81 82 83 84 85 86 | |
clear() -> None
Remove all values from the window.
Source code in pysatl_tsp/core/scrubber/abstract.py
93 94 95 96 | |
copy() -> ScrubberWindow[T]
Create a deep copy of the window.
Returns:
| Type | Description |
|---|---|
ScrubberWindow[T]
|
A new ScrubberWindow with copies of the values and indices |
Source code in pysatl_tsp/core/scrubber/abstract.py
98 99 100 101 102 103 | |
popleft() -> None
Remove the oldest (leftmost) value from the window.
Source code in pysatl_tsp/core/scrubber/abstract.py
88 89 90 91 | |
linear_scrubber
LinearScrubber
Bases: SlidingScrubber[T]
A scrubber that creates fixed-size sliding windows with configurable overlap.
This is a specialized sliding scrubber that emits windows of a fixed size and allows controlling the overlap between consecutive windows through a shift factor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
window_length
|
int
|
Number of points in each window, defaults to 100 |
100
|
shift_factor
|
float
|
Fraction of window to shift after each emission, defaults to 1/3 (e.g., 0.5 means 50% overlap between consecutive windows) |
1.0 / 3.0
|
source
|
Handler[Any, T] | None
|
The handler providing input data, defaults to None Example: |
None
|
Source code in pysatl_tsp/core/scrubber/linear_scrubber.py
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 | |
__init__(
window_length: int = 100,
shift_factor: float = 1.0 / 3.0,
source: Handler[Any, T] | None = None,
) -> None
Initialize a linear scrubber with fixed window size and overlap.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
window_length
|
int
|
Number of points in each window, defaults to 100 |
100
|
shift_factor
|
float
|
Fraction of window to shift after each emission, defaults to 1/3 |
1.0 / 3.0
|
source
|
Handler[Any, T] | None
|
The handler providing input data, defaults to None |
None
|
Source code in pysatl_tsp/core/scrubber/linear_scrubber.py
117 118 119 120 121 122 123 124 125 126 127 | |
SlidingScrubber
Bases: Scrubber[T]
A flexible scrubber that creates sliding windows of time series data based on custom conditions.
This scrubber allows defining custom conditions for when to emit a window and how far to slide the window after each emission. It accumulates data points in a buffer and yields the current window whenever the take condition evaluates to True.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
take_condition
|
Callable[[ScrubberWindow[T]], bool]
|
Function that determines when to emit the current window |
required |
shift
|
int
|
Number of points to shift the window after each emission |
required |
source
|
Handler[Any, T] | None
|
The handler providing input data, defaults to None Example: |
None
|
Source code in pysatl_tsp/core/scrubber/linear_scrubber.py
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 | |
__init__(
take_condition: Callable[[ScrubberWindow[T]], bool],
shift: int,
source: Handler[Any, T] | None = None,
) -> None
Initialize a sliding scrubber with custom condition and shift.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
take_condition
|
Callable[[ScrubberWindow[T]], bool]
|
Function that determines when to emit the current window |
required |
shift
|
int
|
Number of points to shift the window after each emission |
required |
source
|
Handler[Any, T] | None
|
The handler providing input data, defaults to None |
None
|
Source code in pysatl_tsp/core/scrubber/linear_scrubber.py
49 50 51 52 53 54 55 56 57 58 59 60 61 | |
__iter__() -> Iterator[ScrubberWindow[T]]
Create an iterator that yields windows based on the take condition.
This method accumulates data points in a buffer and yields the current window whenever the take condition evaluates to True. After yielding, it shifts the window by the specified number of points.
Returns:
| Type | Description |
|---|---|
Iterator[ScrubberWindow[T]]
|
Iterator yielding ScrubberWindow instances |
Raises:
| Type | Description |
|---|---|
ValueError
|
If no source has been set |
Source code in pysatl_tsp/core/scrubber/linear_scrubber.py
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 | |
segmentation_scrubber
OfflineSegmentationScrubber
Bases: Scrubber[T]
A scrubber that segments time series data based on changepoints in batch mode.
This scrubber processes the entire input data in a batch (offline) mode and segments it according to a provided segmentation rule. The rule identifies changepoints in the data, which are then used to create non-overlapping segments.
This approach is suitable for scenarios where the entire dataset is available upfront and the segmentation logic requires global context or multiple passes over the data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
segmentation_rule
|
Callable[[ScrubberWindow[T]], list[int]]
|
Function that analyzes the complete series and returns a list of changepoint indices |
required |
source
|
Handler[Any, T] | None
|
The handler providing input data, defaults to None Example: |
None
|
Source code in pysatl_tsp/core/scrubber/segmentation_scrubber.py
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 | |
__init__(
segmentation_rule: Callable[
[ScrubberWindow[T]], list[int]
],
source: Handler[Any, T] | None = None,
)
Initialize an offline segmentation scrubber.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
segmentation_rule
|
Callable[[ScrubberWindow[T]], list[int]]
|
Function that analyzes the complete series and returns a list of changepoint indices |
required |
source
|
Handler[Any, T] | None
|
The handler providing input data, defaults to None |
None
|
Source code in pysatl_tsp/core/scrubber/segmentation_scrubber.py
55 56 57 58 59 60 61 62 63 64 | |
__iter__() -> Iterator[ScrubberWindow[T]]
Create an iterator that yields segments based on detected changepoints.
This method collects all data from the source, applies the segmentation rule to identify changepoints, and then yields segments between the detected changepoints.
Returns:
| Type | Description |
|---|---|
Iterator[ScrubberWindow[T]]
|
Iterator yielding ScrubberWindow instances for each segment |
Raises:
| Type | Description |
|---|---|
ValueError
|
If no source has been set |
Source code in pysatl_tsp/core/scrubber/segmentation_scrubber.py
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 | |
OnlineSegmentationScrubber
Bases: Scrubber[T]
A scrubber that segments time series data in real-time based on a condition.
This scrubber processes data points sequentially (online mode) and segments the time series whenever a specified condition is met or a maximum segment size is reached. It's designed for streaming data where segments need to be identified in real-time without waiting for the complete dataset.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
segmentation_rule
|
Callable[[ScrubberWindow[T]], bool]
|
Function that evaluates the current window and returns True when a segment should end |
required |
max_segment_size
|
int
|
Maximum number of points in a segment before forcing a split, defaults to 2^64 |
2 ** 64
|
source
|
Handler[Any, T] | None
|
The handler providing input data, defaults to None Example: |
None
|
Source code in pysatl_tsp/core/scrubber/segmentation_scrubber.py
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 | |
__init__(
segmentation_rule: Callable[[ScrubberWindow[T]], bool],
max_segment_size: int = 2**64,
source: Handler[Any, T] | None = None,
)
Initialize an online segmentation scrubber.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
segmentation_rule
|
Callable[[ScrubberWindow[T]], bool]
|
Function that evaluates the current window and returns True when a segment should end |
required |
max_segment_size
|
int
|
Maximum number of points in a segment before forcing a split, defaults to 2^64 |
2 ** 64
|
source
|
Handler[Any, T] | None
|
The handler providing input data, defaults to None |
None
|
Source code in pysatl_tsp/core/scrubber/segmentation_scrubber.py
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 | |
__iter__() -> Iterator[ScrubberWindow[T]]
Create an iterator that yields segments as they're detected in real-time.
This method processes data points one by one, accumulating them in a buffer and checking after each addition whether the segmentation condition is met or the maximum segment size is reached.
Returns:
| Type | Description |
|---|---|
Iterator[ScrubberWindow[T]]
|
Iterator yielding ScrubberWindow instances for each detected segment |
Raises:
| Type | Description |
|---|---|
ValueError
|
If no source has been set |
Source code in pysatl_tsp/core/scrubber/segmentation_scrubber.py
152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 | |
implementations
This module provides implementations of time series processing techniques.
KalmanFilterHandler
Bases: OnlineFilterHandler[float, float]
A handler that applies the Kalman filter to time series data in real-time.
This handler integrates the complete Kalman filter functionality for processing noisy time series data. It estimates the underlying state of a system based on a sequence of noisy measurements.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
F
|
ndarray[Any, dtype[float64]]
|
State transition matrix |
required |
H
|
ndarray[Any, dtype[float64]]
|
Measurement matrix |
required |
B
|
Union[float, ndarray[Any, dtype[float64]]] | None
|
Control input matrix, defaults to 0 |
None
|
Q
|
ndarray[Any, dtype[float64]] | None
|
Process noise covariance matrix, defaults to identity matrix |
None
|
R
|
ndarray[Any, dtype[float64]] | None
|
Measurement noise covariance matrix, defaults to identity matrix |
None
|
P
|
ndarray[Any, dtype[float64]] | None
|
Initial state covariance matrix, defaults to identity matrix |
None
|
x0
|
ndarray[Any, dtype[float64]] | None
|
Initial state vector, defaults to zero vector |
None
|
source
|
Handler[Any, float] | None
|
The handler providing input data, defaults to None Example: |
None
|
Source code in pysatl_tsp/implementations/processor/kalman_filter_handler.py
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 | |
__init__
__init__(
F: ndarray[Any, dtype[float64]],
H: ndarray[Any, dtype[float64]],
B: Union[float, ndarray[Any, dtype[float64]]]
| None = None,
Q: ndarray[Any, dtype[float64]] | None = None,
R: ndarray[Any, dtype[float64]] | None = None,
P: ndarray[Any, dtype[float64]] | None = None,
x0: ndarray[Any, dtype[float64]] | None = None,
source: Handler[Any, float] | None = None,
) -> None
Initialize the Kalman filter handler with all necessary matrices.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
F
|
ndarray[Any, dtype[float64]]
|
State transition matrix |
required |
H
|
ndarray[Any, dtype[float64]]
|
Measurement matrix |
required |
B
|
Union[float, ndarray[Any, dtype[float64]]] | None
|
Control input matrix, defaults to None |
None
|
Q
|
ndarray[Any, dtype[float64]] | None
|
Process noise covariance matrix, defaults to None |
None
|
R
|
ndarray[Any, dtype[float64]] | None
|
Measurement noise covariance matrix, defaults to None |
None
|
P
|
ndarray[Any, dtype[float64]] | None
|
Initial state covariance matrix, defaults to None |
None
|
x0
|
ndarray[Any, dtype[float64]] | None
|
Initial state vector, defaults to None |
None
|
source
|
Handler[Any, float] | None
|
The handler providing input data, defaults to None |
None
|
Source code in pysatl_tsp/implementations/processor/kalman_filter_handler.py
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 | |
predict
predict(
u: Union[float, ndarray[Any, dtype[float64]]] = 0,
) -> np.ndarray[Any, np.dtype[np.float64]]
Predict the next state based on the model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
u
|
Union[float, ndarray[Any, dtype[float64]]]
|
Control input, defaults to 0 |
0
|
Returns:
| Type | Description |
|---|---|
ndarray[Any, dtype[float64]]
|
Predicted state vector |
Source code in pysatl_tsp/implementations/processor/kalman_filter_handler.py
97 98 99 100 101 102 103 104 105 106 107 108 109 | |
update
update(z: float) -> None
Update the state estimate based on the measurement.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
z
|
float
|
Measurement |
required |
Source code in pysatl_tsp/implementations/processor/kalman_filter_handler.py
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 | |
TimeSeriesCrossValidator
Bases: Handler[T, tuple[ScrubberWindow[T], ScrubberWindow[T]]]
A handler that implements expanding window cross-validation for time series data.
This handler produces a sequence of train-validation splits suitable for time series validation, where each split preserves the temporal order of data. It implements an expanding window approach, where the training set grows over time while the validation set has a fixed size and slides forward.
The handler ensures that:
1. The training set always has at least min_train_size points
2. The validation set always has exactly val_size points
3. The validation set always follows the training set temporally
4. Each new split adds val_size points to the training set
This approach respects the temporal nature of time series data and prevents data leakage from future to past.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
min_train_size
|
int
|
Minimum number of points in the initial training set |
required |
val_size
|
int
|
Number of points in each validation set |
required |
source
|
Optional[Handler[Any, T]]
|
The handler providing input data, defaults to None Example: |
None
|
Source code in pysatl_tsp/implementations/processor/time_series_cross_validator.py
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 | |
__init__
__init__(
min_train_size: int,
val_size: int,
source: Optional[Handler[Any, T]] = None,
)
Initialize a time series cross-validator.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
min_train_size
|
int
|
Minimum number of points in the initial training set |
required |
val_size
|
int
|
Number of points in each validation set |
required |
source
|
Optional[Handler[Any, T]]
|
The handler providing input data, defaults to None |
None
|
Source code in pysatl_tsp/implementations/processor/time_series_cross_validator.py
110 111 112 113 114 115 116 117 118 119 | |
__iter__
__iter__() -> Iterator[
tuple[ScrubberWindow[T], ScrubberWindow[T]]
]
Create an iterator that yields train-validation splits for time series cross-validation.
This method creates splits where: 1. The first split has exactly min_train_size points for training 2. Each subsequent split adds val_size points to the training set 3. Each validation set has exactly val_size points and follows the training set
Returns:
| Type | Description |
|---|---|
Iterator[tuple[ScrubberWindow[T], ScrubberWindow[T]]]
|
Iterator yielding tuples of (training_window, validation_window) |
Raises:
| Type | Description |
|---|---|
ValueError
|
If no source has been set |
Source code in pysatl_tsp/implementations/processor/time_series_cross_validator.py
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 | |
processor
Module for time series processing implementations.
KalmanFilterHandler
Bases: OnlineFilterHandler[float, float]
A handler that applies the Kalman filter to time series data in real-time.
This handler integrates the complete Kalman filter functionality for processing noisy time series data. It estimates the underlying state of a system based on a sequence of noisy measurements.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
F
|
ndarray[Any, dtype[float64]]
|
State transition matrix |
required |
H
|
ndarray[Any, dtype[float64]]
|
Measurement matrix |
required |
B
|
Union[float, ndarray[Any, dtype[float64]]] | None
|
Control input matrix, defaults to 0 |
None
|
Q
|
ndarray[Any, dtype[float64]] | None
|
Process noise covariance matrix, defaults to identity matrix |
None
|
R
|
ndarray[Any, dtype[float64]] | None
|
Measurement noise covariance matrix, defaults to identity matrix |
None
|
P
|
ndarray[Any, dtype[float64]] | None
|
Initial state covariance matrix, defaults to identity matrix |
None
|
x0
|
ndarray[Any, dtype[float64]] | None
|
Initial state vector, defaults to zero vector |
None
|
source
|
Handler[Any, float] | None
|
The handler providing input data, defaults to None Example: |
None
|
Source code in pysatl_tsp/implementations/processor/kalman_filter_handler.py
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 | |
__init__
__init__(
F: ndarray[Any, dtype[float64]],
H: ndarray[Any, dtype[float64]],
B: Union[float, ndarray[Any, dtype[float64]]]
| None = None,
Q: ndarray[Any, dtype[float64]] | None = None,
R: ndarray[Any, dtype[float64]] | None = None,
P: ndarray[Any, dtype[float64]] | None = None,
x0: ndarray[Any, dtype[float64]] | None = None,
source: Handler[Any, float] | None = None,
) -> None
Initialize the Kalman filter handler with all necessary matrices.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
F
|
ndarray[Any, dtype[float64]]
|
State transition matrix |
required |
H
|
ndarray[Any, dtype[float64]]
|
Measurement matrix |
required |
B
|
Union[float, ndarray[Any, dtype[float64]]] | None
|
Control input matrix, defaults to None |
None
|
Q
|
ndarray[Any, dtype[float64]] | None
|
Process noise covariance matrix, defaults to None |
None
|
R
|
ndarray[Any, dtype[float64]] | None
|
Measurement noise covariance matrix, defaults to None |
None
|
P
|
ndarray[Any, dtype[float64]] | None
|
Initial state covariance matrix, defaults to None |
None
|
x0
|
ndarray[Any, dtype[float64]] | None
|
Initial state vector, defaults to None |
None
|
source
|
Handler[Any, float] | None
|
The handler providing input data, defaults to None |
None
|
Source code in pysatl_tsp/implementations/processor/kalman_filter_handler.py
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 | |
predict
predict(
u: Union[float, ndarray[Any, dtype[float64]]] = 0,
) -> np.ndarray[Any, np.dtype[np.float64]]
Predict the next state based on the model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
u
|
Union[float, ndarray[Any, dtype[float64]]]
|
Control input, defaults to 0 |
0
|
Returns:
| Type | Description |
|---|---|
ndarray[Any, dtype[float64]]
|
Predicted state vector |
Source code in pysatl_tsp/implementations/processor/kalman_filter_handler.py
97 98 99 100 101 102 103 104 105 106 107 108 109 | |
update
update(z: float) -> None
Update the state estimate based on the measurement.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
z
|
float
|
Measurement |
required |
Source code in pysatl_tsp/implementations/processor/kalman_filter_handler.py
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 | |
TimeSeriesCrossValidator
Bases: Handler[T, tuple[ScrubberWindow[T], ScrubberWindow[T]]]
A handler that implements expanding window cross-validation for time series data.
This handler produces a sequence of train-validation splits suitable for time series validation, where each split preserves the temporal order of data. It implements an expanding window approach, where the training set grows over time while the validation set has a fixed size and slides forward.
The handler ensures that:
1. The training set always has at least min_train_size points
2. The validation set always has exactly val_size points
3. The validation set always follows the training set temporally
4. Each new split adds val_size points to the training set
This approach respects the temporal nature of time series data and prevents data leakage from future to past.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
min_train_size
|
int
|
Minimum number of points in the initial training set |
required |
val_size
|
int
|
Number of points in each validation set |
required |
source
|
Optional[Handler[Any, T]]
|
The handler providing input data, defaults to None Example: |
None
|
Source code in pysatl_tsp/implementations/processor/time_series_cross_validator.py
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 | |
__init__
__init__(
min_train_size: int,
val_size: int,
source: Optional[Handler[Any, T]] = None,
)
Initialize a time series cross-validator.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
min_train_size
|
int
|
Minimum number of points in the initial training set |
required |
val_size
|
int
|
Number of points in each validation set |
required |
source
|
Optional[Handler[Any, T]]
|
The handler providing input data, defaults to None |
None
|
Source code in pysatl_tsp/implementations/processor/time_series_cross_validator.py
110 111 112 113 114 115 116 117 118 119 | |
__iter__
__iter__() -> Iterator[
tuple[ScrubberWindow[T], ScrubberWindow[T]]
]
Create an iterator that yields train-validation splits for time series cross-validation.
This method creates splits where: 1. The first split has exactly min_train_size points for training 2. Each subsequent split adds val_size points to the training set 3. Each validation set has exactly val_size points and follows the training set
Returns:
| Type | Description |
|---|---|
Iterator[tuple[ScrubberWindow[T], ScrubberWindow[T]]]
|
Iterator yielding tuples of (training_window, validation_window) |
Raises:
| Type | Description |
|---|---|
ValueError
|
If no source has been set |
Source code in pysatl_tsp/implementations/processor/time_series_cross_validator.py
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 | |
dema_handler
DEMAHandler
Bases: Handler[float | None, float | None]
A handler that calculates the Double Exponential Moving Average (DEMA).
The Double Exponential Moving Average (DEMA) is designed to reduce the lag associated with traditional moving averages. It puts more weight on recent data by using the formula: DEMA = 2 * EMA - EMA of EMA.
This implementation automatically configures a pipeline of EMA handlers to calculate both the primary EMA and the EMA of that EMA to produce DEMA values.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
length
|
int
|
The period for EMA calculations, defaults to 10 |
10
|
source
|
Handler[Any, float | None] | None
|
Input data source, defaults to None Example: |
None
|
Source code in pysatl_tsp/implementations/processor/dema_handler.py
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 | |
__init__(
length: int = 10,
source: Handler[Any, float | None] | None = None,
)
Initialize a DEMA handler.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
length
|
int
|
The period for EMA calculations, defaults to 10 |
10
|
source
|
Handler[Any, float | None] | None
|
Input data source, defaults to None |
None
|
Source code in pysatl_tsp/implementations/processor/dema_handler.py
41 42 43 44 45 46 47 48 | |
__iter__() -> Iterator[float | None]
Create an iterator that yields DEMA values.
This method constructs a pipeline that: 1. Takes values from the source 2. Calculates the primary EMA 3. Calculates the EMA of the EMA 4. Combines them using the DEMA formula
Returns:
| Type | Description |
|---|---|
Iterator[float | None]
|
Iterator yielding DEMA values |
Raises:
| Type | Description |
|---|---|
ValueError
|
If no source has been set |
Source code in pysatl_tsp/implementations/processor/dema_handler.py
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 | |
ema_handler
EMAHandler
Bases: InductiveHandler[float | None, float | None]
Exponential Moving Average (EMA) handler.
Calculates EMA values for a sequence of input values, matching the functionality of pandas_ta.EMA implementation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
length
|
int
|
The period for EMA calculation, defaults to 10 |
10
|
adjust
|
bool
|
Whether to use adjusted weights in calculation, defaults to False |
False
|
sma
|
bool
|
Whether to use SMA for initial value, defaults to True |
True
|
alpha
|
float | None
|
Custom smoothing factor, defaults to 2/(length+1) if None |
None
|
source
|
Handler[Any, float | None] | None
|
Input data source, defaults to None Example: |
None
|
Source code in pysatl_tsp/implementations/processor/ema_handler.py
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 | |
__init__(
length: int = 10,
adjust: bool = False,
sma: bool = True,
alpha: float | None = None,
source: Handler[Any, float | None] | None = None,
)
Initialize EMA handler with specified parameters.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
length
|
int
|
The period for EMA calculation, defaults to 10 |
10
|
adjust
|
bool
|
Whether to use adjusted weights in calculation, defaults to False |
False
|
sma
|
bool
|
Whether to use SMA for initial value, defaults to True |
True
|
alpha
|
float | None
|
Custom smoothing factor, defaults to 2/(length+1) if None |
None
|
source
|
Handler[Any, float | None] | None
|
Input data source, defaults to None |
None
|
Source code in pysatl_tsp/implementations/processor/ema_handler.py
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 | |
fwma_handler
FWMAHandler
Bases: WeightedMovingAverageHandler
Fibonacci Weighted Moving Average (FWMA) handler.
Calculates a moving average using Fibonacci sequence numbers as weights. The Fibonacci sequence (1, 1, 2, 3, 5, 8, 13, ...) provides a natural weighting scheme where each number is the sum of the two preceding ones.
By default, higher weights are assigned to more recent values (when asc=False), making this moving average more responsive to recent changes in the data.
Inherits general behavior from WeightedMovingAverageHandler, only changing the weight calculation method.
Example:
# Create a data source with numeric values
data_source = SimpleDataProvider([1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0])
# Create a FWMA handler with length of 5
fwma_handler = FWMAHandler(length=5)
fwma_handler.set_source(data_source)
# Process the data
for value in fwma_handler:
print(value)
# First 4 values will be None (not enough data points)
# Subsequent values will be weighted averages using Fibonacci weights
# For length=5, weights would be [0.01, 0.01, 0.02, 0.03, 0.05] (normalized)
# or [0.05, 0.03, 0.02, 0.01, 0.01] when asc=False (default)
Source code in pysatl_tsp/implementations/processor/fwma_handler.py
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 | |
hma_handler
HMAHandler
Bases: Handler[float | None, float | None]
Hull Moving Average (HMA) handler.
The Hull Moving Average is designed to reduce lag while maintaining smoothness. It uses weighted moving averages (WMA) in a multi-step process to create a more responsive indicator that better follows price action.
The HMA is calculated using the following formula: HMA = WMA(2*WMA(n/2) - WMA(n), sqrt(n))
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
length
|
int
|
The period for HMA calculation Example: |
required |
Source code in pysatl_tsp/implementations/processor/hma_handler.py
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 | |
__init__(length: int)
Initialize a Hull Moving Average handler.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
length
|
int
|
The period for HMA calculation |
required |
Source code in pysatl_tsp/implementations/processor/hma_handler.py
43 44 45 46 47 48 49 | |
__iter__() -> Iterator[float | None]
Create an iterator that yields HMA values.
This method constructs a pipeline that: 1. Takes values from the source 2. Calculates two WMAs with different periods (length//2 and length) 3. Combines them using the formula: 2*WMA(length//2) - WMA(length) 4. Applies another WMA with period=sqrt(length) to the result
Returns:
| Type | Description |
|---|---|
Iterator[float | None]
|
Iterator yielding HMA values |
Raises:
| Type | Description |
|---|---|
ValueError
|
If no source has been set |
Source code in pysatl_tsp/implementations/processor/hma_handler.py
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 | |
kalman_filter_handler
KalmanFilterHandler
Bases: OnlineFilterHandler[float, float]
A handler that applies the Kalman filter to time series data in real-time.
This handler integrates the complete Kalman filter functionality for processing noisy time series data. It estimates the underlying state of a system based on a sequence of noisy measurements.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
F
|
ndarray[Any, dtype[float64]]
|
State transition matrix |
required |
H
|
ndarray[Any, dtype[float64]]
|
Measurement matrix |
required |
B
|
Union[float, ndarray[Any, dtype[float64]]] | None
|
Control input matrix, defaults to 0 |
None
|
Q
|
ndarray[Any, dtype[float64]] | None
|
Process noise covariance matrix, defaults to identity matrix |
None
|
R
|
ndarray[Any, dtype[float64]] | None
|
Measurement noise covariance matrix, defaults to identity matrix |
None
|
P
|
ndarray[Any, dtype[float64]] | None
|
Initial state covariance matrix, defaults to identity matrix |
None
|
x0
|
ndarray[Any, dtype[float64]] | None
|
Initial state vector, defaults to zero vector |
None
|
source
|
Handler[Any, float] | None
|
The handler providing input data, defaults to None Example: |
None
|
Source code in pysatl_tsp/implementations/processor/kalman_filter_handler.py
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 | |
__init__(
F: ndarray[Any, dtype[float64]],
H: ndarray[Any, dtype[float64]],
B: Union[float, ndarray[Any, dtype[float64]]]
| None = None,
Q: ndarray[Any, dtype[float64]] | None = None,
R: ndarray[Any, dtype[float64]] | None = None,
P: ndarray[Any, dtype[float64]] | None = None,
x0: ndarray[Any, dtype[float64]] | None = None,
source: Handler[Any, float] | None = None,
) -> None
Initialize the Kalman filter handler with all necessary matrices.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
F
|
ndarray[Any, dtype[float64]]
|
State transition matrix |
required |
H
|
ndarray[Any, dtype[float64]]
|
Measurement matrix |
required |
B
|
Union[float, ndarray[Any, dtype[float64]]] | None
|
Control input matrix, defaults to None |
None
|
Q
|
ndarray[Any, dtype[float64]] | None
|
Process noise covariance matrix, defaults to None |
None
|
R
|
ndarray[Any, dtype[float64]] | None
|
Measurement noise covariance matrix, defaults to None |
None
|
P
|
ndarray[Any, dtype[float64]] | None
|
Initial state covariance matrix, defaults to None |
None
|
x0
|
ndarray[Any, dtype[float64]] | None
|
Initial state vector, defaults to None |
None
|
source
|
Handler[Any, float] | None
|
The handler providing input data, defaults to None |
None
|
Source code in pysatl_tsp/implementations/processor/kalman_filter_handler.py
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 | |
predict(
u: Union[float, ndarray[Any, dtype[float64]]] = 0,
) -> np.ndarray[Any, np.dtype[np.float64]]
Predict the next state based on the model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
u
|
Union[float, ndarray[Any, dtype[float64]]]
|
Control input, defaults to 0 |
0
|
Returns:
| Type | Description |
|---|---|
ndarray[Any, dtype[float64]]
|
Predicted state vector |
Source code in pysatl_tsp/implementations/processor/kalman_filter_handler.py
97 98 99 100 101 102 103 104 105 106 107 108 109 | |
update(z: float) -> None
Update the state estimate based on the measurement.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
z
|
float
|
Measurement |
required |
Source code in pysatl_tsp/implementations/processor/kalman_filter_handler.py
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 | |
midpoint_handler
MidpointHandler
Bases: MovingWindowHandler[float | None, float | None]
Midpoint price handler.
Calculates the average of highest and lowest values over the period. This handler is useful for identifying the central price level within a range, providing a simple measure of the balance between high and low extremes.
Inherits parameters from MovingWindowHandler:
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
length
|
The period for the calculation, defaults to 10 |
required | |
source
|
Input data source, defaults to None Example: |
required |
Source code in pysatl_tsp/implementations/processor/midpoint_handler.py
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 | |
midprice_handler
MidpriceHandler
Bases: MovingWindowHandler[tuple[float | None, float | None], float | None]
Midprice handler that processes high/low price tuples.
Calculates the average of the highest high and lowest low over a period. This handler is particularly useful for financial time series data where both high and low prices are available, providing a measure of the center of the price range over the specified period.
Unlike simple averages, the midprice considers only extreme values, making it useful for range-bound markets and support/resistance identification.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
length
|
The period for the calculation, defaults to 10 |
required | |
source
|
Input data source providing (high, low) tuples, defaults to None Example: |
required |
Source code in pysatl_tsp/implementations/processor/midprice_handler.py
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 | |
ohlc4_handler
Ohlc4Handler
Bases: MappingHandler[tuple[float | None, float | None, float | None, float | None], float | None]
A handler that calculates the average of OHLC (Open, High, Low, Close) price data.
This handler computes the OHLC4 (also known as the typical price), which is the simple arithmetic mean of the Open, High, Low, and Close prices for each time period. The calculation helps smooth price data and can be used as input for other indicators.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
Handler[Any, tuple[float | None, float | None, float | None, float | None]] | None
|
The handler providing OHLC tuples, defaults to None Example: |
None
|
Source code in pysatl_tsp/implementations/processor/ohlc4_handler.py
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 | |
__init__(
source: Handler[
Any,
tuple[
float | None,
float | None,
float | None,
float | None,
],
]
| None = None,
)
Initialize an OHLC4 handler.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
Handler[Any, tuple[float | None, float | None, float | None, float | None]] | None
|
The handler providing OHLC tuples, defaults to None |
None
|
Source code in pysatl_tsp/implementations/processor/ohlc4_handler.py
57 58 59 60 61 62 63 64 | |
pwma_handler
PWMAHandler
Bases: WeightedMovingAverageHandler
Pascal Weighted Moving Average (PWMA) handler.
Calculates a weighted moving average using coefficients from Pascal's triangle as weights. Pascal's triangle provides a natural weighting scheme where the central values receive more weight than the extremes, creating a balanced but still centered weighting distribution.
This implementation matches the functionality of pandas_ta.pwma.
Inherits parameters from WeightedMovingAverageHandler:
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
length
|
The period for the calculation, defaults to 10 |
required | |
asc
|
Whether weights should be applied in ascending order, defaults to False |
required | |
source
|
Input data source, defaults to None Example: |
required |
Source code in pysatl_tsp/implementations/processor/pwma_handler.py
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 | |
rma_handler
RMAHandler
Bases: InductiveHandler[float | None, float | None]
Wilder's Moving Average (RMA) Handler.
The Wilder's Moving Average is an Exponential Moving Average (EMA) with a modified alpha = 1 / length. It was introduced by J. Welles Wilder and is also known as the Smoothed Moving Average.
RMA gives greater weight to recent data and less weight to older data, but does so more gradually than a standard EMA, resulting in a smoother line. It's commonly used in technical analysis for calculating indicators like the Relative Strength Index (RSI).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
length
|
int
|
The number of periods for the moving average calculation, defaults to 10 |
10
|
source
|
Handler[Any, float | None] | None
|
Source handler providing the input data, defaults to None Example: |
None
|
Source code in pysatl_tsp/implementations/processor/rma_handler.py
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 | |
__init__(
length: int = 10,
source: Handler[Any, float | None] | None = None,
)
Initialize a Wilder's Moving Average handler.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
length
|
int
|
The number of periods for the moving average calculation, defaults to 10 |
10
|
source
|
Handler[Any, float | None] | None
|
Source handler providing the input data, defaults to None |
None
|
Source code in pysatl_tsp/implementations/processor/rma_handler.py
40 41 42 43 44 45 46 47 48 | |
sma_handler
SMAHandler
Bases: MovingWindowHandler[float | None, float | None]
Simple Moving Average (SMA) Handler.
The Simple Moving Average is the classic moving average that is the equally weighted average over n periods. It's one of the most common technical analysis tools that smooths price data by calculating the arithmetic mean of a given set of values over the specified period.
This handler properly handles None values by ignoring them in the calculation, and allows specifying a minimum number of valid observations required before producing a result.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
length
|
int
|
The period for the SMA calculation, defaults to 10 |
10
|
min_periods
|
int | None
|
Minimum number of observations required to have a value, defaults to length |
None
|
source
|
Handler[Any, float | None] | None
|
Input data source, defaults to None Example: |
None
|
Source code in pysatl_tsp/implementations/processor/sma_handler.py
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 | |
__init__(
length: int = 10,
min_periods: int | None = None,
source: Handler[Any, float | None] | None = None,
)
Initialize SMA handler with specified parameters.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
length
|
int
|
The period for the SMA calculation, defaults to 10 |
10
|
min_periods
|
int | None
|
Minimum number of non-None observations required to calculate a result, defaults to length if None |
None
|
source
|
Handler[Any, float | None] | None
|
Input data source, defaults to None |
None
|
Source code in pysatl_tsp/implementations/processor/sma_handler.py
48 49 50 51 52 53 54 55 56 57 58 59 | |
t3_handler
T3Handler
Bases: Handler[float | None, float | None]
Tim Tillson's T3 Moving Average handler with lazy evaluation.
This handler implements the T3 adaptive moving average developed by Tim Tillson, which is designed to reduce lag and improve smoothness. The T3 is calculated as: T3 = c1 * e6 + c2 * e5 + c3 * e4 + c4 * e3, where e1-e6 are sequentially computed EMAs.
All calculations are performed lazily in a streaming fashion, computing values only when requested by the iterator.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
length
|
int
|
Period for each EMA calculation, defaults to 10 |
10
|
a
|
float
|
Volume factor (0 < a < 1), controls smoothness vs. responsiveness, defaults to 0.7 |
0.7
|
source
|
Handler[Any, float | None] | None
|
Input data source, defaults to None Example: |
None
|
Source code in pysatl_tsp/implementations/processor/t3_handler.py
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 | |
__init__(
length: int = 10,
a: float = 0.7,
source: Handler[Any, float | None] | None = None,
)
Initialize a T3 moving average handler.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
length
|
int
|
Period for each EMA calculation, defaults to 10 |
10
|
a
|
float
|
Volume factor (0 < a < 1), controls smoothness vs. responsiveness, defaults to 0.7 |
0.7
|
source
|
Handler[Any, float | None] | None
|
Input data source, defaults to None |
None
|
Source code in pysatl_tsp/implementations/processor/t3_handler.py
44 45 46 47 48 49 50 51 52 53 | |
__iter__() -> Iterator[float | None]
Create an iterator that yields T3 moving average values.
This method constructs a pipeline of six cascaded EMA calculations, where each EMA takes the output of the previous one as input. The final T3 value is a weighted sum of the last four EMAs in the sequence.
Returns:
| Type | Description |
|---|---|
Iterator[float | None]
|
Iterator yielding T3 values |
Raises:
| Type | Description |
|---|---|
ValueError
|
If no source has been set |
Source code in pysatl_tsp/implementations/processor/t3_handler.py
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 | |
tema_handler
TEMAHandler
Bases: Handler[float | None, float | None]
Triple Exponential Moving Average (TEMA) handler with lazy evaluation.
This handler implements the TEMA indicator developed by Patrick Mulloy, which reduces lag by applying the formula: TEMA = 3 * (EMA1 - EMA2) + EMA3. Here EMA1 is the EMA of the original data, EMA2 is the EMA of EMA1, and EMA3 is the EMA of EMA2.
All calculations are performed lazily in a streaming fashion, computing values only when requested by the iterator.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
length
|
int
|
Period for each EMA calculation Example: |
required |
Source code in pysatl_tsp/implementations/processor/tema_handler.py
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 | |
__init__(length: int)
Initialize a TEMA handler.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
length
|
int
|
Period for each EMA calculation |
required |
Source code in pysatl_tsp/implementations/processor/tema_handler.py
43 44 45 46 47 48 49 | |
__iter__() -> Iterator[float | None]
Create an iterator that yields TEMA values.
This method constructs a pipeline of three cascaded EMA calculations and applies the TEMA formula: 3 * (EMA1 - EMA2) + EMA3.
Returns:
| Type | Description |
|---|---|
Iterator[float | None]
|
Iterator yielding TEMA values |
Raises:
| Type | Description |
|---|---|
ValueError
|
If no source has been set |
Source code in pysatl_tsp/implementations/processor/tema_handler.py
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 | |
time_series_cross_validator
TimeSeriesCrossValidator
Bases: Handler[T, tuple[ScrubberWindow[T], ScrubberWindow[T]]]
A handler that implements expanding window cross-validation for time series data.
This handler produces a sequence of train-validation splits suitable for time series validation, where each split preserves the temporal order of data. It implements an expanding window approach, where the training set grows over time while the validation set has a fixed size and slides forward.
The handler ensures that:
1. The training set always has at least min_train_size points
2. The validation set always has exactly val_size points
3. The validation set always follows the training set temporally
4. Each new split adds val_size points to the training set
This approach respects the temporal nature of time series data and prevents data leakage from future to past.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
min_train_size
|
int
|
Minimum number of points in the initial training set |
required |
val_size
|
int
|
Number of points in each validation set |
required |
source
|
Optional[Handler[Any, T]]
|
The handler providing input data, defaults to None Example: |
None
|
Source code in pysatl_tsp/implementations/processor/time_series_cross_validator.py
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 | |
__init__(
min_train_size: int,
val_size: int,
source: Optional[Handler[Any, T]] = None,
)
Initialize a time series cross-validator.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
min_train_size
|
int
|
Minimum number of points in the initial training set |
required |
val_size
|
int
|
Number of points in each validation set |
required |
source
|
Optional[Handler[Any, T]]
|
The handler providing input data, defaults to None |
None
|
Source code in pysatl_tsp/implementations/processor/time_series_cross_validator.py
110 111 112 113 114 115 116 117 118 119 | |
__iter__() -> Iterator[
tuple[ScrubberWindow[T], ScrubberWindow[T]]
]
Create an iterator that yields train-validation splits for time series cross-validation.
This method creates splits where: 1. The first split has exactly min_train_size points for training 2. Each subsequent split adds val_size points to the training set 3. Each validation set has exactly val_size points and follows the training set
Returns:
| Type | Description |
|---|---|
Iterator[tuple[ScrubberWindow[T], ScrubberWindow[T]]]
|
Iterator yielding tuples of (training_window, validation_window) |
Raises:
| Type | Description |
|---|---|
ValueError
|
If no source has been set |
Source code in pysatl_tsp/implementations/processor/time_series_cross_validator.py
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 | |
trima_handler
TRIMAHandler
Bases: Handler[float | None, float | None]
Triangular Moving Average (TRIMA) Handler.
A weighted moving average where the shape of the weights are triangular and the greatest weight is in the middle of the period. Implemented as a pipeline of two SMA calculations with half of the requested length.
TRIMA gives more weight to the middle portion of the price series and less weight to the oldest and newest data. It is slower to respond to price changes but better at filtering out market noise than a simple moving average.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
length
|
int
|
The period for the TRIMA calculation, defaults to 10 |
10
|
source
|
Handler[Any, float | None] | None
|
Input data source, defaults to None Example: |
None
|
Source code in pysatl_tsp/implementations/processor/trima_handler.py
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 | |
__init__(
length: int = 10,
source: Handler[Any, float | None] | None = None,
)
Initialize TRIMA handler with specified parameters.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
length
|
int
|
The period for the TRIMA calculation, defaults to 10 |
10
|
source
|
Handler[Any, float | None] | None
|
Input data source, defaults to None |
None
|
Source code in pysatl_tsp/implementations/processor/trima_handler.py
43 44 45 46 47 48 49 50 51 | |
__iter__() -> Iterator[float | None]
Create an iterator that yields TRIMA values.
This method implements the TRIMA calculation by creating a pipeline of two consecutive SMA calculations, each with half_length. This approach is mathematically equivalent to a weighted moving average with triangular weights.
Returns:
| Type | Description |
|---|---|
Iterator[float | None]
|
Iterator yielding TRIMA values |
Raises:
| Type | Description |
|---|---|
ValueError
|
If no source has been set |
Source code in pysatl_tsp/implementations/processor/trima_handler.py
53 54 55 56 57 58 59 60 61 62 63 64 65 66 | |
wma_handler
WMAHandler
Bases: WeightedMovingAverageHandler
Weighted Moving Average (WMA) handler.
Calculates a moving average where each data point is multiplied by a weight before being included in the average. The weights increase or decrease linearly, giving more importance to recent data points by default.
This implementation matches the functionality of pandas_ta.wma, using a linear weighting scheme where the weight of each value is proportional to its position in the window.
Inherits parameters from WeightedMovingAverageHandler:
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
length
|
The period for the calculation, defaults to 10 |
required | |
asc
|
Whether weights should be applied in ascending order, defaults to False When False, most recent values get higher weights |
required | |
source
|
Input data source, defaults to None Example: |
required |
Source code in pysatl_tsp/implementations/processor/wma_handler.py
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 | |
zlma_handler
ZLMAHandler
Bases: Handler[float | None, float | None]
Zero Lag Moving Average (ZLMA) handler with lazy evaluation.
Implements the formula ZLMA = MA(2 * close - close.shift(lag)), where lag = int(0.5 * (length - 1)). All calculations are performed lazily in a streaming fashion, computing values only when requested by the iterator.
The ZLMA reduces lag by applying a forward-shifted moving average that compensates for the lag inherent in traditional moving averages.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
length
|
int
|
Period for the moving average calculation |
10
|
ma_handler
|
Handler[Any, float | None] | None
|
Moving average handler to apply. Default is EMA with the specified length. |
None
|
source
|
Handler[Any, float | None] | None
|
Input data source, defaults to None Example: |
None
|
Source code in pysatl_tsp/implementations/processor/zlma_handler.py
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 | |
__init__(
length: int = 10,
ma_handler: Handler[Any, float | None] | None = None,
source: Handler[Any, float | None] | None = None,
)
Initialize a Zero Lag Moving Average handler.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
length
|
int
|
Period for the moving average calculation, defaults to 10 |
10
|
ma_handler
|
Handler[Any, float | None] | None
|
Moving average handler to apply, defaults to EMAHandler with the specified length |
None
|
source
|
Handler[Any, float | None] | None
|
Input data source, defaults to None |
None
|
Source code in pysatl_tsp/implementations/processor/zlma_handler.py
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 | |
__iter__() -> Iterator[float | None]
Create an iterator that yields ZLMA values.
This method implements the ZLMA calculation pipeline according to the formula: ZLMA = MA(2 * close - close.shift(lag)), where lag = int(0.5 * (length - 1)).
Returns:
| Type | Description |
|---|---|
Iterator[float | None]
|
Iterator yielding ZLMA values |
Raises:
| Type | Description |
|---|---|
ValueError
|
If no source has been set |
Source code in pysatl_tsp/implementations/processor/zlma_handler.py
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 | |