Skip to main content

Python wrapper for 3D Cones MRI k-space trajectory design

Project description

conegrad

Python wrapper around the conegrad and conegrad_vd C functions for designing 3D Cones MRI k-space trajectories.

Gurney, P.T., Hargreaves, B.A. and Nishimura, D.G. (2006), Design and analysis of a practical 3D cones trajectory. Magn. Reson. Med., 55: 575-582. https://doi.org/10.1002/mrm.20796

Installation

pip install conegrad

Quick start

import numpy as np
import conegrad

res = [1e-3, 1e-3]  # [m], this is XY, and Z
fov = np.array([0.24, 0.24])  # [m], this is XY, and Z
gmax = 0.08  # [T/m]
smax = 80  # [T/m/s]
# Note: units cant be in CGS, just change the `units` argument

dt = 4e-6  # [s]
t_readout = 3e-3 # [s]

rewind_flag = 1  # Do rewinding lobe

n_pts = int(t_readout / dt)
out = conegrad.conegrad(res, fov, 
                        gmax=gmax, smax=smax, 
                        gsp=dt, grad_points=n_pts, 
                        units='SI', rewind_flag=rewind_flag)

# out is now the base cones
print(result.gx.shape, result.gx.dtype)  # (numcones, ngradact) float32, G/cm
print(result.ntheta, result.nintpc)      # number of theta bands, interleaves per band

# To exand the base cones to all cones in the trajectory:
exp = out.expand_trajectory()

# Now exp contains the full gradient waveforms
print(exp.gx.shape)

Arguments

The unit columns below are written as cgs / SI — both unit systems are supported via the units="cgs" (default) or units="SI" keyword argument.

Scan geometry (required positional)

Arg Type Shape Units (cgs / SI) Meaning
res float32 (2,) mm / m, × gamma_ratio Spatial resolution [xy, z]. For proton, gamma_ratio = 1; for other nuclei, scale by gamma_nucleus / gamma_proton.
fov float32 (2,) for conegrad; (300,) for conegrad_vd cm / m Field of view. See "Variable-density FOV layout" below for conegrad_vd.

Sequence timing (required, keyword-only)

Arg Type Units Typical Meaning
gsp float seconds 4e-6 Gradient sample period (i.e. 4 µs grid).
grad_points int samples a few hundred to several thousand Number of gradient samples during the readout window.
tsp float, optional seconds 4e-6 Readout (ADC) sample period. Defaults to gsp if omitted.
read_points int, optional samples up to a few thousand Number of oversampled readout sample points. Defaults to grad_points if omitted.

Note: grad_points drives the cone design; read_points/tsp are only used when writing the k-space trajectory file (ktraj_out_flag=1). Omit them unless you need the file output.

Scanner gradient limits (keyword-only)

Arg Type Units (cgs / SI) Typical 3T (cgs / SI) Meaning
gmax float G/cm / T/m 4.5 / 0.045 Max gradient amplitude during readout. Required.
smax float G/cm/s / T/m/s ~7960 / ~79.6 Max slew rate during readout. Required.
sys_max_rewind_g float, optional G/cm / T/m 2.6 / 0.026 Max gradient during rewinder. Defaults to gmax / sqrt(3).
max_s_rewind float, optional G/cm/s / T/m/s ~4600 / ~46 Max slew rate during rewinder. Defaults to smax / sqrt(3).
sys_gmax float, optional G/cm / T/m Hardware gradient ceiling, used only for internal int-amp scaling; the wrapper inverts it on output so it has no user-visible effect. Defaults to gmax.

Cone design (optional, keyword-only)

Arg Type Default Range Meaning
numcones int 32 1..100 Number of base cone waveforms designed (covers polar angles 0..π/2).
precision float 0.5 0..1 Cones design tolerance.
dcf float 0.0 0..1 Density compensation factor.
oversample int 1 1..1024 Trajectory oversampling factor.
mindens float 0.0 0..10 Minimum sampling density.
rewind_flag int 1 0 or 1 1 = full rewinder (return k to 0); anything else = ramp grad to 0 only. The original EPIC sequence also defined values 2/3/4 for alternative rewinder strategies, but those were handled outside scones_design.c and have no effect here.
sym_flag int 1 1, 2 1 = k-space symmetric (mirrors design across equator), 2 = asymmetric.
acq_mode int 1 1, 2 1 = Cones, 2 = Projection Reconstruction.
rot_flag float 1.0 -1 or +1 Direction of azimuthal rotation between interleaves.
slab_kz float 0.0 kz phase across the slab (added to all kz values).
t_fracx, t_fracy, t_fracz float 0.0 Per-axis fractional gradient delays (timing calibration).

