@@ -54,9 +54,28 @@ def test_FieldmapEstimation(testdata_dir, inputfiles, method, nsources):
54
54
"""Test errors."""
55
55
sub_dir = testdata_dir / "sub-01"
56
56
57
- fe = FieldmapEstimation ([sub_dir / f for f in inputfiles ])
57
+ sources = [sub_dir / f for f in inputfiles ]
58
+ fe = FieldmapEstimation (sources )
58
59
assert fe .method == method
59
60
assert len (fe .sources ) == nsources
61
+ assert fe .bids_id is not None and fe .bids_id .startswith ("auto_" )
62
+
63
+ # Attempt to change bids_id
64
+ with pytest .raises (ValueError ):
65
+ fe .bids_id = "other"
66
+
67
+ # Setting the same value should not raise
68
+ fe .bids_id = fe .bids_id
69
+
70
+ # Ensure duplicate B0FieldIdentifier are not accepted
71
+ with pytest .raises (ValueError ):
72
+ FieldmapEstimation (sources , bids_id = fe .bids_id )
73
+
74
+ # B0FieldIdentifier can be generated manually
75
+ # Creating two FieldmapEstimation objects from the same sources SHOULD fail
76
+ # or be better handled in the future (see #129).
77
+ fe2 = FieldmapEstimation (sources , bids_id = f"no{ fe .bids_id } " )
78
+ assert fe2 .bids_id and fe2 .bids_id .startswith ("noauto_" )
60
79
61
80
62
81
@pytest .mark .parametrize (
@@ -74,3 +93,38 @@ def test_FieldmapEstimationError(testdata_dir, inputfiles, errortype):
74
93
75
94
with pytest .raises (errortype ):
76
95
FieldmapEstimation ([sub_dir / f for f in inputfiles ])
96
+
97
+
98
+ def test_FieldmapEstimationIdentifier (testdata_dir ):
99
+ """Check some use cases of B0FieldIdentifier."""
100
+ with pytest .raises (ValueError ):
101
+ FieldmapEstimation ([
102
+ FieldmapFile (testdata_dir / "sub-01" / "fmap/sub-01_fieldmap.nii.gz" ,
103
+ metadata = {"Units" : "Hz" , "B0FieldIdentifier" : "fmap_0" }),
104
+ FieldmapFile (testdata_dir / "sub-01" / "fmap/sub-01_magnitude.nii.gz" ,
105
+ metadata = {"Units" : "Hz" , "B0FieldIdentifier" : "fmap_1" })
106
+ ]) # Inconsistent identifiers
107
+
108
+ fe = FieldmapEstimation ([
109
+ FieldmapFile (testdata_dir / "sub-01" / "fmap/sub-01_fieldmap.nii.gz" ,
110
+ metadata = {"Units" : "Hz" , "B0FieldIdentifier" : "fmap_0" }),
111
+ FieldmapFile (testdata_dir / "sub-01" / "fmap/sub-01_magnitude.nii.gz" ,
112
+ metadata = {"Units" : "Hz" , "B0FieldIdentifier" : "fmap_0" })
113
+ ])
114
+ assert fe .bids_id == "fmap_0"
115
+
116
+ with pytest .raises (ValueError ):
117
+ FieldmapEstimation ([
118
+ FieldmapFile (testdata_dir / "sub-01" / "fmap/sub-01_fieldmap.nii.gz" ,
119
+ metadata = {"Units" : "Hz" , "B0FieldIdentifier" : "fmap_0" }),
120
+ FieldmapFile (testdata_dir / "sub-01" / "fmap/sub-01_magnitude.nii.gz" ,
121
+ metadata = {"Units" : "Hz" , "B0FieldIdentifier" : "fmap_0" })
122
+ ]) # Consistent, but already exists
123
+
124
+ fe = FieldmapEstimation ([
125
+ FieldmapFile (testdata_dir / "sub-01" / "fmap/sub-01_fieldmap.nii.gz" ,
126
+ metadata = {"Units" : "Hz" , "B0FieldIdentifier" : "fmap_1" }),
127
+ FieldmapFile (testdata_dir / "sub-01" / "fmap/sub-01_magnitude.nii.gz" ,
128
+ metadata = {"Units" : "Hz" , "B0FieldIdentifier" : "fmap_1" })
129
+ ])
130
+ assert fe .bids_id == "fmap_1"
0 commit comments