diff --git a/src/mrinufft/io/nsp.py b/src/mrinufft/io/nsp.py index b0594e2e..dfe86152 100644 --- a/src/mrinufft/io/nsp.py +++ b/src/mrinufft/io/nsp.py @@ -484,7 +484,7 @@ def read_arbgrad_rawdat( if "ARBGRAD_VE11C" in data_type: hdr["type"] = "ARBGRAD_GRE" hdr["shifts"] = () - for s in [7, 6, 8]: + for s in [6, 7, 8]: shift = twixObj.search_header_for_val( "Phoenix", ("sWiPMemBlock", "adFree", str(s)) ) diff --git a/src/mrinufft/io/siemens.py b/src/mrinufft/io/siemens.py index b336ca45..0b1d3af6 100644 --- a/src/mrinufft/io/siemens.py +++ b/src/mrinufft/io/siemens.py @@ -42,6 +42,7 @@ def read_siemens_rawdat( Imported data formatted as n_coils X n_samples X n_slices X n_contrasts hdr: dict Extra information about the data parsed from the twix file + This header also contains the ACS data as "acs" if it was found in raw data. Raises ------ @@ -75,7 +76,12 @@ def read_siemens_rawdat( "n_slices": int(twixObj.image.NSli), "n_average": int(twixObj.image.NAve), "orientation": siemens_quat_to_rot_mat(twixObj.image.slicePos[0][-4:]), + "acs": None, } + if "refscan" in twixObj.keys(): + twixObj.refscan.squeeze = True + acs = twixObj.refscan[""].astype(np.complex64) + hdr["acs"] = acs.swapaxes(0, 1) if slice_num is not None and hdr["n_slices"] < slice_num: raise ValueError("The slice number is out of bounds.") if contrast_num is not None and hdr["n_contrasts"] < contrast_num: @@ -97,7 +103,8 @@ def read_siemens_rawdat( data = data.reshape( hdr["n_coils"], - hdr["n_shots"] * hdr["n_adc_samples"], + 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, diff --git a/src/mrinufft/io/utils.py b/src/mrinufft/io/utils.py index 7c6433b7..dd2230fd 100644 --- a/src/mrinufft/io/utils.py +++ b/src/mrinufft/io/utils.py @@ -60,3 +60,30 @@ def siemens_quat_to_rot_mat(quat): R[2] = -R[2] R[-1, -1] = 1 return R + + +def remove_extra_kspace_samples(kspace_data, num_samples_per_shot): + """Remove extra samples from k-space data. + + This function is useful when the k-space data has extra samples + mainly as ADC samples at only at specific number of samples. + This sometimes leads to a situation where we will have more ADC samples + than what is expected. + + Parameters + ---------- + kspace_data : np.ndarray + The k-space data ordered as NCha X NShot X NSamples. + num_samples_per_shot : int + The number of samples per shot in trajectory + + Returns + ------- + np.ndarray + The k-space data with extra samples removed. + """ + n_samples = kspace_data.shape[-1] + n_extra_samples = n_samples - num_samples_per_shot + if n_extra_samples > 0: + kspace_data = kspace_data[..., :-n_extra_samples] + return kspace_data