# Hdf5 to NRRD to SEQ.NRRD

**URL:** <https://discourse.slicer.org/t/hdf5-to-nrrd-to-seq-nrrd/18277>\
**Category:** Support\
**Tags:** nrrd\
**Created:** [June 22, 2021, 6:13pm UTC](https://discourse.slicer.org/t/hdf5-to-nrrd-to-seq-nrrd/18277 "2021-06-22T18:13:28Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jamal\_K](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/jamal_k/32/11344_2.png) [@Jamal\_K](https://discourse.slicer.org/u/Jamal_K)\
**Post date:** [June 22, 2021, 6:13pm UTC](https://discourse.slicer.org/t/hdf5-to-nrrd-to-seq-nrrd/18277/1 "2021-06-22T18:13:28Z")

</div>

I have an hdf5 4D Volume rendering with 1 dimension begin time. I transformed this file using python into an NRRD for Slicer to read it. I then added the ‘seq’ label to the file as mentioned here ([Documentation/4.10/Extensions/Sequences - Slicer Wiki](https://www.slicer.org/wiki/Documentation/4.10/Extensions/Sequences)) so that it is a sequence.

When I load this data file into Slicer and set it as a sequence it gives me the following error:  
Error: Loading /path/rec07\_61982292\_uint8\_x42y73z304t962\_data.nrrd - Failed to read node rec07\_61982292\_uint8\_x42y73z304t962\_data\_1 (vtkMRMLSequenceNode1) from filename=’/path/rec07\_61982292\_uint8\_x42y73z304t962\_data.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:** [June 22, 2021, 11:58pm UTC](https://discourse.slicer.org/t/hdf5-to-nrrd-to-seq-nrrd/18277/2 "2021-06-22T23:58:50Z")

</div>

Can you copy here the Python code that you used for conversion?  
It would also help a lot if you could share an example nrrd file (upload somewhere and post the link here).

---

<div class="post-metadata">

**Author:** ![Jamal\_K](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/jamal_k/32/11344_2.png) [@Jamal\_K](https://discourse.slicer.org/u/Jamal_K)\
**Post date:** [June 25, 2021, 9:52pm UTC](https://discourse.slicer.org/t/hdf5-to-nrrd-to-seq-nrrd/18277/3 "2021-06-25T21:52:18Z")

</div>

The data I have is for a specific patient so given confidentiality, I cannot share it, however here is the code for a file xyz.hdf5, I tried to print as much info as possible. If there anything else I can provide please tell me to.

```auto
#importing
import h5py
import nrrd
import numpy as np

#Read the hdf5 file
f = h5py.File('xyz.hdf5','r')
print('File name is:')
print(f.name)

print('File keys are:')
print(list(f.keys()))

```

Out:  
File name is:  
/  
File keys are:  
[‘volume’]

```auto
#Slicing file into ndarray
data = f['volume'][:10]
print(data.shape)

```

Out:  
(10, 42, 73, 304)

```auto
#Copying data to NRRD file (readable by Slicer)
f_nrrd_name = 'xyz.nrrd'
nrrd.write(f_nrrd_name, data, index_order = 'C')
# Read the data back from file
readdata, header = nrrd.read(f_nrrd_name)
print(readdata.shape)

```

Out:  
(304, 73, 42, 10)

---

<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:** [June 25, 2021, 10:23pm UTC](https://discourse.slicer.org/t/hdf5-to-nrrd-to-seq-nrrd/18277/4 "2021-06-25T22:23:02Z")

</div>

You can write a valid seq.nrrd file from an `img` numpy array of size `(26, 102, 102, 61)` (corresponds to number of volumes, colums, rows, slices):

```python
import nrrd
header = {
    'type': 'int',
    'dimension': 4,
    'space': 'right-anterior-superior',
    'space directions': [[float('nan'), float('nan'), float('nan')], [1.953125, 0. , 0.], [0. , 1.953125, 0.], [0. , 0. , 1.953125]],
    'kinds': ['list', 'domain', 'domain', 'domain'],
    'labels': ['frame', '', '', ''], 
    'endian': 'little',
    'encoding': 'raw',
    'space origin': [-137.16099548, -36.80649948, -309.71899414],
    'measurement frame': [[1., 0., 0.], [0., 1., 0.], [0., 0., 1.]],
    'axis 0 index type': 'numeric',
    'axis 0 index values': '0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25'
}
nrrd.write("c:/tmp/test.seq.nrrd", img, header)

```
