Slicelet

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Slicelet

Felix
Dear slicer users,

I'm trying to execute a python script which load a few .nii files and saves
the whole scene as single mrb file. This is done because other users will
remotely download from the XNAT server using the xnat gateway.

 If I use slicer --no-main-window --phython-script sceneComposer.py
inputFile1.nii inputFile2.nii ROI.nii output.mrb > log.txt. Nothing happens
and two processes (slicer.exe and slicerApp-real.exe) remain alive even when
the commandline exited from the execution.

If I don't use --no-main-window I can see the nifti loaded. But the script
does not finishes its execution because neither mrml file + Data folder
appears nor mrb file are created.

If I execute the script step by step in the python interactor it seems to
work properly.

This is the script:

# -*- coding: utf-8 -*-
import sys
import vtk
import slicer
import os
import shutil

#Create tree
mrml = slicer.vtkMRMLScene()
vl = slicer.vtkSlicerVolumesLogic()
vl.SetAndObserveMRMLScene(mrml)

#Load volumes/ROI
for argument in range(3,len(sys.argv)-1):
        if sys.argv[argument]=='ROI.nii':
                print(sys.argv[argument] + ' as labelmap')
                slicer.util.loadLabelVolume(sys.argv[argument])
        else:
                print(sys.argv[argument] + ' as volume')
                slicer.util.loadVolume(sys.argv[argument])

#Create folder
tempDir =os.path.join(os.getcwd(), 'sceneData')
os.mkdir(tempDir)

#Save scene
l = slicer.app.applicationLogic()
l.SaveSceneToSlicerDataBundleDirectory(tempDir)

print('Compressing' + tempDir)
slicer.app.applicationLogic().Zip(sys.argv[len(sys.argv)-1], str(tempDir))

exit()


Does any of you have an idea about why it does not work when I run it from
commandline?



--
View this message in context: http://slicer-users.65878.n3.nabble.com/Slicelet-tp4031398.html
Sent from the slicer-users mailing list archive at Nabble.com.
_______________________________________________
slicer-users mailing list
[hidden email]
http://massmail.spl.harvard.edu/mailman/listinfo/slicer-users
To unsubscribe: send email to [hidden email] with unsubscribe as the subject
http://www.slicer.org/slicerWiki/index.php/Documentation/4.3/FAQ
Reply | Threaded
Open this post in threaded view
|

Re: Slicelet

Andras Lasso-2
I'm not sure if you can pass arguments to a python script like that. You can specify input files if you use --python-code argument. For example:

"c:\Program Files\Slicer 4.2.0-2013-04-30\Slicer.exe" --testing --no-splash --no-main-window --ignore-slicerrc --python-code "import RegisterRtImages; logic=RegisterRtImages.RegisterRtImagesLogic(); logic.computeMriToMriTranslation('1.nrrd','2.nrrd','result.txt');"

Some more examples:
https://app.assembla.com/spaces/slicerrt/subversion/source/HEAD/trunk/SlicerRt/sandbox/SliceletTest

Andras

-----Original Message-----
From: slicer-users [mailto:[hidden email]] On Behalf Of Felix
Sent: December 7, 2016 15:23
To: SPL Slicer Users <[hidden email]>
Subject: [slicer-users] Slicelet

Dear slicer users,

I'm trying to execute a python script which load a few .nii files and saves the whole scene as single mrb file. This is done because other users will remotely download from the XNAT server using the xnat gateway.

 If I use slicer --no-main-window --phython-script sceneComposer.py inputFile1.nii inputFile2.nii ROI.nii output.mrb > log.txt. Nothing happens and two processes (slicer.exe and slicerApp-real.exe) remain alive even when the commandline exited from the execution.

If I don't use --no-main-window I can see the nifti loaded. But the script does not finishes its execution because neither mrml file + Data folder appears nor mrb file are created.

If I execute the script step by step in the python interactor it seems to work properly.

This is the script:

# -*- coding: utf-8 -*-
import sys
import vtk
import slicer
import os
import shutil

#Create tree
mrml = slicer.vtkMRMLScene()
vl = slicer.vtkSlicerVolumesLogic()
vl.SetAndObserveMRMLScene(mrml)

#Load volumes/ROI
for argument in range(3,len(sys.argv)-1):
        if sys.argv[argument]=='ROI.nii':
                print(sys.argv[argument] + ' as labelmap')
                slicer.util.loadLabelVolume(sys.argv[argument])
        else:
                print(sys.argv[argument] + ' as volume')
                slicer.util.loadVolume(sys.argv[argument])

#Create folder
tempDir =os.path.join(os.getcwd(), 'sceneData')
os.mkdir(tempDir)

#Save scene
l = slicer.app.applicationLogic()
l.SaveSceneToSlicerDataBundleDirectory(tempDir)

print('Compressing' + tempDir)
slicer.app.applicationLogic().Zip(sys.argv[len(sys.argv)-1], str(tempDir))

exit()


Does any of you have an idea about why it does not work when I run it from commandline?



