Skip to content

Commit

Permalink
STYLE: Cleanup UI file and logging statements
Browse files Browse the repository at this point in the history
  • Loading branch information
sbelsk committed Nov 22, 2024
1 parent 15fb943 commit ffe64d1
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 77 deletions.
27 changes: 14 additions & 13 deletions AutoscoperM/AutoscoperM.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,8 @@ def setup(self):
self.ui.volumeSelector.connect("currentNodeChanged(vtkMRMLNode*)", self.onCurrentNodeChanged)
self.ui.tiffGenButton.connect("clicked(bool)", self.onGeneratePartialVolumes)
self.ui.configGenButton.connect("clicked(bool)", self.onGenerateConfig)
self.ui.segmentationButton.connect("clicked(bool)", self.onSegmentation)
self.ui.importModelsButton.connect("clicked(bool)", self.onImportModels)
self.ui.segGen_segmentationButton.connect("clicked(bool)", self.onSegmentation)
self.ui.segSTL_importModelsButton.connect("clicked(bool)", self.onImportModels)
self.ui.loadPVButton.connect("clicked(bool)", self.onLoadPV)
self.ui.populateTrialNameListButton.connect("clicked(bool)", self.onPopulateTrialNameList)
self.ui.populatePartialVolumeListButton.connect("clicked(bool)", self.onPopulatePartialVolumeList)
Expand Down Expand Up @@ -489,7 +489,7 @@ def onGenerateConfig(self):
configPath = os.path.join(mainOutputDir, f"{configFileName}.cfg")

tiffSubDir = self.ui.tiffSubDir.text
vrgSubDir = self.ui.vrgSubDir.text
radiographSubDir = self.ui.radiographSubDir.text
calibrationSubDir = self.ui.cameraSubDir.text

trialList = self.ui.trialList
Expand All @@ -502,7 +502,7 @@ def onGenerateConfig(self):
mainOutputDir=mainOutputDir,
configFileName=configFileName,
tiffSubDir=tiffSubDir,
vrgSubDir=vrgSubDir,
radiographSubDir=radiographSubDir,
calibrationSubDir=calibrationSubDir,
trialList=trialList,
partialVolumeList=partialVolumeList,
Expand All @@ -513,7 +513,7 @@ def onGenerateConfig(self):
if not self.logic.validatePaths(
mainOutputDir=mainOutputDir,
tiffDir=os.path.join(mainOutputDir, tiffSubDir),
vrgDir=os.path.join(mainOutputDir, vrgSubDir),
vrgDir=os.path.join(mainOutputDir, radiographSubDir),
calibDir=os.path.join(mainOutputDir, calibrationSubDir),
):
raise ValueError("Invalid paths")
Expand All @@ -530,7 +530,7 @@ def get_checked_items(listWidget):
# extract filenames from UI lists, and use them to construct the paths relative to mainOutputDir
# FIXME: don't assume the list of camera files is given in the same order as the list of radiograph root dir!
camCalFiles = [os.path.join(calibrationSubDir, item) for item in get_checked_items(camCalList)]
trialDirs = [os.path.join(vrgSubDir, item) for item in get_checked_items(trialList)]
trialDirs = [os.path.join(radiographSubDir, item) for item in get_checked_items(trialList)]

if not len(camCalFiles) == len(trialDirs):
raise ValueError(
Expand Down Expand Up @@ -614,8 +614,8 @@ def onImportModels(self):
raise ValueError("Invalid inputs")
return

if self.ui.segGen_fileRadioButton.isChecked():
segmentationFileDir = self.ui.segGen_lineEdit.currentPath
if self.ui.segSTL_loadRadioButton.isChecked():
segmentationFileDir = self.ui.segSTL_modelsDir.currentPath
if not self.logic.validatePaths(segmentationFileDir=segmentationFileDir):
raise ValueError("Invalid paths")
return
Expand Down Expand Up @@ -662,7 +662,7 @@ def onSegmentation(self):
self.logic.cleanFilename(currentVolumeNode.GetName(), i)
segmentationNode = SubVolumeExtraction.automaticSegmentation(
currentVolumeNode,
self.ui.segGen_ThresholdSpinBox.value,
self.ui.segGen_thresholdSpinBox.value,
self.ui.segGen_marginSizeSpin.value,
progressCallback=self.updateProgressBar,
)
Expand Down Expand Up @@ -748,7 +748,7 @@ def onPopulateTrialNameList(self):
"""
Populates trial name UI list using files from the selected radiograph directory
"""
radiographDir = os.path.join(self.ui.mainOutputSelector.currentPath, self.ui.vrgSubDir.text)
radiographDir = os.path.join(self.ui.mainOutputSelector.currentPath, self.ui.radiographSubDir.text)
try:
self.populateFileList(self.ui.trialList, radiographDir, itemType="dir")
except ValueError as errMsg:
Expand Down Expand Up @@ -779,9 +779,10 @@ def populateFileList(self, listWidget, fileDir, itemType="file"):
Populates input UI list with files/directories that exist in the given input directory
"""
listWidget.clear()
if not self.logic.validatePaths(
fileDir=fileDir,
):
if not self.logic.validateInputs(listWidget=listWidget):
raise ValueError(f"Invalid input: list widget to be populated is None.")
return
if not self.logic.validatePaths(fileDir=fileDir,):
raise ValueError(f"Invalid input: subdirectory '{fileDir}' does not exist.")
return

Expand Down
3 changes: 0 additions & 3 deletions AutoscoperM/AutoscoperMLib/IO.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ def generateConfigFile(
"""
import datetime

logging.info(f"generateConfigFile: writing to '{outputConfigPath}'")
with open(outputConfigPath, "w+") as f:
# Trial Name as comment
f.write(f"# {trialName} configuration file\n")
Expand Down Expand Up @@ -104,8 +103,6 @@ def generateConfigFile(
f.write("OptimizationOffsets " + " ".join([str(x) for x in optimizationOffsets]) + "\n")
f.write("\n")

return True


def writeVolume(volumeNode: slicer.vtkMRMLVolumeNode, filename: str):
"""
Expand Down
Loading

0 comments on commit ffe64d1

Please sign in to comment.