mrphy.utils

MRphy utilities

Utilities for data indexing, conversions, spin rotation.

mrphy.utils.ctrsub(shape: Any) Any

Compute center subscript indices of a regular grid

Usage:

cSub = ctrsub(shape)

mrphy.utils.g2k(g: Tensor, isTx: bool, dt: Tensor = tensor(4.0000e-06, dtype=torch.float64), *, γ: Tensor = tensor(4257.6000, dtype=torch.float64)) Tensor

Compute k-space from gradients.

Usage:

k = g2k(g, isTx, dt, *, γ)

Inputs:
  • g: (N, xyz, nT), “Gauss/cm”, gradient

  • isTx, if true, compute transmit k-space, k, ends at the origin.

Optionals:
  • γ: ()(N ⊻ 1, *Nd ⊻ 1,), “Hz/Gauss”, gyro ratio

  • dt: ()(N ⊻ 1,), “Sec”, dwell time.

Outputs:
  • k: (N, xyz, nT), “cycle/cm”, Tx or Rx k-space.

See Also:

g2s(), k2g()

mrphy.utils.g2s(g: Tensor, dt: Tensor = tensor(4.0000e-06, dtype=torch.float64)) Tensor

Compute slew rates from gradients.

Usage:

s = g2s(g, dt)

Inputs:
  • g: (N, xyz, nT), “Gauss/cm”, gradient

Optionals:
  • dt: ()(N ⊻ 1,), “Sec”, dwell time.

Outputs:
  • s: (N, xyz, nT), “cycle/cm/sec”, slew rate

See Also:

g2k(), s2g()

mrphy.utils.k2g(k: Tensor, isTx: bool, dt: Tensor = tensor(4.0000e-06, dtype=torch.float64), *, γ: Tensor = tensor(4257.6000, dtype=torch.float64)) Tensor

Compute k-space from gradients

Usage:

k = k2g(k, isTx, dt, *, γ)

Inputs:
  • k: (N, xyz, nT), “cycle/cm”, Tx or Rx k-space.

  • isTx, if true, compute transmit k-space, k, must end at the origin.

Optionals:
  • γ: ()(N ⊻ 1, *Nd ⊻ 1,), “Hz/Gauss”, gyro ratio

  • dt: ()(N ⊻ 1,), “Sec”, dwell time.

Outputs:
  • g: (N, xyz, nT), “Gauss/cm”, gradient

See Also:

g2k()

mrphy.utils.rf2tρθ(rf: Tensor, rfmax: Tensor) Tuple[Tensor, Tensor]

Convert real RF to tρ ≔ tan(ρ/ρ_max⋅π/2), and θ

Usage:

tρ, θ = rf2tρθ(rf, rfmax)

Inputs:
  • rf: (N, xy, nT, (nCoils)), RF pulse, Gauss, x: real, y: imag.

  • rfmax: (N, (nCoils)), RF pulse, Gauss, x for real, y for imag.

Outputs:
  • : (N, 1, nT, (nCoils)), tan(ρ/rfmax*π/2), [0, +∞).

  • θ: (N, 1, nT, (nCoils)), RF phase, [-π, π).

See Also:

tρθ2rf()

mrphy.utils.rf_c2r(rf: ndarray) ndarray

Convert complex RF to real RF

Usage:

rf = rf_c2r(rf)

Inputs:
  • rf: (N, 1, nT, (nCoils)), RF pulse, complex

Outputs:
  • rf: (N, xy, nT, (nCoils)), RF pulse, x for real, y for imag.

See Also:

rf_r2c()

mrphy.utils.rf_r2c(rf: ndarray) ndarray

Convert real RF to complex RF

Usage:

rf = rf_r2c(rf)

Inputs:
  • rf: (N, xy, nT, (nCoils)), RF pulse, x for real, y for imag.

Outputs:
  • rf: (N, 1, nT, (nCoils)), RF pulse, complex.

See Also:

rf_c2r()

mrphy.utils.rfclamp(rf: Tensor, rfmax: Tensor, *, eps: Number = 1e-07) Tensor