--
View this message in context: http://slicer-users.65878.n3.nabble.com/Slicelet-tp4031398.html
Sent from the slicer-users mailing list archive at Nabble.com.
_______________________________________________
slicer-users mailing list
[hidden email]
http://massmail.spl.harvard.edu/mailman/listinfo/slicer-users
To unsubscribe: send email to [hidden email] with unsubscribe as the subject http://www.slicer.org/slicerWiki/index.php/Documentation/4.3/FAQ
_______________________________________________
slicer-users mailing list
[hidden email]
http://massmail.spl.harvard.edu/mailman/listinfo/slicer-users
To unsubscribe: send email to [hidden email] with unsubscribe as the subject
http://www.slicer.org/slicerWiki/index.php/Documentation/4.3/FAQ
Reply | Threaded
Open this post in threaded view
|

Re: Slicelet

Csaba Pinter-2
Hi Felix,

You can use this module as example to see how to pass arguments to a python script
https://github.com/SlicerRt/SlicerRT/tree/master/BatchProcessing
Also I believe it works without the main window.

To reduce confusion: your program is not a slicelet, just a python script that uses Slicer functions, so is the referenced one above.

csaba

-----Original Message-----
From: slicer-users [mailto:[hidden email]] On Behalf Of Andras Lasso
Sent: Wednesday, December 7, 2016 16:15
To: Felix <[hidden email]>; SPL Slicer Users <[hidden email]>
Subject: Re: [slicer-users] Slicelet

I'm not sure if you can pass arguments to a python script like that. You can specify input files if you use --python-code argument. For example:

"c:\Program Files\Slicer 4.2.0-2013-04-30\Slicer.exe" --testing --no-splash --no-main-window --ignore-slicerrc --python-code "import RegisterRtImages; logic=RegisterRtImages.RegisterRtImagesLogic(); logic.computeMriToMriTranslation('1.nrrd','2.nrrd','result.txt');"

Some more examples:
https://app.assembla.com/spaces/slicerrt/subversion/source/HEAD/trunk/SlicerRt/sandbox/SliceletTest

Andras

-----Original Message-----
From: slicer-users [mailto:[hidden email]] On Behalf Of Felix
Sent: December 7, 2016 15:23
To: SPL Slicer Users <[hidden email]>
Subject: [slicer-users] Slicelet

Dear slicer users,

I'm trying to execute a python script which load a few .nii files and saves the whole scene as single mrb file. This is done because other users will remotely download from the XNAT server using the xnat gateway.

 If I use slicer --no-main-window --phython-script sceneComposer.py inputFile1.nii inputFile2.nii ROI.nii output.mrb > log.txt. Nothing happens and two processes (slicer.exe and slicerApp-real.exe) remain alive even when the commandline exited from the execution.

If I don't use --no-main-window I can see the nifti loaded. But the script does not finishes its execution because neither mrml file + Data folder appears nor mrb file are created.

If I execute the script step by step in the python interactor it seems to work properly.

This is the script:

# -*- coding: utf-8 -*-
import sys
import vtk
import slicer
import os
import shutil

#Create tree
mrml = slicer.vtkMRMLScene()
vl = slicer.vtkSlicerVolumesLogic()
vl.SetAndObserveMRMLScene(mrml)

#Load volumes/ROI
for argument in range(3,len(sys.argv)-1):
        if sys.argv[argument]=='ROI.nii':
                print(sys.argv[argument] + ' as labelmap')
                slicer.util.loadLabelVolume(sys.argv[argument])
        else:
                print(sys.argv[argument] + ' as volume')
                slicer.util.loadVolume(sys.argv[argument])

#Create folder
tempDir =os.path.join(os.getcwd(), 'sceneData')
os.mkdir(tempDir)

#Save scene
l = slicer.app.applicationLogic()
l.SaveSceneToSlicerDataBundleDirectory(tempDir)

print('Compressing' + tempDir)
slicer.app.applicationLogic().Zip(sys.argv[len(sys.argv)-1], str(tempDir))

exit()


Does any of you have an idea about why it does not work when I run it from commandline?



--
View this message in context: http://slicer-users.65878.n3.nabble.com/Slicelet-tp4031398.html
Sent from the slicer-users mailing list archive at Nabble.com.
_______________________________________________
slicer-users mailing list
[hidden email]
http://massmail.spl.harvard.edu/mailman/listinfo/slicer-users
To unsubscribe: send email to [hidden email] with unsubscribe as the subject http://www.slicer.org/slicerWiki/index.php/Documentation/4.3/FAQ
_______________________________________________
slicer-users mailing list
[hidden email]
http://massmail.spl.harvard.edu/mailman/listinfo/slicer-users
To unsubscribe: send email to [hidden email] with unsubscribe as the subject http://www.slicer.org/slicerWiki/index.php/Documentation/4.3/FAQ
_______________________________________________
slicer-users mailing list
[hidden email]
http://massmail.spl.harvard.edu/mailman/listinfo/slicer-users
To unsubscribe: send email to [hidden email] with unsubscribe as the subject
http://www.slicer.org/slicerWiki/index.php/Documentation/4.3/FAQ