Skip to content

fpl tests #158

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

Closed
wants to merge 3 commits into from
Closed
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
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -131,3 +131,7 @@ dmypy.json
# Pycharm
.idea/

# screenshots for tests
/examples/screenshots
/examples/data

40 changes: 40 additions & 0 deletions examples/gridplot/gridplot_cmap.py
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess we can just keep it to make sure accessing graphics within a gridplot works etc.

Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
"""
GridPlot
============

Example showing cmap changes in simple 2x3 GridPlot with pre-saved 512x512 random images.
"""

# test_example = true

from fastplotlib import GridPlot
import numpy as np

from wgpu.gui.offscreen import WgpuCanvas
from pygfx import WgpuRenderer

canvas = WgpuCanvas()
renderer = WgpuRenderer(canvas)

plot = GridPlot(shape=(2,3), canvas=canvas, renderer=renderer)

data = np.load("../data/random.npy")

for subplot in plot:
subplot.add_image(data=data)

plot.show()

for subplot in plot:
subplot.center_scene()

plot[0, 0].graphics[0].cmap = "gray"
plot[0, 2].graphics[0].cmap = "plasma"
plot[1, 2].graphics[0].cmap = "viridis"

img = np.asarray(plot.renderer.target.draw())

#np.save('../screenshots/gridplot_cmap.npy', img)

if __name__ == "__main__":
print(__doc__)
36 changes: 36 additions & 0 deletions examples/gridplot/gridplot_simple.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
"""
GridPlot Simple
============

Example showing simple 2x3 GridPlot with pre-saved 512x512 random images.
"""

# test_example = true

from fastplotlib import GridPlot
import numpy as np

from wgpu.gui.offscreen import WgpuCanvas
from pygfx import WgpuRenderer

canvas = WgpuCanvas()
renderer = WgpuRenderer(canvas)

plot = GridPlot(shape=(2,3), canvas=canvas, renderer=renderer)

data = np.load("../data/random.npy")

for subplot in plot:
subplot.add_image(data=data)

plot.show()

for subplot in plot:
subplot.center_scene()

img = np.asarray(plot.renderer.target.draw())

#np.save('../screenshots/gridplot_simple.npy', img)

if __name__ == "__main__":
print(__doc__)
39 changes: 39 additions & 0 deletions examples/gridplot/gridplot_vminvmax.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
"""
GridPlot
============

Example showing vmin/vmax changes in simple 2x3 GridPlot with pre-saved 512x512 random images.
"""

# test_example = true

from fastplotlib import GridPlot
import numpy as np

from wgpu.gui.offscreen import WgpuCanvas
from pygfx import WgpuRenderer

canvas = WgpuCanvas()
renderer = WgpuRenderer(canvas)

plot = GridPlot(shape=(2,3), canvas=canvas, renderer=renderer)

data = np.load("../data/random.npy")

for subplot in plot:
subplot.add_image(data=data)

plot.show()

for subplot in plot:
subplot.center_scene()

plot[0, 0].graphics[0].vmin = 0.5
plot[0, 0].graphics[0].vmin = 0.75

img = np.asarray(plot.renderer.target.draw())

#np.save('../screenshots/gridplot_vminvmax.npy', img)

if __name__ == "__main__":
print(__doc__)
32 changes: 32 additions & 0 deletions examples/image/cmap.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
"""
Simple Plot
============

Example showing simple plot creation and subsequent cmap change with 512 x 512 pre-saved random image.
"""
# test_example = true

from fastplotlib import Plot
import numpy as np

from wgpu.gui.offscreen import WgpuCanvas
from pygfx import WgpuRenderer

canvas = WgpuCanvas()
renderer = WgpuRenderer(canvas)

plot = Plot(canvas=canvas, renderer=renderer)

data = np.load("../data/random.npy")

# plot the image data
image_graphic = plot.add_image(data=data, name="random-image")

plot.show()

image_graphic.cmap = "viridis"

img = np.asarray(plot.renderer.target.draw())

if __name__ == "__main__":
print(__doc__)
31 changes: 31 additions & 0 deletions examples/image/rgb.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
"""
Simple Plot
============

Example showing the simple plot creation with 512 x 512 2D RGB image.
"""
# test_example = true

from fastplotlib import Plot
import numpy as np
import imageio.v3 as iio

from wgpu.gui.offscreen import WgpuCanvas
from pygfx import WgpuRenderer

canvas = WgpuCanvas()
renderer = WgpuRenderer(canvas)

plot = Plot(canvas=canvas, renderer=renderer)

im = iio.imread("imageio:astronaut.png")

# plot the image data
image_graphic = plot.add_image(data=im, name="iio astronaut")

plot.show()

img = np.asarray(plot.renderer.target.draw())

if __name__ == "__main__":
print(__doc__)
34 changes: 34 additions & 0 deletions examples/image/rgbvminvmax.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
"""
Simple Plot
============

Example showing the simple plot followed by changing the vmin/vmax with 512 x 512 2D RGB image.
"""
# test_example = true

