# CLI module that outputs multiple volumes

**URL:** <https://discourse.slicer.org/t/cli-module-that-outputs-multiple-volumes/7309>\
**Category:** Development\
**Created:** [June 25, 2019, 10:42pm UTC](https://discourse.slicer.org/t/cli-module-that-outputs-multiple-volumes/7309 "2019-06-25T22:42:56Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![kmanduca](https://avatars.discourse-cdn.com/v4/letter/k/58956e/32.png) [@kmanduca](https://discourse.slicer.org/u/kmanduca)\
**Post date:** [June 25, 2019, 10:42pm UTC](https://discourse.slicer.org/t/cli-module-that-outputs-multiple-volumes/7309/1 "2019-06-25T22:42:56Z")

</div>

Operating system: linux  
Slicer version: 4.10.1  
Expected behavior: create 3 volumes from a CLI module  
Actual behavior: Slicer crashes

We’re trying to create a CLI module that reads from a directory of dicom files and outputs a DWI volume, a scalar volume, and a label map volume for the data set. The module loads and runs without error, but Slicer crashes after the module finishes before displaying any of the volumes.

Initially, we tried this with the CLI taking the directory as input and returning a single scalar volume, which worked as expected.

How can we create three volumes, including display properties for each, and return them from a CLI module?

Our XML definition file looks like:  
\<?xml version="1.0" encoding="utf-8"?\>  
  
phantom  
phantom\_cli  
  
[http://www.example.com/Slicer/Modules/phantom\_cli](http://www.example.com/Slicer/Modules/phantom_cli)  
Slicer  
…  
…  
  
IO  
  
  
inputDir  
Input Directory  
input  
0  
  
  
  
outputDWIVolume  
Output DWI Volume  
output  
1  
  
  
  
outputVolume  
Output Scalar Volume  
output  
2  
  
  
  
outputVOIVolume  
Output Label Map Volume  
output  
3

Thanks.

---

<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 26, 2019, 2:25am UTC](https://discourse.slicer.org/t/cli-module-that-outputs-multiple-volumes/7309/2 "2019-06-26T02:25:22Z")

</div>

Most likely one of the volumes is invalid. If I remember correctly, an invalid DWI volume can force Slicer to crash, so I would have a closer look at that first.

Enable “Developer mode” in Slicer application settings to make Slicer keep CLI input and output files (normally they are deleted when CLI execution is completed) and check if you can make Slicer crash by loading them manually (using menu: File / Add data).

---

<div class="post-metadata">

**Author:** ![kmanduca](https://avatars.discourse-cdn.com/v4/letter/k/58956e/32.png) [@kmanduca](https://discourse.slicer.org/u/kmanduca)\
**Post date:** [June 27, 2019, 8:39pm UTC](https://discourse.slicer.org/t/cli-module-that-outputs-multiple-volumes/7309/3 "2019-06-27T20:39:21Z")

</div>

Thanks for the reply, I’ve been looking specifically at the DWI volume:

If you open Slicer and run the CLI it runs without error, but displays this line several times before Slicer crashes:

```
Input port 0 of algorithm vtkImageExtractComponents(0x8fdd970) has 0 connections but is not optional.

```

If you then restart Slicer and load the DWI volume through ‘Add data’ it loads without error, but if you try to show it in the 3D display it does this (without crashing):

```
Failed to determine texture parameters. IF=0 F=6407 T=5121

```

The other nodes (Scalar and Label Map) both load without error and display normally. If you’ve been using Slicer with other modules, and then try to run the CLI it doesn’t crash and displays the Scalar Volume and the Label Map Volume, but when you try to display the DWI Volume it doesn’t update the display.

Our python code creating the DWI reads:

> ```
> dwi_out = slicer.vtkMRMLNRRDStorageNode()
> dwi_out.SetFileName(args.outputDWIVolume) 
> 
> dwi_node = mrml.vtkMRMLDiffusionWeightedVolumeNode()
> slicer.util.updateVolumeFromArray(dwi_node, dwi_array) # dwi_array is created elsewhere and has shape 
> 
> # Update RAS matrix
> ijktoras = vtk.vtkMatrix4x4()
> ijktoras.SetElement(2,2,-1)
> dwi_node.SetIJKToRASMatrix(ijktoras)
> 
> # Update origin and spacing
> origin = (cs.pixel_x0_left_cm * -10, cs.pixel_y0_posterior_cm * -10, cs.min_superior_cm * -10)
> spacing = (cs.pixel_spacing_cm * 10, cs.pixel_spacing_cm * 10, cs.spacing_between_slices_cm * 10)
> dwi_node.SetOrigin(origin)
> dwi_node.SetSpacing(spacing)
> 
> dwi_node.Modified()
> dwi_out.WriteData(dwi_node)
> 
> ```

The scalar volume and label map are created with identical calls (except the type of volume node). Are we missing something in creating the DWI volume?

---

<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 28, 2019, 10:28pm UTC](https://discourse.slicer.org/t/cli-module-that-outputs-multiple-volumes/7309/4 "2019-06-28T22:28:06Z")

</div>

DWI volume is much harder to create correctly. I would suggest to compare the file that you create to the DWI volume in SampleData module and make sure they are in the exact same format.
