Skip to content

bugfixes and more tests #358

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 18 commits into from
Nov 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 0 additions & 2 deletions docs/source/api/graphics/HeatmapGraphic.rst
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ Properties
HeatmapGraphic.position_y
HeatmapGraphic.position_z
HeatmapGraphic.visible
HeatmapGraphic.vmax
HeatmapGraphic.vmin
HeatmapGraphic.world_object

Methods
Expand Down
3 changes: 3 additions & 0 deletions docs/source/api/layouts/gridplot.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ Properties

GridPlot.canvas
GridPlot.renderer
GridPlot.toolbar
GridPlot.widget

Methods
~~~~~~~
Expand All @@ -36,4 +38,5 @@ Methods
GridPlot.remove_animation
GridPlot.render
GridPlot.show
GridPlot.start_render

3 changes: 3 additions & 0 deletions docs/source/api/layouts/plot.rst
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ Properties
Plot.renderer
Plot.scene
Plot.selectors
Plot.toolbar
Plot.viewport
Plot.widget

Methods
~~~~~~~
Expand Down Expand Up @@ -67,4 +69,5 @@ Methods
Plot.set_title
Plot.set_viewport_rect
Plot.show
Plot.start_render

1 change: 1 addition & 0 deletions docs/source/api/selectors/Synchronizer.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,6 @@ Methods
:toctree: Synchronizer_api

Synchronizer.add
Synchronizer.clear
Synchronizer.remove

2 changes: 2 additions & 0 deletions docs/source/api/widgets/ImageWidget.rst
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ Properties
ImageWidget.ndim
ImageWidget.slider_dims
ImageWidget.sliders
ImageWidget.widget
ImageWidget.window_funcs

Methods
Expand All @@ -38,6 +39,7 @@ Methods

ImageWidget.close
ImageWidget.reset_vmin_vmax
ImageWidget.reset_vmin_vmax_frame
ImageWidget.set_data
ImageWidget.show

34 changes: 34 additions & 0 deletions examples/desktop/gridplot/gridplot_non_square.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
"""
GridPlot Simple
============
Example showing simple 2x2 GridPlot with Standard images from imageio.
"""

# test_example = true

import fastplotlib as fpl
import imageio.v3 as iio


plot = fpl.GridPlot(shape=(2, 2), controllers="sync")
# to force a specific framework such as glfw:
# plot = fpl.GridPlot(canvas="glfw")

im = iio.imread("imageio:clock.png")
im2 = iio.imread("imageio:astronaut.png")
im3 = iio.imread("imageio:coffee.png")

plot[0, 0].add_image(data=im)
plot[0, 1].add_image(data=im2)
plot[1, 0].add_image(data=im3)

plot.show()

plot.canvas.set_logical_size(800, 800)

for subplot in plot:
subplot.auto_scale()

if __name__ == "__main__":
print(__doc__)
fpl.run()
Empty file.
37 changes: 37 additions & 0 deletions examples/desktop/heatmap/heatmap.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
"""
Simple Heatmap
==============
Example showing how to plot a heatmap
"""

# test_example = true

import fastplotlib as fpl
import numpy as np

plot = fpl.Plot()
# to force a specific framework such as glfw:
# plot = fpl.Plot(canvas="glfw")

xs = np.linspace(0, 1_000, 10_000)

sine = np.sin(xs)
cosine = np.cos(xs)

# alternating sines and cosines
data = np.zeros((10_000, 10_000), dtype=np.float32)
data[::2] = sine
data[1::2] = cosine

# plot the image data
heatmap_graphic = plot.add_heatmap(data=data, name="heatmap")

plot.show()

plot.canvas.set_logical_size(1500, 1500)

plot.auto_scale()

if __name__ == "__main__":
print(__doc__)
fpl.run()
39 changes: 39 additions & 0 deletions examples/desktop/heatmap/heatmap_cmap.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
"""
Heatmap change cmap
===================
Change the cmap of a heatmap
"""

# test_example = true

import fastplotlib as fpl
import numpy as np

plot = fpl.Plot()
# to force a specific framework such as glfw:
# plot = fpl.Plot(canvas="glfw")

xs = np.linspace(0, 1_000, 10_000)

sine = np.sin(xs)
cosine = np.cos(xs)

# alternating sines and cosines
data = np.zeros((10_000, 10_000), dtype=np.float32)
data[::2] = sine
data[1::2] = cosine

# plot the image data
heatmap_graphic = plot.add_heatmap(data=data, name="heatmap")

plot.show()

plot.canvas.set_logical_size(1500, 1500)

plot.auto_scale()

heatmap_graphic.cmap = "viridis"

if __name__ == "__main__":
print(__doc__)
fpl.run()
41 changes: 41 additions & 0 deletions examples/desktop/heatmap/heatmap_data.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
"""
Heatmap change data
===================
Change the data of a heatmap
"""

# test_example = true

import fastplotlib as fpl
import numpy as np

plot = fpl.Plot()
# to force a specific framework such as glfw:
# plot = fpl.Plot(canvas="glfw")

