@@ -98,10 +98,13 @@ def _validate_positive(value: float | int | None, name: str) -> None:
9898
9999
100100def _validate_atlas_nifti (path : Path ) -> None :
101- """Warn if a custom atlas NIfTI has a non- integer dtype or is 4 -D.
101+ """Validate a custom atlas NIfTI has integer labels and is 3 -D.
102102
103103 Args:
104104 path: Path to a NIfTI atlas file.
105+
106+ Raises:
107+ ValueError: If the atlas is not a 3-D volume.
105108 """
106109 try :
107110 hdr = nib .nifti1 .load (path ).header
@@ -112,17 +115,16 @@ def _validate_atlas_nifti(path: Path) -> None:
112115 if dtype .kind not in ("i" , "u" ): # integer or unsigned integer
113116 _logger .warning (
114117 "Atlas %s has dtype %s (expected integer labels). "
115- "Timeseries extraction may produce unexpected results." ,
118+ "Parcellation-based extraction may produce unexpected results." ,
116119 path .name ,
117120 dtype ,
118121 )
119122 shape = hdr .get_data_shape ()
120123 if len (shape ) > 3 :
121- _logger .warning (
122- "Atlas %s is %d-D (expected 3-D parcellation). "
123- "Only the first volume will be used." ,
124- path .name ,
125- len (shape ),
124+ raise ValueError (
125+ f"Atlas { path .name } is { len (shape )} -D (expected a 3-D "
126+ f"parcellation). Multi-volume atlases are ambiguous; extract "
127+ f"the desired volume first."
126128 )
127129
128130
@@ -150,20 +152,14 @@ def _build_brain_extraction_templates(
150152 n_custom ,
151153 )
152154 return BrainExtractionTemplates (
153- template = (
154- ns .brain_extraction_template
155- if ns .brain_extraction_template is not None
156- else BRAIN_EXTRACTION_TEMPLATES .template
155+ template = _or_default (
156+ ns .brain_extraction_template , BRAIN_EXTRACTION_TEMPLATES .template
157157 ),
158- probability_mask = (
159- ns .brain_extraction_prob_mask
160- if ns .brain_extraction_prob_mask is not None
161- else BRAIN_EXTRACTION_TEMPLATES .probability_mask
158+ probability_mask = _or_default (
159+ ns .brain_extraction_prob_mask , BRAIN_EXTRACTION_TEMPLATES .probability_mask
162160 ),
163- registration_mask = (
164- ns .brain_extraction_reg_mask
165- if ns .brain_extraction_reg_mask is not None
166- else BRAIN_EXTRACTION_TEMPLATES .registration_mask
161+ registration_mask = _or_default (
162+ ns .brain_extraction_reg_mask , BRAIN_EXTRACTION_TEMPLATES .registration_mask
167163 ),
168164 )
169165
0 commit comments