Skip to content

affine

Abstract base class for transforms.

If the transform is invertible, implement via neg method.

Source code in navis/transforms/base.py
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
class BaseTransform(ABC):
    """Abstract base class for transforms.

    If the transform is invertible, implement via __neg__ method.
    """

    def append(self, other: 'BaseTransform'):
        """Append another transform to this one.

        This is used to try to concatenate transforms of the same type into
        a single step to speed things up (e.g. for CMTK transforms). If that's
        not possible or not useful, must raise a `NotImplementedError`.
        """
        raise NotImplementedError(f'Unable to append {type(other)} to {type(self)}')

    def check_if_possible(self, on_error: str = 'raise'):
        """Test if running the transform is possible."""
        return

    @abstractmethod
    def copy(self) -> 'BaseTransform':
        """Return copy."""
        pass

    @abstractmethod
    def xform(self, points: np.ndarray) -> np.ndarray:
        """Return copy.

        Must accept a (N, 3) numpy array as first input and return the
        transformed (N, 3) points as sole output.s
        """
        pass

Append another transform to this one.

This is used to try to concatenate transforms of the same type into a single step to speed things up (e.g. for CMTK transforms). If that's not possible or not useful, must raise a NotImplementedError.

Source code in navis/transforms/base.py
45
46
47
48
49
50
51
52
def append(self, other: 'BaseTransform'):
    """Append another transform to this one.

    This is used to try to concatenate transforms of the same type into
    a single step to speed things up (e.g. for CMTK transforms). If that's
    not possible or not useful, must raise a `NotImplementedError`.
    """
    raise NotImplementedError(f'Unable to append {type(other)} to {type(self)}')

Test if running the transform is possible.

Source code in navis/transforms/base.py
54
55
56
def check_if_possible(self, on_error: str = 'raise'):
    """Test if running the transform is possible."""
    return

Return copy.

Source code in navis/transforms/base.py
58
59
60
61
@abstractmethod
def copy(self) -> 'BaseTransform':
    """Return copy."""
    pass

Return copy.

Must accept a (N, 3) numpy array as first input and return the transformed (N, 3) points as sole output.s

Source code in navis/transforms/base.py
63
64
65
66
67
68
69
70
@abstractmethod
def xform(self, points: np.ndarray) -> np.ndarray:
    """Return copy.

    Must accept a (N, 3) numpy array as first input and return the
    transformed (N, 3) points as sole output.s
    """
    pass