How to use the slicer.cli.run function in slicer

To help you get started, we’ve selected a few slicer examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github SlicerProstate / SliceTracker / SliceTracker / SliceTrackerUtils / algorithms / zFrameRegistration.py View on Github external
def runRegistration(self, start, end):
    assert start != -1 and end != -1
    seriesNumber = self.inputVolume.GetName().split(":")[0]
    self.outputTransform = self.createLinearTransformNode(seriesNumber + "-" + self.ZFRAME_TRANSFORM_NAME)

    params = {'inputVolume': self.inputVolume, 'startSlice': start, 'endSlice': end,
              'outputTransform': self.outputTransform}
    slicer.cli.run(slicer.modules.zframeregistration, None, params, wait_for_completion=True)
github SlicerProstate / SliceTracker / SliceTracker.py View on Github external
def BRAINSResample(self, inputVolume, referenceVolume, outputVolume, warpTransform):

    params = {'inputVolume': inputVolume, 'referenceVolume': referenceVolume, 'outputVolume': outputVolume,
              'warpTransform': warpTransform, 'interpolationMode': 'NearestNeighbor'}

    logging.debug('about to run BRAINSResample CLI with those params: ')
    logging.debug(params)
    slicer.cli.run(slicer.modules.brainsresample, None, params, wait_for_completion=True)
    logging.debug('resample labelmap through')
    slicer.mrmlScene.AddNode(outputVolume)
github SlicerDMRI / SlicerDMRI / Modules / Scripted / DICOM2FullBrainTractography / DICOM2FullBrainTractographyLib / full_tractography_workflow.py View on Github external
if not hasattr(self, 'tractography_node'):
            self.tractography_node = slicer.vtkMRMLFiberBundleNode()
            slicer.mrmlScene.AddNode(self.tractography_node)

        parameters = {
            'InputVolume':self.tensor_node.GetID(),
            'OutputFibers':self.tractography_node.GetID(),
            'SeedSpacing':data[step_object.id()]['seedSpacing'],
            'StoppingValue':data[step_object.id()]['stoppingFAValue'],
            'StoppingCurvature':data[step_object.id()]['stoppingTrackCurvature'],
            'ClTh':data[step_object.id()]['minimumFAValueSeed'],
        }

        parameters.update(data[step_object.id()])

        self.seeding_parameter_node = slicer.cli.run(
            slicer.modules.tractographylabelmapseeding, self.seeding_parameter_node,
            parameters,
            wait_for_completion=True
        )

        result_status = self.seeding_parameter_node.GetStatusString() == 'Completing' or \
                             self.seeding_parameter_node.GetStatusString() == 'Completed'

        if not result_status:
            display_error("Error in tractography")

        return result_status
github QIICR / QuantitativeReporting / QuantitativeReporting / QuantitativeReporting.py View on Github external
data["Measurements"] = \
      self.segmentEditorWidget.logic.segmentStatisticsLogic.generateJSON4DcmSR(referencedSegmentation,
                                                                               self.segmentEditorWidget.masterVolumeNode)
    logging.debug("DICOM SR Metadata output:")
    logging.debug(json.dumps(data, indent=2, separators=(',', ': ')))

    metaFilePath = self.saveJSON(data, os.path.join(self.dicomSegmentationExporter.tempDir, "sr_meta.json"))
    outputSRPath = os.path.join(self.dicomSegmentationExporter.tempDir, "sr.dcm")

    params = {"metaDataFileName": metaFilePath,
              "compositeContextDataDir": compositeContextDataDir,
              "imageLibraryDataDir": imageLibraryDataDir,
              "outputFileName": outputSRPath}

    logging.debug(params)
    cliNode = slicer.cli.run(slicer.modules.tid1500writer, None, params, wait_for_completion=True)

    if cliNode.GetStatusString() != 'Completed':
      raise Exception("tid1500writer CLI did not complete cleanly")
    return outputSRPath
