-
Notifications
You must be signed in to change notification settings - Fork 53
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
fpl tests #158
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -131,3 +131,7 @@ dmypy.json | |
# Pycharm | ||
.idea/ | ||
|
||
# screenshots for tests | ||
/examples/screenshots | ||
/examples/data | ||
|
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__) |
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__) |
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__) |
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__) |
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__) |
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__) |
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__) |
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__) | ||
|
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() | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
clewis7 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
iw.plot.center_scene() | ||
|
||
clewis7 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
img = np.asarray(iw.renderer.target.draw()) | ||
|
||
#np.save('../screenshots/iw_simple.npy', img) | ||
|
||
if __name__ == "__main__": | ||
print(__doc__) |
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") | ||
clewis7 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
# 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__) |
There was a problem hiding this comment.
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.