Skip to content

Commit

Permalink
Add average and fix bug for cartesian data (#166)
Browse files Browse the repository at this point in the history
* Add average and fix bug for cartesian data

* Added codes
  • Loading branch information
chaithyagr authored Jul 19, 2024
1 parent 30e9f3a commit 293ecbe
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/mrinufft/io/nsp.py
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,7 @@ def read_trajectory(
def read_arbgrad_rawdat(
filename: str,
removeOS: bool = False,
doAverage: bool = True,
squeeze: bool = True,
slice_num: int | None = None,
contrast_num: int | None = None,
Expand All @@ -417,6 +418,8 @@ def read_arbgrad_rawdat(
The path to the Siemens MRI file.
removeOS : bool, optional
Whether to remove the oversampling, by default False.
doAverage : bool, optional
Whether to average the data acquired along NAve dimension, by default True.
squeeze : bool, optional
Whether to squeeze the dimensions of the data, by default True.
slice_num : int, optional
Expand Down Expand Up @@ -447,6 +450,7 @@ def read_arbgrad_rawdat(
data, hdr, twixObj = read_siemens_rawdat(
filename=filename,
removeOS=removeOS,
doAverage=doAverage,
squeeze=squeeze,
slice_num=slice_num,
contrast_num=contrast_num,
Expand Down
8 changes: 7 additions & 1 deletion src/mrinufft/io/siemens.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
def read_siemens_rawdat(
filename: str,
removeOS: bool = False,
doAverage: bool = True,
squeeze: bool = True,
return_twix: bool = True,
slice_num: int | None = None,
Expand All @@ -21,6 +22,8 @@ def read_siemens_rawdat(
The path to the Siemens MRI file.
removeOS : bool, optional
Whether to remove the oversampling, by default False.
doAverage : bool, option
Whether to average the data acquired along NAve dimension.
squeeze : bool, optional
Whether to squeeze the dimensions of the data, by default True.
data_type : str, optional
Expand Down Expand Up @@ -61,12 +64,14 @@ def read_siemens_rawdat(
if isinstance(twixObj, list):
twixObj = twixObj[-1]
twixObj.image.flagRemoveOS = removeOS
twixObj.image.flagDoAverage = doAverage
hdr = {
"n_coils": int(twixObj.image.NCha),
"n_shots": int(twixObj.image.NLin),
"n_shots": int(twixObj.image.NLin) * int(twixObj.image.NPar),
"n_contrasts": int(twixObj.image.NSet),
"n_adc_samples": int(twixObj.image.NCol),
"n_slices": int(twixObj.image.NSli),
"n_average": int(twixObj.image.NAve),
}
if slice_num is not None and hdr["n_slices"] < slice_num:
raise ValueError("The slice number is out of bounds.")
Expand All @@ -92,6 +97,7 @@ def read_siemens_rawdat(
hdr["n_shots"] * hdr["n_adc_samples"],
hdr["n_slices"] if slice_num is None else 1,
hdr["n_contrasts"] if contrast_num is None else 1,
hdr["n_average"] if hdr["n_average"] > 1 and not doAverage else 1,
)
if return_twix:
return data, hdr, twixObj
Expand Down

0 comments on commit 293ecbe

Please sign in to comment.