Skip to content

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ endif()

#add_subdirectory(CLI/ComputeMeanShapes)
add_subdirectory(CLI/SurfaceFeaturesExtractor)
add_subdirectory(ShapeVariationAnalyzerSampleData)
## NEXT_MODULE


Expand Down
2 changes: 0 additions & 2 deletions ShapeVariationAnalyzer/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,4 @@ if(BUILD_TESTING)
# Note that the test will also be available at runtime.
slicer_add_python_unittest(SCRIPT ${MODULE_NAME}.py)

# Additional build-time testing
add_subdirectory(Testing)
endif()
1,152 changes: 0 additions & 1,152 deletions ShapeVariationAnalyzer/Data/Input/g01_bent00.vtk

This file was deleted.

1,152 changes: 0 additions & 1,152 deletions ShapeVariationAnalyzer/Data/Input/g01_bent01.vtk

This file was deleted.

1,152 changes: 0 additions & 1,152 deletions ShapeVariationAnalyzer/Data/Input/g01_bent02.vtk

This file was deleted.

1,152 changes: 0 additions & 1,152 deletions ShapeVariationAnalyzer/Data/Input/g01_bent03.vtk

This file was deleted.

1,152 changes: 0 additions & 1,152 deletions ShapeVariationAnalyzer/Data/Input/g01_bent04.vtk

This file was deleted.

1,152 changes: 0 additions & 1,152 deletions ShapeVariationAnalyzer/Data/Input/g01_bent05.vtk

This file was deleted.

1,152 changes: 0 additions & 1,152 deletions ShapeVariationAnalyzer/Data/Input/g01_bent06.vtk

This file was deleted.

1,152 changes: 0 additions & 1,152 deletions ShapeVariationAnalyzer/Data/Input/g01_bent07.vtk

This file was deleted.

1,152 changes: 0 additions & 1,152 deletions ShapeVariationAnalyzer/Data/Input/g01_bent08.vtk

This file was deleted.

1,152 changes: 0 additions & 1,152 deletions ShapeVariationAnalyzer/Data/Input/g01_bent09.vtk

This file was deleted.

18 changes: 16 additions & 2 deletions ShapeVariationAnalyzer/ShapeVariationAnalyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import math
import shutil

import glob

import pickle
import numpy as np
Expand Down Expand Up @@ -2553,9 +2554,22 @@ def runTest(self):

def test_ShapeVariationAnalyzer(self):


sampleDataLogic = slicer.modules.sampledata.widgetRepresentation().self().logic
sampleDataLogic.downloadSample("ShapeVariationAnalyzerSampleData")

logic = ShapeVariationAnalyzerLogic()
input_dir = os.path.join(logic.dataPath(), "Input")
filepath_in = os.path.join(input_dir, "test.csv")

base_dir = slicer.mrmlScene.GetCacheManager().GetRemoteCacheDirectory() + '/ShapeVariationAnalyzerSampleData/'

# The csv file requires paths to the vtk files so let's create the csv since the path wouldn't be known beforehand
vtk_files = glob.glob(base_dir + '*.vtk')

filepath_in = f"{base_dir}test.csv"
with open(filepath_in, "w") as csv_file:
csv_file.write("VTK Files,Group\n")
for vtk_file in vtk_files:
csv_file.write(f"{vtk_file},0\n")
Comment on lines +2568 to +2572
Copy link
Contributor Author

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.


# Test of all the groups
keygroup = "All"
Expand Down
27 changes: 0 additions & 27 deletions ShapeVariationAnalyzer/Testing/CMakeLists.txt

This file was deleted.

27 changes: 27 additions & 0 deletions ShapeVariationAnalyzerSampleData/CMakeLists.txt
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()
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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):
Copy link
Contributor Author

Choose a reason for hiding this comment

The 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',
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Few comments:

  • There already a file called SVASampleData.zip on the server. It is available at https://data.kitware.com/#collection/586fbb7b8d777f05f44a5c7b/folder/5d5c195085f25b11ff3e1ad8

  • After looking at the SHA512 of the one associated with the SampleDataSource, I realized that the file downloaded is instead in a Public folder associated with a user (see screenshot below). We should avoid doing and instead consistently organize the zip files.

  • The zip files should all be versioned (e.g SVASampleData-YYYY-MM-DD.zip

image

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)