Closed christian-oreilly closed 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).
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?
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")
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.
@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
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).
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 ?
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?
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
closing as solved
The path of the volume passed to the
Niivue.set_volume
seems to have no effect. For example:As expected, I suppose, for this example from the doc. But now look at this example: