# Loading 4D volume as Sequence using python script

**URL:** <https://discourse.slicer.org/t/loading-4d-volume-as-sequence-using-python-script/13076>\
**Category:** Development\
**Created:** [August 18, 2020, 4:13pm UTC](https://discourse.slicer.org/t/loading-4d-volume-as-sequence-using-python-script/13076 "2020-08-18T16:13:47Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![CJohnson](https://avatars.discourse-cdn.com/v4/letter/c/3be4f8/32.png) [@CJohnson](https://discourse.slicer.org/u/CJohnson)\
**Post date:** [August 18, 2020, 4:13pm UTC](https://discourse.slicer.org/t/loading-4d-volume-as-sequence-using-python-script/13076/1 "2020-08-18T16:13:48Z")

</div>

Operating system: Windows 10  
Slicer version: Slicer 4.11.0  
Expected behavior: Load 4D volume nrrd file as sequence using script  
Actual behavior: volume is loaded as vtkMRMLMultiVolumeNode

Hi All  
I can’t find the right methods to load the 4D volume nrrd file as a Sequence with the vtkMRMLScalarVolumeNode being created in the Subject Hierarchy.

I have the Sequences Extension installed and have saved a multivolume file as a nrrd file. I can load this manually using the Add Data dialog with the “Volume Sequence” option in the description dropdown.

How do I do this using scripting?

---

<div class="post-metadata">

**Author:** ![adamrankin](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/adamrankin/32/155_2.png) [@adamrankin](https://discourse.slicer.org/u/adamrankin)\
**Post date:** [August 18, 2020, 4:21pm UTC](https://discourse.slicer.org/t/loading-4d-volume-as-sequence-using-python-script/13076/2 "2020-08-18T16:21:42Z")

</div>

Is there a `slicer.util.loadSequence` function?

---

<div class="post-metadata">

**Author:** ![CJohnson](https://avatars.discourse-cdn.com/v4/letter/c/3be4f8/32.png) [@CJohnson](https://discourse.slicer.org/u/CJohnson)\
**Post date:** [August 18, 2020, 4:33pm UTC](https://discourse.slicer.org/t/loading-4d-volume-as-sequence-using-python-script/13076/3 "2020-08-18T16:33:30Z")

</div>

Unfortunately there isn’t.

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [August 18, 2020, 4:46pm UTC](https://discourse.slicer.org/t/loading-4d-volume-as-sequence-using-python-script/13076/4 "2020-08-18T16:46:37Z")

</div>

You can use `slicer.util.loadNodeFromFile`. For example:

```
sequenceNode = slicer.util.loadNodeFromFile("c:/tmp/something.seq.nrrd", "SequenceFile")

```

I’ve [added a `slicer.uitil.loadSequence` convenience function](https://github.com/Slicer/Slicer/commit/752f5f9161cf27c830303f26b4bd74feb72669ba) to make this easier to figure out.

---

<div class="post-metadata">

**Author:** ![CJohnson](https://avatars.discourse-cdn.com/v4/letter/c/3be4f8/32.png) [@CJohnson](https://discourse.slicer.org/u/CJohnson)\
**Post date:** [August 18, 2020, 6:10pm UTC](https://discourse.slicer.org/t/loading-4d-volume-as-sequence-using-python-script/13076/5 "2020-08-18T18:10:22Z")

</div>

Typing this into the Python Interactor (as well as my code) gives me a runtime error:

Traceback (most recent call last):  
File “”, line 1, in   
File “C:\Users\Carol\AppData\Local\NA-MIC\Slicer 4.11.0-2019-07-15\bin\Python\slicer\util.py”, line 398, in loadNodeFromFile  
raise RuntimeError(errorMessage)  
RuntimeError: Failed to load node from file: D:\BainesWork…\ImageVolumes\DCE\ShortName.seq.nrrd

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [August 18, 2020, 6:13pm UTC](https://discourse.slicer.org/t/loading-4d-volume-as-sequence-using-python-script/13076/6 "2020-08-18T18:13:21Z")

</div>

Make sure you specify path correctly (using forward-slash, double-backslash, or raw string):

> [@Subprocess.call does not work!](https://discourse.slicer.org/t/subprocess-call-does-not-work/2837/14):
>
> FYI, since backslash (\) is an escape character in Python, you cannot simply use it in a string literal in Python. The easiest is to indicate that you specify a raw string by prepending an r character before the string. This is correct: somePath = r"F:\someFolder\python.exe" If you need to use a regular string then backslash can be entered by typing double-backslash. This is correct: somePath = "F:\\someFolder\\python.exe" You may also use Unix-type separators. This is correct: somePath = …

If you still have issues, upgrade to latest Slicer Preview Release.

---

<div class="post-metadata">

**Author:** ![CJohnson](https://avatars.discourse-cdn.com/v4/letter/c/3be4f8/32.png) [@CJohnson](https://discourse.slicer.org/u/CJohnson)\
**Post date:** [August 18, 2020, 8:36pm UTC](https://discourse.slicer.org/t/loading-4d-volume-as-sequence-using-python-script/13076/7 "2020-08-18T20:36:06Z")

</div>

This does work with the latest nightly version of Slicer.

Thank you.
