fpcs 1.0.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- fpcs-1.0.0/LICENSE +21 -0
- fpcs-1.0.0/MANIFEST.in +6 -0
- fpcs-1.0.0/PKG-INFO +218 -0
- fpcs-1.0.0/README.md +189 -0
- fpcs-1.0.0/pyproject.toml +51 -0
- fpcs-1.0.0/setup.cfg +4 -0
- fpcs-1.0.0/setup.py +34 -0
- fpcs-1.0.0/src/fpcs/__init__.py +38 -0
- fpcs-1.0.0/src/fpcs/fpcs_cy.c +33354 -0
- fpcs-1.0.0/src/fpcs/fpcs_cy.pyx +446 -0
- fpcs-1.0.0/src/fpcs/fpcs_pure.py +305 -0
- fpcs-1.0.0/src/fpcs.egg-info/PKG-INFO +218 -0
- fpcs-1.0.0/src/fpcs.egg-info/SOURCES.txt +14 -0
- fpcs-1.0.0/src/fpcs.egg-info/dependency_links.txt +1 -0
- fpcs-1.0.0/src/fpcs.egg-info/requires.txt +8 -0
- fpcs-1.0.0/src/fpcs.egg-info/top_level.txt +1 -0
fpcs-1.0.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Thomas Michelat
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
fpcs-1.0.0/MANIFEST.in
ADDED
fpcs-1.0.0/PKG-INFO
ADDED
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: fpcs
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: Feature-Preserving Compensated Sampling for time series downsampling
|
|
5
|
+
Author-email: Thomas Michelat <thomas.michelat@gmail.com>
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/tmichela/fpcs
|
|
8
|
+
Project-URL: Repository, https://github.com/tmichela/fpcs
|
|
9
|
+
Keywords: downsampling,time series,visualization,data science
|
|
10
|
+
Classifier: Intended Audience :: Developers
|
|
11
|
+
Classifier: Intended Audience :: Science/Research
|
|
12
|
+
Classifier: Operating System :: OS Independent
|
|
13
|
+
Classifier: Programming Language :: Python :: 3
|
|
14
|
+
Classifier: Programming Language :: Cython
|
|
15
|
+
Classifier: Topic :: Scientific/Engineering :: Information Analysis
|
|
16
|
+
Classifier: Topic :: Scientific/Engineering :: Physics
|
|
17
|
+
Classifier: Topic :: Scientific/Engineering :: Visualization
|
|
18
|
+
Requires-Python: >=3.11
|
|
19
|
+
Description-Content-Type: text/markdown
|
|
20
|
+
License-File: LICENSE
|
|
21
|
+
Requires-Dist: numpy
|
|
22
|
+
Provides-Extra: dev
|
|
23
|
+
Requires-Dist: cython; extra == "dev"
|
|
24
|
+
Requires-Dist: matplotlib; extra == "dev"
|
|
25
|
+
Requires-Dist: lttbc; extra == "dev"
|
|
26
|
+
Requires-Dist: pytest; extra == "dev"
|
|
27
|
+
Requires-Dist: pytest-benchmark; extra == "dev"
|
|
28
|
+
Dynamic: license-file
|
|
29
|
+
|
|
30
|
+
# FPCS - Feature-Preserving Compensated Sampling
|
|
31
|
+
|
|
32
|
+
[](https://opensource.org/licenses/MIT)
|
|
33
|
+
|
|
34
|
+
**FPCS** is a high-performance time series downsampling algorithm designed to
|
|
35
|
+
preserve critical visual features (peaks and valleys) while significantly
|
|
36
|
+
reducing data size. It is particularly well-suited for real-time visualization
|
|
37
|
+
and streaming data applications.
|
|
38
|
+
|
|
39
|
+
Implementation based on the [Feature-Preserving Compensated Sampling for Time
|
|
40
|
+
Series Visualization](https://ieeexplore.ieee.org/document/10669793)
|
|
41
|
+
publication.
|
|
42
|
+
|
|
43
|
+
---
|
|
44
|
+
|
|
45
|
+
## Why FPCS?
|
|
46
|
+
|
|
47
|
+
Unlike simple decimation or even some advanced algorithms like LTTB, FPCS
|
|
48
|
+
retains the min/max within each sampling window, helping preserve prominent
|
|
49
|
+
peaks and valleys while allowing smaller local extrema to be dropped.
|
|
50
|
+
|
|
51
|
+
### Visual Comparison (FPCS vs LTTB)
|
|
52
|
+
FPCS maintains the full range of the signal even at high downsampling ratios,
|
|
53
|
+
whereas LTTB may miss sharp spikes in noisy datasets.
|
|
54
|
+
|
|
55
|
+

|
|
56
|
+
|
|
57
|
+
### Key Features
|
|
58
|
+
- **High Performance:** Cython-optimized core is competitive with optimized LTTB
|
|
59
|
+
(see benchmarks below).
|
|
60
|
+
- **Streaming data:** Supports incremental processing via `FPCSDownsampler`.
|
|
61
|
+
- **Feature preserving:** Guarantees retention of min/max points within each
|
|
62
|
+
window.
|
|
63
|
+
- **Robust:** Native handling of `NaN` and `Inf` values.
|
|
64
|
+
- **Batched processing:** Efficiently downsample multiple series at once.
|
|
65
|
+
|
|
66
|
+
---
|
|
67
|
+
|
|
68
|
+
## Installation
|
|
69
|
+
|
|
70
|
+
```bash
|
|
71
|
+
# Install from PyPI
|
|
72
|
+
pip install fpcs
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
**Requirements**
|
|
76
|
+
- Python >= 3.11
|
|
77
|
+
- NumPy
|
|
78
|
+
|
|
79
|
+
**Optional (for the Cython extension)**
|
|
80
|
+
- C compiler and Python headers
|
|
81
|
+
- Cython (the package falls back to the pure Python backend if Cython isn't
|
|
82
|
+
available)
|
|
83
|
+
|
|
84
|
+
```bash
|
|
85
|
+
# Install from source (local checkout)
|
|
86
|
+
pip install .
|
|
87
|
+
|
|
88
|
+
# For development (includes Cython, pytest, benchmarks)
|
|
89
|
+
pip install -e ".[dev]"
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
---
|
|
93
|
+
|
|
94
|
+
## Usage
|
|
95
|
+
|
|
96
|
+
### Batch Downsampling
|
|
97
|
+
Processing existing datasets:
|
|
98
|
+
```python
|
|
99
|
+
import numpy as np
|
|
100
|
+
from fpcs import downsample
|
|
101
|
+
|
|
102
|
+
# Generate 1M points
|
|
103
|
+
x = np.arange(1_000_000, dtype=np.float64)
|
|
104
|
+
y = np.sin(x * 0.01) + np.random.randn(1_000_000) * 0.5
|
|
105
|
+
|
|
106
|
+
# Downsample by a factor of 100
|
|
107
|
+
x_ds, y_ds = downsample(x, y, ratio=100)
|
|
108
|
+
|
|
109
|
+
print(f"Original: {len(x)} points | Downsampled: {len(x_ds)} points")
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
### Streaming data
|
|
113
|
+
Processing data in real-time:
|
|
114
|
+
```python
|
|
115
|
+
from fpcs import FPCSDownsampler
|
|
116
|
+
|
|
117
|
+
downsampler = FPCSDownsampler(ratio=10)
|
|
118
|
+
|
|
119
|
+
# Simulate a stream
|
|
120
|
+
for xi, yi in zip(stream_x, stream_y):
|
|
121
|
+
# .add() yields retained points immediately
|
|
122
|
+
for rx, ry in downsampler.add(xi, yi):
|
|
123
|
+
update_plot(rx, ry)
|
|
124
|
+
|
|
125
|
+
# Flush any remaining points at the end of the stream
|
|
126
|
+
for rx, ry in downsampler.flush():
|
|
127
|
+
update_plot(rx, ry)
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
## API Reference
|
|
131
|
+
|
|
132
|
+
### `downsample(x, y, ratio)`
|
|
133
|
+
The main entry point for batch processing.
|
|
134
|
+
- **Parameters:**
|
|
135
|
+
- `x` (Array-like): The x-coordinates (e.g., timestamps).
|
|
136
|
+
- `y` (Array-like): The y-coordinates.
|
|
137
|
+
- `ratio` (int): The sampling window size (R). Must be >= 1.
|
|
138
|
+
- **Returns:**
|
|
139
|
+
- `(np.ndarray, np.ndarray)`: A tuple of `(x_downsampled, y_downsampled)`.
|
|
140
|
+
- **Notes:**
|
|
141
|
+
- The first and last input points are always retained in batch mode.
|
|
142
|
+
- `NaN` values are always retained to preserve gaps.
|
|
143
|
+
- `±Inf` values are treated as extrema.
|
|
144
|
+
- Integer inputs are supported; the Cython backend converts them to float64.
|
|
145
|
+
|
|
146
|
+
### `FPCSDownsampler`
|
|
147
|
+
Class for streaming/incremental downsampling.
|
|
148
|
+
|
|
149
|
+
#### `__init__(ratio: int)`
|
|
150
|
+
Initialize the downsampler.
|
|
151
|
+
- `ratio`: Sampling window size. Must be >= 1.
|
|
152
|
+
|
|
153
|
+
#### `add(x: float, y: float) -> Iterator[tuple[float, float]]`
|
|
154
|
+
Add a single point to the downsampler.
|
|
155
|
+
- **Yields:** Tuples of `(x, y)` for any points retained during this step.
|
|
156
|
+
- **Notes:**
|
|
157
|
+
- Streaming mode does **not** auto-include the first/last points; if you
|
|
158
|
+
need them, add them yourself.
|
|
159
|
+
- `NaN` values are always retained and `±Inf` values are treated as extrema.
|
|
160
|
+
|
|
161
|
+
#### `flush() -> Iterator[tuple[float, float]]`
|
|
162
|
+
Flush any remaining points from the internal buffer (e.g., at the end of a
|
|
163
|
+
stream).
|
|
164
|
+
- **Yields:** Tuples of `(x, y)` for remaining points.
|
|
165
|
+
|
|
166
|
+
#### `reset()`
|
|
167
|
+
Resets the downsampler state to initial conditions.
|
|
168
|
+
|
|
169
|
+
### Advanced / Optimization API
|
|
170
|
+
These functions are available when the Cython extension is successfully
|
|
171
|
+
compiled. You can check the active backend with `get_backend()`.
|
|
172
|
+
|
|
173
|
+
#### `downsample_into(x, y, ratio, out_x, out_y) -> int`
|
|
174
|
+
Downsample into pre-allocated output buffers to reduce memory allocation
|
|
175
|
+
overhead.
|
|
176
|
+
- **Parameters:**
|
|
177
|
+
- `x`, `y`: Input arrays (integer inputs are supported and converted to float64).
|
|
178
|
+
- `out_x`, `out_y`: Output buffers (contiguous float64, must be large enough).
|
|
179
|
+
- **Returns:** Number of points written.
|
|
180
|
+
- **Notes:** Recommended output buffer size is `((len(x) + ratio - 1) // ratio)
|
|
181
|
+
* 2 + 2`.
|
|
182
|
+
|
|
183
|
+
#### `downsample_batch(x_arrays, y_arrays, ratio) -> List[tuple]`
|
|
184
|
+
Efficiently process a list of time series. Reduces Python overhead compared to a
|
|
185
|
+
loop.
|
|
186
|
+
|
|
187
|
+
### Backend Availability
|
|
188
|
+
- `downsample` and `FPCSDownsampler` are always available.
|
|
189
|
+
- `downsample_into` and `downsample_batch` are only available with the Cython
|
|
190
|
+
backend (they are `None` when using pure Python).
|
|
191
|
+
- Use `get_backend()` to check which backend is active (`"cython"` or
|
|
192
|
+
`"python"`).
|
|
193
|
+
|
|
194
|
+
---
|
|
195
|
+
|
|
196
|
+
## Performance
|
|
197
|
+
Comparison between FPCS (Python/Cython) and a C implementation of the LTTB
|
|
198
|
+
algorithm.
|
|
199
|
+
|
|
200
|
+
**Algorithm comparison**
|
|
201
|
+
|
|
202
|
+
| Name (time in ms) | Min | Max | Mean | StdDev | OPS |
|
|
203
|
+
|:---|---:|---:|---:|---:|---:|
|
|
204
|
+
| **Cython FPCS** | 1.2370 | 1.3534 | 1.2546 | 0.0162 | 797.0606 |
|
|
205
|
+
| **LTTB (C impl)** | 2.5252 | 2.6372 | 2.5394 | 0.0166 | 393.7865 |
|
|
206
|
+
| **Pure Python** | 393.6482 | 398.6493 | 395.6410 | 2.3321 | 2.5275 |
|
|
207
|
+
|
|
208
|
+
**Ratio scaling (Cython)**
|
|
209
|
+
|
|
210
|
+
| Ratio | Mean Time (ms) | StdDev |
|
|
211
|
+
|:---|---:|---:|
|
|
212
|
+
| **10** | 4.05 | 0.81 |
|
|
213
|
+
| **50** | 3.86 | 0.89 |
|
|
214
|
+
| **100** | 4.02 | 0.90 |
|
|
215
|
+
| **500** | 4.32 | 0.74 |
|
|
216
|
+
|
|
217
|
+
## License
|
|
218
|
+
This project is licensed under the MIT Licence - see the LICENSE file for details.
|
fpcs-1.0.0/README.md
ADDED
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
# FPCS - Feature-Preserving Compensated Sampling
|
|
2
|
+
|
|
3
|
+
[](https://opensource.org/licenses/MIT)
|
|
4
|
+
|
|
5
|
+
**FPCS** is a high-performance time series downsampling algorithm designed to
|
|
6
|
+
preserve critical visual features (peaks and valleys) while significantly
|
|
7
|
+
reducing data size. It is particularly well-suited for real-time visualization
|
|
8
|
+
and streaming data applications.
|
|
9
|
+
|
|
10
|
+
Implementation based on the [Feature-Preserving Compensated Sampling for Time
|
|
11
|
+
Series Visualization](https://ieeexplore.ieee.org/document/10669793)
|
|
12
|
+
publication.
|
|
13
|
+
|
|
14
|
+
---
|
|
15
|
+
|
|
16
|
+
## Why FPCS?
|
|
17
|
+
|
|
18
|
+
Unlike simple decimation or even some advanced algorithms like LTTB, FPCS
|
|
19
|
+
retains the min/max within each sampling window, helping preserve prominent
|
|
20
|
+
peaks and valleys while allowing smaller local extrema to be dropped.
|
|
21
|
+
|
|
22
|
+
### Visual Comparison (FPCS vs LTTB)
|
|
23
|
+
FPCS maintains the full range of the signal even at high downsampling ratios,
|
|
24
|
+
whereas LTTB may miss sharp spikes in noisy datasets.
|
|
25
|
+
|
|
26
|
+

|
|
27
|
+
|
|
28
|
+
### Key Features
|
|
29
|
+
- **High Performance:** Cython-optimized core is competitive with optimized LTTB
|
|
30
|
+
(see benchmarks below).
|
|
31
|
+
- **Streaming data:** Supports incremental processing via `FPCSDownsampler`.
|
|
32
|
+
- **Feature preserving:** Guarantees retention of min/max points within each
|
|
33
|
+
window.
|
|
34
|
+
- **Robust:** Native handling of `NaN` and `Inf` values.
|
|
35
|
+
- **Batched processing:** Efficiently downsample multiple series at once.
|
|
36
|
+
|
|
37
|
+
---
|
|
38
|
+
|
|
39
|
+
## Installation
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
# Install from PyPI
|
|
43
|
+
pip install fpcs
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
**Requirements**
|
|
47
|
+
- Python >= 3.11
|
|
48
|
+
- NumPy
|
|
49
|
+
|
|
50
|
+
**Optional (for the Cython extension)**
|
|
51
|
+
- C compiler and Python headers
|
|
52
|
+
- Cython (the package falls back to the pure Python backend if Cython isn't
|
|
53
|
+
available)
|
|
54
|
+
|
|
55
|
+
```bash
|
|
56
|
+
# Install from source (local checkout)
|
|
57
|
+
pip install .
|
|
58
|
+
|
|
59
|
+
# For development (includes Cython, pytest, benchmarks)
|
|
60
|
+
pip install -e ".[dev]"
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
---
|
|
64
|
+
|
|
65
|
+
## Usage
|
|
66
|
+
|
|
67
|
+
### Batch Downsampling
|
|
68
|
+
Processing existing datasets:
|
|
69
|
+
```python
|
|
70
|
+
import numpy as np
|
|
71
|
+
from fpcs import downsample
|
|
72
|
+
|
|
73
|
+
# Generate 1M points
|
|
74
|
+
x = np.arange(1_000_000, dtype=np.float64)
|
|
75
|
+
y = np.sin(x * 0.01) + np.random.randn(1_000_000) * 0.5
|
|
76
|
+
|
|
77
|
+
# Downsample by a factor of 100
|
|
78
|
+
x_ds, y_ds = downsample(x, y, ratio=100)
|
|
79
|
+
|
|
80
|
+
print(f"Original: {len(x)} points | Downsampled: {len(x_ds)} points")
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
### Streaming data
|
|
84
|
+
Processing data in real-time:
|
|
85
|
+
```python
|
|
86
|
+
from fpcs import FPCSDownsampler
|
|
87
|
+
|
|
88
|
+
downsampler = FPCSDownsampler(ratio=10)
|
|
89
|
+
|
|
90
|
+
# Simulate a stream
|
|
91
|
+
for xi, yi in zip(stream_x, stream_y):
|
|
92
|
+
# .add() yields retained points immediately
|
|
93
|
+
for rx, ry in downsampler.add(xi, yi):
|
|
94
|
+
update_plot(rx, ry)
|
|
95
|
+
|
|
96
|
+
# Flush any remaining points at the end of the stream
|
|
97
|
+
for rx, ry in downsampler.flush():
|
|
98
|
+
update_plot(rx, ry)
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
## API Reference
|
|
102
|
+
|
|
103
|
+
### `downsample(x, y, ratio)`
|
|
104
|
+
The main entry point for batch processing.
|
|
105
|
+
- **Parameters:**
|
|
106
|
+
- `x` (Array-like): The x-coordinates (e.g., timestamps).
|
|
107
|
+
- `y` (Array-like): The y-coordinates.
|
|
108
|
+
- `ratio` (int): The sampling window size (R). Must be >= 1.
|
|
109
|
+
- **Returns:**
|
|
110
|
+
- `(np.ndarray, np.ndarray)`: A tuple of `(x_downsampled, y_downsampled)`.
|
|
111
|
+
- **Notes:**
|
|
112
|
+
- The first and last input points are always retained in batch mode.
|
|
113
|
+
- `NaN` values are always retained to preserve gaps.
|
|
114
|
+
- `±Inf` values are treated as extrema.
|
|
115
|
+
- Integer inputs are supported; the Cython backend converts them to float64.
|
|
116
|
+
|
|
117
|
+
### `FPCSDownsampler`
|
|
118
|
+
Class for streaming/incremental downsampling.
|
|
119
|
+
|
|
120
|
+
#### `__init__(ratio: int)`
|
|
121
|
+
Initialize the downsampler.
|
|
122
|
+
- `ratio`: Sampling window size. Must be >= 1.
|
|
123
|
+
|
|
124
|
+
#### `add(x: float, y: float) -> Iterator[tuple[float, float]]`
|
|
125
|
+
Add a single point to the downsampler.
|
|
126
|
+
- **Yields:** Tuples of `(x, y)` for any points retained during this step.
|
|
127
|
+
- **Notes:**
|
|
128
|
+
- Streaming mode does **not** auto-include the first/last points; if you
|
|
129
|
+
need them, add them yourself.
|
|
130
|
+
- `NaN` values are always retained and `±Inf` values are treated as extrema.
|
|
131
|
+
|
|
132
|
+
#### `flush() -> Iterator[tuple[float, float]]`
|
|
133
|
+
Flush any remaining points from the internal buffer (e.g., at the end of a
|
|
134
|
+
stream).
|
|
135
|
+
- **Yields:** Tuples of `(x, y)` for remaining points.
|
|
136
|
+
|
|
137
|
+
#### `reset()`
|
|
138
|
+
Resets the downsampler state to initial conditions.
|
|
139
|
+
|
|
140
|
+
### Advanced / Optimization API
|
|
141
|
+
These functions are available when the Cython extension is successfully
|
|
142
|
+
compiled. You can check the active backend with `get_backend()`.
|
|
143
|
+
|
|
144
|
+
#### `downsample_into(x, y, ratio, out_x, out_y) -> int`
|
|
145
|
+
Downsample into pre-allocated output buffers to reduce memory allocation
|
|
146
|
+
overhead.
|
|
147
|
+
- **Parameters:**
|
|
148
|
+
- `x`, `y`: Input arrays (integer inputs are supported and converted to float64).
|
|
149
|
+
- `out_x`, `out_y`: Output buffers (contiguous float64, must be large enough).
|
|
150
|
+
- **Returns:** Number of points written.
|
|
151
|
+
- **Notes:** Recommended output buffer size is `((len(x) + ratio - 1) // ratio)
|
|
152
|
+
* 2 + 2`.
|
|
153
|
+
|
|
154
|
+
#### `downsample_batch(x_arrays, y_arrays, ratio) -> List[tuple]`
|
|
155
|
+
Efficiently process a list of time series. Reduces Python overhead compared to a
|
|
156
|
+
loop.
|
|
157
|
+
|
|
158
|
+
### Backend Availability
|
|
159
|
+
- `downsample` and `FPCSDownsampler` are always available.
|
|
160
|
+
- `downsample_into` and `downsample_batch` are only available with the Cython
|
|
161
|
+
backend (they are `None` when using pure Python).
|
|
162
|
+
- Use `get_backend()` to check which backend is active (`"cython"` or
|
|
163
|
+
`"python"`).
|
|
164
|
+
|
|
165
|
+
---
|
|
166
|
+
|
|
167
|
+
## Performance
|
|
168
|
+
Comparison between FPCS (Python/Cython) and a C implementation of the LTTB
|
|
169
|
+
algorithm.
|
|
170
|
+
|
|
171
|
+
**Algorithm comparison**
|
|
172
|
+
|
|
173
|
+
| Name (time in ms) | Min | Max | Mean | StdDev | OPS |
|
|
174
|
+
|:---|---:|---:|---:|---:|---:|
|
|
175
|
+
| **Cython FPCS** | 1.2370 | 1.3534 | 1.2546 | 0.0162 | 797.0606 |
|
|
176
|
+
| **LTTB (C impl)** | 2.5252 | 2.6372 | 2.5394 | 0.0166 | 393.7865 |
|
|
177
|
+
| **Pure Python** | 393.6482 | 398.6493 | 395.6410 | 2.3321 | 2.5275 |
|
|
178
|
+
|
|
179
|
+
**Ratio scaling (Cython)**
|
|
180
|
+
|
|
181
|
+
| Ratio | Mean Time (ms) | StdDev |
|
|
182
|
+
|:---|---:|---:|
|
|
183
|
+
| **10** | 4.05 | 0.81 |
|
|
184
|
+
| **50** | 3.86 | 0.89 |
|
|
185
|
+
| **100** | 4.02 | 0.90 |
|
|
186
|
+
| **500** | 4.32 | 0.74 |
|
|
187
|
+
|
|
188
|
+
## License
|
|
189
|
+
This project is licensed under the MIT Licence - see the LICENSE file for details.
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools", "wheel", "numpy", "cython"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "fpcs"
|
|
7
|
+
authors = [
|
|
8
|
+
{ name = "Thomas Michelat", email = "thomas.michelat@gmail.com" },
|
|
9
|
+
]
|
|
10
|
+
description = "Feature-Preserving Compensated Sampling for time series downsampling"
|
|
11
|
+
dynamic = ["version", "readme"]
|
|
12
|
+
license = "MIT"
|
|
13
|
+
keywords = ["downsampling", "time series", "visualization", "data science"]
|
|
14
|
+
classifiers = [
|
|
15
|
+
"Intended Audience :: Developers",
|
|
16
|
+
"Intended Audience :: Science/Research",
|
|
17
|
+
"Operating System :: OS Independent",
|
|
18
|
+
"Programming Language :: Python :: 3",
|
|
19
|
+
"Programming Language :: Cython",
|
|
20
|
+
"Topic :: Scientific/Engineering :: Information Analysis",
|
|
21
|
+
"Topic :: Scientific/Engineering :: Physics",
|
|
22
|
+
"Topic :: Scientific/Engineering :: Visualization",
|
|
23
|
+
]
|
|
24
|
+
requires-python = ">=3.11"
|
|
25
|
+
dependencies = [
|
|
26
|
+
"numpy",
|
|
27
|
+
]
|
|
28
|
+
|
|
29
|
+
[project.urls]
|
|
30
|
+
Homepage = "https://github.com/tmichela/fpcs"
|
|
31
|
+
Repository = "https://github.com/tmichela/fpcs"
|
|
32
|
+
|
|
33
|
+
[project.optional-dependencies]
|
|
34
|
+
dev = [
|
|
35
|
+
"cython",
|
|
36
|
+
"matplotlib",
|
|
37
|
+
"lttbc",
|
|
38
|
+
"pytest",
|
|
39
|
+
"pytest-benchmark",
|
|
40
|
+
]
|
|
41
|
+
|
|
42
|
+
[tool.setuptools]
|
|
43
|
+
package-dir = {"" = "src"}
|
|
44
|
+
packages = ["fpcs"]
|
|
45
|
+
|
|
46
|
+
[tool.setuptools.dynamic]
|
|
47
|
+
version = { attr = "fpcs.__version__" }
|
|
48
|
+
readme = { file = ["README.md"], content-type = "text/markdown" }
|
|
49
|
+
|
|
50
|
+
[tool.pytest.ini_options]
|
|
51
|
+
pythonpath = ["src"]
|
fpcs-1.0.0/setup.cfg
ADDED
fpcs-1.0.0/setup.py
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
from setuptools import setup, Extension
|
|
2
|
+
import numpy as np
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
def get_extensions():
|
|
6
|
+
"""Get extension modules, returns empty list if Cython not available."""
|
|
7
|
+
try:
|
|
8
|
+
from Cython.Build import cythonize
|
|
9
|
+
|
|
10
|
+
extensions = [
|
|
11
|
+
Extension(
|
|
12
|
+
"fpcs.fpcs_cy",
|
|
13
|
+
sources=["src/fpcs/fpcs_cy.pyx"],
|
|
14
|
+
include_dirs=[np.get_include()],
|
|
15
|
+
)
|
|
16
|
+
]
|
|
17
|
+
|
|
18
|
+
return cythonize(
|
|
19
|
+
extensions,
|
|
20
|
+
compiler_directives={
|
|
21
|
+
"language_level": "3",
|
|
22
|
+
"boundscheck": False,
|
|
23
|
+
"wraparound": False,
|
|
24
|
+
"cdivision": True,
|
|
25
|
+
"initializedcheck": False,
|
|
26
|
+
"nonecheck": False,
|
|
27
|
+
},
|
|
28
|
+
)
|
|
29
|
+
except ImportError:
|
|
30
|
+
print("WARNING: Cython not available. Using pure Python implementation.")
|
|
31
|
+
return []
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
setup(ext_modules=get_extensions())
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"""
|
|
2
|
+
FPCS - Feature-Preserving Compensated Sampling
|
|
3
|
+
|
|
4
|
+
A high-performance time series downsampling algorithm that preserves
|
|
5
|
+
important visual features (peaks, valleys) while reducing data size.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
__version__ = "1.0.0"
|
|
9
|
+
|
|
10
|
+
# Try to import optimized Cython implementation first
|
|
11
|
+
try:
|
|
12
|
+
from .fpcs_cy import downsample, downsample_into, downsample_batch
|
|
13
|
+
_BACKEND = "cython"
|
|
14
|
+
except ImportError:
|
|
15
|
+
# Fall back to pure Python implementation
|
|
16
|
+
from .fpcs_pure import downsample
|
|
17
|
+
_BACKEND = "python"
|
|
18
|
+
|
|
19
|
+
# These are not available in pure Python
|
|
20
|
+
downsample_into = None
|
|
21
|
+
downsample_batch = None
|
|
22
|
+
|
|
23
|
+
# Always available from pure Python
|
|
24
|
+
from .fpcs_pure import FPCSDownsampler
|
|
25
|
+
|
|
26
|
+
__all__ = [
|
|
27
|
+
"downsample",
|
|
28
|
+
"downsample_into",
|
|
29
|
+
"downsample_batch",
|
|
30
|
+
"FPCSDownsampler",
|
|
31
|
+
"_BACKEND",
|
|
32
|
+
"__version__",
|
|
33
|
+
]
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def get_backend():
|
|
37
|
+
"""Return the active backend: 'cython' or 'python'."""
|
|
38
|
+
return _BACKEND
|