xs = np.linspace(0, 1_000, 10_000)

sine = np.sin(xs)
cosine = np.cos(xs)

# alternating sines and cosines
data = np.zeros((10_000, 10_000), dtype=np.float32)
data[::2] = sine
data[1::2] = cosine

# plot the image data
heatmap_graphic = plot.add_heatmap(data=data, name="heatmap")

plot.show()

plot.canvas.set_logical_size(1500, 1500)

plot.auto_scale()

heatmap_graphic.data[:5_000] = sine
heatmap_graphic.data[5_000:] = cosine


if __name__ == "__main__":
print(__doc__)
fpl.run()
40 changes: 40 additions & 0 deletions examples/desktop/heatmap/heatmap_vmin_vmax.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
"""
Heatmap change vmin vmax
========================
Change the vmin vmax of a heatmap
"""

# test_example = true

import fastplotlib as fpl
import numpy as np

plot = fpl.Plot()
# to force a specific framework such as glfw:
# plot = fpl.Plot(canvas="glfw")

xs = np.linspace(0, 1_000, 10_000)

sine = np.sin(xs)
cosine = np.cos(xs)

# alternating sines and cosines
data = np.zeros((10_000, 10_000), dtype=np.float32)
data[::2] = sine
data[1::2] = cosine

# plot the image data
heatmap_graphic = plot.add_heatmap(data=data, name="heatmap")

plot.show()

plot.canvas.set_logical_size(1500, 1500)

plot.auto_scale()

heatmap_graphic.cmap.vmin = -0.5
heatmap_graphic.cmap.vmax = 0.5

if __name__ == "__main__":
print(__doc__)
fpl.run()
3 changes: 3 additions & 0 deletions examples/desktop/screenshots/gridplot_non_square.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions examples/desktop/screenshots/heatmap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions examples/desktop/screenshots/heatmap_cmap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions examples/desktop/screenshots/heatmap_data.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions examples/desktop/screenshots/heatmap_vmin_vmax.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions examples/tests/testutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
# examples live in themed sub-folders
example_globs = [
"image/*.py",
"heatmap/*.py",
"scatter/*.py",
"line/*.py",
"line_collection/*.py",
Expand Down
23 changes: 22 additions & 1 deletion fastplotlib/graphics/_features/_colors.py
Original file line number Diff line number Diff line change
Expand Up @@ -401,8 +401,29 @@ class HeatmapCmapFeature(ImageCmapFeature):
"""

def _set(self, cmap_name: str):
# in heatmap we use one material for all ImageTiles
self._parent._material.map.data[:] = make_colors(256, cmap_name)
self._parent._material.map.update_range((0, 0, 0), size=(256, 1, 1))
self.name = cmap_name
self._name = cmap_name

self._feature_changed(key=None, new_data=self.name)

@property
def vmin(self) -> float:
"""Minimum contrast limit."""
return self._parent._material.clim[0]

@vmin.setter
def vmin(self, value: float):
"""Minimum contrast limit."""
self._parent._material.clim = (value, self._parent._material.clim[1])

@property
def vmax(self) -> float:
"""Maximum contrast limit."""
return self._parent._material.clim[1]

@vmax.setter
def vmax(self, value: float):
"""Maximum contrast limit."""
self._parent._material.clim = (self._parent._material.clim[0], value)
20 changes: 0 additions & 20 deletions fastplotlib/graphics/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -480,26 +480,6 @@ def __init__(
# set it with the actual data
self.data = data

@property
def vmin(self) -> float:
"""Minimum contrast limit."""
return self._material.clim[0]

@vmin.setter
def vmin(self, value: float):
"""Minimum contrast limit."""
self._material.clim = (value, self._material.clim[1])

@property
def vmax(self) -> float:
"""Maximum contrast limit."""
return self._material.clim[1]

@vmax.setter
def vmax(self, value: float):
"""Maximum contrast limit."""
self._material.clim = (self._material.clim[0], value)

def set_feature(self, feature: str, new_data: Any, indices: Any):
pass

Expand Down
4 changes: 3 additions & 1 deletion fastplotlib/layouts/_plot_area.py
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,9 @@ def auto_scale(self, maintain_aspect: bool = False, zoom: float = 0.8):
zoom value for the camera after auto-scaling, if zoom = 1.0 then the graphics
in the scene will fill the entire canvas.
"""
# hacky workaround for now until we decided if we want to put selectors in their own scene
if not len(self.scene.children) > 0:
return
# hacky workaround for now until we decide if we want to put selectors in their own scene
# remove all selectors from a scene to calculate scene bbox
for selector in self.selectors:
self.scene.remove(selector.world_object)
Expand Down
3 changes: 0 additions & 3 deletions fastplotlib/widgets/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -869,9 +869,6 @@ def set_data(
# force graphics to update
self.current_index = self.current_index

# if reset_vmin_vmax:
# self.reset_vmin_vmax()

def show(self, toolbar: bool = True, sidecar: bool = False, sidecar_kwargs: dict = None):
"""
Show the widget
Expand Down