Skip to content

Commit

Permalink
Copy some tests into 'interactive tests'
Browse files Browse the repository at this point in the history
Moving forward the 'tests' directory will be used for unit type tests
that will be run with pytest.  They will use dummy data to test if the
software is functioning right and producing correct values for simulated
cases.

'interactive tests' will be used to test and troubleshoot with real
files.
  • Loading branch information
bnorthan committed Feb 7, 2024
1 parent c65185d commit f3be702
Show file tree
Hide file tree
Showing 7 changed files with 91 additions and 42 deletions.
File renamed without changes.
16 changes: 16 additions & 0 deletions python/interactive tests/test_libs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from clij2fft.libs import getlib
from clij2fft.richardson_lucy import richardson_lucy
import numpy as np


lib = getlib()
lib.print_platforms_and_devices()

img= np.ones((256, 256, 128), dtype=np.float32)
psf = np.ones((128, 128, 64), dtype=np.float32)

result = richardson_lucy(img, psf, 100, 0, platform=0, device=0)
#result = richardson_lucy(img, psf, 100, 0, platform=1, device=0)

print()
print(result.shape, result.mean())
File renamed without changes.
File renamed without changes.
51 changes: 51 additions & 0 deletions python/interactive tests/test_richardson_lucy_dask.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
from clij2fft.richardson_lucy_dask import richardson_lucy_dask
from skimage.io import imread
import numpy as np
from matplotlib import pyplot as plt
import pyopencl as cl
import os

use_ones = False

# we have the option of just using arrays of ones to test that the code runs...
if use_ones:
img = np.ones((256, 256, 128), dtype=np.float32)
psf = np.ones((128, 128, 64), dtype=np.float32)
# ...or we can use real images
else:
clij2fft_images_path = r'/home/bnorthan/images/clij2-fft-images'

img_name=os.path.join(clij2fft_images_path, 'Bars-G10-P15-stack.tif')
psf_name=os.path.join(clij2fft_images_path, 'PSF-Bars-stack.tif')

img=imread(img_name)
print('image shape is',img.shape)
psf=imread(psf_name)

pad_z=50
pad_y=50
pad_x=50
mem_to_use=1

img = np.pad(img, [(pad_z,pad_z),(pad_y, pad_y),(pad_x, pad_x)], mode = 'constant', constant_values = 0)
print('image shape is',img.shape)

platforms = cl.get_platforms()

for platform in platforms:
# print number of devices per platform
print("Platform: {} has {} devices".format(platform.name, len(platform.get_devices())))
for device in platform.get_devices():
print(' ',device)

platform_to_use = 0
decon=richardson_lucy_dask(img, psf, 50, 0.0001, mem_to_use=mem_to_use, platform = 0, num_devices = len(platforms[0].get_devices()), debug = False)

fig, ax = plt.subplots(1,2)
ax[0].imshow(img.max(axis=0))
ax[0].set_title('img')

ax[1].imshow(decon.max(axis=0))
ax[1].set_title('deconvolution')

plt.show()
18 changes: 10 additions & 8 deletions python/tests/test_libs.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@
from clij2fft.richardson_lucy import richardson_lucy
import numpy as np

lib = getlib()
lib.print_platforms_and_devices()

img= np.ones((256, 256, 128), dtype=np.float32)
psf = np.ones((128, 128, 64), dtype=np.float32)
def test_libs():
lib = getlib()
lib.print_platforms_and_devices()

result = richardson_lucy(img, psf, 100, 0, platform=0, device=0)
#result = richardson_lucy(img, psf, 100, 0, platform=1, device=0)
img= np.ones((256, 256, 128), dtype=np.float32)
psf = np.ones((128, 128, 64), dtype=np.float32)

print()
print(result.shape, result.mean())
result = richardson_lucy(img, psf, 100, 0, platform=0, device=0)
#result = richardson_lucy(img, psf, 100, 0, platform=1, device=0)

print()
print(result.shape, result.mean())
48 changes: 14 additions & 34 deletions python/tests/test_richardson_lucy_dask.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,47 +5,27 @@
import pyopencl as cl
import os

use_ones = False
def test_richardson_lucy_dask():

# we have the option of just using arrays of ones to test that the code runs...
if use_ones:
img = np.ones((256, 256, 128), dtype=np.float32)
psf = np.ones((128, 128, 64), dtype=np.float32)
# ...or we can use real images
else:
clij2fft_images_path = r'/home/bnorthan/images/clij2-fft-images'

img_name=os.path.join(clij2fft_images_path, 'Bars-G10-P15-stack.tif')
psf_name=os.path.join(clij2fft_images_path, 'PSF-Bars-stack.tif')
pad_z=50
pad_y=50
pad_x=50
mem_to_use=1

img=imread(img_name)
img = np.pad(img, [(pad_z,pad_z),(pad_y, pad_y),(pad_x, pad_x)], mode = 'constant', constant_values = 0)
print('image shape is',img.shape)
psf=imread(psf_name)

pad_z=50
pad_y=50
pad_x=50
mem_to_use=1
platforms = cl.get_platforms()

img = np.pad(img, [(pad_z,pad_z),(pad_y, pad_y),(pad_x, pad_x)], mode = 'constant', constant_values = 0)
print('image shape is',img.shape)
for platform in platforms:
# print number of devices per platform
print("Platform: {} has {} devices".format(platform.name, len(platform.get_devices())))
for device in platform.get_devices():
print(' ',device)

platforms = cl.get_platforms()
platform_to_use = 0
decon=richardson_lucy_dask(img, psf, 50, 0.0001, mem_to_use=mem_to_use, platform = 0, num_devices = len(platforms[0].get_devices()), debug = False)

for platform in platforms:
# print number of devices per platform
print("Platform: {} has {} devices".format(platform.name, len(platform.get_devices())))
for device in platform.get_devices():
print(' ',device)

platform_to_use = 0
decon=richardson_lucy_dask(img, psf, 50, 0.0001, mem_to_use=mem_to_use, platform = 0, num_devices = len(platforms[0].get_devices()), debug = False)

fig, ax = plt.subplots(1,2)
ax[0].imshow(img.max(axis=0))
ax[0].set_title('img')

ax[1].imshow(decon.max(axis=0))
ax[1].set_title('deconvolution')

plt.show()

0 comments on commit f3be702

Please sign in to comment.