File output (optional, keyword-only — all default to 0)

These trigger file writes into the current working directory. Defaults are off since most users only want the in-memory arrays.

Arg Type Effect
output_grad int 1 → write kacq_cone_g{x,y,z}.<uid> (per-cone gradient binaries).
ktraj_flag int 1 → run k-space-trajectory + density computation (needed for nintpc, rspthetas, max_gradient). Defaults to 1 in this wrapper.
ktraj_out_flag int 1 → write kacq_cone_{ktraj,dens,npc}.<uid> AND populate snr_efficiency.
endian_flag int Output file endianness flag (currently inert — endian conversion code is commented in scones_design.c).
rhkacq_uid int UID used in output filenames.
cones_plot_flag int 0..3 — generate gnuplot scripts of gradient (1) / k-space (2) / both (3).
verbose bool True → forward C-side printf debug output to stdout.
units str "cgs" (default) or "SI". Sets units for both inputs (m, T/m, T/m/s in SI mode; cm, G/cm, G/cm/s in cgs) and the returned gx/gy/gz/max_gradient (T/m vs G/cm).

Variable-density FOV layout (conegrad_vd only)

fov is a length-300 array laid out as three concatenated 100-sample channels:

Slice Meaning
fov[0:100] FOV_xy as a function of normalized k-radius
fov[100:200] FOV_z as a function of normalized k-radius
fov[200:300] Normalized k-radius (typically linspace(0, 1, 100))

Use conegrad.make_vd_fov(fov_full, fov_under=0.5, n_full=20) to build this table with the standard EPIC profile: inner n_full samples at the full FOV, outer samples linearly ramping to fov_under * fov_full.

Outputs

Both conegrad() and conegrad_vd() return a ConegradResult:

Field Type Shape Units Meaning
gx, gy, gz float32 (numcones, ngradact) G/cm (cgs) or T/m (SI) Per-cone base waveforms in physical units. gx[i], gy[i], gz[i] are a coupled triplet for cone i — do not mix indices across axes.
ntheta int scalar Number of polar bands designed in the upper hemisphere. Total bands in the full sphere acquisition = 2 * ntheta - 1.
nintpc int32 (2*ntheta-1,) shots Number of azimuthal interleaves per polar band. sum(nintpc) is total shots in the full acquisition.
rspthetas float32 (2*ntheta-1,) radians Polar angle θ of each band, in [-π/2, π/2] (full hemisphere range).
max_gradient float scalar G/cm Max gradient amplitude actually used in the design.
snr_efficiency float scalar percent Only populated when ktraj_out_flag=1 (which also writes files). 0 otherwise.
ngradact int scalar samples Per-cone waveform length (readout + rewinder).

Expanding to full per-shot trajectory

The 32 base waveforms are designed for the upper hemisphere only; the full sphere is built at scan time by polar-scaling and azimuthally rotating each base cone. Call result.expand_trajectory(rot_flag=...) to do this in Python:

et = result.expand_trajectory(rot_flag=1.0)
et.gx.shape  # (sum(nintpc), ngradact)  — every shot in the acquisition
et.band_index, et.interleaf_index  # which polar band / which interleaf each shot is

Returns an ExpandedTrajectory:

Field Type Shape Meaning
gx, gy, gz float32 (n_shots, ngradact) Per-shot gradient waveforms in the same physical units as the parent ConegradResult (G/cm in cgs mode, T/m in SI mode), already polar-scaled and z-rotated.
band_index int32 (n_shots,) Polar band each shot belongs to (0..2*ntheta-2).
interleaf_index int32 (n_shots,) Azimuthal interleaf within the band (0..nintpc[band]-1).

The polar scaling and z-rotation applied per shot match the EPIC scan-time code at mm4dflow.e:17050+. Specifically: for polar band t and interleaf k, base cone ci = ceil(|rspthetas[t]| / (π/2) · numcones) - 1:

xyscale = cos(theta) / cos(theta_down)
zscale  = sin(theta) / sin(theta_up)         # automatically negative below the equator
phi     = k · rot_flag · 2π / nintpc[t]

gx_shot = xyscale · (cos(phi)·gx_base − sin(phi)·gy_base)
gy_shot = xyscale · (sin(phi)·gx_base + cos(phi)·gy_base)
gz_shot = zscale  · gz_base

