SlicerDMRI / whitematteranalysis

White matter tractography clustering and more...
https://dmri.slicer.org/whitematteranalysis/
Other
69 stars 34 forks source link

wm_harden_transform.py error: Could not load polydata file #230

Closed jennydaman closed 10 months ago

jennydaman commented 10 months ago

With the most recent version of whitematteranalysis, Slicer v5.6.1, and Python 3.9, I am getting the error when running wm_harden_transform.py:

wm_harden_transform.py -t path/to/dHCP_enlarge1.5.tfm input/dir/ output/dir/ /path/to/Slicer-5.6.1-linux-amd64/Slicer 

The command produces output/dir/log.txt which contains:

Could not load polydata file: input/dir/data.vtk

Using a container I installed 9d24e5e832ceb02ef0fce47f1089774e8e47d407 with Python 2.7 and Slicer v4.10.2. This older version of wm_harden_transform.py worked. See https://github.com/FNNDSC/ukftractography-container/blob/463efdc6738da3a89cb4aa9d096fa59280623ef4/Dockerfile

jhlegarreta commented 10 months ago

Using the current master commit (165cfcd) , 3D Slicer 5.2.2 and Pyhon 3.10 (sorry, I do not have all versions installed), and both *.vtk (file downloaded from https://github.com/Slicer/slicer.kitware.com-midas3-archive/releases/download/SHA256/06d5b5777915857fbac7b3cbd9c371523d1371f29b0c89eb7a33d86d780d5b2b, tract1.vtk) and *.vtp tractography files the command succeeds without issues on an Ubuntu 22.04 machine.

So there is maybe some change across 3D Slicer versions concerning how tractography files are dealt with.

You may want to look into that direction and hopefully propose a fix.

jennydaman commented 10 months ago

@jhlegarreta thanks for taking a look. I am getting the same error as before, running https://github.com/SlicerDMRI/whitematteranalysis/commit/165cfcdb321adf7177938d7c2f6723500cc4c9eb, Python 3.10, Slicer 5.2.2, Ubuntu 22.04.3.

Could you clarify how you've downloaded the example data? Here's what I did:

wget -O trac1.vtk https://github.com/Slicer/slicer.kitware.com-midas3-archive/releases/download/SHA256/06d5b5777915857fbac7b3cbd9c371523d1371f29b0c89eb7a33d86d780d5b2b
jennydaman commented 10 months ago

I see the error is being raised on these lines:

https://github.com/SlicerDMRI/whitematteranalysis/blob/165cfcdb321adf7177938d7c2f6723500cc4c9eb/bin/harden_transform_with_slicer.py#L20C5-L23

Using the Slicer-5.2.2 Python console I tried:

Python 3.9.10 (main, Feb 22 2023, 05:49:21) 
[GCC 7.3.1 20180303 (Red Hat 7.3.1-5)] on linux2
>>> import slicer.util
>>> polydata = 'trac1.vtk'
>>> check_load, polydata_node = slicer.util.loadFiberBundle(str(polydata), 1)
[Python] loadNodeFromFile `returnNode` argument is deprecated. Loaded node is now returned directly if `returnNode` is not specified.
>>> check_load
False
>>> 

Comparing the code to 9d24e5e832ceb02ef0fce47f1089774e8e47d407 I see slicer.util.loadModel is called instead of slicer.util.loadFiberBundle

https://github.com/SlicerDMRI/whitematteranalysis/blob/9d24e5e832ceb02ef0fce47f1089774e8e47d407/bin/harden_transform_with_slicer.py#L38-L41

The function slicer.util.loadModel did work for me in Slicer versions 5.2.2, 5.6.1, and 4.10.2.

BTW the context here is I'm acting as a pet bioinformatician to a collaborator. I have zero experience with Slicer and won't be able to contribute beyond troubleshooting, sorry...

jhlegarreta commented 10 months ago

Could you clarify how you've downloaded the example data? Here's what I did:

wget with the given URL or copy and paste the URL in your browser. Rename the file to tract1.vtk.

Using the 3D Slicer 5.2.2 Python Console:

Python 3.9.10 (main, Feb 22 2023, 05:49:21) 
[GCC 7.3.1 20180303 (Red Hat 7.3.1-5)] on linux2
>>> polydata = '/my/path/to/tract1.vtk'
>>> check_load, polydata_node = slicer.util.loadFiberBundle(str(polydata), 1) # no need to str() though; `polydata` is an str
[Python] loadNodeFromFile `returnNode` argument is deprecated. Loaded node is now returned directly if `returnNode` is not specified.
>>> check_load
True

or

>>> polydata = '/my/path/to/tract1.vtk'
>>> polydata_node = slicer.util.loadFiberBundle(polydata)

And I effectively see the fiber bundle having been loaded to 3D Slicer's 3D window/scene in both cases.

The deprecation message is just that, a message. Harmless in this case/so far.

The function slicer.util.loadModel did work for me in Slicer versions 5.2.2, 5.6.1, and 4.10.2.

There is a PR in 3D Slicer that would ensure that slicer.util.loadFiberBundle works as expected: https://github.com/Slicer/Slicer/pull/7375

It has been there for some time. You may want to add a comment to the PR stating that, as a user of both 3D Slicer and SlicerDMRI, and belonging to a lab that is an important user of both tools, you think the test is useful and should be merged as soon as possible. You may want to tag maintainers and other relevant actors in that PR.

BTW the context here is I'm acting as a pet bioinformatician to a collaborator. I have zero experience with Slicer and won't be able to contribute beyond troubleshooting, sorry...

My resources, bandwidth, and time I can devote to this project are similarly limited.

jennydaman commented 10 months ago

@jhlegarreta thanks for sharing the link to https://github.com/Slicer/Slicer/pull/7375. From the diff I saw that it is required for the SlicerDMRI extension to be installed in order for slicer.util.loadFiberBundle to work.

Would you mind adding a note to the README.md?

jhlegarreta commented 10 months ago

Would you mind adding a note to the README.md?

It was requested to be a warning in the method docstring: https://github.com/Slicer/Slicer/pull/7375#discussion_r1426205864

jhlegarreta commented 10 months ago

@jennydaman Can this issue be closed then?

jennydaman commented 10 months ago

Sure

AlbertoImg commented 4 months ago

Hi there, I am getting similar error when using harden_transform_with_slicer.py and slicer.util.loadFiberBundle. Do you know if the tracts in *.vtp format are working in the current version?

CODE Slicer-5.2.0-linux-amd64/Slicer --python-script $(which harden_transform_with_slicer.py) tracts_pp/FiberClustering/OutlierRemovedClusters/tracts_pp_reg_outlier_removed tracts_pp/TractRegistration/tracts_pp/output_tractography/itk_txform_tracts_pp.tfm 1 tracts_pp/FiberClustering/TransformedClusters/tracts_pp --testing --no-splash --no-main-window

OUTPUT qSlicerMarkupsModulePrivate::addToolBar: no main window is available, toolbar is not added qSlicerSequencesModulePrivate::addToolBar: no main window is available, toolbar is not added Could not load polydata file: tracts_pp/FiberClustering/OutlierRemovedClusters/tracts_pp_reg_outlier_removed/cluster_00001.vtp

Thanks Best Alberto