github SlicerDMRI / SlicerDMRI / Modules / Scripted / DMRIPlugins / DICOMDiffusionVolumePlugin.py View on Github external
nodeFactory.setMRMLScene(slicer.mrmlScene)
    diffusionNode = nodeFactory.createNode('vtkMRMLDiffusionWeightedVolumeNode')
    diffusionNode.SetName(loadable.name)
    # set up the parameters
    parameters = {}
    tempDir = slicer.util.tempDirectory()
    import shutil
    for filePath in loadable.files:
      base = os.path.basename(filePath)
      shutil.copy(filePath, os.path.join(tempDir, base))
    parameters['inputDicomDirectory'] = tempDir
    parameters['outputDirectory'] = slicer.app.temporaryPath
    parameters['outputVolume'] = diffusionNode.GetID()
    # run the module
    dicomDWIConverter = slicer.modules.dwiconvert
    cliNode = slicer.cli.run(dicomDWIConverter, None, parameters, wait_for_completion = True)
    success = False
    if cliNode.GetStatusString() == "Completing" or cliNode.GetStatusString() == "Completed":
      if diffusionNode.GetImageData():
        success = True

    # create Subject Hierarchy nodes for the loaded series
    self.addSeriesInSubjectHierarchy(loadable,diffusionNode)

    # remove temp directory of dwi series
    shutil.rmtree(tempDir)

    return success
github SlicerDMRI / SlicerDMRI / Modules / Loadable / TractographyDisplay / Testing / Python / NsgPlanTracto.py View on Github external
fibers = slicer.vtkMRMLFiberBundleNode()
    slicer.mrmlScene.AddNode(fibers)
    parameters['OutputFibers'] = fibers.GetID()
    parameters['UseIndexSpace'] = 1
    parameters['StoppingValue'] = 0.15
    parameters['ROIlabel'] = 293
    parameters['ThresholdMode'] = 'FractionalAnisotropy'
    # defaults
    # parameters['ClTh'] = 0.3
    # parameters['MinimumLength'] = 20
    # parameters['MaximumLength'] = 800
    # parameters['StoppingCurvature'] = 0.7
    # parameters['IntegrationStepLength'] = 0.5
    # parameters['SeedSpacing'] = 2
    # and run it
    slicer.cli.run(tractographyLabelSeeding, None, parameters)
    self.takeScreenshot('NeurosurgicalPlanning-LabelMapSeeding','Showing Tractography Label Seeding Results',-1)

    #
    # tractography fiducial seeding
    #
    moduleSelector.selectModule('TractographyInteractiveSeeding')
    self.takeScreenshot('NeurosurgicalPlanning-TIS','Showing Tractography Interactive Seeding Module',-1)

    # DTI in background
    sliceLogic = slicer.app.layoutManager().sliceWidget('Red').sliceLogic()
    sliceLogic.StartSliceCompositeNodeInteraction(1)
    compositeNode = sliceLogic.GetSliceCompositeNode()
    compositeNode.SetBackgroundVolumeID(dtiVolume.GetID())
    sliceLogic.EndSliceCompositeNodeInteraction()

    # DTI visible in 3D
github QIICR / QuantitativeReporting / DICOMPlugins / DICOMParametricMapPlugin.py View on Github external
self.cleanup()
      return False

    parameters = {
      "inputFileName": pmFileName,
      "outputDirName": self.tempDir,
      }
    try:
      pm2nrrd = slicer.modules.paramap2itkimage
    except AttributeError:
      logging.debug('Unable to find CLI module paramap2itkimage, unable to load DICOM ParametricMap object')
      self.cleanup()
      return False

    cliNode = None
    cliNode = slicer.cli.run(pm2nrrd, cliNode, parameters, wait_for_completion=True)
    if cliNode.GetStatusString() != 'Completed':
      logging.debug('PM converter did not complete successfully, unable to load DICOM ParametricMap')
      self.cleanup()
      return False

    pmNode = slicer.util.loadVolume(os.path.join(self.tempDir,"pmap.nrrd"))

    # load the metadata JSON to retrieve volume semantics (quantity stored and units)
    with open(os.path.join(self.tempDir,"meta.json")) as metafile:
      meta = json.load(metafile)
      qJson = meta["QuantityValueCode"]
      uJson = meta["MeasurementUnitsCode"]

      quantity = slicer.vtkCodedEntry()
      quantity.SetValueSchemeMeaning(qJson["CodeValue"], qJson["CodingSchemeDesignator"], qJson["CodeMeaning"])