Python script : Time series of 4D volume & loading synchronized nodes

valery
Fri, 23 Apr 2021 12:26:54 +0000
Support

Hello,

I’m playing with 4D data format and Slicer. I found lots of information on the forum but I’m looking for additional details.

The final objective.

To load multiple 4D nifti volume (3D+time) in the sequence module and synchronise them to plot for instance the 1D profil of all datasets together. Such routine have to be done with the python script.

The current workflow.

a) conversion of the 4D nifti in nrrd file that is the format dedicated to handle 4D data in slicer. I used the multivolume importer. [OK]
b) save the data as an nrrd. [OK] Reloading the nrrd file and plotting them work using the multivolume explorer [OK]
c) Load the nrrd file as a sequence node, as suggested here [OK] link
d) load the nrrd file as synchronized node in the sequence module ?

The questions

In a) I have a warning message for

    Warning: /home/vozenne/Test_D_0.5_Q_0.75.nii.gz does not have TimeSeries intent, instead it has "Nothing"
Trying to read as TimeSeries anyway

That’s expected becasue the nifti format only specify the “spacing” of each direction. The 4th dimension being the time but to my knowledge, there is no specific time header per image in nifti.

Q1: Is it possible to fill the TimeSeries information inside slicer ?

Q2: Is it possible to change the name of the node, or to change the name of sequence node using python ?

Q3 While step a), b) and c) is working , the code create two sequences (this is normal) but I wish to have one sequence with synchronized nodes, do you have any example in python for such feature ?

Thanks in advance
Best
Valéry

I put the code below

import numpy as np
import os

import MultiVolumeImporter

importer = MultiVolumeImporter.MultiVolumeImporterWidget()

mvNode1 = slicer.mrmlScene.CreateNodeByClass('vtkMRMLMultiVolumeNode')
slicer.mrmlScene.AddNode(mvNode1)
niiFilePath ="/home/vozenne/Test_D_0.5_Q_0.5.nii.gz"
importer.read4DNIfTI(mvNode1, niiFilePath)
slicer.util.saveNode(mvNode1 , "/home/vozenne/Test_D_0.5_Q_0.5.nrrd")


mvNode2 = slicer.mrmlScene.CreateNodeByClass('vtkMRMLMultiVolumeNode')
slicer.mrmlScene.AddNode(mvNode2)
niiFilePath ="/home/vozenne/Test_D_1_Q_1.nii.gz"
importer.read4DNIfTI(mvNode2, niiFilePath)
slicer.util.saveNode(mvNode2 , "/home/vozenne/Test_D_1_Q_1.nrrd")

# see https://discourse.slicer.org/t/loading-4d-volume-as-sequence-using-python-script/13076/4
sequenceNode1 = slicer.util.loadNodeFromFile("/home/vozenne/Test_D_0.5_Q_0.5.nrrd", "SequenceFile")
sequenceNode2 = slicer.util.loadNodeFromFile("/home/vozenne/Test_D_1_Q_1.nrrd", "SequenceFile")
#exit()

5 posts - 2 participants