niivue / ipyniivue

A WebGL-powered Jupyter Widget for Niivue based on anywidget
BSD 2-Clause "Simplified" License
25 stars 8 forks source link

Argument of set_volume not being taken into account. #18

Closed christian-oreilly closed 1 year ago

christian-oreilly commented 1 year ago

The path of the volume passed to the Niivue.set_volume seems to have no effect. For example:

image

As expected, I suppose, for this example from the doc. But now look at this example:

image
AnthonyAndroulakis commented 1 year ago

Interesting. I'll test this out today and get back to you. Also, set_volume is a temporary function (currently used for testing on_change callbacks).

christian-oreilly commented 1 year ago

Thanks for the feedback. If it is intended as a temporary function, what is the function that is expected in long run to be used to load the data that we want to work with?

AnthonyAndroulakis commented 1 year ago

add_volume_from_url would be the similar function:

import ipyniivue
nv = ipyniivue.Niivue()
nv.add_volume_from_url("https://niivue.github.io/niivue/images/mni152.nii.gz")
christian-oreilly commented 1 year ago

That is fine, but most neuroimaging work is not done on the web but on local computer (or on the local file system of a cluster). I'd personally consider loading a volume from a local system an "essential feature" and loading a file from a URL only a "nice to have" feature.

hanayik commented 1 year ago

@AnthonyAndroulakis and @christian-oreilly , add_volume_from_url should also be able to load a volume from the users's file system.

For example, you can see how I do it here using a local nodejs server in the niivue desktop app. I thought that we could do something similar in python. You can see how AFNI do this using Flask in python here

AnthonyAndroulakis commented 1 year ago

Sounds good. I'll look into it. It might be possible to just read the data and pass that data into Niivue? It's a planned feature to be able to load in an image from data or nibabel.Nifti1Image object (see nilearn).

christian-oreilly commented 1 year ago

I don't mind if, behind the scene, everything is loaded as url, with local files being served through a server (I trust your opinion on potential performance issues) but from a usability point of view, I think we would need to abstract this from the user (i.e., I don't think the user should have to worry about setting a local file server for typical workflows; this should probably be done under the hood and the local path provided by the user be translated automatically). Then, the set_volume function can just be a thin layer of abstraction using add_volume_from_url for the heavy lifting. WOuld that make sens to you @AnthonyAndroulakis and @hanayik ?

AnthonyAndroulakis commented 1 year ago

I agree that the set_volume function can just be a thin layer of abstraction that uses add_volume_from_url.

Instead of hosting files on a server perhaps we can use NVImage.loadFromBase64?

AnthonyAndroulakis commented 1 year ago

I replaced the set_volume function with an add_volume function. This function takes in 1 input: the location of the file. This can either be a url or a local file. Examples:

import ipyniivue
w = ipyniivue.Niivue(crosshair_color=[0,1,0,1])
w.add_volume('https://niivue.github.io/niivue/images/mni152.nii.gz')
display(w)
import ipyniivue
w = ipyniivue.Niivue(crosshair_color=[0,1,0,1])
w.add_volume('/Users/anthony/Downloads/CT_pitch.nii.gz')
display(w)

This add_volume function also accepts file urls, like file:///Users/anthony/Downloads/CT_pitch.nii.gz

AnthonyAndroulakis commented 1 year ago

closing as solved