from fastplotlib import Plot
import numpy as np
import imageio.v3 as iio

from wgpu.gui.offscreen import WgpuCanvas
from pygfx import WgpuRenderer

canvas = WgpuCanvas()
renderer = WgpuRenderer(canvas)

plot = Plot(canvas=canvas, renderer=renderer)

im = iio.imread("imageio:astronaut.png")

# plot the image data
image_graphic = plot.add_image(data=im, name="iio astronaut")

plot.show()

image_graphic.vmin = 0.5
image_graphic.vmax = 0.75

img = np.asarray(plot.renderer.target.draw())

if __name__ == "__main__":
print(__doc__)
30 changes: 30 additions & 0 deletions examples/image/simple.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
"""
Simple Plot
============

Example showing the simple plot creation with 512 x 512 pre-saved random image.
"""
# test_example = true

from fastplotlib import Plot
import numpy as np

from wgpu.gui.offscreen import WgpuCanvas
from pygfx import WgpuRenderer

canvas = WgpuCanvas()
renderer = WgpuRenderer(canvas)

plot = Plot(canvas=canvas, renderer=renderer)

data = np.load("../data/random.npy")

# plot the image data
image_graphic = plot.add_image(data=data, name="random-image")

plot.show()

img = np.asarray(plot.renderer.target.draw())

if __name__ == "__main__":
print(__doc__)
34 changes: 34 additions & 0 deletions examples/image/vminvmax.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
"""
Simple Plot
============

Example showing the simple plot creation followed by changing the vmin/vmax with 512 x 512 pre-saved random image.
"""
# test_example = true

from fastplotlib import Plot
import numpy as np

from wgpu.gui.offscreen import WgpuCanvas
from pygfx import WgpuRenderer

canvas = WgpuCanvas()
renderer = WgpuRenderer(canvas)

plot = Plot(canvas=canvas, renderer=renderer)

data = np.load("../data/random.npy")

# plot the image data
image_graphic = plot.add_image(data=data, name="random-image")

plot.show()

image_graphic.vmin = 0.5
image_graphic.vmax = 0.75

img = np.asarray(plot.renderer.target.draw())

if __name__ == "__main__":
print(__doc__)

43 changes: 43 additions & 0 deletions examples/imagewidget/iw_simple.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
"""
ImageWidget Simple
============

Example showing simple ImageWidget with pre-saved 512x512 random image.
"""

# test_example = true

from fastplotlib import ImageWidget
import numpy as np

from wgpu.gui.offscreen import WgpuCanvas
from pygfx import WgpuRenderer

canvas = WgpuCanvas()
renderer = WgpuRenderer(canvas)

a = np.random.rand(500, 512, 512)

data = np.load("../data/random3D.npy")

iw = ImageWidget(
data=data,
slider_dims=["t"],
vmin_vmax_sliders=True,
cmap="gnuplot2"
)

data = np.load("../data/random.npy")

iw.show()

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you test before and after setting timepoint?

set timepoint using the slider as well as @current_index

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

need to think some more about testing image widget, somehow need renderer and canvas to be offscreen as in the other examples

iw["t"] = 250

iw.plot.center_scene()

img = np.asarray(iw.renderer.target.draw())

#np.save('../screenshots/iw_simple.npy', img)

if __name__ == "__main__":
print(__doc__)
56 changes: 56 additions & 0 deletions examples/line/colorslice.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
"""
Line Plot
============

Example showing color slicing with cosine, sine, sinc lines.
"""

# test_example = true

from fastplotlib import Plot
import numpy as np

from wgpu.gui.offscreen import WgpuCanvas
from pygfx import WgpuRenderer

canvas = WgpuCanvas()
renderer = WgpuRenderer(canvas)

plot = Plot(canvas=canvas, renderer=renderer)

sine = np.load("../data/sine.npy")
cosine = np.load("../data/cosine.npy")
sinc = np.load("../data/sinc.npy")

# plot sine wave, use a single color
sine_graphic = plot.add_line(data=sine, thickness=5, colors="magenta")

# you can also use colormaps for lines!
cosine_graphic = plot.add_line(data=cosine, thickness=12, cmap="autumn")

# or a list of colors for each datapoint
colors = ["r"] * 25 + ["purple"] * 25 + ["y"] * 25 + ["b"] * 25
sinc_graphic = plot.add_line(data=sinc, thickness=5, colors=colors)

plot.show()

# indexing of colors
cosine_graphic.colors[:15] = "magenta"
cosine_graphic.colors[90:] = "red"
cosine_graphic.colors[60] = "w"

# indexing to assign colormaps to entire lines or segments
sinc_graphic.cmap[10:50] = "gray"
sine_graphic.cmap = "seismic"

# more complex indexing, set the blue value directly from an array
cosine_graphic.colors[65:90, 0] = np.linspace(0, 1, 90-65)

plot.center_scene()

img = np.asarray(plot.renderer.target.draw())

#np.save('../screenshots/colorslice.npy', img)

if __name__ == "__main__":
print(__doc__)
Loading