Building from source

pip install .

Requires a C and C++17 compiler, CMake >= 3.18, and Python >= 3.11. nanobind is fetched automatically as a build dependency.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

conegrad-0.0.1.tar.gz (6.1 MB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

conegrad-0.0.1-cp312-abi3-win_amd64.whl (127.7 kB view details)

Uploaded CPython 3.12+Windows x86-64

conegrad-0.0.1-cp312-abi3-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl (151.7 kB view details)

Uploaded CPython 3.12+manylinux: glibc 2.24+ x86-64manylinux: glibc 2.28+ x86-64

conegrad-0.0.1-cp312-abi3-macosx_11_0_arm64.whl (123.4 kB view details)

Uploaded CPython 3.12+macOS 11.0+ ARM64

conegrad-0.0.1-cp312-abi3-macosx_10_13_x86_64.whl (132.2 kB view details)

Uploaded CPython 3.12+macOS 10.13+ x86-64

File details

Details for the file conegrad-0.0.1.tar.gz.

File metadata

  • Download URL: conegrad-0.0.1.tar.gz
  • Upload date:
  • Size: 6.1 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for conegrad-0.0.1.tar.gz
Algorithm Hash digest
SHA256 c2cb574e9c5897a6523a634b4829d22c579d17c69df55182e5ae78670f3e2f30
MD5 65501d3298d5ec95b2abf3408fae1a7e
BLAKE2b-256 a9aff569077145fd0a6658f7d6d3853179bed9adf83d5208724b39f8a14ca50a

See more details on using hashes here.

Provenance

The following attestation bundles were made for conegrad-0.0.1.tar.gz:

Publisher: wheels.yml on cmr-group/conegrad

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file conegrad-0.0.1-cp312-abi3-win_amd64.whl.

File metadata

  • Download URL: conegrad-0.0.1-cp312-abi3-win_amd64.whl
  • Upload date:
  • Size: 127.7 kB
  • Tags: CPython 3.12+, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for conegrad-0.0.1-cp312-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 ebc080700e984b56b42b7dbb592c589906b5120be3ab6b015ae198503bcd5cce
MD5 d486bf880cddeb6340085a152058d3f3
BLAKE2b-256 1e418d72f9d2cdb1225ef8a9324f4728ec05b0f31d6461902b1f930c9b6d19a9

See more details on using hashes here.

Provenance

The following attestation bundles were made for conegrad-0.0.1-cp312-abi3-win_amd64.whl:

Publisher: wheels.yml on cmr-group/conegrad

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file conegrad-0.0.1-cp312-abi3-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for conegrad-0.0.1-cp312-abi3-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 b659001809ab6fff6bfc080428adb4a56867b8a58153d0a94e2624e446d84bd8
MD5 df65e807b2e7a83dcefeef4d60330458
BLAKE2b-256 54a454ddff13541d8fc9296a459876a4795c09afa82843e43a3fa9e6ae4d2b08

See more details on using hashes here.

Provenance

The following attestation bundles were made for conegrad-0.0.1-cp312-abi3-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl:

Publisher: wheels.yml on cmr-group/conegrad

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file conegrad-0.0.1-cp312-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for conegrad-0.0.1-cp312-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 8072d91aac9614887e8a6a4d9496736634f2781e4ed36b8cbe6e3c86abd6593b
MD5 212e773a11801105b33ef0463e38a86a
BLAKE2b-256 3a6ab963a9823ac5ce27ad34224905662dd834e3356e78c85e1f450b1d904b13

See more details on using hashes here.

Provenance

The following attestation bundles were made for conegrad-0.0.1-cp312-abi3-macosx_11_0_arm64.whl:

Publisher: wheels.yml on cmr-group/conegrad

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file conegrad-0.0.1-cp312-abi3-macosx_10_13_x86_64.whl.

File metadata

File hashes

Hashes for conegrad-0.0.1-cp312-abi3-macosx_10_13_x86_64.whl
Algorithm Hash digest
SHA256 a98ad8da30588a18b78e77e666746f4a770bd19a65460345b99e5b5a248313a5
MD5 54f2bb595315d492a0376b602238d2be
BLAKE2b-256 a4f6a87385d608677c49f07fb21c4d506b4160ed95732915818c13c66a9759bc

See more details on using hashes here.

Provenance

The following attestation bundles were made for conegrad-0.0.1-cp312-abi3-macosx_10_13_x86_64.whl:

Publisher: wheels.yml on cmr-group/conegrad

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page