what thing do I miss to create volume sequence from tiff

Hi,
I’m new to Slicer and Python
I want to load 512x512x619x9 uint16 data from microscopy into Slicer as volume sequence data.

First, I save ome.tiff as nrrd (C2withmeta.nrrd) via Fiji after I checked the properties.
I tried load it in slicer but it became 512x512x5571.
Then I used python to edit and save nrrd data via CMD.
(Python 3.8.11 (default, Aug 3 2021, 06:49:12) [MSC v.1916 64 bit (AMD64)] :: Anaconda, Inc. on win32)

From this post, I tried to add some header for .seq.nrdd and reshape to make frame as first dimension.

Here are the code

import numpy as np
import nrrd
import os
filename = "~/Desktop/C2nrrd/C2withmeta.nrrd"
filedata, fileheader = nrrd.read(filename)
filedata.shape
(512, 512, 5571)
newdata = filedata.reshape(619,512,512,9)
newheader = {
    'type': 'uint16',
    'encoding': 'raw',
    'endian': 'big',
    'dimension': 4,
    'sizes': [619, 512, 512,9],
    'kinds': ['list', 'domain', 'domain', 'domain'],
    'labels': ['frame', '', '', ''],
    'space': 'right-anterior-superior',
    'space dimension': 3, 
    'space directions': [[0.184687, 0. , 0.  ], [0.   , 0.184687, 0.   ],   [0.   , 0.    , 3.75    ]],
    'space origin': [ 0, 0, 0],
    'space units': ['s','microns', 'microns', 'microns'],
    'measurement frame': [[1., 0., 0.], [0., 1., 0.], [0., 0., 1.]],
    'axis 0 index type': 'numeric',
    'axis 0 index values': tuple(range(0,619))
    }
outname = "~Desktop/C2nrrd/C2new2.nrrd" 
nrrd.write (outname, newdata, newheader)

I tried save .nrrd or .seq.nrrd and tried load them in slicer as volum or sequence, but all failed.
when I load it as sequence, error

Error: Loading ~/Desktop/C2nrrd/C2new.seq.nrrd - Failed to read node C2new_1 (vtkMRMLSequenceNode2) from filename=‘~/Desktop/C2nrrd/C2new.seq.nrrd’

when I load it as volume

Error: Loading ~/Desktop/C2nrrd/C2new.seq.nrrd - load failed.

So I want to know what is the problem?

There are a number of differences between your header fields and the working example looked. Do not add any extra fields (space dimension, sizes, …) and specify space directions, and set axis 0 index vales as a space separated list.

I would recommend to first start with a small volume, for example 62x512x512x9 (it can be a small patch that you cut from the full volume). If it fails then upload the .seq.nrrd file somewhere and I’ll take a look.

Thank your reply, lassoan.

In this post, there is size field and the space directions looks like it is a 4D list.

So I don’t understand this

  1. Where should I put size info in my data?

  2. What should space directions look like?
    [[nan,nan,nan], [0.184687, 0. , 0. ], [0. , 0.184687, 0. ], [0. , 0. , 3.75 ] ?
    or
    [nan], [0.184687, 0. , 0. ], [0. , 0.184687, 0. ], [0. , 0. , 3.75 ] ?

Nowhere. Size is defined by your numpy array.

It should be the same as the working example - with three float('nan') values.

Thank you for reply, lassoan

I found the problem also come from units,
it doesn’t accept others except time,
so I successfully load it in using 'units': "s", "","",""

Yes, you need to follow the nrrd standard - see details here: http://teem.sourceforge.net/nrrd/format.html

Could you post your final, working code snippet for future reference?