Skip to content

Commit fd6f970

Browse files
Fix : add negate flag to switch sign convention in ORC (#256)
* Fix : add negate flag to switch sign convention in ORC * Add isign flag to MRIFourierCorrected to control phase convention in B0 correction * Fix : style issues with black * style : fix linter line too long (E501) * style : fix formatting issues with black * Update style : fix formatting issues with black * fix: use the negate arg. * fix: E501 --------- Co-authored-by: Pierre-antoine Comby <[email protected]>
1 parent bb525af commit fd6f970

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

src/mrinufft/operators/off_resonance.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,9 @@ class MRIFourierCorrected(FourierOperatorBase):
198198
Must have same shape as ``b0_map``.
199199
The default is ``None`` (purely imaginary field).
200200
Also supports Cupy arrays and Torch tensors.
201+
negate: bool, optional, default=False
202+
If True, negate the field map. Useful for matching the convention of
203+
your field map generation.
201204
backend: str, optional
202205
The backend to use for computations. Either 'cpu', 'gpu' or 'torch'.
203206
The default is `cpu`.
@@ -221,6 +224,7 @@ def __init__(
221224
r2star_map=None,
222225
B=None,
223226
tl=None,
227+
negate=False,
224228
backend="cpu",
225229
):
226230
if backend == "gpu" and not CUPY_AVAILABLE:
@@ -235,7 +239,9 @@ def __init__(
235239
raise ValueError("Unsupported backend.")
236240

237241
self._fourier_op = fourier_op
238-
242+
if not isinstance(negate, bool):
243+
raise ValueError("negate must be a boolean value.")
244+
self.isign = -1 if negate else 1
239245
self.n_coils = fourier_op.n_coils
240246
self.shape = fourier_op.shape
241247
self.smaps = fourier_op.smaps
@@ -275,7 +281,7 @@ def __init__(
275281
self.C = None
276282
self.field_map = field_map
277283
else:
278-
self.C = _get_spatial_coefficients(field_map, self.tl)
284+
self.C = _get_spatial_coefficients(field_map, self.tl, isign=self.isign)
279285
self.field_map = None
280286

281287
def op(self, data, *args):
@@ -377,11 +383,10 @@ def _get_complex_fieldmap(b0_map, r2star_map=None):
377383
return field_map
378384

379385

380-
def _get_spatial_coefficients(field_map, tl):
386+
def _get_spatial_coefficients(field_map, tl, isign=-1):
381387
xp = get_array_module(field_map)
382-
383388
# get spatial coeffs
384-
C = xp.exp(-tl * field_map[..., None])
389+
C = xp.exp(isign * tl * field_map[..., None])
385390
C = C[None, ...].swapaxes(0, -1)[
386391
..., 0
387392
] # (..., n_time_segments) -> (n_time_segments, ...)

0 commit comments

Comments
 (0)