Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
1fea4aa
started implementation of ImageWidget, nothing is tested yet
kushalkolar Dec 2, 2022
1bc65a0
basic stuff finished for single plot with a slider, need to test
kushalkolar Dec 2, 2022
6592cc3
basic image widget works
kushalkolar Dec 2, 2022
658f298
docs
kushalkolar Dec 2, 2022
5cc91ae
splitting imagewidget into two classes
kushalkolar Dec 4, 2022
7a6a136
split ImageWidget into ImageWidgetSingle and later ImageWidgetGrid
kushalkolar Dec 4, 2022
7cce91f
combined single and grid ImageWidget into single class
kushalkolar Dec 4, 2022
56a9b1c
simple and grid image widget works, tested with simple args, need to …
kushalkolar Dec 4, 2022
79f4452
catch another user error
kushalkolar Dec 4, 2022
e4f6b12
fix type annotation
kushalkolar Dec 4, 2022
5028ce7
docstrings, started slice_avg implementation
kushalkolar Dec 4, 2022
5ef32eb
slice averaging on single and multiple dimensions works perfectly
kushalkolar Dec 5, 2022
eca6599
is_array() checks for and attr, better error messages
kushalkolar Dec 8, 2022
0e3cf16
rename axis -> dims
kushalkolar Dec 10, 2022
570c076
make most imagewidget methods private, most attributes as read-only p…
kushalkolar Dec 10, 2022
4764b84
quick_min_max() returns pre-computed min max if int or float, imagewi…
kushalkolar Dec 10, 2022
afc0378
vmin vmax for gridplot
kushalkolar Dec 10, 2022
fc3365b
Merge branch 'master' into high-level-widgets
kushalkolar Dec 11, 2022
b1e922c
update Image -> ImageGraphic
kushalkolar Dec 11, 2022
e6c5d3a
refactor, window_funcs now works very well, slow with multiple dims b…
kushalkolar Dec 11, 2022
64faffd
vminmax works, also added names for subplots, everything works
kushalkolar Dec 11, 2022
8fc63b3
proper-ish image widget example
kushalkolar Dec 11, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
basic image widget works
  • Loading branch information
kushalkolar committed Dec 2, 2022
commit 6592cc3a6ea3f678f91cdbdf0e73c0626755b562
1 change: 1 addition & 0 deletions fastplotlib/widgets/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .image import ImageWidget
42 changes: 26 additions & 16 deletions fastplotlib/widgets/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ def calc_gridshape(n):


def get_indexer(ndim: int, dim_index: int, slice_index: int) -> slice:
dim_index = [slice(None)] * ndim
dim_index[dim_index] = slice_index
return tuple(dim_index)
indexer = [slice(None)] * ndim
indexer[dim_index] = slice_index
return tuple(indexer)


class ImageWidget:
Expand All @@ -43,9 +43,9 @@ def __init__(
):
# single image
if isinstance(data, np.ndarray):
self.plot_type = Plot
self.data: List[np.ndarray] = [data]
ndim = data[0].ndim
self.plot_type = Plot
self.data: List[np.ndarray] = [data]
ndim = self.data[0].ndim

# list of lists
elif isinstance(data, list):
Expand All @@ -67,7 +67,7 @@ def __init__(
)

self.data: List[np.ndarray] = data
ndim = data[0].ndim
ndim = self.data[0].ndim

else:
raise TypeError(
Expand All @@ -78,6 +78,13 @@ def __init__(
if axes_order is None:
self.axes_order: List[str] = [DEFAULT_AXES_ORDER[ndim] for i in range(len(data))]

else:
self.axes_order = axes_order

# assume 0 if slider axes is None
if slider_axes is None:
slider_axes = self.axes_order.index("t")

# if a single one is provided
if isinstance(slider_axes, (int, str)):
if isinstance(slider_axes, (int)):
Expand Down Expand Up @@ -114,10 +121,10 @@ def __init__(
# matchup to the given axes_order dict
_axes = [
self.axes_order[array].index(slider_axes[array])
if isinstance(dim_index, str)
else dim_index
for
array, dim_index in slider_axes.items()
if isinstance(dim_index, str)
else dim_index
for
array, dim_index in slider_axes.items()
]

self.sliders: Dict[IntSlider] = {
Expand All @@ -136,30 +143,33 @@ def __init__(
slice_index = get_indexer(ndim, self._slider_axes, slice_index=0)

self.image_graphics: List[Image] = [self.plot.image(
data=data[0][slice_index],
data=self.data[0][slice_index],
**kwargs
)]

self.slider.observe(
lambda x: self.image_graphics[0].update_data(
data[0][
self.data[0][
get_indexer(ndim, self._slider_axes, slice_index=x["new"])
]
),
names="value"
)

self.widget = VBox([self.plot, self.slider])
self.plot.renderer.add_event_handler(self._set_frame_slider_width, "resize")

self.widget = VBox([self.plot.canvas, self.slider])

elif self.plot_type == GridPlot:
pass

def set_frame_slider_width(self):
def _set_frame_slider_width(self, *args):
w, h = self.plot.renderer.logical_size
self.slider.layout = Layout(width=f"{w}px")

def slider_changed(self):
pass

def show(self):
pass
self.plot.show()
return self.widget