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

UnboundLocalError: local variable 'slide_dimensions' referenced before assignment #93

Open
melanieloth opened this issue Jan 17, 2024 · 2 comments

Comments

@melanieloth
Copy link

Hi,

I am trying to register five .tif images by running the following code:

import time
import os
from valis import registration
from valis.slide_io import BioFormatsSlideReader

# the images for this script are all the h and e images
# This script is testing the ordering function for valis
# inital test to make sure that the script was working for registration
slide_src_dir = "./Demo1/"
results_dst_dir = "./01_demo"


# Create a Valis object and use it to register the slides in slide_src_dir
start = time.time()
registrar = registration.Valis(slide_src_dir, results_dst_dir)
registrar_rigid, registrar_nonrigid, error_df = registrar.register(reader_cls=BioFormatsSlideReader)
stop = time.time()
elapsed = stop - start
print(f"regisration time is {elapsed/60} minutes")


# Check results in registered_slide_dst_dir. If they look good, export the registered slides
registered_slide_dst_dir = os.path.join("./01_demo/registered_slides", registrar.name)
#start = time.time()
registrar.warp_and_save_slides(registered_slide_dst_dir)
#stop = time.time()
#elapsed = stop - start
#print(f"saving {registrar.size} slides took {elapsed/60} minutes")



# Shutdown the JVM
registration.kill_jvm()

This code yields the following error:

Exception origin:
  File "/home/mloth/miniconda3/envs/valis_wsi_update/lib/python3.9/site-packages/interpolation/splines/eval_splines.py", line 116, in __eval_spline
    kk = (order).literal_value

  return _eval_cubic(*args)
^M  0%|          | 0/5 [00:00<?, ?it/s]^M 40%|████	| 2/5 [00:00<00:00, 15.57it/s]^M 80%|████████  | 4/5 [00:00<00:00, 12.69it/s]^M100%|██████████| 5/5 [$
^M  0%|          | 0/5 [00:00<?, ?it/s]^M  0%|          | 0/5 [00:00<?, ?it/s]
Traceback (most recent call last):
  File "/home/mloth/Humam/01_demo.py", line 25, in <module>
    registrar.warp_and_save_slides(registered_slide_dst_dir)
  File "/home/mloth/miniconda3/envs/valis_wsi_update/lib/python3.9/site-packages/valis/valtils.py", line 121, in wrapper
    return f(*args, **kwargs)
  File "/home/mloth/miniconda3/envs/valis_wsi_update/lib/python3.9/site-packages/valis/registration.py", line 3789, in warp_and_save_slides
    slide_obj.warp_and_save_slide(dst_f=dst_f, level = level,
  File "/home/mloth/miniconda3/envs/valis_wsi_update/lib/python3.9/site-packages/valis/valtils.py", line 121, in wrapper
    return f(*args, **kwargs)
  File "/home/mloth/miniconda3/envs/valis_wsi_update/lib/python3.9/site-packages/valis/registration.py", line 931, in warp_and_save_slide
    warped_slide = self.warp_slide(level=level, non_rigid=non_rigid,
  File "/home/mloth/miniconda3/envs/valis_wsi_update/lib/python3.9/site-packages/valis/valtils.py", line 121, in wrapper
    return f(*args, **kwargs)
  File "/home/mloth/miniconda3/envs/valis_wsi_update/lib/python3.9/site-packages/valis/registration.py", line 862, in warp_slide
    warped_slide = slide_tools.warp_slide(src_f, M=self.M,
  File "/home/mloth/miniconda3/envs/valis_wsi_update/lib/python3.9/site-packages/valis/slide_tools.py", line 266, in warp_slide
    reader_cls = slide_io.get_slide_reader(src_f, series=series)
  File "/home/mloth/miniconda3/envs/valis_wsi_update/lib/python3.9/site-packages/valis/slide_io.py", line 2003, in get_slide_reader
    is_flattened_tiff, bf_reads_flat = check_flattened_pyramid_tiff(src_f)[0:2]
  File "/home/mloth/miniconda3/envs/valis_wsi_update/lib/python3.9/site-packages/valis/slide_io.py", line 494, in check_flattened_pyramid_tiff
    can_use_bf = bf_levels >= len(slide_dimensions) and bf_channels == n_channels
UnboundLocalError: local variable 'slide_dimensions' referenced before assignment
@cdgatenbee
Copy link
Collaborator

Hi @melanieloth,
Apologies for the delay in getting back to you. I think I'll be removing the interpolation package in the next release (1.0.3), which will hopefully resolve this issue. I've also been working on improving the slide read/write functions, which I think will also solve your other issue. I'll let you know when the new release is available, but I hope to have it out sometime this week.

Best,
-Chandler

@cdgatenbee
Copy link
Collaborator

Hi @melanieloth,
I just pushed the update (1.0.3) that I think will resolve the issues you've been running into. Please try updating valis and let me know if the new version is working better for you.

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