Coverage for nilearn/_utils/exceptions.py: 50%
26 statements
« prev ^ index » next coverage.py v7.9.1, created at 2025-06-20 10:58 +0200
« prev ^ index » next coverage.py v7.9.1, created at 2025-06-20 10:58 +0200
1AuthorizedException = (
2 BufferError,
3 ArithmeticError,
4 AssertionError,
5 AttributeError,
6 EnvironmentError,
7 EOFError,
8 LookupError,
9 MemoryError,
10 ReferenceError,
11 RuntimeError,
12 SystemError,
13 TypeError,
14 ValueError,
15)
18class DimensionError(TypeError):
19 """Custom error type for dimension checking.
21 This error is used in recursive calls in check_niimg to keep track of the
22 dimensionality of the data. Its final goal it to generate a user friendly
23 message.
25 Parameters
26 ----------
27 file_dimension : integer
28 Indicates the dimensionality of the bottom-level nifti file.
30 required_dimension : integer
31 The dimension the nifti file should have.
33 """
35 def __init__(self, file_dimension, required_dimension):
36 self.file_dimension = file_dimension
37 self.required_dimension = required_dimension
38 self.stack_counter = 0
40 super().__init__()
42 def increment_stack_counter(self):
43 """Increments the counter of recursive calls.
45 Called when the error is caught and re-raised to count the
46 number of recursive calls, ie the number of dimensions added by
47 imbrication in lists.
49 """
50 self.stack_counter += 1
52 @property
53 def message(self):
54 """Format error message."""
55 expected_dim = self.required_dimension + self.stack_counter
56 total_file_dim = f" ({self.file_dimension + self.stack_counter}D)"
57 return (
58 "Input data has incompatible dimensionality: "
59 f"Expected dimension is {expected_dim}D and you provided a "
60 f"{'list of ' * self.stack_counter}{self.file_dimension}D "
61 f"image{'s' * (self.stack_counter > 0)}"
62 f"{total_file_dim * (self.stack_counter > 0)}. "
63 "See https://nilearn.github.io/stable/manipulating_images/"
64 "input_output.html."
65 )
67 def __str__(self):
68 return self.message
71class AllVolumesRemovedError(Exception):
72 """Warns the user if no volumes were kept.
74 Exception is raised when all volumes are scrubbed, i.e.,
75 `sample_mask` is an empty array.
76 """
78 def __init__(self):
79 super().__init__(
80 "The size of the sample mask is 0. "
81 "All volumes were marked as motion outliers "
82 "can not proceed. "
83 )
85 def __str__(self):
86 return f"[AllVolumesRemoved Error] {self.args[0]}"
89class MeshDimensionError(ValueError):
90 """Exception raised when meshes have incompatible dimensions."""
92 def __init__(self, msg="Meshes have incompatible dimensions."):
93 super().__init__(msg)
95 def __str__(self):
96 return f"[MeshDimensionError] {self.args[0]}"