Skip to content

Commit

Permalink
Adding k-space IO test, Black reformatting
Browse files Browse the repository at this point in the history
  • Loading branch information
mcencini authored and mcencini committed Jan 23, 2024
1 parent f2cee1b commit 3174270
Show file tree
Hide file tree
Showing 89 changed files with 2,796 additions and 1,878 deletions.
44 changes: 23 additions & 21 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@

# -- Project information -----------------------------------------------------

project = u"deepmr"
copyright = u"2023, Matteo Cencini"
author = u"Matteo Cencini"
project = "deepmr"
copyright = "2023, Matteo Cencini"
author = "Matteo Cencini"

# -- General configuration ---------------------------------------------------

Expand All @@ -17,27 +17,30 @@
# ones.
extensions = [
"myst_nb",
# "autoapi.extension",
"sphinx.ext.autodoc",
"sphinx.ext.autosummary",
# "autoapi.extension",
"sphinx.ext.autodoc",
"sphinx.ext.autosummary",
"sphinx.ext.napoleon",
"sphinx.ext.viewcode",
]

autodoc_mock_imports = ["deepinv",
"h5py",
"ismrmrd",
"mat73",
"matplotlib",
"nibabel",
"numpy",
"numba",
"pydicom",
"pywt",
"ptwt",
"scipy",
"torch",
"tqdm"]
autodoc_mock_imports = [
"dacite",
"deepinv",
"h5py",
"ismrmrd",
"mat73",
"matplotlib",
"nibabel",
"numpy",
"numba",
"pydicom",
"pywt",
"ptwt",
"scipy",
"torch",
"tqdm",
]

# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
Expand All @@ -62,5 +65,4 @@
"image_dark": "https://github.com/INFN-PREDATOR/deep-mr/blob/main/docs/source/figures/deepmr_logo_dark.png?raw=true",
"scale": "10%",
},

}
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ python_requires = >=3.9
# For more information, check out https://semver.org/.
install_requires =
importlib-metadata; python_version<"3.9"
dacite
deepinv
h5py
ismrmrd
Expand Down
4 changes: 3 additions & 1 deletion src/deepmr/__init__.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
# read version from installed package
from importlib.metadata import version

__version__ = version("deepmr")

# from . import bloch
from . import io

# from . import optim
# from . import prox

from .testdata import testdata
from .testdata import testdata
5 changes: 2 additions & 3 deletions src/deepmr/bloch/blocks/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@
from . import prep as _prep
from . import readout as _readout

from .prep import * # noqa
from .readout import * # noqa
from .prep import * # noqa
from .readout import * # noqa

__all__ = []
__all__.extend(_prep.__all__)
__all__.extend(_readout.__all__)

15 changes: 9 additions & 6 deletions src/deepmr/bloch/blocks/prep.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@

from .. import ops


def InversionPrep(TI, T1, T2, weight, k, inv_props):
"""
Adiabatic inversion operator.
Consists of a 180° pulse followed by a crusher gradient.
Args:
Expand Down Expand Up @@ -39,12 +40,12 @@ def InversionPrep(TI, T1, T2, weight, k, inv_props):
return ops.CompositeOperator(Sinv, Einv, Tinv, name="Inversion Propagator")
else:
return ops.Identity(name="Inversion Propagator")


def T2Prep(Tprep, T1, T2, weight, k, prep_props):
"""
T2 prep operator.
Consists of a 90°-180°--90° composite pulse followed by a crusher gradient.
Args:
Expand Down Expand Up @@ -79,6 +80,8 @@ def T2Prep(Tprep, T1, T2, weight, k, prep_props):
)
Sprep = ops.Spoil(name="Prep Crusher")

return ops.CompositeOperator(Sprep, T90m, Eprep, T180, Eprep, T90p, name="Inversion Propagator")
return ops.CompositeOperator(
Sprep, T90m, Eprep, T180, Eprep, T90p, name="Inversion Propagator"
)
else:
return ops.Identity(name="Inversion Propagator")
return ops.Identity(name="Inversion Propagator")
96 changes: 68 additions & 28 deletions src/deepmr/bloch/blocks/readout.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,24 @@ def ExcPulse(states, B1, rf_props):

return ops.RFPulse(device, nlocs=nlocs, B1=B1, name="Excitation Pulse", **rf_props)

def FSEStep(states, ESP, T1, T2, weight=None, k=None, chemshift=None, D=None, v=None, grad_props=None):

def FSEStep(
states,
ESP,
T1,
T2,
weight=None,
k=None,
chemshift=None,
D=None,
v=None,
grad_props=None,
):
"""
(Unbalanced) SSFP propagator.
Consists of rfpulse (omitted) - free precession - spoiling gradient.
Args:
states (tensor): EPG states matrix.
ESP (float): Echo Spacing in ms.
Expand All @@ -51,20 +63,23 @@ def FSEStep(states, ESP, T1, T2, weight=None, k=None, chemshift=None, D=None, v=
TETRop (epgtorch.Operator): Propagator until next TR.
"""
X, S = _free_precess(states, 0.5 * ESP, T1, T2, weight, k, chemshift, D, v, grad_props)

X, S = _free_precess(
states, 0.5 * ESP, T1, T2, weight, k, chemshift, D, v, grad_props
)

# build Xpre and Xpost
Xpre = ops.CompositeOperator(S, X, name="FSEpre")
Xpost = ops.CompositeOperator(X, S, name="FSEpost")

return Xpre, Xpost


def bSSFPStep(states, TE, TR, T1, T2, weight=None, k=None, chemshift=None):
"""
(Balanced) SSFP propagator.
Consists of rfpulse (omitted) - free precession.
Args:
states (tensor): EPG states matrix.
TE (float): Echo Time in ms.
Expand All @@ -84,15 +99,30 @@ def bSSFPStep(states, TE, TR, T1, T2, weight=None, k=None, chemshift=None):
"""
XTE, _ = _free_precess(states, TE, T1, T2, weight, k, chemshift, None, None, None)
XTETR, _ = _free_precess(states, TR-TE, T1, T2, weight, k, chemshift, None, None, None)
XTETR, _ = _free_precess(
states, TR - TE, T1, T2, weight, k, chemshift, None, None, None
)
return XTE, XTETR

def SSFPFidStep(states, TE, TR, T1, T2, weight=None, k=None, chemshift=None, D=None, v=None, grad_props=None):

def SSFPFidStep(
states,
TE,
TR,
T1,
T2,
weight=None,
k=None,
chemshift=None,
D=None,
v=None,
grad_props=None,
):
"""
(Unbalanced) SSFP propagator.
Consists of rfpulse (omitted) - free precession - spoiling gradient.
Args:
states (tensor): EPG states matrix.
TE (float): Echo Time in ms.
Expand All @@ -112,15 +142,30 @@ def SSFPFidStep(states, TE, TR, T1, T2, weight=None, k=None, chemshift=None, D=N
"""
XTE, _ = _free_precess(states, TE, T1, T2, weight, k, chemshift, D, v, grad_props)
XTETR, S = _free_precess(states, TR-TE, T1, T2, weight, k, chemshift, D, v, grad_props)
XTETR, S = _free_precess(
states, TR - TE, T1, T2, weight, k, chemshift, D, v, grad_props
)
return XTE, ops.CompositeOperator(S, XTETR, name="SSFPFid TE-TR Propagator")

def SSFPEchoStep(states, TE, TR, T1, T2, weight=None, k=None, chemshift=None, D=None, v=None, grad_props=None):

def SSFPEchoStep(
states,
TE,
TR,
T1,
T2,
weight=None,
k=None,
chemshift=None,
D=None,
v=None,
grad_props=None,
):
"""
(Reverse) SSFP propagator.
Consists of rfpulse (omitted) - spoiling gradient - free precession.
Args:
states (tensor): EPG states matrix.
TE (float): Echo Time in ms.
Expand All @@ -140,7 +185,9 @@ def SSFPEchoStep(states, TE, TR, T1, T2, weight=None, k=None, chemshift=None, D=
"""
XTE, _ = _free_precess(states, TE, T1, T2, weight, k, chemshift, D, v, grad_props)
XTETR, S = _free_precess(states, TR-TE, T1, T2, weight, k, chemshift, D, v, grad_props)
XTETR, S = _free_precess(
states, TR - TE, T1, T2, weight, k, chemshift, D, v, grad_props
)
return ops.CompositeOperator(S, XTE, name="SSFPFid TE-TR Propagator"), XTETR


Expand All @@ -155,7 +202,7 @@ def _free_precess(states, t, T1, T2, weight, k, chemshift, D, v, grad_props):
grad_props.pop("duration")
else:
tau = 0.0

# parse
device = states["F"].device
nstates = states["F"].shape[-4]
Expand All @@ -179,10 +226,8 @@ def _free_precess(states, t, T1, T2, weight, k, chemshift, D, v, grad_props):
name="Relaxation-MT",
)
else:
E = ops.Relaxation(
device, t, T1, T2, name="Relaxation"
)

E = ops.Relaxation(device, t, T1, T2, name="Relaxation")

# setup washout
if hasV and "moving" in states:
W = ops.FlowWash(
Expand All @@ -194,15 +239,15 @@ def _free_precess(states, t, T1, T2, weight, k, chemshift, D, v, grad_props):
)
else:
W = ops.Identity(name="Inflow+Washout")

# set up diffusion
if hasD:
D = ops.DiffusionDamping(
device, tau, D, nstates, name="Diffusion Damping", **grad_props
)
else:
D = ops.Identity(name="Diffusion until TE")

# set up flow
if hasV:
J = ops.FlowDephasing(
Expand All @@ -215,7 +260,6 @@ def _free_precess(states, t, T1, T2, weight, k, chemshift, D, v, grad_props):
D = ops.Identity(name="Diffusion Damping")
J = ops.Identity(name="Flow Dephasing")
W = ops.Identity(name="Inflow-Washout")


# set up gradient spoiling
S = ops.Shift(name="Gradient Spoiling")
Expand All @@ -224,7 +268,3 @@ def _free_precess(states, t, T1, T2, weight, k, chemshift, D, v, grad_props):
X = ops.CompositeOperator(W, J, D, E, name="Free Precession")

return X, S




Loading

0 comments on commit 3174270

Please sign in to comment.