Experimentally Measuring Magnetic Fields

This post will go over how we experimentally measured the magnetic field profiles of our NMR Mandhalas to compare with the theoretical simulations. These were done with a manual xy-stage, custom-printed holders, and a DC Gaussmeter.

The x and y position as well as the magnitude of the magnetic field at each position in the x and y directions were then plotted using the Jupyter notebook and the following Python code:

import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
from scipy.interpolate import griddata
sns.set_style('ticks')
sns.set_palette('deep',color_codes = True)
%matplotlib inline

# Load data from CSV
fullfilename = 'data_MandhalaA' + '.csv'
data = np.loadtxt(fullfilename,delimiter = ',', skiprows=1)

# Flipping signs of X and Y from data because was writing down position of Mandhala, but want to plot position of sensor, which is opposite
X = -data[:,0]
Y = -data[:,1]
Bx = data[:,2]
By = data[:,3]


# create x-y points to be used in heatmap
xi = np.linspace(X.min(),X.max(),100)
yi = np.linspace(Y.min(),Y.max(),100)

# Bi is a matrix of magnitude of the magnetic field at different x-y values
Bi = griddata((X, Y), np.sqrt(Bx**2 + By**2), (xi[None,:], yi[:,None]), method='cubic')

# Create the contour plot, the number is the number of contours to plot
CS = plt.contourf(xi, yi, Bi, 28, cmap=plt.cm.rainbow, vmin=700, vmax=3500)
cb = plt.colorbar()
cb.set_label('Magnetic Field Amplitude (Gauss)')
plt.quiver(X, Y, Bx, By)
plt.xlabel('x')
plt.ylabel('y')
plt.title('Magnetic Field Plotting for NMR Mandhala A')
plt.show()

When plotting different 2D planes along the z axis, the following code was used:

from matplotlib import gridspec

fig = plt.figure()
gs = gridspec.GridSpec(2, 4)

ax1 = fig.add_subplot(gs[0:,0:2])
ax1.contourf(xi, yi, Bi, 12, cmap=plt.cm.rainbow, vmin=700, vmax=3500)
cb = plt.colorbar(CS)
cb.set_label('Magnetic Field Amplitude (Gauss)')
ax1.quiver(X, Y, Bx, By)
plt.xlabel('x')
plt.ylabel('y')
ax1.set_title('Center')

ax2 = fig.add_subplot(gs[0,3])
ax2.contourf(x2i, y2i, B2i, 5, cmap=plt.cm.rainbow, vmin=700, vmax=3500)
ax2.quiver(X2, Y2, B2x, B2y)
plt.setp(ax2.get_xticklabels(), visible=False)
plt.ylabel('y')
ax2.set_title('Upper Half')

ax3 = fig.add_subplot(gs[1,3], sharex=ax2)
ax3.contourf(x1i, y1i, B1i, 14, cmap=plt.cm.rainbow, vmin=700, vmax=3500)
ax3.quiver(X1, Y1, B1x, B1y)
plt.xlabel('x')
plt.ylabel('y')
ax3.set_title('Lower Half')


fig = plt.gcf()
fig.suptitle('Magnetic Field Plotting for Stack of Mandhalas A & B', fontsize=16)
fig.tight_layout(pad = 2.5, h_pad =0, w_pad = -4)