qsm_core/constants.rs
1//! Physical constants shared across the crate.
2//!
3//! Use these wherever QSM.rs converts between radians, Hz and ppm itself, and wherever a host
4//! converts QSM.rs's outputs (e.g. ppm → Hz for a BIDS `fieldmap`), so both agree.
5//!
6//! Ported methods that hard-code a different value in their authors' code (DECOMPOSE's 42.58,
7//! TGV-QSM's 42.5781, HEIDI's 2.67522128e8 rad/s/T, QSMART's 2.675e8, ...) keep that value
8//! locally, so the port matches the reference. Those sites say so; do not point them here.
9
10/// Proton reduced gyromagnetic ratio γ̄ = γ/2π, in Hz/T.
11///
12/// 42.576 MHz/T, the value QSM.rs has always used and the one the QSM-CI contract states for
13/// Hz ↔ ppm.
14///
15/// CODATA 2018 reference values:
16/// - shielded proton in water (25 °C, spherical sample), γ'ₚ/2π = 42.576 384 74 MHz/T, which is
17/// the relevant one for water-proton MRI;
18/// - free proton, γₚ/2π = 42.577 478 518 MHz/T.
19///
20/// 42.576 is within 1e-5 (relative) of the shielded value, closer to both than the 42.58 some
21/// toolboxes use. It is not set to the CODATA figure exactly because that would change every
22/// output; that is a separate decision.
23pub const GAMMA_BAR_HZ_PER_T: f64 = 42.576e6;
24
25/// [`GAMMA_BAR_HZ_PER_T`] in MHz/T, for formulas written as `2π · γ̄[MHz/T] · B0 · TE` (ppm → rad).
26pub const GAMMA_BAR_MHZ_PER_T: f64 = 42.576;
27
28/// Proton gyromagnetic ratio γ = 2π·γ̄, in rad/s/T.
29pub const GAMMA_RAD_PER_S_PER_T: f64 = 2.0 * std::f64::consts::PI * GAMMA_BAR_HZ_PER_T;
30
31#[cfg(test)]
32mod tests {
33 use super::*;
34
35 #[test]
36 fn units_agree() {
37 assert!((GAMMA_BAR_MHZ_PER_T * 1e6 - GAMMA_BAR_HZ_PER_T).abs() < 1e-6);
38 assert!((GAMMA_RAD_PER_S_PER_T - 2.675_128_97e8).abs() < 1.0);
39 }
40}