plopp 25.6.0__py3-none-any.whl → 25.7.0__py3-none-any.whl
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.
- plopp/core/graph.py +2 -2
- plopp/core/helpers.py +1 -1
- plopp/core/node_class.py +3 -3
- plopp/graphics/graphicalview.py +1 -1
- plopp/plotting/common.py +116 -77
- plopp/plotting/slicer.py +10 -1
- plopp/plotting/xyplot.py +11 -4
- plopp/widgets/drawing.py +2 -2
- plopp/widgets/linesave.py +1 -1
- plopp/widgets/slice.py +97 -46
- {plopp-25.6.0.dist-info → plopp-25.7.0.dist-info}/METADATA +2 -2
- {plopp-25.6.0.dist-info → plopp-25.7.0.dist-info}/RECORD +15 -15
- {plopp-25.6.0.dist-info → plopp-25.7.0.dist-info}/WHEEL +0 -0
- {plopp-25.6.0.dist-info → plopp-25.7.0.dist-info}/licenses/LICENSE +0 -0
- {plopp-25.6.0.dist-info → plopp-25.7.0.dist-info}/top_level.txt +0 -0
plopp/core/graph.py
CHANGED
|
@@ -23,8 +23,8 @@ def _make_graphviz_digraph(*args, **kwargs):
|
|
|
23
23
|
def _walk_graph(start, nodes, edges, views, labels):
|
|
24
24
|
label = (
|
|
25
25
|
escape(str(start.func)) + '\nid = ' + start.id
|
|
26
|
-
if start.
|
|
27
|
-
else escape(start.
|
|
26
|
+
if start.pretty_name is None
|
|
27
|
+
else escape(start.pretty_name)
|
|
28
28
|
)
|
|
29
29
|
nodes[start.id] = label
|
|
30
30
|
for child in start.children:
|
plopp/core/helpers.py
CHANGED
|
@@ -38,6 +38,6 @@ def widget_node(widget) -> Node:
|
|
|
38
38
|
``ipywidgets`` library, or a custom widget.
|
|
39
39
|
"""
|
|
40
40
|
n = Node(func=lambda: widget.value)
|
|
41
|
-
n.
|
|
41
|
+
n.pretty_name = f'Widget <{type(widget).__name__}: {type(widget.value).__name__}>'
|
|
42
42
|
widget.observe(n.notify_children, names="value")
|
|
43
43
|
return n
|
plopp/core/node_class.py
CHANGED
|
@@ -64,10 +64,10 @@ class Node:
|
|
|
64
64
|
)
|
|
65
65
|
)
|
|
66
66
|
fname = getattr(self.func, "__name__", str(self.func))
|
|
67
|
-
self.
|
|
67
|
+
self.pretty_name = f'{fname}({args_string})'
|
|
68
68
|
else:
|
|
69
69
|
val_str = f'={func!r}' if isinstance(func, int | float | str) else ""
|
|
70
|
-
self.
|
|
70
|
+
self.pretty_name = f'Input <{type(func).__name__}{val_str}>'
|
|
71
71
|
|
|
72
72
|
# Attempt to set children after setting name in case error message is needed
|
|
73
73
|
for parent in chain(self.parents, self.kwparents.values()):
|
|
@@ -194,7 +194,7 @@ class Node:
|
|
|
194
194
|
return self.id == other.id
|
|
195
195
|
|
|
196
196
|
def __repr__(self) -> str:
|
|
197
|
-
return f"Node(name={self.
|
|
197
|
+
return f"Node(name={self.pretty_name})"
|
|
198
198
|
|
|
199
199
|
def __add__(self, other: Node | Any) -> Node:
|
|
200
200
|
return Node(lambda x, y: x + y, self, other)
|
plopp/graphics/graphicalview.py
CHANGED
|
@@ -59,7 +59,7 @@ class GraphicalView(View):
|
|
|
59
59
|
title: str | None = None,
|
|
60
60
|
figsize: tuple[float, float] | None = None,
|
|
61
61
|
format: Literal['svg', 'png'] | None = None,
|
|
62
|
-
legend: bool | tuple[float, float] =
|
|
62
|
+
legend: bool | tuple[float, float] = True,
|
|
63
63
|
camera: Camera | None = None,
|
|
64
64
|
autoscale: bool = True,
|
|
65
65
|
ax: Any = None,
|
plopp/plotting/common.py
CHANGED
|
@@ -76,64 +76,28 @@ def to_variable(obj) -> sc.Variable:
|
|
|
76
76
|
return out
|
|
77
77
|
|
|
78
78
|
|
|
79
|
-
def
|
|
80
|
-
da: sc.DataArray, coords: list[str] | None
|
|
81
|
-
) -> sc.DataArray:
|
|
82
|
-
if coords is None:
|
|
83
|
-
coords = list(da.dims)
|
|
84
|
-
elif missing := set(coords) - set(da.coords.keys()):
|
|
85
|
-
raise ValueError(f"Specified coords do not exist: {missing}")
|
|
86
|
-
|
|
87
|
-
# Remove unused coords
|
|
88
|
-
da = da.drop_coords(list(set(da.coords) - set(coords)))
|
|
89
|
-
# Assign dim coords where missing. The above checks ensure that all missing
|
|
90
|
-
# coords are dim coords, i.e., that `name in out.dims`.
|
|
91
|
-
da = da.assign_coords(
|
|
92
|
-
{
|
|
93
|
-
name: sc.arange(name, da.sizes[name], unit=None)
|
|
94
|
-
for name in set(coords) - set(da.coords)
|
|
95
|
-
}
|
|
96
|
-
)
|
|
97
|
-
return da
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
def to_data_array(
|
|
101
|
-
obj: Plottable | list,
|
|
102
|
-
coords: list[str] | None = None,
|
|
103
|
-
) -> sc.DataArray:
|
|
79
|
+
def to_data_array(obj: Plottable | list) -> sc.DataArray:
|
|
104
80
|
"""
|
|
105
|
-
Convert an input to a DataArray
|
|
106
|
-
|
|
81
|
+
Convert an input to a DataArray.
|
|
82
|
+
Returns a shallow copy of the input if it is already a DataArray.
|
|
107
83
|
|
|
108
84
|
Parameters
|
|
109
85
|
----------
|
|
110
86
|
obj:
|
|
111
87
|
The input object to be converted.
|
|
112
|
-
coords:
|
|
113
|
-
If supplied, use these coords instead of the input's dimension coordinates.
|
|
114
88
|
"""
|
|
89
|
+
if isinstance(obj, sc.DataArray):
|
|
90
|
+
return obj.copy(deep=False)
|
|
115
91
|
out = _maybe_to_variable(obj)
|
|
116
92
|
if isinstance(out, sc.Variable):
|
|
117
93
|
out = sc.DataArray(data=out)
|
|
118
94
|
out = from_compatible_lib(out)
|
|
119
95
|
if not isinstance(out, sc.DataArray):
|
|
120
96
|
raise TypeError(f"Cannot convert input of type {type(obj)} to a DataArray.")
|
|
121
|
-
out = _ensure_data_array_coords(out, coords)
|
|
122
|
-
for name, coord in out.coords.items():
|
|
123
|
-
if not coord.dims:
|
|
124
|
-
raise ValueError(
|
|
125
|
-
"Input data cannot be plotted: it has a scalar coordinate along "
|
|
126
|
-
f"dimension {name}. Consider dropping this coordinate before plotting. "
|
|
127
|
-
f"Use ``data.drop_coords('{name}').plot()``."
|
|
128
|
-
)
|
|
129
|
-
for name in out.coords:
|
|
130
|
-
other_dims = [dim for dim in out.coords[name].dims if dim not in out.dims]
|
|
131
|
-
for dim in other_dims:
|
|
132
|
-
out.coords[name] = out.coords[name].mean(dim)
|
|
133
97
|
return out
|
|
134
98
|
|
|
135
99
|
|
|
136
|
-
def _check_size(da: sc.DataArray):
|
|
100
|
+
def _check_size(da: sc.DataArray) -> None:
|
|
137
101
|
"""
|
|
138
102
|
Prevent slow figure rendering by raising an error if the data array exceeds a
|
|
139
103
|
default size.
|
|
@@ -149,7 +113,7 @@ def _check_size(da: sc.DataArray):
|
|
|
149
113
|
)
|
|
150
114
|
|
|
151
115
|
|
|
152
|
-
def check_not_binned(da: sc.DataArray):
|
|
116
|
+
def check_not_binned(da: sc.DataArray) -> None:
|
|
153
117
|
"""
|
|
154
118
|
Plopp cannot plot binned data.
|
|
155
119
|
This function will raise an error if the input data is binned.
|
|
@@ -169,7 +133,7 @@ def check_not_binned(da: sc.DataArray):
|
|
|
169
133
|
)
|
|
170
134
|
|
|
171
135
|
|
|
172
|
-
def check_allowed_dtypes(da: sc.DataArray):
|
|
136
|
+
def check_allowed_dtypes(da: sc.DataArray) -> None:
|
|
173
137
|
"""
|
|
174
138
|
Currently, Plopp cannot plot data that contains vector and matrix dtypes.
|
|
175
139
|
This function will raise an error if the input data type is not supported.
|
|
@@ -185,10 +149,108 @@ def check_allowed_dtypes(da: sc.DataArray):
|
|
|
185
149
|
)
|
|
186
150
|
|
|
187
151
|
|
|
188
|
-
def _all_dims_sorted(var, order='ascending'):
|
|
152
|
+
def _all_dims_sorted(var, order='ascending') -> bool:
|
|
153
|
+
"""
|
|
154
|
+
Check if all dimensions of a variable are sorted in the specified order.
|
|
155
|
+
This is used to ensure that the coordinates are sorted before plotting.
|
|
156
|
+
"""
|
|
189
157
|
return all(sc.allsorted(var, dim, order=order) for dim in var.dims)
|
|
190
158
|
|
|
191
159
|
|
|
160
|
+
def _rename_dims_from_coords(da: sc.DataArray, coords: Iterable[str]) -> sc.DataArray:
|
|
161
|
+
"""
|
|
162
|
+
If coordinates are provided, rename the dimensions of the data array to match the
|
|
163
|
+
names of the coordinates, so that they effectively become the dimension coordinates.
|
|
164
|
+
"""
|
|
165
|
+
renamed_dims = {}
|
|
166
|
+
underlying_dims = set()
|
|
167
|
+
for dim in coords:
|
|
168
|
+
underlying = da.coords[dim].dims[-1]
|
|
169
|
+
if underlying in underlying_dims:
|
|
170
|
+
raise ValueError(
|
|
171
|
+
"coords: Cannot use more than one coordinate associated with "
|
|
172
|
+
f"the same underlying dimension ({underlying})."
|
|
173
|
+
)
|
|
174
|
+
renamed_dims[underlying] = dim
|
|
175
|
+
underlying_dims.add(underlying)
|
|
176
|
+
return da.rename_dims(**renamed_dims)
|
|
177
|
+
|
|
178
|
+
|
|
179
|
+
def _add_missing_dimension_coords(da: sc.DataArray) -> sc.DataArray:
|
|
180
|
+
"""
|
|
181
|
+
Add missing dimension coordinates to the data array.
|
|
182
|
+
If a dimension does not have a coordinate, it will be added with a range of values.
|
|
183
|
+
"""
|
|
184
|
+
return da.assign_coords(
|
|
185
|
+
{
|
|
186
|
+
dim: sc.arange(dim, da.sizes[dim], unit=None)
|
|
187
|
+
for dim in da.dims
|
|
188
|
+
if dim not in da.coords
|
|
189
|
+
}
|
|
190
|
+
)
|
|
191
|
+
|
|
192
|
+
|
|
193
|
+
def _drop_non_dimension_coords(da: sc.DataArray) -> sc.DataArray:
|
|
194
|
+
"""
|
|
195
|
+
Drop all coordinates that are not dimension coordinates.
|
|
196
|
+
This is useful to ensure that only the coordinates that are actually used for
|
|
197
|
+
plotting are kept.
|
|
198
|
+
"""
|
|
199
|
+
return da.drop_coords([name for name in da.coords if name not in da.dims])
|
|
200
|
+
|
|
201
|
+
|
|
202
|
+
def _handle_coords_with_left_over_dimensions(da: sc.DataArray) -> sc.DataArray:
|
|
203
|
+
"""
|
|
204
|
+
In some rare cases, the coordinate may have dimensions that are not present in the
|
|
205
|
+
data array. This can happen for example when a 2d coord with bin edges is sliced
|
|
206
|
+
along one dimension, leaving a coordinate with the other dimension, and a dimension
|
|
207
|
+
of length 2 (because of the bin edges) in th sliced dimension.
|
|
208
|
+
|
|
209
|
+
This function will handle such cases by averaging the coordinate over the left-over
|
|
210
|
+
dimensions, effectively reducing the coordinate to a single value for each
|
|
211
|
+
dimension that is not present in the data array.
|
|
212
|
+
"""
|
|
213
|
+
return da.assign_coords(
|
|
214
|
+
{
|
|
215
|
+
name: da.coords[name].mean(
|
|
216
|
+
[dim for dim in da.coords[name].dims if dim not in da.dims]
|
|
217
|
+
)
|
|
218
|
+
for name in da.coords
|
|
219
|
+
}
|
|
220
|
+
)
|
|
221
|
+
|
|
222
|
+
|
|
223
|
+
def _check_coord_sanity(da: sc.DataArray) -> None:
|
|
224
|
+
"""
|
|
225
|
+
Warn if any coordinate is not sorted. This can lead to unpredictable results
|
|
226
|
+
when plotting.
|
|
227
|
+
Also, raise an error if any coordinate is scalar.
|
|
228
|
+
"""
|
|
229
|
+
for name, coord in da.coords.items():
|
|
230
|
+
try:
|
|
231
|
+
if not (
|
|
232
|
+
_all_dims_sorted(coord, order='ascending')
|
|
233
|
+
or _all_dims_sorted(coord, order='descending')
|
|
234
|
+
):
|
|
235
|
+
warnings.warn(
|
|
236
|
+
'The input contains a coordinate with unsorted values '
|
|
237
|
+
f'({name}). The results may be unpredictable. '
|
|
238
|
+
'Coordinates can be sorted using '
|
|
239
|
+
'`scipp.sort(data, dim="to_be_sorted", order="ascending")`.',
|
|
240
|
+
RuntimeWarning,
|
|
241
|
+
stacklevel=2,
|
|
242
|
+
)
|
|
243
|
+
except sc.DTypeError:
|
|
244
|
+
pass
|
|
245
|
+
|
|
246
|
+
if not coord.dims:
|
|
247
|
+
raise ValueError(
|
|
248
|
+
"Input data cannot be plotted: it has a scalar coordinate along "
|
|
249
|
+
f"dimension {name}. Consider dropping this coordinate before plotting. "
|
|
250
|
+
f"Use ``data.drop_coords('{name}').plot()``."
|
|
251
|
+
)
|
|
252
|
+
|
|
253
|
+
|
|
192
254
|
def preprocess(
|
|
193
255
|
obj: Plottable | list,
|
|
194
256
|
name: str | None = None,
|
|
@@ -219,42 +281,19 @@ def preprocess(
|
|
|
219
281
|
elif coords is not None:
|
|
220
282
|
coords = list(coords)
|
|
221
283
|
|
|
222
|
-
out = to_data_array(obj
|
|
284
|
+
out = to_data_array(obj)
|
|
223
285
|
check_not_binned(out)
|
|
224
286
|
check_allowed_dtypes(out)
|
|
225
287
|
if name is not None:
|
|
226
|
-
out.name = name
|
|
288
|
+
out.name = str(name)
|
|
227
289
|
if not ignore_size:
|
|
228
290
|
_check_size(out)
|
|
229
291
|
if coords is not None:
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
"coords: Cannot use more than one coordinate associated with "
|
|
236
|
-
f"the same underlying dimension ({underlying})."
|
|
237
|
-
)
|
|
238
|
-
renamed_dims[underlying] = dim
|
|
239
|
-
out = out.rename_dims(**renamed_dims)
|
|
240
|
-
for n, coord in out.coords.items():
|
|
241
|
-
if (coord.ndim == 0) or (n not in out.dims):
|
|
242
|
-
continue
|
|
243
|
-
try:
|
|
244
|
-
if not (
|
|
245
|
-
_all_dims_sorted(coord, order='ascending')
|
|
246
|
-
or _all_dims_sorted(coord, order='descending')
|
|
247
|
-
):
|
|
248
|
-
warnings.warn(
|
|
249
|
-
'The input contains a coordinate with unsorted values '
|
|
250
|
-
f'({n}). The results may be unpredictable. '
|
|
251
|
-
'Coordinates can be sorted using '
|
|
252
|
-
'`scipp.sort(data, dim="to_be_sorted", order="ascending")`.',
|
|
253
|
-
RuntimeWarning,
|
|
254
|
-
stacklevel=2,
|
|
255
|
-
)
|
|
256
|
-
except sc.DTypeError:
|
|
257
|
-
pass
|
|
292
|
+
out = _rename_dims_from_coords(out, coords)
|
|
293
|
+
out = _add_missing_dimension_coords(out)
|
|
294
|
+
out = _drop_non_dimension_coords(out)
|
|
295
|
+
out = _handle_coords_with_left_over_dimensions(out)
|
|
296
|
+
_check_coord_sanity(out)
|
|
258
297
|
return out
|
|
259
298
|
|
|
260
299
|
|
|
@@ -277,9 +316,9 @@ def input_to_nodes(obj: PlottableMulti, processor: Callable) -> list[Node]:
|
|
|
277
316
|
nodes = [Node(processor, inp, name=name) for name, inp in to_nodes]
|
|
278
317
|
for node in nodes:
|
|
279
318
|
if hasattr(processor, 'func'):
|
|
280
|
-
node.
|
|
319
|
+
node.pretty_name = processor.func.__name__
|
|
281
320
|
else:
|
|
282
|
-
node.
|
|
321
|
+
node.pretty_name = 'Preprocess data'
|
|
283
322
|
return nodes
|
|
284
323
|
|
|
285
324
|
|
plopp/plotting/slicer.py
CHANGED
|
@@ -60,6 +60,7 @@ class Slicer:
|
|
|
60
60
|
vmin: VariableLike | float = None,
|
|
61
61
|
vmax: VariableLike | float = None,
|
|
62
62
|
cbar: bool = True,
|
|
63
|
+
enable_player: bool = False,
|
|
63
64
|
**kwargs,
|
|
64
65
|
):
|
|
65
66
|
nodes = input_to_nodes(
|
|
@@ -98,7 +99,9 @@ class Slicer:
|
|
|
98
99
|
from ..widgets import SliceWidget, slice_dims
|
|
99
100
|
|
|
100
101
|
self.slider = SliceWidget(
|
|
101
|
-
nodes[0](),
|
|
102
|
+
nodes[0](),
|
|
103
|
+
dims=[dim for dim in dims if dim not in keep],
|
|
104
|
+
enable_player=enable_player,
|
|
102
105
|
)
|
|
103
106
|
self.slider_node = widget_node(self.slider)
|
|
104
107
|
self.slice_nodes = [slice_dims(node, self.slider_node) for node in nodes]
|
|
@@ -130,6 +133,7 @@ def slicer(
|
|
|
130
133
|
vmin: VariableLike | float = None,
|
|
131
134
|
vmax: VariableLike | float = None,
|
|
132
135
|
cbar: bool = True,
|
|
136
|
+
enable_player: bool = False,
|
|
133
137
|
**kwargs,
|
|
134
138
|
) -> FigureLike:
|
|
135
139
|
"""
|
|
@@ -156,6 +160,10 @@ def slicer(
|
|
|
156
160
|
The maximum value of the y-axis (1d plots) or color range (2d plots).
|
|
157
161
|
cbar:
|
|
158
162
|
Whether to display a colorbar for 2D plots.
|
|
163
|
+
enable_player:
|
|
164
|
+
Add a play button to animate the sliders if True. Defaults to False.
|
|
165
|
+
|
|
166
|
+
.. versionadded:: 25.07.0
|
|
159
167
|
**kwargs:
|
|
160
168
|
See :py:func:`plopp.plot` for the full list of figure customization arguments.
|
|
161
169
|
"""
|
|
@@ -167,5 +175,6 @@ def slicer(
|
|
|
167
175
|
vmax=vmax,
|
|
168
176
|
coords=coords,
|
|
169
177
|
cbar=cbar,
|
|
178
|
+
enable_player=enable_player,
|
|
170
179
|
**kwargs,
|
|
171
180
|
).figure
|
plopp/plotting/xyplot.py
CHANGED
|
@@ -23,7 +23,17 @@ def _make_data_array(x: sc.Variable, y: sc.Variable) -> sc.DataArray:
|
|
|
23
23
|
y:
|
|
24
24
|
The variable to use as the data.
|
|
25
25
|
"""
|
|
26
|
-
|
|
26
|
+
if x.ndim != 1 or y.ndim != 1:
|
|
27
|
+
raise sc.DimensionError(
|
|
28
|
+
f'Expected 1 dimension, got {x.ndim} for x and {y.ndim} for y.'
|
|
29
|
+
)
|
|
30
|
+
dim = x.dim
|
|
31
|
+
return sc.DataArray(
|
|
32
|
+
data=sc.array(dims=[dim], values=y.values, variances=y.variances, unit=y.unit)
|
|
33
|
+
if y.dim != dim
|
|
34
|
+
else y,
|
|
35
|
+
coords={dim: x},
|
|
36
|
+
)
|
|
27
37
|
|
|
28
38
|
|
|
29
39
|
def xyplot(
|
|
@@ -48,7 +58,4 @@ def xyplot(
|
|
|
48
58
|
"""
|
|
49
59
|
x = Node(to_variable, x)
|
|
50
60
|
y = Node(to_variable, y)
|
|
51
|
-
dim = x().dim
|
|
52
|
-
if dim != y().dim:
|
|
53
|
-
raise sc.DimensionError("Dimensions of x and y must match")
|
|
54
61
|
return linefigure(Node(_make_data_array, x=x, y=y), **kwargs)
|
plopp/widgets/drawing.py
CHANGED
|
@@ -86,12 +86,12 @@ class DrawingTool(ToggleTool):
|
|
|
86
86
|
|
|
87
87
|
def make_node(self, artist):
|
|
88
88
|
draw_node = Node(self._get_artist_info(artist=artist, figure=self._figure))
|
|
89
|
-
draw_node.
|
|
89
|
+
draw_node.pretty_name = f'Draw node {len(self._draw_nodes)}'
|
|
90
90
|
nodeid = draw_node.id
|
|
91
91
|
self._draw_nodes[nodeid] = draw_node
|
|
92
92
|
artist.nodeid = nodeid
|
|
93
93
|
output_node = node(self._func)(self._input_node, draw_node)
|
|
94
|
-
output_node.
|
|
94
|
+
output_node.pretty_name = f'Output node {len(self._output_nodes)}'
|
|
95
95
|
self._output_nodes[nodeid] = output_node
|
|
96
96
|
if self._destination_is_fig:
|
|
97
97
|
output_node.add_view(self._destination.view)
|
plopp/widgets/linesave.py
CHANGED
|
@@ -45,7 +45,7 @@ class LineSaveTool(VBar):
|
|
|
45
45
|
|
|
46
46
|
data = self._data_node.request_data()
|
|
47
47
|
node = Node(data)
|
|
48
|
-
node.
|
|
48
|
+
node.pretty_name = f'Save node {len(self._lines)}'
|
|
49
49
|
line_id = node._id
|
|
50
50
|
node.add_view(self._fig.view)
|
|
51
51
|
self._fig.view.render()
|
plopp/widgets/slice.py
CHANGED
|
@@ -12,74 +12,121 @@ from ..core.utils import coord_element_to_string
|
|
|
12
12
|
from .box import VBar
|
|
13
13
|
|
|
14
14
|
|
|
15
|
+
class DimSlicer(ipw.VBox):
|
|
16
|
+
def __init__(
|
|
17
|
+
self,
|
|
18
|
+
dim: str,
|
|
19
|
+
size: int,
|
|
20
|
+
coord: sc.Variable,
|
|
21
|
+
slider_constr: type[ipw.Widget],
|
|
22
|
+
enable_player: bool = False,
|
|
23
|
+
):
|
|
24
|
+
if enable_player and not issubclass(slider_constr, ipw.IntSlider):
|
|
25
|
+
raise TypeError(
|
|
26
|
+
"Player can only be enabled for IntSlider, not for IntRangeSlider."
|
|
27
|
+
)
|
|
28
|
+
widget_args = {
|
|
29
|
+
'step': 1,
|
|
30
|
+
'description': dim,
|
|
31
|
+
'min': 0,
|
|
32
|
+
'max': size - 1,
|
|
33
|
+
'value': (size - 1) // 2 if slider_constr is ipw.IntSlider else None,
|
|
34
|
+
'continuous_update': True,
|
|
35
|
+
'readout': False,
|
|
36
|
+
'layout': {"width": "200px", "margin": "0px 0px 0px 10px"},
|
|
37
|
+
'style': {'description_width': 'initial'},
|
|
38
|
+
}
|
|
39
|
+
self.slider = slider_constr(**widget_args)
|
|
40
|
+
self.continuous_update = ipw.Checkbox(
|
|
41
|
+
value=True,
|
|
42
|
+
tooltip="Continuous update",
|
|
43
|
+
indent=False,
|
|
44
|
+
layout={"width": "20px"},
|
|
45
|
+
)
|
|
46
|
+
self.label = ipw.Label(
|
|
47
|
+
value=coord_element_to_string(coord[dim, self.slider.value])
|
|
48
|
+
)
|
|
49
|
+
ipw.jslink(
|
|
50
|
+
(self.continuous_update, 'value'), (self.slider, 'continuous_update')
|
|
51
|
+
)
|
|
52
|
+
|
|
53
|
+
children = [self.slider, self.continuous_update, self.label]
|
|
54
|
+
if enable_player:
|
|
55
|
+
self.player = ipw.Play(
|
|
56
|
+
value=self.slider.value,
|
|
57
|
+
min=self.slider.min,
|
|
58
|
+
max=self.slider.max,
|
|
59
|
+
step=self.slider.step,
|
|
60
|
+
interval=100,
|
|
61
|
+
description='Play',
|
|
62
|
+
)
|
|
63
|
+
ipw.jslink((self.player, 'value'), (self.slider, 'value'))
|
|
64
|
+
children.insert(0, self.player)
|
|
65
|
+
|
|
66
|
+
self.dim = dim
|
|
67
|
+
self.coord = coord
|
|
68
|
+
self.slider.observe(self._update_label, names='value')
|
|
69
|
+
|
|
70
|
+
super().__init__([ipw.HBox(children)])
|
|
71
|
+
|
|
72
|
+
def _update_label(self, change: dict[str, Any]):
|
|
73
|
+
"""
|
|
74
|
+
Update the readout label with the coordinate value, instead of the integer
|
|
75
|
+
readout index.
|
|
76
|
+
"""
|
|
77
|
+
self.label.value = coord_element_to_string(self.coord[self.dim, change['new']])
|
|
78
|
+
|
|
79
|
+
@property
|
|
80
|
+
def value(self) -> int | tuple[int, int]:
|
|
81
|
+
"""
|
|
82
|
+
The value of the slider.
|
|
83
|
+
"""
|
|
84
|
+
return self.slider.value
|
|
85
|
+
|
|
86
|
+
@value.setter
|
|
87
|
+
def value(self, value: int | tuple[int, int]):
|
|
88
|
+
self.slider.value = value
|
|
89
|
+
|
|
90
|
+
|
|
15
91
|
class _BaseSliceWidget(VBar, ipw.ValueWidget):
|
|
16
|
-
def __init__(
|
|
92
|
+
def __init__(
|
|
93
|
+
self,
|
|
94
|
+
da: sc.DataArray,
|
|
95
|
+
dims: list[str],
|
|
96
|
+
slider_constr: ipw.Widget,
|
|
97
|
+
enable_player: bool = False,
|
|
98
|
+
):
|
|
17
99
|
if isinstance(dims, str):
|
|
18
100
|
dims = [dims]
|
|
19
|
-
self._slider_dims = dims
|
|
20
101
|
self.controls = {}
|
|
21
102
|
self.view = None
|
|
22
103
|
children = []
|
|
23
104
|
|
|
24
|
-
for dim in
|
|
105
|
+
for dim in dims:
|
|
25
106
|
coord = (
|
|
26
107
|
da.coords[dim]
|
|
27
108
|
if dim in da.coords
|
|
28
109
|
else sc.arange(dim, da.sizes[dim], unit=None)
|
|
29
110
|
)
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
if slider_constr is ipw.IntSlider
|
|
37
|
-
else None,
|
|
38
|
-
'continuous_update': True,
|
|
39
|
-
'readout': False,
|
|
40
|
-
'layout': {"width": "200px"},
|
|
41
|
-
'style': {'description_width': 'initial'},
|
|
42
|
-
}
|
|
43
|
-
slider = slider_constr(**widget_args)
|
|
44
|
-
continuous_update = ipw.Checkbox(
|
|
45
|
-
value=True,
|
|
46
|
-
tooltip="Continuous update",
|
|
47
|
-
indent=False,
|
|
48
|
-
layout={"width": "20px"},
|
|
111
|
+
self.controls[dim] = DimSlicer(
|
|
112
|
+
dim=dim,
|
|
113
|
+
size=da.sizes[dim],
|
|
114
|
+
coord=coord,
|
|
115
|
+
slider_constr=slider_constr,
|
|
116
|
+
enable_player=enable_player,
|
|
49
117
|
)
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
self.controls[dim] = {
|
|
54
|
-
'continuous': continuous_update,
|
|
55
|
-
'slider': slider,
|
|
56
|
-
'label': label,
|
|
57
|
-
'coord': coord,
|
|
58
|
-
}
|
|
59
|
-
slider.observe(self._update_label, names='value')
|
|
60
|
-
slider.observe(self._on_subwidget_change, names='value')
|
|
61
|
-
children.append(ipw.HBox([continuous_update, slider, label]))
|
|
118
|
+
self.controls[dim].slider.observe(self._on_subwidget_change, names='value')
|
|
119
|
+
children.append(self.controls[dim])
|
|
62
120
|
|
|
63
121
|
self._on_subwidget_change()
|
|
64
122
|
super().__init__(children)
|
|
65
123
|
|
|
66
|
-
def _update_label(self, change: dict[str, Any]):
|
|
67
|
-
"""
|
|
68
|
-
Update the readout label with the coordinate value, instead of the integer
|
|
69
|
-
readout index.
|
|
70
|
-
"""
|
|
71
|
-
dim = change['owner'].description
|
|
72
|
-
coord = self.controls[dim]['coord'][dim, change['new']]
|
|
73
|
-
self.controls[dim]['label'].value = coord_element_to_string(coord)
|
|
74
|
-
|
|
75
124
|
def _on_subwidget_change(self, _=None):
|
|
76
125
|
"""
|
|
77
126
|
Update the value of the widget.
|
|
78
127
|
The value is a dict containing one entry per slider, giving the slider's value.
|
|
79
128
|
"""
|
|
80
|
-
self.value = {
|
|
81
|
-
dim: self.controls[dim]['slider'].value for dim in self._slider_dims
|
|
82
|
-
}
|
|
129
|
+
self.value = {dim: slicer.slider.value for dim, slicer in self.controls.items()}
|
|
83
130
|
|
|
84
131
|
|
|
85
132
|
SliceWidget = partial(_BaseSliceWidget, slider_constr=ipw.IntSlider)
|
|
@@ -95,6 +142,10 @@ da:
|
|
|
95
142
|
The input data array.
|
|
96
143
|
dims:
|
|
97
144
|
The dimensions to make sliders for.
|
|
145
|
+
enable_player:
|
|
146
|
+
Add a play button to animate the slider if True. Defaults to False.
|
|
147
|
+
|
|
148
|
+
.. versionadded:: 25.07.0
|
|
98
149
|
"""
|
|
99
150
|
|
|
100
151
|
RangeSliceWidget = partial(_BaseSliceWidget, slider_constr=ipw.IntRangeSlider)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: plopp
|
|
3
|
-
Version: 25.
|
|
3
|
+
Version: 25.7.0
|
|
4
4
|
Summary: Visualization library for Scipp
|
|
5
5
|
Author: Scipp contributors
|
|
6
6
|
License: BSD 3-Clause License
|
|
@@ -84,7 +84,7 @@ Dynamic: license-file
|
|
|
84
84
|
|
|
85
85
|
[](CODE_OF_CONDUCT.md)
|
|
86
86
|
[](https://pypi.python.org/pypi/plopp)
|
|
87
|
-
[](https://anaconda.org/conda-forge/plopp)
|
|
88
88
|
[](https://scipp.github.io/plopp/)
|
|
89
89
|
[](LICENSE)
|
|
90
90
|
[](https://zenodo.org/badge/latestdoi/528859752)
|
|
@@ -25,10 +25,10 @@ plopp/backends/pythreejs/outline.py,sha256=WUqtUj8GMAUzUqOocFjdT8F7WBeV9jgMSYmXD
|
|
|
25
25
|
plopp/backends/pythreejs/scatter3d.py,sha256=Z8D0l3hBJ2qlC4BIAAoHCAa97uf6IViFNt23f9wzFFI,7049
|
|
26
26
|
plopp/core/__init__.py,sha256=s25RIbKplHSRn0jjtLADPQl72JLf_KLRMRCfeMDI_UA,205
|
|
27
27
|
plopp/core/__init__.pyi,sha256=FU5U5nymhzbgBRolZSh1tqYDJ3M2djUv71mriWHD1hI,294
|
|
28
|
-
plopp/core/graph.py,sha256=
|
|
29
|
-
plopp/core/helpers.py,sha256=
|
|
28
|
+
plopp/core/graph.py,sha256=dTJa1QIQDEuDUYZIwF7NT444wkuXxb0wwBrx311vTT8,3855
|
|
29
|
+
plopp/core/helpers.py,sha256=BVunzkcYOXoYjawutFtKP8WbWN1h1OlRrSd_i9TY090,1200
|
|
30
30
|
plopp/core/limits.py,sha256=ojb3MTxlWNz2ibHXu9P-agzYV8HxPCGSB2D0oxoO9RQ,3572
|
|
31
|
-
plopp/core/node_class.py,sha256=
|
|
31
|
+
plopp/core/node_class.py,sha256=Vzjf0f7UTiCVZC8m_dwh2gGPwnJqD0HOR8HuUX5TsDI,7483
|
|
32
32
|
plopp/core/typing.py,sha256=JL_mMdFq2dNu6LuZYSBfOXGZSEn0VIJK_lr-LbC11t4,2903
|
|
33
33
|
plopp/core/utils.py,sha256=qxdOLRODgv3b0dDywT0JomsVrgifS_siC-ZpzJqgblo,7120
|
|
34
34
|
plopp/core/view.py,sha256=9WulgLHg8aPjePz967WLWieTM40dvqlgJitu-AS3WdM,1972
|
|
@@ -43,33 +43,33 @@ plopp/graphics/bbox.py,sha256=3WeMgu5LgWIXLJTYVT7_USwaAcS7cQPNCk6B0gvuNGo,3596
|
|
|
43
43
|
plopp/graphics/camera.py,sha256=fXc1YH7Tp-rwKkcYeE-mHrxMz3SKauj5xJCRuKv-QPs,5323
|
|
44
44
|
plopp/graphics/colormapper.py,sha256=u5cADKU9lrRkJ_a969i_5z-mdT0-lBnEonc0PW_xSXA,9643
|
|
45
45
|
plopp/graphics/figures.py,sha256=PLWQLnQNWz8epubYlK7HLSkvPGJmTAmHjJM2DqpvLe8,2735
|
|
46
|
-
plopp/graphics/graphicalview.py,sha256=
|
|
46
|
+
plopp/graphics/graphicalview.py,sha256=07xpJVnvuNlaWGsJshg_wL81jG57JhRxI23E7_WYI2M,9435
|
|
47
47
|
plopp/graphics/tiled.py,sha256=gXYZVAs6wRFKezzN3VlEvm7_z2zx3IDYfGZQZqrpL80,1386
|
|
48
48
|
plopp/plotting/__init__.py,sha256=s25RIbKplHSRn0jjtLADPQl72JLf_KLRMRCfeMDI_UA,205
|
|
49
49
|
plopp/plotting/__init__.pyi,sha256=95wYGfM5PT0Y0Ov_ue7rBrHvHxrtex-2WEYtfFzBvE0,475
|
|
50
|
-
plopp/plotting/common.py,sha256=
|
|
50
|
+
plopp/plotting/common.py,sha256=dwtOpmMNY8deLWskiByKXficZUqX1pPGrkT_ieDN36c,10984
|
|
51
51
|
plopp/plotting/inspector.py,sha256=fT4v342pqTzihKaweoGD4WaQ5eDdyngK7W451Mh2Ffw,3586
|
|
52
52
|
plopp/plotting/mesh3d.py,sha256=KjAtlVlLYslwgP_uE067WtJRgNURkhaz0PPUuYLlJyw,2778
|
|
53
53
|
plopp/plotting/plot.py,sha256=WQzw1vHGljWY1tQU1InQWe2-M-vCW2IRiL-v7cnw46w,3886
|
|
54
54
|
plopp/plotting/scatter.py,sha256=ybPWFHFwxt_Bzv3Dy-yAFCRHW5HQEggcNihpzWduH7A,3161
|
|
55
55
|
plopp/plotting/scatter3d.py,sha256=oizd-BCgmvNu_fSV6FQt9oe7lPn4h2Zc1ohKmor-d78,3819
|
|
56
|
-
plopp/plotting/slicer.py,sha256=
|
|
56
|
+
plopp/plotting/slicer.py,sha256=ym20mXJtp_msGOet18wr0mb4TL0z4ti6W9uFo_5cvKc,6169
|
|
57
57
|
plopp/plotting/superplot.py,sha256=0EnzgSmNrdPHXooqj6GNR0IAApEHyfjgxYIPgPVO_5o,1416
|
|
58
|
-
plopp/plotting/xyplot.py,sha256=
|
|
58
|
+
plopp/plotting/xyplot.py,sha256=zi-RcsgonnR747aH3zp75at4ntgZ0t0rSdKEeVlReMI,1641
|
|
59
59
|
plopp/widgets/__init__.py,sha256=s25RIbKplHSRn0jjtLADPQl72JLf_KLRMRCfeMDI_UA,205
|
|
60
60
|
plopp/widgets/__init__.pyi,sha256=4hVX7I3VEjE3oy2AGVvguYsIgg7cVrhKGpX7xVgGe9Y,844
|
|
61
61
|
plopp/widgets/box.py,sha256=v5Gd3sY0WXcc3UfkcXxZboPG02sfOMXIo50tmpxPwVs,1806
|
|
62
62
|
plopp/widgets/checkboxes.py,sha256=52yJryEu1upYafFxqoTOdAZmHeKzCI_CJiCWSezCtRA,2430
|
|
63
63
|
plopp/widgets/clip3d.py,sha256=L90HUd3bjEU3BaPdK8DnUbeeFNqfFyBWDEwaG9nP-M8,14602
|
|
64
64
|
plopp/widgets/debounce.py,sha256=V5aIcnb465oqXZX-UG_DR7GjvoG6D_C2jjEUBmguGDA,1292
|
|
65
|
-
plopp/widgets/drawing.py,sha256=
|
|
66
|
-
plopp/widgets/linesave.py,sha256=
|
|
67
|
-
plopp/widgets/slice.py,sha256=
|
|
65
|
+
plopp/widgets/drawing.py,sha256=Pcozffq7I5H9x57GNBJVvkCjVR6eaPBuxyHlFkEEjzQ,6252
|
|
66
|
+
plopp/widgets/linesave.py,sha256=s5QcY-31x7Hvf9iLHmzfFIzodXTD9BX0Av3NlG8GS88,2458
|
|
67
|
+
plopp/widgets/slice.py,sha256=hG1QzLsjmxjY4fjQwtlu8GxK6zzalrZsZxZzhwIaskg,5499
|
|
68
68
|
plopp/widgets/style.py,sha256=Fw4S8te0xDyT8-kWu4Ut35aLgyr98qMlWZRbXbd1-dk,184
|
|
69
69
|
plopp/widgets/toolbar.py,sha256=ueNeOZSC2suAG7nCJzqwl8DmtWD5c2J8VkuP-XzJRwI,4683
|
|
70
70
|
plopp/widgets/tools.py,sha256=9l7LmB8qG0OTt5ZJihJzqRna1ouxJthO_Ahnq7WKTtY,7172
|
|
71
|
-
plopp-25.
|
|
72
|
-
plopp-25.
|
|
73
|
-
plopp-25.
|
|
74
|
-
plopp-25.
|
|
75
|
-
plopp-25.
|
|
71
|
+
plopp-25.7.0.dist-info/licenses/LICENSE,sha256=fCqnkzCwkGneGtgOidkO2b3ed6SGZT0yhuworuJG0K0,1553
|
|
72
|
+
plopp-25.7.0.dist-info/METADATA,sha256=ORDD8s280azbvWqw84HVSpZ9uZ1HoGB8L13Uf7LTyVg,4545
|
|
73
|
+
plopp-25.7.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
74
|
+
plopp-25.7.0.dist-info/top_level.txt,sha256=Lk_GLFh37eX-3PO3c6bPkDpir7GjJmbQHYza3IpIphc,6
|
|
75
|
+
plopp-25.7.0.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|