# Loading nrrd data in python Jupyter notebook script

**URL:** <https://discourse.slicer.org/t/loading-nrrd-data-in-python-jupyter-notebook-script/22637>\
**Category:** Development\
**Tags:** python, jupyter, data-loading\
**Created:** [March 22, 2022, 2:01pm UTC](https://discourse.slicer.org/t/loading-nrrd-data-in-python-jupyter-notebook-script/22637 "2022-03-22T14:01:38Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Hanne1234](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/hanne1234/32/14755_2.png) [@Hanne1234](https://discourse.slicer.org/u/Hanne1234)\
**Post date:** [March 22, 2022, 2:01pm UTC](https://discourse.slicer.org/t/loading-nrrd-data-in-python-jupyter-notebook-script/22637/1 "2022-03-22T14:01:38Z")

</div>

Hi,

I am new working with the PyRadiomics package and I have a very basic question. How to load in the data in the Jupyter Notebook script?  
I used 3D slicer to perform a segmentation on a PET image and I want to load this in the PyRadiomics package on python. However, I am not sure where to start with loading the nrrd file. I downloaded the pynrrd package (not even sure if this is necessary) but when I perform ‘import pynrrd’ it already gives the error that there is no module named ‘nrrd’.

So therefore, my question is, what is the first step in loading a dataset?

Thank you!

---

<div class="post-metadata">

**Author:** ![pieper](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/pieper/32/8_2.png) [@pieper](https://discourse.slicer.org/u/pieper)\
**Post date:** [March 22, 2022, 5:19pm UTC](https://discourse.slicer.org/t/loading-nrrd-data-in-python-jupyter-notebook-script/22637/2 "2022-03-22T17:19:24Z")

</div>

> **[pynrrd](https://pypi.org/project/pynrrd/)**
>
> Pure python module for reading and writing NRRD files.

You need to install pynrrd and import 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:** [March 22, 2022, 5:58pm UTC](https://discourse.slicer.org/t/loading-nrrd-data-in-python-jupyter-notebook-script/22637/3 "2022-03-22T17:58:57Z")

</div>

If you want to load a nrrd file into a volume node then you can use [loadVolume function](https://slicer.readthedocs.io/en/latest/developer_guide/script_repository.html#load-volume-from-file).

---

<div class="post-metadata">

**Author:** ![Hanne1234](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/hanne1234/32/14755_2.png) [@Hanne1234](https://discourse.slicer.org/u/Hanne1234)\
**Post date:** [March 27, 2022, 11:32am UTC](https://discourse.slicer.org/t/loading-nrrd-data-in-python-jupyter-notebook-script/22637/4 "2022-03-27T11:32:20Z")

</div>

Thank you for your answer! Is it correct that the load volume function is used in 3D slicer? Since I cannot find a Python package what supports this. I am actually searching for a method that can load the nrrd data files in Python so I can perform feature extraction using PyRadiomics.

---

<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:** [April 2, 2022, 2:17am UTC](https://discourse.slicer.org/t/loading-nrrd-data-in-python-jupyter-notebook-script/22637/5 "2022-04-02T02:17:37Z")

</div>

You can load nrrd images into numpy array without using Slicer using the `pynrrd` or similar package. This is used for example in [slicerio](https://pypi.org/project/slicerio/) for reading segmentations from nrrd files.

---

<div class="post-metadata">

**Author:** ![emma1201](https://avatars.discourse-cdn.com/v4/letter/e/9f8e36/32.png) [@emma1201](https://discourse.slicer.org/u/emma1201)\
**Post date:** [April 9, 2022, 5:17pm UTC](https://discourse.slicer.org/t/loading-nrrd-data-in-python-jupyter-notebook-script/22637/6 "2022-04-09T17:17:54Z")

</div>

Hi Mr Lasso,

Apologies for bringing up an old thread as I am also a Slicer beginner. I am also trying to load an nrrd image into numpy array in Python. However, I am struggling to make sense of the output of the numpy array. What does it mean that I get an array of all 0s and how does one interpret this? I am also not sure what to make of the headers. Do let me know if this is not the appropriate place to post this and if I should try another forum. Thank you! 🙂

 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/6/7/6770abdba912e3cff6619458de1bbcba65002073.png)

---

<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:** [April 9, 2022, 6:18pm UTC](https://discourse.slicer.org/t/loading-nrrd-data-in-python-jupyter-notebook-script/22637/7 "2022-04-09T18:18:30Z")

</div>

You only see the first and last values in a couple of rows and columns. If the image has a black border it is fine to have all zeros there. You can check the minimum and maximum value in the array to see if indeed all you have is zeros.

---

<div class="post-metadata">

**Author:** ![emma1201](https://avatars.discourse-cdn.com/v4/letter/e/9f8e36/32.png) [@emma1201](https://discourse.slicer.org/u/emma1201)\
**Post date:** [April 12, 2022, 4:49pm UTC](https://discourse.slicer.org/t/loading-nrrd-data-in-python-jupyter-notebook-script/22637/8 "2022-04-12T16:49:51Z")

</div>

Thank you so much for the very quick reply!
