Skip to content
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

Unable to run the example #33

Closed
JACKCHAN000 opened this issue Jan 14, 2023 · 7 comments
Closed

Unable to run the example #33

JACKCHAN000 opened this issue Jan 14, 2023 · 7 comments

Comments

@JACKCHAN000
Copy link

Hi! I just run the example register_and_merge_cycif.py but it comes up with some error.
I read this #12 before but I have installed the latest version of valis already.
Therefore, I have no idea what the problem is. Any suggestion?

Package version:

valis-wsi                          1.0.0rc12
interpolation                      2.2.4
C:\Users\JACK\anaconda3\lib\site-packages\valis\valtils.py:75: UserWarning: 
  warnings.warn(warning_msg, warning_type)
Traceback (most recent call last):
  File "C:\Users\JACK\anaconda3\lib\site-packages\valis\registration.py", line 3380, in register
    non_rigid_registrar = self.non_rigid_register(rigid_registrar,
  File "C:\Users\JACK\anaconda3\lib\site-packages\valis\registration.py", line 3031, in non_rigid_register
    thumbanil_deform_grid = viz.color_displacement_tri_grid(bk_dx=thumbnail_bk_dxdy[..., 0],
  File "C:\Users\JACK\anaconda3\lib\site-packages\valis\viz.py", line 781, in color_displacement_tri_grid
    warped_xy = warp_tools.warp_xy(tri_verts, bk_dxdy=[padded_dx, padded_dy])
  File "C:\Users\JACK\anaconda3\lib\site-packages\valis\warp_tools.py", line 2176, in warp_xy
    warped_xy = _warp_xy_numpy(xy, M, transformation_src_shape_rc=transformation_src_shape_rc,
  File "C:\Users\JACK\anaconda3\lib\site-packages\valis\warp_tools.py", line 2096, in _warp_xy_numpy
    grid = UCGrid((0.0, float(displacement_shape_rc[1]-1), displacement_shape_rc[1]),
  File "C:\Users\JACK\anaconda3\lib\site-packages\interpolation\splines\__init__.py", line 14, in UCGrid
    assert numba.typeof(a) == tt
AssertionError

JVM has been killed. If this was due to an error, then a new Python session will need to be started
@cdgatenbee
Copy link
Collaborator

Hi @JACKCHAN000,
Thanks for bringing this to my attention. Could you please check which version of numba you are using? I was able to run the example using interpolation 2.2.4 and numba 0.56.4.

Best,
-Chandler

@JACKCHAN000
Copy link
Author

Thank you for your help! I created a new environment and run the example again. It still has the same error.
The interpolation version is 2.2.4 and numba version is still 0.56.4.

Package               Version
--------------------- -----------
beautifulsoup4        4.11.1
bioformats-jar        2020.5.27
certifi               2022.12.7
cffi                  1.15.1
colorama              0.4.6
colour-science        0.4.1
contourpy             1.0.7
cycler                0.11.0
dnspython             2.3.0
elementpath           3.0.2
email-validator       1.3.0
fastcluster           1.2.6
fonttools             4.38.0
idna                  3.4
imageio               2.24.0
importlib-metadata    6.0.0
interpolation         2.2.4
jgo                   1.0.5
joblib                1.2.0
JPype1                1.4.1
kiwisolver            1.4.4
llvmlite              0.39.1
lxml                  4.9.2
matplotlib            3.6.3
networkx              3.0
numba                 0.56.4
numpy                 1.23.5
ome-types             0.3.2
opencv-contrib-python 4.7.0.68
packaging             21.3
pandas                1.5.2
Pillow                9.4.0
Pint                  0.20.1
pip                   22.3.1
psutil                5.9.4
pycparser             2.21
pydantic              1.10.4
pyparsing             3.0.9
python-dateutil       2.8.2
pytz                  2022.7.1
pyvips                2.2.1
PyWavelets            1.4.1
scikit-image          0.19.3
scikit-learn          1.2.0
scipy                 1.10.0
scyjava               1.8.1
setuptools            65.6.3
shapely               2.0.0
SimpleITK             2.2.1
six                   1.16.0
soupsieve             2.3.2.post1
Tempita               0.5.2
threadpoolctl         3.1.0
tifffile              2022.10.10
tqdm                  4.64.1
typing_extensions     4.4.0
valis-wsi             1.0.0rc12
weightedstats         0.4.1
wheel                 0.37.1
wincertstore          0.2
xmlschema             2.1.1
zipp                  3.11.0

@cdgatenbee
Copy link
Collaborator

Hi @JACKCHAN000, that's really strange. The assertion that's being violated appears to be the requirement that a is a tuple containing (float64, float64, int64), and based on the error the tuple passed in should be exactly that (i.e. (0.0, float(displacement_shape_rc[1]-1), displacement_shape_rc[1]), where displacement_shape_rc is just the shape of a numpy array). Could you try the following, and let me know if it works?

import numpy as np
import numba
from interpolation.splines import UCGrid
from valis import warp_tools

dxdy = [np.ones((100, 200)), np.ones((100, 200))]
displacement_shape_rc = dxdy[0].shape[0:2]
tt = numba.typeof((10.0, 1.0, 1))

# Check using numpy array as source for displacement_shape_rc
grid_shape = ((0.0, float(displacement_shape_rc[1]-1), displacement_shape_rc[1]),
              (0.0, float(displacement_shape_rc[0]-1), displacement_shape_rc[0]))

a = grid_shape[0]
numba.typeof(a) == tt # assertion being violated

grid = UCGrid((0.0, float(displacement_shape_rc[1]-1), displacement_shape_rc[1]),
              (0.0, float(displacement_shape_rc[0]-1), displacement_shape_rc[0]))


# Check using pyvips.Image as source for displacement_shape_rc
vips_dxdy = warp_tools.numpy2vips(np.dstack(dxdy))
vips_displacement_shape_rc = np.array([vips_dxdy.height, vips_dxdy.width])

vips_grid_shape = ((0.0, float(vips_displacement_shape_rc[1]-1), vips_displacement_shape_rc[1]),
                   (0.0, float(vips_displacement_shape_rc[0]-1), vips_displacement_shape_rc[0]))

vips_a = vips_grid_shape[0]
numba.typeof(vips_a) == tt # assertion being violated

vips_grid = UCGrid((0.0, float(vips_displacement_shape_rc[1]-1), vips_displacement_shape_rc[1]),
                   (0.0, float(vips_displacement_shape_rc[0]-1), vips_displacement_shape_rc[0]))

Best,
-Chandler

@JACKCHAN000
Copy link
Author

Hi @JACKCHAN000, that's really strange. The assertion that's being violated appears to be the requirement that a is a tuple containing (float64, float64, int64), and based on the error the tuple passed in should be exactly that (i.e. (0.0, float(displacement_shape_rc[1]-1), displacement_shape_rc[1]), where displacement_shape_rc is just the shape of a numpy array). Could you try the following, and let me know if it works?

import numpy as np
import numba
from interpolation.splines import UCGrid
from valis import warp_tools

dxdy = [np.ones((100, 200)), np.ones((100, 200))]
displacement_shape_rc = dxdy[0].shape[0:2]
tt = numba.typeof((10.0, 1.0, 1))

# Check using numpy array as source for displacement_shape_rc
grid_shape = ((0.0, float(displacement_shape_rc[1]-1), displacement_shape_rc[1]),
              (0.0, float(displacement_shape_rc[0]-1), displacement_shape_rc[0]))

a = grid_shape[0]
numba.typeof(a) == tt # assertion being violated

grid = UCGrid((0.0, float(displacement_shape_rc[1]-1), displacement_shape_rc[1]),
              (0.0, float(displacement_shape_rc[0]-1), displacement_shape_rc[0]))


# Check using pyvips.Image as source for displacement_shape_rc
vips_dxdy = warp_tools.numpy2vips(np.dstack(dxdy))
vips_displacement_shape_rc = np.array([vips_dxdy.height, vips_dxdy.width])

vips_grid_shape = ((0.0, float(vips_displacement_shape_rc[1]-1), vips_displacement_shape_rc[1]),
                   (0.0, float(vips_displacement_shape_rc[0]-1), vips_displacement_shape_rc[0]))

vips_a = vips_grid_shape[0]
numba.typeof(vips_a) == tt # assertion being violated

vips_grid = UCGrid((0.0, float(vips_displacement_shape_rc[1]-1), vips_displacement_shape_rc[1]),
                   (0.0, float(vips_displacement_shape_rc[0]-1), vips_displacement_shape_rc[0]))

Best, -Chandler

It raises an error on the last line.

exception: no description
  File "C:\Users\JACK\Desktop\aaa.py", line 32, in <module>
    vips_grid = UCGrid((0.0, float(vips_displacement_shape_rc[1]-1), vips_displacement_shape_rc[1]), (0.0, float(vips_displacement_shape_rc[0]-1), vips_displacement_shape_rc[0]))
AssertionError: 

However, if I change last line into vips_grid = UCGrid((0.0, 199.0, 200),(0.0, 99.0, 100)). It can run without any errors.

@JACKCHAN000
Copy link
Author

vips_grid = UCGrid((0.0, float(vips_displacement_shape_rc[1]-1), vips_displacement_shape_rc[1]),
(0.0, float(vips_displacement_shape_rc[0]-1), vips_displacement_shape_rc[0]))

I change the last line into vips_grid = UCGrid((0.0, float(vips_displacement_shape_rc[1]-1), int(vips_displacement_shape_rc[1])), (0.0, float(vips_displacement_shape_rc[0]-1), int(vips_displacement_shape_rc[0])))
The code can run successfully now.

The vips_displacement_shape_rc[1] here is numpy.int32 not int

@cdgatenbee
Copy link
Collaborator

Hi @JACKCHAN000, thanks for confirming that the issue is that pyvips.Image shape values aren't Python ints, but numpy.ints instead. It's so strange though, as the code above works fine on my Mac. Maybe it's a Windows specific issue? No matter, I'll update the code to fix this bug in the next version (1.0.0rc13), which should be available soon.
Best,
-Chandler

@cdgatenbee
Copy link
Collaborator

Hi @JACKCHAN000,
I've pushed the most recent version of valis that has this bug fixed. I'll close the issue for now, but please reopen it if you continue to have this issue.

Best,
-Chandler

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants