Skip to content

Commit

Permalink
Update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
mcencini committed Jan 25, 2024
1 parent bfe04ae commit 33ea9fa
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 21 deletions.
20 changes: 13 additions & 7 deletions src/deepmr/io/header/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,16 +124,20 @@ def read_acqheader(filepath, *args, device="cpu", verbose=False, **kwargs):
try:
head = _mrd.read_mrd_acqhead(filepath)
done = True
except Exception:
pass
except Exception as e:
msg0 = e
else:
msg0 = ""

# matfile
if filepath.endswith(".mat") and not (done):
try:
head = _matlab.read_matlab_acqhead(filepath, *args, **kwargs)
done = True
except Exception:
raise
except Exception as e:
msg1 = e
else:
msg1 = ""

# bart
# if filepath.endswith(".cfl") and not(done):
Expand All @@ -148,12 +152,14 @@ def read_acqheader(filepath, *args, device="cpu", verbose=False, **kwargs):
try:
done = True
head = _base.read_base_acqheader(filepath)
except Exception:
raise RuntimeError(f"File (={filepath}) not recognized!")
except Exception as e:
msg2 = e
else:
msg2 = ""

# check if we loaded data
if not (done):
raise RuntimeError(f"File (={filepath}) not recognized!")
raise RuntimeError(f"File (={filepath}) not recognized! Error:\nMRD {msg0}\nMATLAB {msg1}\nBase {msg2}")

# normalize trajectory
if head.traj is not None:
Expand Down
15 changes: 9 additions & 6 deletions src/deepmr/io/header/matlab.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,9 +206,11 @@ def _get_sampling_time(matfile):

def _get_shape(matfile, ndim):
if "mtx" in matfile:
shape = matfile["mtx"][::-1].squeeze()
shape = matfile["mtx"].squeeze()
shape = shape[::-1]
elif "npix" in matfile:
shape = matfile["npix"][::-1].squeeze()
shape = matfile["npix"].squeeze()
shape = shape[::-1]
elif "shape" in matfile:
shape = matfile["shape"]
else:
Expand All @@ -219,7 +221,7 @@ def _get_shape(matfile, ndim):
shape = [int(shape)] * ndim
else:
shape = shape.astype(int)

return shape


Expand All @@ -228,7 +230,8 @@ def _get_resolution_and_spacing(matfile, shape, ndim):
resolution = matfile["resolution"]
else:
if "fov" in matfile:
fov = matfile["fov"][::-1].squeeze() * 1e3
fov = matfile["fov"].squeeze() * 1e3
fov = fov[::-1]
else:
raise RuntimeError("Field of View not found!")

Expand All @@ -243,7 +246,7 @@ def _get_resolution_and_spacing(matfile, shape, ndim):
spacing = matfile["spacing"]
else:
spacing = resolution[0]

return resolution, spacing


Expand Down Expand Up @@ -392,7 +395,7 @@ def _reformat_trajectory(head, acq_type, reshape):

if reshape:
if acq_type == "hybrid" or acq_type == "cart":
nz = shape[0]
nz = shape[-1]
kz = k[:, 0, -1].astype(float) * nz + nz // 2 # (nviews,)

# check if it is fully sampled
Expand Down
21 changes: 13 additions & 8 deletions src/deepmr/io/kspace/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,16 +168,16 @@ def read_rawdata(filepath, acqheader=None, device="cpu", verbose=0):
try:
data, head = _mrd.read_mrd_rawdata(filepath)
done = True
except Exception:
pass
except Exception as e:
msg0 = e

# gehc
if not (done):
try:
data, head = _gehc.read_gehc_rawdata(filepath, acqheader)
done = True
except Exception:
pass
except Exception as e:
msg1 = e

# siemens
# if not(done):
Expand All @@ -189,7 +189,7 @@ def read_rawdata(filepath, acqheader=None, device="cpu", verbose=0):

# check if we loaded data
if not (done):
raise RuntimeError(f"File (={filepath}) not recognized!")
raise RuntimeError(f"File (={filepath}) not recognized! Errors:\nMRD: {msg0}\nGEHC: {msg1}")
if verbose == 2:
t1 = time.time()
print(f"done! Elapsed time: {round(t1-t0, 2)} s")
Expand Down Expand Up @@ -323,9 +323,14 @@ def read_rawdata(filepath, acqheader=None, device="cpu", verbose=0):
f"Trajectory shape: (ncontrasts={head.traj.shape[0]}, nviews={head.traj.shape[1]}, nsamples={head.traj.shape[2]}, ndim={head.traj.shape[-1]})"
)
if head.dcf is not None:
print(
f"DCF shape: (ncontrasts={head.dcf.shape[0]}, nviews={head.dcf.shape[1]}, nsamples={head.dcf.shape[2]})"
)
if len(head.dcf.shape) == 1:
print(
f"DCF shape: (nsamples={head.dcf.shape[-1]})"
)
else:
print(
f"DCF shape: (ncontrasts={head.dcf.shape[0]}, nviews={head.dcf.shape[1]}, nsamples={head.dcf.shape[2]})"
)
if head.FA is not None:
if len(np.unique(head.FA)) > 1:
if verbose == 2:
Expand Down

0 comments on commit 33ea9fa

Please sign in to comment.