From a7fafd7f2ab773ba27994ffb3d64eb5678147a87 Mon Sep 17 00:00:00 2001 From: Jean-Christophe Fillion-Robin Date: Fri, 14 Dec 2018 19:00:43 -0500 Subject: [PATCH] STYLE: Add SampleData.downloadSample --- ...RAINSFitRigidRegistrationCrashIssue4139.py | 6 ++-- .../SlicerApp/Testing/Python/CLIEventTest.py | 4 +-- .../Python/FiducialLayoutSwitchBug1914.py | 4 +-- .../Testing/Python/RSNAQuantTutorial.py | 4 +-- .../Testing/Python/SlicerBoundsTest.py | 4 +-- .../SlicerMRBMultipleSaveRestoreLoopTest.py | 4 +-- .../SlicerMRBMultipleSaveRestoreTest.py | 4 +-- .../SlicerMRBSaveRestoreCheckPathsTest.py | 4 +-- .../Python/SlicerOrientationSelectorTest.py | 4 +-- .../Python/SlicerTransformInteractionTest1.py | 4 +-- .../SlicerApp/Testing/Python/UtilTest.py | 28 +++++++++---------- ...iewControllersSliceInterpolationBug1926.py | 6 ++-- .../Testing/Python/sceneImport2428.py | 4 +-- Base/Python/slicer/util.py | 4 +-- Base/Python/tests/test_sitkUtils.py | 8 +++--- ...riptedSegmentEditorEffectModuleTemplate.py | 4 +-- .../Testing/Python/CropVolumeSelfTest.py | 6 ++-- .../Python/MarkupsInCompareViewersSelfTest.py | 4 +-- .../Testing/Python/MarkupsInViewsSelfTest.py | 4 +-- ...surgicalPlanningTutorialMarkupsSelfTest.py | 4 +-- .../AddStorableDataAfterSceneViewTest.py | 6 ++-- .../Python/SegmentationWidgetsTest1.py | 6 ++-- .../Python/VolumeRenderingSceneClose.py | 4 +-- .../Python/VolumeRenderingThreeDOnlyLayout.py | 4 +-- .../LoadVolumeDisplaybleSceneModelClose.py | 4 +-- .../VolumesLogicCompareVolumeGeometry.py | 4 +-- .../Testing/StandaloneEditorWidgetTest.py | 4 +-- .../Testing/ThresholdThreadingTest.py | 4 +-- .../LabelStatistics/LabelStatistics.py | 6 ++-- .../PerformanceTests/PerformanceTests.py | 4 +-- Modules/Scripted/SampleData/SampleData.py | 5 ++++ .../Scripted/ScreenCapture/ScreenCapture.py | 6 ++-- .../SegmentStatistics/SegmentStatistics.py | 8 +++--- .../SegmentEditorTemplateKey.py | 4 +-- 34 files changed, 94 insertions(+), 89 deletions(-) diff --git a/Applications/SlicerApp/Testing/Python/BRAINSFitRigidRegistrationCrashIssue4139.py b/Applications/SlicerApp/Testing/Python/BRAINSFitRigidRegistrationCrashIssue4139.py index a477a9524..ef92aae57 100644 --- a/Applications/SlicerApp/Testing/Python/BRAINSFitRigidRegistrationCrashIssue4139.py +++ b/Applications/SlicerApp/Testing/Python/BRAINSFitRigidRegistrationCrashIssue4139.py @@ -103,12 +103,12 @@ class BRAINSFitRigidRegistrationCrashIssue4139Test(ScriptedLoadableModuleTest): logic = BRAINSFitRigidRegistrationCrashIssue4139Logic() - from SampleData import SampleDataLogic + import SampleData - fixed = SampleDataLogic().downloadMRBrainTumor1() + fixed = SampleData.downloadSample('MRBrainTumor1')[0] self.assertIsNotNone(logic.hasImageData(fixed)) - moving = SampleDataLogic().downloadMRBrainTumor2() + moving = SampleData.downloadSample('MRBrainTumor2')[0] self.assertIsNotNone(logic.hasImageData(moving)) self.delayDisplay('Finished with download and loading') diff --git a/Applications/SlicerApp/Testing/Python/CLIEventTest.py b/Applications/SlicerApp/Testing/Python/CLIEventTest.py index a7de28161..1027ee207 100644 --- a/Applications/SlicerApp/Testing/Python/CLIEventTest.py +++ b/Applications/SlicerApp/Testing/Python/CLIEventTest.py @@ -219,8 +219,8 @@ class CLIEventTestTest(ScriptedLoadableModuleTest): self.delayDisplay('Test that output node moved to referenced node location in subject hierarchy') self.delayDisplay('Load input volume') - from SampleData import SampleDataLogic - inputVolume = SampleDataLogic().downloadMRHead() + import SampleData + inputVolume = SampleData.downloadSample("MRHead")[0] self.delayDisplay('Create subject hierarchy of input volume') shNode = slicer.vtkMRMLSubjectHierarchyNode.GetSubjectHierarchyNode(slicer.mrmlScene) diff --git a/Applications/SlicerApp/Testing/Python/FiducialLayoutSwitchBug1914.py b/Applications/SlicerApp/Testing/Python/FiducialLayoutSwitchBug1914.py index 5e8cddb0a..9f5735550 100644 --- a/Applications/SlicerApp/Testing/Python/FiducialLayoutSwitchBug1914.py +++ b/Applications/SlicerApp/Testing/Python/FiducialLayoutSwitchBug1914.py @@ -135,8 +135,8 @@ class FiducialLayoutSwitchBug1914Logic(ScriptedLoadableModuleLogic): self.delayDisplay("Conventional view") # Download MRHead from sample data - from SampleData import SampleDataLogic - mrHeadVolume = SampleDataLogic().downloadMRHead() + import SampleData + mrHeadVolume = SampleData.downloadSample("MRHead")[0] # Place a fiducial on the red slice markupsLogic = slicer.modules.markups.logic() diff --git a/Applications/SlicerApp/Testing/Python/RSNAQuantTutorial.py b/Applications/SlicerApp/Testing/Python/RSNAQuantTutorial.py index 6d9e9f925..c09997bee 100644 --- a/Applications/SlicerApp/Testing/Python/RSNAQuantTutorial.py +++ b/Applications/SlicerApp/Testing/Python/RSNAQuantTutorial.py @@ -158,8 +158,8 @@ class RSNAQuantTutorialTest(ScriptedLoadableModuleTest): # # first, get some data # - from SampleData import SampleDataLogic - tumor = SampleDataLogic().downloadMRBrainTumor1() + import SampleData + tumor = SampleData.downloadSample('MRBrainTumor1')[0] try: # four up view diff --git a/Applications/SlicerApp/Testing/Python/SlicerBoundsTest.py b/Applications/SlicerApp/Testing/Python/SlicerBoundsTest.py index 4a5a1f260..463b8b1e9 100644 --- a/Applications/SlicerApp/Testing/Python/SlicerBoundsTest.py +++ b/Applications/SlicerApp/Testing/Python/SlicerBoundsTest.py @@ -71,8 +71,8 @@ class SlicerBoundsTestTest(ScriptedLoadableModuleTest): """ Test the GetRASBounds & GetBounds method on a volume. """ #self.delayDisplay("Starting test_Volume") - from SampleData import SampleDataLogic - volumeNode = SampleDataLogic().downloadAbdominalCTVolume() + import SampleData + volumeNode = SampleData.downloadSample('CTA abdomen\n(Panoramix)')[0] bounds = range(6) volumeNode.GetRASBounds(bounds) diff --git a/Applications/SlicerApp/Testing/Python/SlicerMRBMultipleSaveRestoreLoopTest.py b/Applications/SlicerApp/Testing/Python/SlicerMRBMultipleSaveRestoreLoopTest.py index 5ca879b99..31d6afa28 100644 --- a/Applications/SlicerApp/Testing/Python/SlicerMRBMultipleSaveRestoreLoopTest.py +++ b/Applications/SlicerApp/Testing/Python/SlicerMRBMultipleSaveRestoreLoopTest.py @@ -89,8 +89,8 @@ class SlicerMRBMultipleSaveRestoreLoop(ScriptedLoadableModuleTest): # first, get the data # print("Getting MR Head Volume") - from SampleData import SampleDataLogic - mrHeadVolume = SampleDataLogic().downloadMRHead() + import SampleData + mrHeadVolume = SampleData.downloadSample("MRHead")[0] # Place a fiducial markupsLogic = slicer.modules.markups.logic() diff --git a/Applications/SlicerApp/Testing/Python/SlicerMRBMultipleSaveRestoreTest.py b/Applications/SlicerApp/Testing/Python/SlicerMRBMultipleSaveRestoreTest.py index 7cdb31827..47e3c6a6e 100644 --- a/Applications/SlicerApp/Testing/Python/SlicerMRBMultipleSaveRestoreTest.py +++ b/Applications/SlicerApp/Testing/Python/SlicerMRBMultipleSaveRestoreTest.py @@ -86,8 +86,8 @@ class SlicerMRBMultipleSaveRestore(ScriptedLoadableModuleTest): # first, get the data # print("Getting MR Head Volume") - from SampleData import SampleDataLogic - mrHeadVolume = SampleDataLogic().downloadMRHead() + import SampleData + mrHeadVolume = SampleData.downloadSample("MRHead")[0] # Place a fiducial markupsLogic = slicer.modules.markups.logic() diff --git a/Applications/SlicerApp/Testing/Python/SlicerMRBSaveRestoreCheckPathsTest.py b/Applications/SlicerApp/Testing/Python/SlicerMRBSaveRestoreCheckPathsTest.py index 8eae0afb9..fe3027688 100644 --- a/Applications/SlicerApp/Testing/Python/SlicerMRBSaveRestoreCheckPathsTest.py +++ b/Applications/SlicerApp/Testing/Python/SlicerMRBSaveRestoreCheckPathsTest.py @@ -154,8 +154,8 @@ class SlicerMRBSaveRestoreCheckPaths(ScriptedLoadableModuleTest): # first, get the volume data # print("Getting MR Head Volume") - from SampleData import SampleDataLogic - mrHeadVolume = SampleDataLogic().downloadMRHead() + import SampleData + mrHeadVolume = SampleData.downloadSample("MRHead")[0] slicer.util.delayDisplay('Finished with download of volume') diff --git a/Applications/SlicerApp/Testing/Python/SlicerOrientationSelectorTest.py b/Applications/SlicerApp/Testing/Python/SlicerOrientationSelectorTest.py index bde741952..c28ef5f8f 100644 --- a/Applications/SlicerApp/Testing/Python/SlicerOrientationSelectorTest.py +++ b/Applications/SlicerApp/Testing/Python/SlicerOrientationSelectorTest.py @@ -100,8 +100,8 @@ class SlicerOrientationSelectorTestTest(ScriptedLoadableModuleTest): logic = SlicerOrientationSelectorTestLogic() self.delayDisplay("Starting the test") - from SampleData import SampleDataLogic - mrHeadVolume = SampleDataLogic().downloadMRHead() + import SampleData + mrHeadVolume = SampleData.downloadSample("MRHead")[0] slicer.util.selectModule('Reformat') diff --git a/Applications/SlicerApp/Testing/Python/SlicerTransformInteractionTest1.py b/Applications/SlicerApp/Testing/Python/SlicerTransformInteractionTest1.py index c68cae575..af6642469 100644 --- a/Applications/SlicerApp/Testing/Python/SlicerTransformInteractionTest1.py +++ b/Applications/SlicerApp/Testing/Python/SlicerTransformInteractionTest1.py @@ -135,8 +135,8 @@ class SlicerTransformInteractionTest1Test(ScriptedLoadableModuleTest): """ logic = SlicerTransformInteractionTest1Logic() - from SampleData import SampleDataLogic - volume = SampleDataLogic().downloadAbdominalCTVolume() + import SampleData + volume = SampleData.downloadSample('CTA abdomen\n(Panoramix)')[0] #self.delayDisplay("Starting test_3D_interactionVolume") logic = SlicerTransformInteractionTest1Logic() diff --git a/Applications/SlicerApp/Testing/Python/UtilTest.py b/Applications/SlicerApp/Testing/Python/UtilTest.py index 1987501b6..7735829a6 100644 --- a/Applications/SlicerApp/Testing/Python/UtilTest.py +++ b/Applications/SlicerApp/Testing/Python/UtilTest.py @@ -96,11 +96,11 @@ class UtilTestTest(ScriptedLoadableModuleTest): self.assertIsNone(redSliceCompositeNode.GetForegroundVolumeID()) self.assertIsNone(redSliceCompositeNode.GetLabelVolumeID()) - from SampleData import SampleDataLogic + import SampleData - backgroundNode = SampleDataLogic().downloadMRHead() + backgroundNode = SampleData.downloadSample("MRHead")[0] backgroundNode.SetName('Background') - foregroundNode = SampleDataLogic().downloadMRHead() + foregroundNode = SampleData.downloadSample("MRHead")[0] foregroundNode.SetName('Foreground') volumesLogic = slicer.modules.volumes.logic() @@ -133,9 +133,9 @@ class UtilTestTest(ScriptedLoadableModuleTest): self.assertEqual(redSliceCompositeNode.GetLabelOpacity(), 0.1) # Try to reset - otherBackgroundNode = SampleDataLogic().downloadMRHead() + otherBackgroundNode = SampleData.downloadSample("MRHead")[0] otherBackgroundNode.SetName('OtherBackground') - otherForegroundNode = SampleDataLogic().downloadMRHead() + otherForegroundNode = SampleData.downloadSample("MRHead")[0] otherForegroundNode.SetName('OtherForeground') otherLabelmapNode = volumesLogic.CreateAndAddLabelVolume( slicer.mrmlScene, backgroundNode, 'OtherLabelmap' ) @@ -199,8 +199,8 @@ class UtilTestTest(ScriptedLoadableModuleTest): # Test if retrieving voxels as a numpy array works self.delayDisplay('Download sample data') - from SampleData import SampleDataLogic - volumeNode = SampleDataLogic().downloadMRHead() + import SampleData + volumeNode = SampleData.downloadSample("MRHead")[0] self.delayDisplay('Test voxel value read') voxelPos = [120,135,89] @@ -221,8 +221,8 @@ class UtilTestTest(ScriptedLoadableModuleTest): # Test if updating voxels from a numpy array works self.delayDisplay('Download sample data') - from SampleData import SampleDataLogic - volumeNode = SampleDataLogic().downloadMRHead() + import SampleData + volumeNode = SampleData.downloadSample("MRHead")[0] import numpy as np import math @@ -254,8 +254,8 @@ class UtilTestTest(ScriptedLoadableModuleTest): self.assertEqual(tableNode1.GetNumberOfRows(), 3) self.delayDisplay('Download sample data') - from SampleData import SampleDataLogic - volumeNode = SampleDataLogic().downloadMRHead() + import SampleData + volumeNode = SampleData.downloadSample("MRHead")[0] self.delayDisplay('Compute histogram') histogram = np.histogram(slicer.util.arrayFromVolume(volumeNode)) @@ -290,8 +290,8 @@ class UtilTestTest(ScriptedLoadableModuleTest): # Test if convenience function of getting numpy array from various nodes works self.delayDisplay('Test array with scalar image') - from SampleData import SampleDataLogic - volumeNode = SampleDataLogic().downloadMRHead() + import SampleData + volumeNode = SampleData.downloadSample("MRHead")[0] voxelPos = [120,135,89] voxelValueVtk = volumeNode.GetImageData().GetScalarComponentAsDouble(voxelPos[0], voxelPos[1], voxelPos[2], 0) narray = slicer.util.arrayFromVolume(volumeNode) @@ -299,7 +299,7 @@ class UtilTestTest(ScriptedLoadableModuleTest): self.assertEqual(voxelValueVtk, voxelValueNumpy) self.delayDisplay('Test array with tensor image') - tensorVolumeNode = SampleDataLogic().downloadDTIBrain() + tensorVolumeNode = SampleData.downloadSample('DTIBrain')[0] narray = slicer.util.array(tensorVolumeNode.GetName()) self.assertEqual(narray.shape, (85, 144, 144, 3, 3)) diff --git a/Applications/SlicerApp/Testing/Python/ViewControllersSliceInterpolationBug1926.py b/Applications/SlicerApp/Testing/Python/ViewControllersSliceInterpolationBug1926.py index 52aa77fdf..e0a63a968 100644 --- a/Applications/SlicerApp/Testing/Python/ViewControllersSliceInterpolationBug1926.py +++ b/Applications/SlicerApp/Testing/Python/ViewControllersSliceInterpolationBug1926.py @@ -96,9 +96,9 @@ class ViewControllersSliceInterpolationBug1926Test(ScriptedLoadableModuleTest): # first, get some data # self.delayDisplay("Getting Data") - from SampleData import SampleDataLogic - head = SampleDataLogic().downloadMRHead() - tumor = SampleDataLogic().downloadMRBrainTumor1() + import SampleData + head = SampleData.downloadSample("MRHead")[0] + tumor = SampleData.downloadSample('MRBrainTumor1')[0] # Change to a CompareView ln = slicer.util.getNode(pattern='vtkMRMLLayoutNode*') diff --git a/Applications/SlicerApp/Testing/Python/sceneImport2428.py b/Applications/SlicerApp/Testing/Python/sceneImport2428.py index aca2f1d25..c7c5ba940 100644 --- a/Applications/SlicerApp/Testing/Python/sceneImport2428.py +++ b/Applications/SlicerApp/Testing/Python/sceneImport2428.py @@ -97,8 +97,8 @@ class sceneImport2428Test(ScriptedLoadableModuleTest): # first, get some data # self.delayDisplay("Getting Data") - from SampleData import SampleDataLogic - head = SampleDataLogic().downloadMRHead() + import SampleData + head = SampleData.downloadSample("MRHead")[0] # # create a label map and set it for editing diff --git a/Base/Python/slicer/util.py b/Base/Python/slicer/util.py index cb9d2d1ed..83db6917c 100644 --- a/Base/Python/slicer/util.py +++ b/Base/Python/slicer/util.py @@ -1366,7 +1366,7 @@ def plot(narray, xColumnIndex = -1, columnNames = None, title = None, show = Tru # Get sample data import numpy as np import SampleData - volumeNode = SampleData.SampleDataLogic().downloadMRHead() + volumeNode = SampleData.downloadSample("MRHead")[0] # Create new plot histogram = np.histogram(arrayFromVolume(volumeNode), bins=50) @@ -1383,7 +1383,7 @@ def plot(narray, xColumnIndex = -1, columnNames = None, title = None, show = Tru # Get sample data import numpy as np import SampleData - volumeNode = SampleData.SampleDataLogic().downloadMRHead() + volumeNode = SampleData.downloadSample("MRHead")[0] # Create variable that will store plot nodes (chart, table, series) plotNodes = {} diff --git a/Base/Python/tests/test_sitkUtils.py b/Base/Python/tests/test_sitkUtils.py index c6ebe1ef2..cef301e3b 100644 --- a/Base/Python/tests/test_sitkUtils.py +++ b/Base/Python/tests/test_sitkUtils.py @@ -13,8 +13,8 @@ class SitkUtilsTests(unittest.TestCase): """ Download the MRHead node """ - from SampleData import SampleDataLogic - SampleDataLogic().downloadMRHead() + import SampleData + SampleData.downloadSample("MRHead")[0] volumeNode1 = slicer.util.getNode('MRHead') self.assertEqual(volumeNode1.GetName(), "MRHead") @@ -86,8 +86,8 @@ class SitkUtilsTests(unittest.TestCase): """ Download the MRHead node """ - from SampleData import SampleDataLogic - SampleDataLogic().downloadMRHead() + import SampleData + SampleData.downloadSample("MRHead")[0] volumeNode1 = slicer.util.getNode('MRHead') self.assertEqual(volumeNode1.GetName(), "MRHead") diff --git a/Extensions/Testing/ScriptedSegmentEditorEffectExtensionTemplate/ScriptedSegmentEditorEffectModuleTemplate/SegmentEditorScriptedSegmentEditorEffectModuleTemplate.py b/Extensions/Testing/ScriptedSegmentEditorEffectExtensionTemplate/ScriptedSegmentEditorEffectModuleTemplate/SegmentEditorScriptedSegmentEditorEffectModuleTemplate.py index ce0c39c82..3cc8dc65f 100644 --- a/Extensions/Testing/ScriptedSegmentEditorEffectExtensionTemplate/ScriptedSegmentEditorEffectModuleTemplate/SegmentEditorScriptedSegmentEditorEffectModuleTemplate.py +++ b/Extensions/Testing/ScriptedSegmentEditorEffectExtensionTemplate/ScriptedSegmentEditorEffectModuleTemplate/SegmentEditorScriptedSegmentEditorEffectModuleTemplate.py @@ -66,8 +66,8 @@ class SegmentEditorScriptedSegmentEditorEffectModuleTemplateTest(ScriptedLoadabl ################################## self.delayDisplay("Load master volume") - from SampleData import SampleDataLogic - masterVolumeNode = SampleDataLogic().downloadMRBrainTumor1() + import SampleData + masterVolumeNode = SampleData.downloadSample('MRBrainTumor1')[0] ################################## self.delayDisplay("Create segmentation containing a few spheres") diff --git a/Modules/Loadable/CropVolume/Testing/Python/CropVolumeSelfTest.py b/Modules/Loadable/CropVolume/Testing/Python/CropVolumeSelfTest.py index fb978a976..6d724b95b 100644 --- a/Modules/Loadable/CropVolume/Testing/Python/CropVolumeSelfTest.py +++ b/Modules/Loadable/CropVolume/Testing/Python/CropVolumeSelfTest.py @@ -58,9 +58,9 @@ class CropVolumeSelfTestTest(ScriptedLoadableModuleTest): print("Running CropVolumeSelfTest Test case:") - from SampleData import SampleDataLogic + import SampleData - vol = SampleDataLogic().downloadMRHead() + vol = SampleData.downloadSample("MRHead")[0] roi = slicer.vtkMRMLAnnotationROINode() roi.Initialize(slicer.mrmlScene) @@ -87,7 +87,7 @@ class CropVolumeSelfTestTest(ScriptedLoadableModuleTest): mainWindow.moduleSelector().selectModule('Transforms') mainWindow.moduleSelector().selectModule('CropVolume') cropVolumeNode = slicer.mrmlScene.GetNodeByID('vtkMRMLCropVolumeParametersNode1') - vol = SampleDataLogic().downloadMRHead() + vol = SampleData.downloadSample("MRHead")[0] roi = slicer.vtkMRMLAnnotationROINode() roi.Initialize(slicer.mrmlScene) cropVolumeNode.SetInputVolumeNodeID(vol.GetID()) diff --git a/Modules/Loadable/Markups/Testing/Python/MarkupsInCompareViewersSelfTest.py b/Modules/Loadable/Markups/Testing/Python/MarkupsInCompareViewersSelfTest.py index 5c70de08e..3ac5ef23f 100644 --- a/Modules/Loadable/Markups/Testing/Python/MarkupsInCompareViewersSelfTest.py +++ b/Modules/Loadable/Markups/Testing/Python/MarkupsInCompareViewersSelfTest.py @@ -80,8 +80,8 @@ class MarkupsInCompareViewersSelfTestLogic(ScriptedLoadableModuleLogic): # first load the data # print("Getting MR Head Volume") - from SampleData import SampleDataLogic - mrHeadVolume = SampleDataLogic().downloadMRHead() + import SampleData + mrHeadVolume = SampleData.downloadSample("MRHead")[0] # # link the viewers diff --git a/Modules/Loadable/Markups/Testing/Python/MarkupsInViewsSelfTest.py b/Modules/Loadable/Markups/Testing/Python/MarkupsInViewsSelfTest.py index 7d83be338..620208d83 100644 --- a/Modules/Loadable/Markups/Testing/Python/MarkupsInViewsSelfTest.py +++ b/Modules/Loadable/Markups/Testing/Python/MarkupsInViewsSelfTest.py @@ -135,8 +135,8 @@ class MarkupsInViewsSelfTestLogic(ScriptedLoadableModuleLogic): # first load the data # print("Getting MR Head Volume") - from SampleData import SampleDataLogic - mrHeadVolume = SampleDataLogic().downloadMRHead() + import SampleData + mrHeadVolume = SampleData.downloadSample("MRHead")[0] # # link the viewers diff --git a/Modules/Loadable/Markups/Testing/Python/NeurosurgicalPlanningTutorialMarkupsSelfTest.py b/Modules/Loadable/Markups/Testing/Python/NeurosurgicalPlanningTutorialMarkupsSelfTest.py index 91b477ded..2799b5a31 100644 --- a/Modules/Loadable/Markups/Testing/Python/NeurosurgicalPlanningTutorialMarkupsSelfTest.py +++ b/Modules/Loadable/Markups/Testing/Python/NeurosurgicalPlanningTutorialMarkupsSelfTest.py @@ -143,8 +143,8 @@ class NeurosurgicalPlanningTutorialMarkupsSelfTestLogic(ScriptedLoadableModuleLo # use the sample data module logic to load data for the self test self.delayDisplay("Getting Baseline volume") - from SampleData import SampleDataLogic - baselineVolume = SampleDataLogic().downloadWhiteMatterExplorationBaselineVolume() + import SampleData + baselineVolume = SampleData.downloadSample('BaselineVolume')[0] self.takeScreenshot('NeurosurgicalPlanning-Loaded','Data loaded') diff --git a/Modules/Loadable/SceneViews/Testing/Python/AddStorableDataAfterSceneViewTest.py b/Modules/Loadable/SceneViews/Testing/Python/AddStorableDataAfterSceneViewTest.py index 8f1e1194a..99245fc21 100644 --- a/Modules/Loadable/SceneViews/Testing/Python/AddStorableDataAfterSceneViewTest.py +++ b/Modules/Loadable/SceneViews/Testing/Python/AddStorableDataAfterSceneViewTest.py @@ -156,8 +156,8 @@ class AddStorableDataAfterSceneViewTestTest(ScriptedLoadableModuleTest): # add another storable node, a volume # slicer.util.delayDisplay("Adding a new storable node, after creating a scene view") - from SampleData import SampleDataLogic - mrHeadVolume = SampleDataLogic().downloadMRHead() + import SampleData + mrHeadVolume = SampleData.downloadSample("MRHead")[0] mrHeadID = mrHeadVolume.GetID() # @@ -178,7 +178,7 @@ class AddStorableDataAfterSceneViewTestTest(ScriptedLoadableModuleTest): # # add new storable again - mrHeadVolume = SampleDataLogic().downloadMRHead() + mrHeadVolume = SampleData.downloadSample("MRHead")[0] mrHeadID = mrHeadVolume.GetID() # diff --git a/Modules/Loadable/Segmentations/Testing/Python/SegmentationWidgetsTest1.py b/Modules/Loadable/Segmentations/Testing/Python/SegmentationWidgetsTest1.py index 4044aaa8f..985155337 100644 --- a/Modules/Loadable/Segmentations/Testing/Python/SegmentationWidgetsTest1.py +++ b/Modules/Loadable/Segmentations/Testing/Python/SegmentationWidgetsTest1.py @@ -132,9 +132,9 @@ class SegmentationWidgetsTest1(ScriptedLoadableModuleTest): closedSurfaceReprName = vtkSegmentationCore.vtkSegmentationConverter.GetClosedSurfaceRepresentationName() # Use MRHead and Tinypatient for testing - from SampleData import SampleDataLogic - mrVolumeNode = SampleDataLogic().downloadMRHead() - [tinyVolumeNode, tinySegmentationNode] = SampleDataLogic().downloadSample('TinyPatient') + import SampleData + mrVolumeNode = SampleData.downloadSample("MRHead")[0] + [tinyVolumeNode, tinySegmentationNode] = SampleData.downloadSample('TinyPatient') # Convert MRHead to oriented image data import vtkSlicerSegmentationsModuleLogicPython as vtkSlicerSegmentationsModuleLogic diff --git a/Modules/Loadable/VolumeRendering/Testing/Python/VolumeRenderingSceneClose.py b/Modules/Loadable/VolumeRendering/Testing/Python/VolumeRenderingSceneClose.py index 1bb05274a..c75a9c253 100644 --- a/Modules/Loadable/VolumeRendering/Testing/Python/VolumeRenderingSceneClose.py +++ b/Modules/Loadable/VolumeRendering/Testing/Python/VolumeRenderingSceneClose.py @@ -97,8 +97,8 @@ class VolumeRenderingSceneCloseLogic(ScriptedLoadableModuleLogic): self.delayDisplay('Running the aglorithm') - from SampleData import SampleDataLogic - ctVolume = SampleDataLogic().downloadCTChest() + import SampleData + ctVolume = SampleData.downloadSample('CTChest')[0] self.delayDisplay('Downloaded CT sample data') # go to the volume rendering module diff --git a/Modules/Loadable/VolumeRendering/Testing/Python/VolumeRenderingThreeDOnlyLayout.py b/Modules/Loadable/VolumeRendering/Testing/Python/VolumeRenderingThreeDOnlyLayout.py index a08071fb0..148f09396 100644 --- a/Modules/Loadable/VolumeRendering/Testing/Python/VolumeRenderingThreeDOnlyLayout.py +++ b/Modules/Loadable/VolumeRendering/Testing/Python/VolumeRenderingThreeDOnlyLayout.py @@ -34,8 +34,8 @@ class VolumeRenderingThreeDOnlyLayout(ScriptedLoadableModuleTest): layoutManager.setMRMLScene(mrmlScene) # Load MRHead volume - from SampleData import SampleDataLogic - SampleDataLogic().downloadMRHead() + import SampleData + SampleData.downloadSample("MRHead")[0] # Enter the volume rendering module slicer.util.mainWindow().moduleSelector().selectModule('VolumeRendering') diff --git a/Modules/Loadable/Volumes/Testing/Python/LoadVolumeDisplaybleSceneModelClose.py b/Modules/Loadable/Volumes/Testing/Python/LoadVolumeDisplaybleSceneModelClose.py index 720dcf4ed..82892899e 100644 --- a/Modules/Loadable/Volumes/Testing/Python/LoadVolumeDisplaybleSceneModelClose.py +++ b/Modules/Loadable/Volumes/Testing/Python/LoadVolumeDisplaybleSceneModelClose.py @@ -17,8 +17,8 @@ class VolumesLoadSceneCloseTesting(ScriptedLoadableModuleTest): # # first, get some sample data # - from SampleData import SampleDataLogic - SampleDataLogic().downloadMRHead() + import SampleData + SampleData.downloadSample("MRHead")[0] # # enter the models module diff --git a/Modules/Loadable/Volumes/Testing/Python/VolumesLogicCompareVolumeGeometry.py b/Modules/Loadable/Volumes/Testing/Python/VolumesLogicCompareVolumeGeometry.py index 7548784a9..9d342022e 100644 --- a/Modules/Loadable/Volumes/Testing/Python/VolumesLogicCompareVolumeGeometry.py +++ b/Modules/Loadable/Volumes/Testing/Python/VolumesLogicCompareVolumeGeometry.py @@ -18,8 +18,8 @@ class VolumesLogicCompareVolumeGeometryTesting(ScriptedLoadableModuleTest): # # first, get some sample data # - from SampleData import SampleDataLogic - head = SampleDataLogic().downloadMRHead() + import SampleData + head = SampleData.downloadSample("MRHead")[0] # # get the volumes logic and print out default epsilon and precision diff --git a/Modules/Scripted/EditorLib/Testing/StandaloneEditorWidgetTest.py b/Modules/Scripted/EditorLib/Testing/StandaloneEditorWidgetTest.py index 49ce46d79..ec012b996 100644 --- a/Modules/Scripted/EditorLib/Testing/StandaloneEditorWidgetTest.py +++ b/Modules/Scripted/EditorLib/Testing/StandaloneEditorWidgetTest.py @@ -30,8 +30,8 @@ class EditorLibTesting(ScriptedLoadableModuleTest): # # first, get some sample data # - from SampleData import SampleDataLogic - head = SampleDataLogic().downloadMRHead() + import SampleData + head = SampleData.downloadSample("MRHead")[0] # # create a label map and set it for editing diff --git a/Modules/Scripted/EditorLib/Testing/ThresholdThreadingTest.py b/Modules/Scripted/EditorLib/Testing/ThresholdThreadingTest.py index e56bff398..eeaf15a40 100644 --- a/Modules/Scripted/EditorLib/Testing/ThresholdThreadingTest.py +++ b/Modules/Scripted/EditorLib/Testing/ThresholdThreadingTest.py @@ -58,8 +58,8 @@ class ThresholdThreadingTestTest(ScriptedLoadableModuleTest): # first, get some sample data # self.delayDisplay("Get some data") - from SampleData import SampleDataLogic - head = SampleDataLogic().downloadMRHead() + import SampleData + head = SampleData.downloadSample("MRHead")[0] # # now, define an ROI in it diff --git a/Modules/Scripted/LabelStatistics/LabelStatistics.py b/Modules/Scripted/LabelStatistics/LabelStatistics.py index 7c18d5015..6f521fe51 100644 --- a/Modules/Scripted/LabelStatistics/LabelStatistics.py +++ b/Modules/Scripted/LabelStatistics/LabelStatistics.py @@ -517,9 +517,9 @@ class LabelStatisticsTest(ScriptedLoadableModuleTest): # # first, get some data # - from SampleData import SampleDataLogic - mrHead = SampleDataLogic().downloadMRHead() - ctChest = SampleDataLogic().downloadCTChest() + import SampleData + mrHead = SampleData.downloadSample("MRHead")[0] + ctChest = SampleData.downloadSample('CTChest')[0] self.delayDisplay('Two data sets loaded') volumesLogic = slicer.modules.volumes.logic() diff --git a/Modules/Scripted/PerformanceTests/PerformanceTests.py b/Modules/Scripted/PerformanceTests/PerformanceTests.py index 9cfa63c38..3b6c8fc2a 100644 --- a/Modules/Scripted/PerformanceTests/PerformanceTests.py +++ b/Modules/Scripted/PerformanceTests/PerformanceTests.py @@ -54,10 +54,10 @@ class PerformanceTestsWidget(ScriptedLoadableModuleWidget): self.layout.addStretch(1) def downloadMRHead(self): - from SampleData import SampleDataLogic + import SampleData self.log.insertHtml('Requesting downloading MRHead') self.log.repaint() - mrHeadVolume = SampleDataLogic().downloadMRHead() + mrHeadVolume = SampleData.downloadSample("MRHead")[0] if mrHeadVolume: self.log.insertHtml('finished.\n') self.log.insertPlainText('\n') diff --git a/Modules/Scripted/SampleData/SampleData.py b/Modules/Scripted/SampleData/SampleData.py index 239226b1e..cc24d1617 100644 --- a/Modules/Scripted/SampleData/SampleData.py +++ b/Modules/Scripted/SampleData/SampleData.py @@ -37,6 +37,11 @@ def downloadFromURL(uris, fileNames, nodeNames=None, uris, fileNames, nodeNames, customDownloader, loadFileTypes, loadFileProperties) +def downloadSample(sampleName): + """For a given sample name this will search the available sources + and load it if it is available. Returns the loaded nodes.""" + return SampleDataLogic().downloadSample(sampleName) + # # SampleData # diff --git a/Modules/Scripted/ScreenCapture/ScreenCapture.py b/Modules/Scripted/ScreenCapture/ScreenCapture.py index f6e22054c..e8f83c13d 100644 --- a/Modules/Scripted/ScreenCapture/ScreenCapture.py +++ b/Modules/Scripted/ScreenCapture/ScreenCapture.py @@ -1130,9 +1130,9 @@ class ScreenCaptureTest(ScriptedLoadableModuleTest): """ Do whatever is needed to reset the state - typically a scene clear will be enough. """ slicer.mrmlScene.Clear(0) - from SampleData import SampleDataLogic - self.image1 = SampleDataLogic().downloadMRBrainTumor1() - self.image2 = SampleDataLogic().downloadMRBrainTumor2() + import SampleData + self.image1 = SampleData.downloadSample('MRBrainTumor1')[0] + self.image2 = SampleData.downloadSample('MRBrainTumor2')[0] # make the output volume appear in all the slice views selectionNode = slicer.app.applicationLogic().GetSelectionNode() diff --git a/Modules/Scripted/SegmentStatistics/SegmentStatistics.py b/Modules/Scripted/SegmentStatistics/SegmentStatistics.py index 1aaca31c5..c1e3bcf83 100644 --- a/Modules/Scripted/SegmentStatistics/SegmentStatistics.py +++ b/Modules/Scripted/SegmentStatistics/SegmentStatistics.py @@ -645,12 +645,12 @@ class SegmentStatisticsTest(ScriptedLoadableModuleTest): self.delayDisplay("Starting test_SegmentStatisticsBasic") import vtkSegmentationCorePython as vtkSegmentationCore - from SampleData import SampleDataLogic + import SampleData from SegmentStatistics import SegmentStatisticsLogic self.delayDisplay("Load master volume") - masterVolumeNode = SampleDataLogic().downloadMRBrainTumor1() + masterVolumeNode = SampleData.downloadSample('MRBrainTumor1')[0] self.delayDisplay("Create segmentation containing a few spheres") @@ -703,12 +703,12 @@ class SegmentStatisticsTest(ScriptedLoadableModuleTest): self.delayDisplay("Starting test_SegmentStatisticsPlugins") import vtkSegmentationCorePython as vtkSegmentationCore - from SampleData import SampleDataLogic + import SampleData from SegmentStatistics import SegmentStatisticsLogic self.delayDisplay("Load master volume") - masterVolumeNode = SampleDataLogic().downloadMRBrainTumor1() + masterVolumeNode = SampleData.downloadSample('MRBrainTumor1')[0] self.delayDisplay("Create segmentation containing a few spheres") diff --git a/Utilities/Templates/Modules/ScriptedSegmentEditorEffect/SegmentEditorTemplateKey.py b/Utilities/Templates/Modules/ScriptedSegmentEditorEffect/SegmentEditorTemplateKey.py index de4a6f7fc..02f2ada77 100644 --- a/Utilities/Templates/Modules/ScriptedSegmentEditorEffect/SegmentEditorTemplateKey.py +++ b/Utilities/Templates/Modules/ScriptedSegmentEditorEffect/SegmentEditorTemplateKey.py @@ -60,13 +60,13 @@ class SegmentEditorTemplateKeyTest(ScriptedLoadableModuleTest): import vtkSegmentationCorePython as vtkSegmentationCore import vtkSlicerSegmentationsModuleLogicPython as vtkSlicerSegmentationsModuleLogic - from SampleData import SampleDataLogic + import SampleData from SegmentStatistics import SegmentStatisticsLogic ################################## self.delayDisplay("Load master volume") - masterVolumeNode = SampleDataLogic().downloadMRBrainTumor1() + masterVolumeNode = SampleData.downloadSample('MRBrainTumor1')[0] ################################## self.delayDisplay("Create segmentation containing a few spheres") -- GitLab