@@ -227,19 +227,30 @@ def _print_coord_trans(
227
227
)
228
228
229
229
230
- def _find_trans (subject , subjects_dir = None ):
231
- if subject is None :
232
- if "SUBJECT" in os .environ :
233
- subject = os .environ ["SUBJECT" ]
234
- else :
235
- raise ValueError ("SUBJECT environment variable not set" )
236
-
237
- trans_fnames = glob .glob (str (subjects_dir / subject / "*-trans.fif" ))
238
- if len (trans_fnames ) < 1 :
239
- raise RuntimeError (f"Could not find the transformation for { subject } " )
240
- elif len (trans_fnames ) > 1 :
241
- raise RuntimeError (f"Found multiple transformations for { subject } " )
242
- return Path (trans_fnames [0 ])
230
+ def _find_trans (* , trans , subject , subjects_dir = None ):
231
+ if isinstance (trans , str ) and trans == "auto" :
232
+ subjects_dir = get_subjects_dir (subjects_dir , raise_error = True )
233
+ # let's try to do this in MRI coordinates so they're easy to plot
234
+ if subject is None :
235
+ if "SUBJECT" in os .environ :
236
+ subject = os .environ ["SUBJECT" ]
237
+ else :
238
+ raise ValueError (
239
+ "subject is None and SUBJECT environment variable not set, cannot "
240
+ "use trans='auto'"
241
+ )
242
+ glob_str = str (subjects_dir / subject / "*-trans.fif" )
243
+ trans_fnames = glob .glob (glob_str )
244
+ if len (trans_fnames ) < 1 :
245
+ raise RuntimeError (
246
+ f"Could not find the transformation for { subject } in: { glob_str } "
247
+ )
248
+ elif len (trans_fnames ) > 1 :
249
+ raise RuntimeError (
250
+ f"Found multiple transformations for { subject } in: { glob_str } "
251
+ )
252
+ trans = Path (trans_fnames [0 ])
253
+ return _get_trans (trans , fro = "head" , to = "mri" )
243
254
244
255
245
256
def apply_trans (trans , pts , move = True ):
0 commit comments