Skip to content

Commit

Permalink
Fixed biot-savart scaling (#141)
Browse files Browse the repository at this point in the history
* Fixed biot-savart scaling

* Fixed test_biot_savart to match same units

* Comment adjustment, standardizing H gyro ratio, removing extraneous print
  • Loading branch information
Lincoln Craven-Brightman committed Oct 9, 2020
1 parent aee2848 commit ed2f2fd
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
6 changes: 3 additions & 3 deletions shimmingtoolbox/coils/biot_savart.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import numpy as np

MU0 = 1.256637e-6 # [H/m]
H_GYROMAGNETIC_RATIO = 4.258e+7 # [Hz/T]
H_GYROMAGNETIC_RATIO = 42.577478518e+6 # [Hz/T]


def biot_savart(centers, normals, radii, segment_numbers, fov_min, fov_max, fov_n):
Expand All @@ -23,7 +23,7 @@ def biot_savart(centers, normals, radii, segment_numbers, fov_min, fov_max, fov_
fov_n (tuple): Integer number of points for each dimension (x, y, z) in mm
Returns:
numpy.ndarray: (|X|, |Y|, |Z|, |centers|) coil profiles of magnetic field z-component -- (X, Y, Z, Channel)
numpy.ndarray: (|X|, |Y|, |Z|, |centers|) coil profiles of magnetic field z-component in Hz/A -- (X, Y, Z, Channel)
"""
ranges = []
Expand All @@ -49,7 +49,7 @@ def biot_savart(centers, normals, radii, segment_numbers, fov_min, fov_max, fov_
if not np.isnan(profiles[i, j, k, ch]):
profiles[i, j, k, ch] += bz

return profiles
return profiles * H_GYROMAGNETIC_RATIO # [Hz/A]


def _loop_segments(center, normal, radius, segment_num):
Expand Down
12 changes: 7 additions & 5 deletions test/test_biot_savart.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@

from shimmingtoolbox.coils.biot_savart import biot_savart

H_GYRO_R = 42.577478518e+6 # [Hz/T]

dummy_data = [
([(0, 0, -0.5)], [(0, 0, 1)], [1, ], [250, ], (0, 0, 0), (0, 0, 1), (1, 1, 3), (0.4495881427866065e-3,
2.2214414690791835e-4,
1.0723951147113824e-4)),
([(0, 0, -0.5)], [(0, 0, 1)], [1, ], [250, ], (0, 0, 0), (0, 0, 1), (1, 1, 3), (0.4495881427866065e-3 * H_GYRO_R,
2.2214414690791835e-4 * H_GYRO_R,
1.0723951147113824e-4 * H_GYRO_R)),
([(-0.5, 0, 0)], [(1, 0, 0)], [1, ], [250, ], (0, 0, 0), (1, 0, 0), (3, 1, 1), (0, 0, 0)),
([(0, -0.5, 0)], [(0, 1, 0)], [1, ], [250, ], (0, 0, 0), (0, 1, 0), (1, 3, 1), (0, 0, 0)),
]
Expand All @@ -23,6 +25,6 @@ def test_normal_use(centers, normals, radii, segment_numbers, fov_min, fov_max,
assert(basis[:, :, :, 0].shape == fov_n)

# Check expected values
actual = np.round(basis[:, :, :, 0].reshape(len(axis_answers)), decimals=7)
expected = np.round(np.asarray(axis_answers), decimals=7)
actual = np.round(basis[:, :, :, 0].reshape(len(axis_answers)), decimals=-1)
expected = np.round(np.asarray(axis_answers), decimals=-1)
assert(np.all(actual == expected))

0 comments on commit ed2f2fd

Please sign in to comment.