@@ -13,15 +13,19 @@ class BrainAtlas:
1313
1414 ATLAS_JSON_PATH = os .path .join (os .path .dirname (__file__ ))
1515
16- def __init__ (self , atlas_name : str = 'MNI2009' ):
16+ def __init__ (self , atlas_name : str = 'MNI2009' , resolution : str = '1mm' ):
1717 """
1818 Initializes the BrainAtlas class with a specified atlas name.
1919 If no atlas name is provided, it defaults to 'MNI2009'.
2020
2121 Args:
2222 atlas_name (str, optional): The name of the atlas to be used. Defaults to 'MNI2009'.
2323 """
24+ self ._check_resolution_input (resolution )
25+
2426 self ._chosen_atlas = None
27+ self ._resolution = resolution
28+
2529 self .set_atlas (atlas_name )
2630
2731 def set_atlas (self , atlas_name : str ):
@@ -61,6 +65,7 @@ def set_atlas(self, atlas_name: str):
6165 # Assuming the atlas_data is a dictionary, we can add the path to it
6266 atlas_data ['atlas_file_location' ] = path
6367 # Assuming the atlas data contains a key for T1-weighted and Label image data
68+ atlas_data ['resolution' ] = self ._resolution
6469 atlas_data ['t1_data' ] = os .path .join (path , self ._collect_t1 (path ))
6570 atlas_data ['label_data' ] = os .path .join (
6671 path , self ._collect_label (path )
@@ -77,6 +82,13 @@ def get_atlas(self):
7782 """
7883 return self ._chosen_atlas
7984
85+ def set_resolution (self , resolution : str ):
86+ self ._check_resolution_input (resolution )
87+ self ._resolution = resolution
88+
89+ def get_resolution (self ):
90+ return self ._resolution
91+
8092 def get_atlas_url (self , atlas_name : str ):
8193 """
8294 Get the brain atlas URL of the chosen format in the ASLtk database.
@@ -145,10 +157,13 @@ def _collect_t1(self, path: str): # pragma: no cover
145157 Returns:
146158 str: The filename of the T1-weighted image data.
147159 """
148- t1_file = next ((f for f in os .listdir (path ) if '_t1' in f ), None )
160+ t1_file = next (
161+ (f for f in os .listdir (path ) if self ._resolution + '_t1' in f ),
162+ None ,
163+ )
149164 if t1_file is None :
150165 raise ValueError (
151- f"No file with '_t1' found in the atlas directory: { path } "
166+ f"No file with '_t1_' and resolution { self . _resolution } found in the atlas directory: { path } "
152167 )
153168
154169 return t1_file
@@ -161,10 +176,20 @@ def _collect_label(self, path: str): # pragma: no cover
161176 Returns:
162177 str: The filename of the label file.
163178 """
164- label_file = next ((f for f in os .listdir (path ) if '_label' in f ), None )
179+ label_file = next (
180+ (f for f in os .listdir (path ) if self ._resolution + '_label' in f ),
181+ None ,
182+ )
165183 if label_file is None :
166184 raise ValueError (
167- f"No file with '_label' found in the atlas directory: { path } "
185+ f"No file with '_label' and resolution { self . _resolution } found in the atlas directory: { path } "
168186 )
169187
170188 return label_file
189+
190+ def _check_resolution_input (self , resolution ):
191+ valid_resolutions = ['1mm' , '2mm' ]
192+ if resolution not in valid_resolutions :
193+ raise ValueError (
194+ f"Invalid resolution '{ resolution } '. Valid options are: { valid_resolutions } "
195+ )
0 commit comments