Skip to content

Commit

Permalink
replace abstractstaticmethod,abstractclassmethod
Browse files Browse the repository at this point in the history
  • Loading branch information
bcdarwin committed Jan 15, 2019
1 parent 541675b commit 2b19c0c
Showing 1 changed file with 32 additions and 18 deletions.
50 changes: 32 additions & 18 deletions pydpiper/minc/nlin.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

from abc import ABCMeta, abstractclassmethod, abstractstaticmethod
from abc import ABCMeta, abstractmethod
from typing import List, Generic, TypeVar, Optional, Sequence

from pydpiper.core.stages import Result
Expand All @@ -11,21 +11,25 @@


class Algorithms(Generic[I, X], metaclass=ABCMeta):
@abstractstaticmethod

@staticmethod
@abstractmethod
def blur(img : I,
fwhm : float,
gradient : bool = True,
subdir : str = "tmp"):
pass

@abstractstaticmethod
@staticmethod
@abstractmethod
def average(imgs : Sequence[I],
output_dir : str = '.',
name_wo_ext : str = "average",
avg_file : I = None) -> Result[I]:
pass

@abstractstaticmethod
@staticmethod
@abstractmethod
def resample(img: I,
xfm: X, # TODO: update to handler?
like: I,
Expand All @@ -43,11 +47,13 @@ def resample(img: I,
# we should have a separate method for averaging purely affine transformations.
# also, we should track whether or not a transform is pure affine (either by inspecting it
# or via additional metadata in pydpiper) in order to use this more efficient functionality when possible
@abstractstaticmethod
@staticmethod
@abstractmethod
def average_transforms(xfms : Sequence[GenericXfmHandler[I, X]], avg_xfm : I) -> X: pass
# TODO: it seems a bit heavyweight to require XfmHandlers here simply for sampling purposes

@abstractstaticmethod
@staticmethod
@abstractmethod
# a bit weird that this takes and XfmH but returns an XfmA, but the extra image data is used for sampling
def scale_transform(xfm : Sequence[GenericXfmHandler[I, X]],
newname_wo_ext : str, scale : float) -> X: pass
Expand All @@ -56,8 +62,6 @@ def scale_transform(xfm : Sequence[GenericXfmHandler[I, X]],
#def invert_xfm(): pass




# TODO not *actually* generic; should take a type as a field, but this is annoying to write down
class NLIN(Generic[I, X], metaclass=ABCMeta):
#class NLIN(metaclass=ABCMeta):
Expand All @@ -74,30 +78,37 @@ class ToMinc(ToMinc): pass

class Algorithms(Algorithms): pass

@abstractstaticmethod
@staticmethod
@abstractmethod
def hierarchical_to_single(m: 'MultiLevelConf') -> Sequence[Conf]: pass

@abstractstaticmethod
@staticmethod
@abstractmethod
def get_default_conf(resolution) -> Optional[Conf]: pass

@abstractstaticmethod
@staticmethod
@abstractmethod
def get_default_multilevel_conf(resolution) -> Optional[MultilevelConf]: pass

@abstractclassmethod
@classmethod
@abstractmethod
def parse_protocol_file(cls, filename : str, resolution : float): pass

# you might think it's odd to have this here, since it's not used by `register`,
# but we want all NLIN classes to be usable for model building, and while we
# could just give a default implementation in NLIN_BUILD_MODEL,
# it seems a bit easier just to make the user supply it here (particularly since it can always be done,
# and we've already implemented for minctracc, ANTS)
@abstractclassmethod
@classmethod
@abstractmethod
def parse_multilevel_protocol_file(cls, filename : str, resolution : float): pass

@abstractstaticmethod
@staticmethod
@abstractmethod
def accepts_initial_transform(): pass

@abstractclassmethod
@classmethod
@abstractmethod
def register(cls,
source : I,
target : I,
Expand All @@ -113,7 +124,8 @@ class NLIN_BUILD_MODEL(NLIN, metaclass=ABCMeta):

class BuildModelConf: pass

@abstractstaticmethod
@staticmethod
@abstractmethod
def build_model(imgs : List[MincAtom],
conf : BuildModelConf,
nlin_dir : str,
Expand All @@ -122,8 +134,10 @@ def build_model(imgs : List[MincAtom],
#mincaverage,
output_name_wo_ext : Optional[str] = None): pass

@abstractstaticmethod
@staticmethod
@abstractmethod
def parse_build_model_protocol(filename : str, resolution : float) -> BuildModelConf: pass

@abstractstaticmethod
@staticmethod
@abstractmethod
def get_default_build_model_conf() -> BuildModelConf: pass

0 comments on commit 2b19c0c

Please sign in to comment.