-
Notifications
You must be signed in to change notification settings - Fork 22
Register test data as SampleDataSource #63
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#----------------------------------------------------------------------------- | ||
set(MODULE_NAME ShapeVariationAnalyzerSampleData) | ||
|
||
#----------------------------------------------------------------------------- | ||
set(MODULE_PYTHON_SCRIPTS | ||
${MODULE_NAME}.py | ||
) | ||
|
||
set(MODULE_PYTHON_RESOURCES | ||
Resources/Icons/bendicon.png | ||
) | ||
|
||
#----------------------------------------------------------------------------- | ||
slicerMacroBuildScriptedModule( | ||
NAME ${MODULE_NAME} | ||
SCRIPTS ${MODULE_PYTHON_SCRIPTS} | ||
RESOURCES ${MODULE_PYTHON_RESOURCES} | ||
WITH_GENERIC_TESTS | ||
) | ||
|
||
#----------------------------------------------------------------------------- | ||
if(BUILD_TESTING) | ||
|
||
# Register the unittest subclass in the main script as a ctest. | ||
# Note that the test will also be available at runtime. | ||
slicer_add_python_unittest(SCRIPT ${MODULE_NAME}.py) | ||
endif() |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import os | ||
import unittest | ||
import vtk, qt, ctk, slicer | ||
from slicer.ScriptedLoadableModule import * | ||
import logging | ||
from pathlib import Path | ||
import shutil | ||
|
||
# | ||
# ShapeVariationAnalyzerSampleData | ||
# | ||
|
||
class ShapeVariationAnalyzerSampleData(ScriptedLoadableModule): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of introducing a new module ... may be worth adopting the style of the template. See https://github.com/Slicer/Slicer/blob/ab0aa85f93e226f40250857ec1c0b09304c4ea16/Utilities/Templates/Modules/Scripted/TemplateKey.py#L45-L50 And considering the reuse of the the sample data directly from SlicerSALT |
||
"""Uses ScriptedLoadableModule base class, available at: | ||
https://github.com/Slicer/Slicer/blob/master/Base/Python/slicer/ScriptedLoadableModule.py | ||
""" | ||
|
||
def __init__(self, parent): | ||
ScriptedLoadableModule.__init__(self, parent) | ||
self.parent.title = "ShapeVariationAnalyzerSampleData" | ||
self.parent.categories = ["TestData"] | ||
self.parent.dependencies = ["SampleData"] | ||
self.parent.helpText = """This module adds sample data for ShapeVariationAnalyzer""" | ||
|
||
# don't show this module - additional data will be shown in SampleData module | ||
parent.hidden = True | ||
|
||
import SampleData | ||
|
||
iconsPath = os.path.join(os.path.dirname(self.parent.path), 'Resources/Icons/') | ||
|
||
SampleData.SampleDataLogic.registerCustomSampleDataSource( | ||
sampleName='ShapeVariationAnalyzerSampleData', | ||
category='ShapeVariationAnalyzer', | ||
uris='https://data.kitware.com/api/v1/item/626850ed4acac99f42121c7f/download', | ||
loadFiles=True, # Unzip it | ||
fileNames='ShapeVariationAnalyzerSampleData.zip', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Few comments:
|
||
loadFileType='ZipFile', | ||
nodeNames='ShapeVariationAnalyzerSampleData', | ||
checksums='SHA512:c2a8b8b33b18bb9ad6308afd2c557a7743edaf77f3e03d50f4df0059d6aa4cdd78093dda144ed2f0a27f088464e30d6e654fc68cd19b37b6027e44bebf97bfc3', | ||
thumbnailFileName=os.path.join(iconsPath, 'bendicon.png'), | ||
customDownloader=self.downloadSampleDataInFolder, | ||
) | ||
|
||
@staticmethod | ||
def downloadSampleDataInFolder(source): | ||
|
||
outPath = slicer.mrmlScene.GetCacheManager().GetRemoteCacheDirectory() | ||
|
||
if not os.path.exists(outPath): | ||
os.mkdir(outPath) | ||
|
||
sampleDataLogic = slicer.modules.sampledata.widgetRepresentation().self().logic | ||
|
||
for uri, fileName, checksums in zip(source.uris, source.fileNames, source.checksums): | ||
sampleDataLogic.downloadFile(uri, outPath, fileName) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Crafting the csv file here is counter productive, any one who would like to try to load the datasets independently would have to manually recreate the file.
Instead, the csv file should be provided and this issue #64 should be addressed.