diff --git a/README.md b/README.md index f71136d4..158418cd 100644 --- a/README.md +++ b/README.md @@ -5,6 +5,7 @@ whitematteranalysis [![Documentation Status](https://readthedocs.org/projects/whitematteranalysis/badge/?version=latest)](https://whitematteranalysis.readthedocs.io/en/latest/?badge=latest) [![code format](https://github.com/SlicerDMRI/whitematteranalysis/actions/workflows/check_format.yml/badge.svg?branch=master)](https://github.com/SlicerDMRI/whitematteranalysis/actions/workflows/check_format.yml?query=branch%3Amaster) [![Imports: isort](https://img.shields.io/badge/%20imports-isort-%231674b1?style=flat&labelColor=ef8336)](https://pycqa.github.io/isort/) +[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black) # Synopsis diff --git a/whitematteranalysis/cluster.py b/whitematteranalysis/cluster.py index 3a4652aa..41308d70 100644 --- a/whitematteranalysis/cluster.py +++ b/whitematteranalysis/cluster.py @@ -8,27 +8,13 @@ import colorsys import os import pickle +from pprint import pprint import numpy +import scipy.cluster.hierarchy +import scipy.cluster.vq import vtk - -try: - import scipy.cluster.hierarchy - import scipy.cluster.vq - USE_SCIPY = 1 -except ImportError: - USE_SCIPY = 0 - print(f"<{os.path.basename(__file__)}> Failed to import scipy.cluster, cannot cluster.") - print(f"<{os.path.basename(__file__)}> Please install scipy for this functionality.") -try: - from joblib import Parallel, delayed - USE_PARALLEL = 1 -except ImportError: - USE_PARALLEL = 0 - print(f"<{os.path.basename(__file__)}> Failed to import joblib, cannot multiprocess.") - print(f"<{os.path.basename(__file__)}> Please install joblib for this functionality.") - -from pprint import pprint +from joblib import Parallel, delayed from . import fibers, filter, io, mrml, render, similarity @@ -510,7 +496,8 @@ def spectral(input_polydata, number_of_clusters=200, print("Silhouette Coefficient: %0.3f" % cluster_metric) else: - print("ERROR: Unknown centroid finder", centroid_finder) + raise NotImplementedError( + f"Workflow not implemented for centroid finder: {centroid_finder}.") ## # This found fewer clusters than we need to represent the anatomy well ## # Leave code here in case wanted in future for more testing. ## print '<cluster.py> Affinity Propagation clustering in embedding space.' diff --git a/whitematteranalysis/register_two_subjects.py b/whitematteranalysis/register_two_subjects.py index 1fc2b761..110bd19c 100644 --- a/whitematteranalysis/register_two_subjects.py +++ b/whitematteranalysis/register_two_subjects.py @@ -10,19 +10,11 @@ class RegisterTractography """ import os - -try: - import scipy.optimize - USE_SCIPY = 1 -except ImportError: - USE_SCIPY = 0 - print(f"<{os.path.basename(__file__)}> Failed to import scipy.optimize, cannot align or register.") - print(f"<{os.path.basename(__file__)}> Please install scipy.optimize for this functionality.") - import sys import time import numpy +import scipy.optimize import vtk try: @@ -270,7 +262,8 @@ def compute(self): print("FLAG:", warnflag) else: - print("Unknown optimizer.") + raise NotImplementedError( + f"Workflow not implemented for optimizer: {self.optimizer}.") self.final_transform = numpy.divide(self.final_transform, self.transform_scaling) diff --git a/whitematteranalysis/register_two_subjects_nonrigid.py b/whitematteranalysis/register_two_subjects_nonrigid.py index 3f3e3e00..4d8eaa89 100644 --- a/whitematteranalysis/register_two_subjects_nonrigid.py +++ b/whitematteranalysis/register_two_subjects_nonrigid.py @@ -10,19 +10,11 @@ class RegisterTractographyNonrigid """ import os - -try: - import scipy.optimize - USE_SCIPY = 1 -except ImportError: - USE_SCIPY = 0 - print(f"<{os.path.basename(__file__)}> Failed to import scipy.optimize, cannot align or register.") - print(f"<{os.path.basename(__file__)}> Please install scipy.optimize for this functionality.") - import sys import time import numpy +import scipy.optimize import vtk try: @@ -322,7 +314,8 @@ def compute(self): print("TRANS:", self.final_transform, "FLAG:", warnflag) else: - print("Unknown optimizer.") + raise NotImplementedError( + f"Workflow not implemented for optimizer: {self.optimizer}.") if self.verbose: print("O:", self.objective_function_values) diff --git a/whitematteranalysis/register_two_subjects_nonrigid_bsplines.py b/whitematteranalysis/register_two_subjects_nonrigid_bsplines.py index 88c8606e..0c25e398 100644 --- a/whitematteranalysis/register_two_subjects_nonrigid_bsplines.py +++ b/whitematteranalysis/register_two_subjects_nonrigid_bsplines.py @@ -9,21 +9,12 @@ class RegisterTractographyNonrigid """ -import os - -try: - import scipy.optimize - USE_SCIPY = 1 -except ImportError: - USE_SCIPY = 0 - print(f"<{os.path.basename(__file__)}> Failed to import scipy.optimize, cannot align or register.") - print(f"<{os.path.basename(__file__)}> Please install scipy.optimize for this functionality.") - import os import sys import time import numpy +import scipy.optimize import vtk import vtk.util.numpy_support @@ -335,7 +326,8 @@ def compute(self): print("TRANS:", self.final_transform, "FLAG:", warnflag) else: - print("Unknown optimizer.") + raise NotImplementedError( + f"Workflow not implemented for optimizer: {self.optimizer}.") progress_file = open(self.progress_filename, 'a') self.total_time = time.time() - self.start_time