Clamp RF to rfmax

Usage:

rf = rfclamp(rf, rfmax, *, eps)

Inputs:
  • rf: (N, xy, nT, (nCoils)), RF pulse, Gauss, x for real, y for imag.

  • rfmax: (N, (nCoils)), RF pulse, Gauss, x for real, y for imag.

Optionals:
  • eps: effective rfmax, is rfmax-eps, numerical precession.

Outputs:
  • rf: (N, xy, nT, (nCoils)), |RF| clampled at rfmax

See Also:

sclamp()

mrphy.utils.s2g(s: Tensor, dt: Tensor = tensor(4.0000e-06, dtype=torch.float64)) Tensor

Compute gradients from slew rates.

Usage:

g = s2g(s, dt)

Inputs:
  • s: (N, xyz, nT), “Gauss/cm/Sec”, Slew rate.

Optionals:
  • dt: ()(N ⊻ 1,), “Sec”, dwell time.

Outputs:
  • g: (N, xyz, nT), “Gauss/cm”, Gradient.

See Also:

g2s()

mrphy.utils.s2ts(s: Tensor, smax: Tensor) Tensor

Convert slew rate to ts ≔ tan(s/s_max⋅π/2)

Usage:

ts = s2ts(s, smax)

Inputs:
  • s: (N, xyz, nT), slew rate, Gauss/cm/Sec.

  • smax: (N, xyz), max |slew rate|, Gauss/cm/Sec.

Outputs:
  • ts: (N, xyz, nT), tan(s/smax*π/2), (-∞, ∞)

See Also:

ts2s()

mrphy.utils.sclamp(s: Tensor, smax: Tensor) Tensor

Clamp slew rate to smax

Usage:

s = sclamp(s, smax)

Inputs:
  • s: (N, xyz, nT), slew rate, Gauss/cm/Sec.

  • smax: (N, xyz), max |slew rate|, Gauss/cm/Sec.

Outputs:
  • s: (N, xyz, nT), slew rate clamped at smax

See Also:

rfclamp()

mrphy.utils.ts2s(ts: Tensor, smax: Tensor) Tensor

Convert ts ≔ tan(s/s_max⋅π/2) to slew rate

Usage:

s = ts2s(ts, smax)

Inputs:
  • ts: (N, xyz, nT), tan(s/smax*π/2), (-∞, ∞)

  • smax: (N, xyz), max |slew rate|, Gauss/cm/Sec.

Outputs:
  • s: (N, xyz, nT), slew rate, Gauss/cm/Sec.

See Also:

s2ts()

mrphy.utils.tρθ2rf(: Tensor, θ: Tensor, rfmax: Tensor) Tensor

Convert tρ ≔ tan(ρ/ρ_max⋅π/2), and θ to real RF

Usage:

rf = tρθ2rf(tρ, θ, rfmax)

Inputs:
  • : (N, 1, nT, (nCoils)), tan(ρ/rfmax*π/2), [0, +∞).

  • θ: (N, 1, nT, (nCoils)), RF phase, [-π/2, π/2].

  • rfmax: (N, (nCoils)), RF pulse, Gauss, x for real, y for imag.

Outputs:
  • rf: (N, xy, nT, (nCoils)), RF pulse, Gauss, x: real, y: imag.

See Also:

rf2tρθ()

mrphy.utils.uφrot(U: Tensor, Φ: Tensor, Vi: Tensor) Tensor

Rotate Vi about axis U by Φ

Usage:

Vo = uϕrot(U, Φ, Vi)

Apply axis-angle, U-Phi rotation on V. Rotation is broadcasted on V. See wikipedia.

Inputs:
  • U: (N, *Nd, xyz), 3D rotation axes, assumed unitary;

  • Φ: (N, *Nd,), rotation angles;

  • Vi: (N, *Nd, xyz, (nV)), vectors to be rotated;

Outputs:
  • Vo: (N, *Nd, xyz, (nV)), vectors rotated;