aggregation
Compatible implementation for various downsample methods and open interface to other downsample methods.
AbstractAggregator
¶
Bases: ABC
Source code in plotly_resampler/aggregation/aggregation_interface.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 |
|
__init__(x_dtype_regex_list=None, y_dtype_regex_list=None, **downsample_kwargs)
¶
Constructor of AbstractSeriesAggregator.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x_dtype_regex_list |
Optional[List[str]]
|
List containing the regex matching the supported datatypes for the x array, by default None. |
None
|
y_dtype_regex_list |
Optional[List[str]]
|
List containing the regex matching the supported datatypes for the y array, by default None. |
None
|
downsample_kwargs |
Additional kwargs passed to the downsample method. |
{}
|
Source code in plotly_resampler/aggregation/aggregation_interface.py
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
|
AbstractGapHandler
¶
Bases: ABC
Source code in plotly_resampler/aggregation/gap_handler_interface.py
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 |
|
__init__(fill_value=None)
¶
Constructor of AbstractGapHandler.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
fill_value |
Optional[float]
|
The value to fill the gaps with, by default None. Note that setting this value to 0 for filled area plots is particularly useful. |
None
|
Source code in plotly_resampler/aggregation/gap_handler_interface.py
14 15 16 17 18 19 20 21 22 23 24 25 |
|
insert_fill_value_between_gaps(x_agg, y_agg, idxs)
¶
Insert the fill_value in the y_agg array where there are gaps.
Gaps are determined by the x_agg array. The _get_gap_mask
method is used to
determine a boolean mask indicating the indices where there are gaps.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x_agg |
np.ndarray
|
The x array. This is used to determine the gaps. |
required |
y_agg |
np.ndarray
|
The y array. A copy of this array will be expanded with fill_values where there are gaps. |
required |
idxs |
np.ndarray
|
The index array. This is relevant aggregators that perform data point selection (e.g., max, min, etc.) - this array will be expanded with the same indices where there are gaps. |
required |
Returns:
Type | Description |
---|---|
Tuple[np.ndarray, np.ndarray]
|
The expanded y_agg array and the expanded idxs array respectively. |
Source code in plotly_resampler/aggregation/gap_handler_interface.py
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 |
|
EveryNthPoint
¶
Bases: DataPointSelector
Naive (but fast) aggregator method which returns every N’th point.
Note
This downsampler supports all dtypes.
Source code in plotly_resampler/aggregation/aggregators.py
248 249 250 251 252 253 254 255 256 257 258 259 260 261 |
|
FuncAggregator
¶
Bases: DataAggregator
Aggregator instance which uses the passed aggregation func.
Warning
The user has total control which aggregation_func
is passed to this method,
hence the user should be careful to not make copies of the data, nor write to
the data. Furthermore, the user should beware of performance issues when
using more complex aggregation functions.
Attention
The user has total control which aggregation_func
is passed to this method,
hence it is the users’ responsibility to handle categorical and bool-based
data types.
Source code in plotly_resampler/aggregation/aggregators.py
264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 |
|
__init__(aggregation_func, x_dtype_regex_list=None, y_dtype_regex_list=None, **downsample_kwargs)
¶
Parameters:
Name | Type | Description | Default |
---|---|---|---|
aggregation_func |
The aggregation function which will be applied on each pin. |
required |
Source code in plotly_resampler/aggregation/aggregators.py
282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 |
|
LTTB
¶
Bases: DataPointSelector
Largest Triangle Three Buckets (LTTB) aggregation method.
This is arguably the most widely used aggregation method. It is based on the effective area of a triangle (inspired from the line simplification domain). The algorithm has $O(n)$ complexity, however, for large datasets, it can be much slower than other algorithms (e.g. MinMax) due to the higher cost of calculating the areas of triangles.
Thesis: https://skemman.is/bitstream/1946/15343/3/SS_MSthesis.pdf
Details on visual representativeness & stability: https://arxiv.org/abs/2304.00900
Tip
LTTB
doesn’t scale super-well when moving to really large datasets, so when
dealing with more than 1 million samples, you might consider using
MinMaxLTTB
.
Note
- This class is mainly designed to operate on numerical data as LTTB calculates
distances on the values.
When dealing with categories, the data is encoded into its numeric codes, these codes are the indices of the category array. - To aggregate category data with LTTB, your
pd.Series
must be of dtype ‘category’.
tip:
if there is an order in your categories, order them that way, LTTB uses
the ordered category codes values (see bullet above) to calculate distances and
make aggregation decisions.
code:
>>> import pandas as pd
>>> s = pd.Series(["a", "b", "c", "a"])
>>> cat_type = pd.CategoricalDtype(categories=["b", "c", "a"], ordered=True)
>>> s_cat = s.astype(cat_type)
LTTB
has no downsample kwargs, as it cannot be paralellized. Instead, you can
use the MinMaxLTTB
downsampler, which performs
minmax preselection (in parallel if configured so), followed by LTTB.
Source code in plotly_resampler/aggregation/aggregators.py
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 |
|
MedDiffGapHandler
¶
Bases: AbstractGapHandler
Gap handling based on the median diff of the x_agg array.
Source code in plotly_resampler/aggregation/gap_handlers.py
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 |
|
MinMaxAggregator
¶
Bases: DataPointSelector
Aggregation method which performs binned min-max aggregation over fully overlapping windows.
This is arguably the most computational efficient downsampling method, as it only performs (non-expensive) comparisons on the data in a single pass.
Details on visual representativeness & stability: https://arxiv.org/abs/2304.00900
Note
This method is rather efficient when scaling to large data sizes and can be used
as a data-reduction step before feeding it to the LTTB
algorithm, as MinMaxLTTB
does with the
MinMaxOverlapAggregator
.
Source code in plotly_resampler/aggregation/aggregators.py
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 |
|
__init__(**downsample_kwargs)
¶
Parameters:
Name | Type | Description | Default |
---|---|---|---|
**downsample_kwargs |
Keyword arguments passed to the :class: |
{}
|
Source code in plotly_resampler/aggregation/aggregators.py
174 175 176 177 178 179 180 181 182 183 184 185 |
|
MinMaxLTTB
¶
Bases: DataPointSelector
Efficient version off LTTB by first reducing really large datasets with
the MinMaxAggregator
and then further aggregating the
reduced result with LTTB
.
Starting from 10M data points, this method performs the MinMax-prefetching of data points to enhance computational efficiency.
Inventors: Jonas & Jeroen Van Der Donckt - 2022
Paper: https://arxiv.org/pdf/2305.00332.pdf
Source code in plotly_resampler/aggregation/aggregators.py
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 237 238 239 240 241 242 243 244 245 |
|
__init__(minmax_ratio=4, **downsample_kwargs)
¶
Parameters:
Name | Type | Description | Default |
---|---|---|---|
minmax_ratio |
int
|
The ratio between the number of data points in the MinMax-prefetching and the number of data points that will be outputted by LTTB. By default, 4. |
4
|
**downsample_kwargs |
Keyword arguments passed to the |
{}
|
Source code in plotly_resampler/aggregation/aggregators.py
211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 |
|
MinMaxOverlapAggregator
¶
Bases: DataPointSelector
Aggregation method which performs binned min-max aggregation over 50% overlapping windows.
In the above image, bin_size: represents the size of (len(series) / n_out). As the windows have 50% overlap and are consecutive, the min & max values are calculated on a windows with size (2x bin-size).
This is very similar to the MinMaxAggregator, emperical results showed no observable difference between both approaches.
Note
This method is implemented in Python (leveraging numpy for vecotrization), but
is significantly slower than the MinMaxAggregator (which is implemented in
the tsdownsample toolkit in Rust).
As such, this class does not support any downsample kwargs.
Note
This downsampler supports all dtypes.
Source code in plotly_resampler/aggregation/aggregators.py
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 |
|
NoGapHandler
¶
Bases: AbstractGapHandler
No gap handling.
Source code in plotly_resampler/aggregation/gap_handlers.py
15 16 17 18 19 |
|
PlotlyAggregatorParser
¶
Source code in plotly_resampler/aggregation/plotly_aggregator_parser.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 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 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 |
|
aggregate(hf_trace_data, start_idx, end_idx)
staticmethod
¶
Aggregate the data in hf_trace_data
between start_idx
and end_idx
.
Returns: - x: the aggregated x-values - y: the aggregated y-values - indices: the indices of the hf_data data that were aggregated
These indices are useful to select the corresponding hf_data from
non `x` and `y` data (e.g. `text`, `marker_size`, `marker_color`).
Source code in plotly_resampler/aggregation/plotly_aggregator_parser.py
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 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 |
|
get_start_end_indices(hf_trace_data, axis_type, start, end)
staticmethod
¶
Get the start & end indices of the high-frequency data.
Source code in plotly_resampler/aggregation/plotly_aggregator_parser.py
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 |
|
parse_hf_data(hf_data)
staticmethod
¶
Parse the high-frequency data to a numpy array.
Source code in plotly_resampler/aggregation/plotly_aggregator_parser.py
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
|
to_same_tz(ts, reference_tz)
staticmethod
¶
Adjust ts
its timezone to the reference_tz
.
Source code in plotly_resampler/aggregation/plotly_aggregator_parser.py
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
|