@@ -377,67 +377,9 @@ def create_fmap_datasource(fmap_dct, wf_name="fmap_datasource"):
377377
378378def get_fmap_phasediff_metadata (data_config_scan_params ):
379379 """Return the scan parameters for a field map phasediff scan."""
380- def get_fmap_type (metadata ):
381- """Determine the type of field map from metadata.
382-
383- reference: https://bids-specification.readthedocs.io/en/latest/modality-specific-files/magnetic-resonance-imaging-data.html#case-1-phase-difference-map-and-at-least-one-magnitude-image
384-
385- Parameters
386- ----------
387- metadata : dict or str
388- Metadata dictionary or path to a JSON file containing metadata.
389-
390- Returns
391- -------
392- str or None
393- Returns the type of field map as a string:
394- - "phasediff" for phase difference maps with two echo times
395- - "phase" for single echo phase maps
396- - "fieldmap" for field maps with units like Hz, rad/s, T, or Tesla
397- - "epi" for EPI field maps with phase encoding direction
398- """
399-
400- if not isinstance (metadata , dict ):
401- if isinstance (metadata , str ) and ".json" in metadata :
402- import json
403-
404- try :
405- with open (metadata , "r" , encoding = "utf-8" ) as f :
406- metadata = json .load (f )
407- except (FileNotFoundError , json .JSONDecodeError ):
408- return None
409- else :
410- return None
411-
412- # Check for required BIDS fields only
413- match (
414- "EchoTime1" in metadata ,
415- "EchoTime2" in metadata ,
416- "EchoTime" in metadata ,
417- "Units" in metadata ,
418- "PhaseEncodingDirection" in metadata ,
419- ):
420- case (True , True , _, _, _):
421- # Case 1: Phase-difference map (REQUIRED: EchoTime1 AND EchoTime2)
422- return "phasediff"
423- case (False , False , True , _, _):
424- # Case 2: Single phase map (REQUIRED: EchoTime, but NOT EchoTime1/2)
425- return "phase"
426- case (_, _, _, True , _):
427- # Case 3: Direct field mapping (REQUIRED: Units)
428- units = metadata ["Units" ].lower ()
429- if units in ["hz" , "rad/s" , "t" , "tesla" , "hertz" ]:
430- return "fieldmap"
431- case (_, _, _, _, True ):
432- # Case 4: EPI field maps (REQUIRED: PhaseEncodingDirection)
433- pe_dir = metadata ["PhaseEncodingDirection" ]
434- if pe_dir in ["i" , "i-" , "j" , "j-" , "k" , "k-" ]:
435- return "epi"
436- case _:
437- return None
438-
439- return None
440380
381+ from CPAC .utils .utils import get_fmap_type
382+
441383 if (
442384 not isinstance (data_config_scan_params , dict )
443385 and ".json" in data_config_scan_params
0 commit comments