8000 window funcs working for NDPositions and NDPP_Pands · fastplotlib/fastplotlib@404bb7b · GitHub
[go: up one dir, main page]

Skip to content

Commit 404bb7b

Browse files
committed
window funcs working for NDPositions and NDPP_Pands
1 parent be437fa commit 404bb7b

File tree

5 files changed

+234
-293
lines changed

5 files changed

+234
-293
lines changed

fastplotlib/widgets/nd_widget/_nd_image.py

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from collections.abc import Hashable
12
import inspect
23
from typing import Literal, Callable, Type, Any
34
from warnings import warn
@@ -143,20 +144,12 @@ def rgb(self, rgb: bool):
143144
self._rgb = rgb
144145

145146
@property
146-
def n_slider_dims(self) -> int:
147-
"""number of slider dimensions"""
148-
if self._data is None:
149-
return 0
150-
151-
return self.ndim - self.n_display_dims - int(self.rgb)
147+
def slider_dims(self) -> set[Hashable]:
148+
return set(self.dims) - set(self.spatial_dims)
152149

153150
@property
154-
def slider_dims(self) -> tuple[int, ...] | None:
155-
"""tuple indicating the slider dimension indices"""
156-
if self.n_slider_dims == 0:
157-
return None
158-
159-
return tuple(range(self.n_slider_dims))
151+
def n_slider_dims(self):
152+
return len(self.slider_dims)
160153

161154
@property
162155
def slider_dims_shape(self) -> tuple[int, ...] | None:
Lines changed: 23 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from typing import Any
2+
13
import numpy as np
24
import pandas as pd
35

@@ -8,13 +10,11 @@ class NDPP_Pandas(NDPositionsProcessor):
810
def __init__(
911
self,
1012
data: pd.DataFrame,
13+
spatial_dims: tuple[str, str, str], # [l, p, d] dims in order
1114
columns: list[tuple[str, str] | tuple[str, str, str]],
1215
tooltip_columns: list[str] = None,
13-
max_display_datapoints: int = 1_000,
1416
**kwargs,
1517
):
16-
data = data
17-
1818
self._columns = columns
1919

2020
if tooltip_columns is not None:
@@ -26,17 +26,22 @@ def __init__(
2626
self._tooltip_columns = None
2727
self._tooltip = False
2828

29+
self._dims = spatial_dims
30+
2931
super().__init__(
3032
data=data,
31-
max_display_datapoints=max_display_datapoints,
33+
dims=spatial_dims,
34+
spatial_dims=spatial_dims,
3235
**kwargs,
3336
)
3437

38+
self._dw_slice = None
39+
3540
@property
3641
def data(self) -> pd.DataFrame:
3742
return self._data
3843

39-
def _validate_data(self, data: pd.DataFrame):
44+
def _validate_data(self, data: pd.DataFrame, dims):
4045
if not isinstance(data, pd.DataFrame):
4146
raise TypeError
4247

@@ -47,56 +52,41 @@ def columns(self) -> list[tuple[str, str] | tuple[str, str, str]]:
4752
return self._columns
4853

4954
@property
50-
def multi(self) -> bool:
51-
return True
52-
53-
@multi.setter
54-
def multi(self, v):
55-
pass
55+
def dims(self) -> tuple[str, str, str]:
56+
return self._dims
5657

5758
@property
58-
def shape(self) -> tuple[int, ...]:
59+
def shape(self) -> dict[str, int]:
5960
# n_graphical_elements, n_timepoints, 2
60-
return len(self.columns), self.data.index.size, 2
61+
return {self.dims[0]: len(self.columns), self.dims[1]: self.data.index.size, self.dims[2]: 2}
6162

6263
@property
6364
def ndim(self) -> int:
6465
return len(self.shape)
6566

66-
@property
67-
def n_slider_dims(self) -> int:
68-
return 1
69-
7067
@property
7168
def tooltip(self) -> bool:
7269
return self._tooltip
7370

7471
def tooltip_format(self, n: int, p: int):
7572
# datapoint index w.r.t. full data
76-
p += self._slices[-1].start
73+
p += self._dw_slice.start
7774
return str(self.data[self._tooltip_columns[n]][p])
7875

79-
def get(self, indices: tuple[float | int, ...]) -> np.ndarray:
80-
if not isinstance(indices, tuple):
81-
raise TypeError(".get() must receive a tuple of float | int indices")
82-
76+
def get(self, indices: dict[str, Any]) -> np.ndarray:
8377
# TODO: LOD by using a step size according to max_p
8478
# TODO: Also what to do if display_window is None and data
8579
# hasn't changed when indices keeps getting set, cache?
8680

87-
# assume no additional slider dims, only time slider dim
88-
if self.display_window is not None:
89-
self._slices = self._get_dw_slices(indices)
90-
gdata_shape = len(self.columns), self._slices[-1].stop - self._slices[-1].start, 3
91-
else:
92-
gdata_shape = len(self.columns), self.data.shape[0], 3
93-
self._slices = (slice(None),)
81+
# assume no additional slider dims
82+
self._dw_slice = self._get_dw_slice(indices)
83+
gdata_shape = len(self.columns), self._dw_slice.stop - self._dw_slice.start, 3
9484

95-
gdata = np.zeros(shape=gdata_shape, dtype=np.float32)
85+
graphic_data = np.zeros(shape=gdata_shape, dtype=np.float32)
9686

9787
for i, col in enumerate(self.columns):
98-
gdata[i, :, :len(col)] = np.column_stack(
99-
[self.data[c][self._slices[-1]] for c in col]
88+
graphic_data[i, :, :len(col)] = np.column_stack(
89+
[self.data[c][self._dw_slice] for c in col]
10090
)
10191

102-
return gdata
92+
return self._apply_dw_window_func(graphic_data)

0 commit comments

Comments
 (0)
0