Note
Go to the end to download the full example code
05. Compute and visualize magnetic field from PCB#
Example demonstrating how to load the PCB from HDF5 files which includes the connection information between wire segments and how to visualize the field due to them.
# Authors: Mainak Jas <mjas@mgh.harvard.edu>
# Gabriel Motta <gabrielbenmotta@gmail.com>
# sphinx_gallery_thumbnail_number = 7
from pathlib import Path
import h5io
from opmcoils.panels import PCBPanel, plot_panel
Let us first load the nulling coils
hardware_folder = Path.cwd().parent / 'hardware' / 'hdf5'
panels = dict()
panels_data = h5io.read_hdf5(hardware_folder / 'panels.hdf5')
for key, pan in panels_data.items():
panels[key] = PCBPanel(panel_dict=pan)
Now we can plot each of the coils
current = dict(left=1e-3, right=1e-3)
for panel_name in panels:
if 'G' in panel_name:
current['right'] = 1e-3
else:
current['right'] = -1e-3
axis = panel_name.strip('B').strip('G')
if axis == 'z':
current['right'] *= -1.
print(f'Length and resistance of the panel {panel_name} is'
f' {panels[panel_name].length:.2f} m and '
f'{panels[panel_name].resistance():.2f} Ohm')
plot_panel(panels[panel_name], .7, 32, current=current, axis=axis,
title=f'{panel_name} Panels')
Length and resistance of the panel Bx is 236.49 m and 11.62 Ohm
Length and resistance of the panel By is 232.18 m and 11.41 Ohm
Length and resistance of the panel Bz is 170.56 m and 8.38 Ohm
Length and resistance of the panel Gx is 164.87 m and 8.10 Ohm
Length and resistance of the panel Gy is 163.26 m and 8.02 Ohm
Length and resistance of the panel Gz is 114.64 m and 5.63 Ohm
We can also compute the combined field due to several nulling coils
from opmcoils import get_sphere_points
from opmcoils.panels import combined_panel_field
target_points, _ = get_sphere_points([0, 0, 0], n=8, sidelength=0.5)
panels = [panels['By'], panels['Bx'], panels['Bz']]
currents = [dict(left=1e-3, right=-1e-3),
dict(left=-1e-3, right=1e-3),
dict(left=.2e-3, right=.2e-3)]
field = combined_panel_field(panels, currents, target_points)
print(field)
[[1.24868485e-09 1.49751433e-09 1.46098810e-09]
[1.26105274e-09 1.48749325e-09 1.42440595e-09]
[1.29909885e-09 1.48197162e-09 1.42632374e-09]
[1.32167942e-09 1.47752131e-09 1.47299832e-09]
[1.26151474e-09 1.45858197e-09 1.45140685e-09]
[1.27444156e-09 1.45340990e-09 1.42030615e-09]
[1.31139839e-09 1.45177814e-09 1.42428863e-09]
[1.33478647e-09 1.45222516e-09 1.47170742e-09]
[1.30036874e-09 1.45946999e-09 1.44576793e-09]
[1.31309733e-09 1.45610016e-09 1.41883119e-09]
[1.35006471e-09 1.45688567e-09 1.42576480e-09]
[1.37365963e-09 1.46325483e-09 1.47740596e-09]
[1.32266443e-09 1.50623394e-09 1.44151032e-09]
[1.33737357e-09 1.50407138e-09 1.41887293e-09]
[1.37543905e-09 1.50873525e-09 1.43189386e-09]
[1.39568261e-09 1.52361757e-09 1.49267135e-09]
[1.32727063e-09 1.47418402e-09 1.44994025e-09]
[1.31727394e-09 1.46775248e-09 1.44482201e-09]
[1.31967429e-09 1.46201669e-09 1.44800405e-09]
[1.31110032e-09 1.45707080e-09 1.46545039e-09]
[1.32635158e-09 1.48776688e-09 1.43568334e-09]
[1.29547673e-09 1.48090746e-09 1.44417923e-09]
[1.29177048e-09 1.47508109e-09 1.43989906e-09]
[1.29805437e-09 1.47096198e-09 1.44418442e-09]
[1.29257986e-09 1.46803592e-09 1.46210679e-09]
[1.25424728e-09 1.46554486e-09 1.48251966e-09]
[1.31573889e-09 1.48082933e-09 1.42998876e-09]
[1.29142990e-09 1.47487534e-09 1.43911380e-09]
[1.29070553e-09 1.47088397e-09 1.43668938e-09]
[1.29824085e-09 1.46915249e-09 1.44261805e-09]
[1.29340073e-09 1.46939361e-09 1.46164442e-09]
[1.25470360e-09 1.47110767e-09 1.48244985e-09]
[1.31778190e-09 1.48229091e-09 1.42510322e-09]
[1.29770196e-09 1.47785764e-09 1.43561485e-09]
[1.29848286e-09 1.47564733e-09 1.43546940e-09]
[1.30601337e-09 1.47635766e-09 1.44380793e-09]
[1.29965267e-09 1.48026639e-09 1.46514354e-09]
[1.25669583e-09 1.48686598e-09 1.48738855e-09]
[1.30906437e-09 1.49821483e-09 1.42152431e-09]
[1.29215732e-09 1.49499756e-09 1.43349265e-09]
[1.29387060e-09 1.49426171e-09 1.43608357e-09]
[1.30013524e-09 1.49734374e-09 1.44792348e-09]
[1.28918693e-09 1.50474684e-09 1.47280018e-09]
[1.23678992e-09 1.51520369e-09 1.49683122e-09]
[1.25363065e-09 1.51496991e-09 1.43223466e-09]
[1.25505445e-09 1.51512337e-09 1.43823331e-09]
[1.25740943e-09 1.51978937e-09 1.45450020e-09]
[1.23730196e-09 1.52886009e-09 1.48318044e-09]
[1.28398551e-09 1.44974053e-09 1.43724290e-09]
[1.28408881e-09 1.44874314e-09 1.44354595e-09]
[1.28211158e-09 1.44703525e-09 1.44451901e-09]
[1.27102337e-09 1.44555143e-09 1.44446436e-09]
[1.28324971e-09 1.47474070e-09 1.41162836e-09]
[1.28386358e-09 1.47312538e-09 1.43662626e-09]
[1.28573517e-09 1.47025667e-09 1.44195077e-09]
[1.28531493e-09 1.46787442e-09 1.44324199e-09]
[1.27591277e-09 1.46630083e-09 1.44346763e-09]
[1.24952193e-09 1.46477773e-09 1.43300013e-09]
[1.28280828e-09 1.47929713e-09 1.41158059e-09]
[1.28524848e-09 1.47689644e-09 1.43461025e-09]
[1.28811449e-09 1.47441040e-09 1.44016816e-09]
[1.28832223e-09 1.47306236e-09 1.44242690e-09]
[1.27942602e-09 1.47291391e-09 1.44327645e-09]
[1.25326141e-09 1.47300570e-09 1.43207851e-09]
[1.28054314e-09 1.47860387e-09 1.41090936e-09]
[1.28460526e-09 1.47689272e-09 1.43305377e-09]
[1.28814978e-09 1.47561164e-09 1.43944118e-09]
[1.28834892e-09 1.47578986e-09 1.44304350e-09]
[1.27875478e-09 1.47737454e-09 1.44474111e-09]
[1.25094299e-09 1.47909381e-09 1.43269084e-09]
[1.26943879e-09 1.47711174e-09 1.41073706e-09]
[1.27517597e-09 1.47617491e-09 1.43242888e-09]
[1.27927671e-09 1.47583471e-09 1.43989099e-09]
[1.27882870e-09 1.47702944e-09 1.44498638e-09]
[1.26713584e-09 1.47944494e-09 1.44740138e-09]
[1.23554418e-09 1.48118150e-09 1.43371955e-09]
[1.24889601e-09 1.46513710e-09 1.43205871e-09]
[1.25321051e-09 1.46437640e-09 1.44061707e-09]
[1.25118150e-09 1.46486221e-09 1.44696774e-09]
[1.23577024e-09 1.46566673e-09 1.44924316e-09]
[1.23659727e-09 1.47215748e-09 1.45012246e-09]
[1.25235081e-09 1.47001848e-09 1.44776756e-09]
[1.25470242e-09 1.46823392e-09 1.44127234e-09]
[1.25068825e-09 1.46774739e-09 1.43256245e-09]
[1.23596093e-09 1.48716323e-09 1.43441072e-09]
[1.26789786e-09 1.48415776e-09 1.44812247e-09]
[1.27992987e-09 1.48046787e-09 1.44564923e-09]
[1.28069945e-09 1.47801169e-09 1.44044536e-09]
[1.27690414e-09 1.47711975e-09 1.43287754e-09]
[1.27146595e-09 1.47687052e-09 1.41112518e-09]
[1.25121256e-09 1.48308109e-09 1.43322892e-09]
[1.27936698e-09 1.48015737e-09 1.44529480e-09]
[1.28929671e-09 1.47734222e-09 1.44354215e-09]
[1.28941793e-09 1.47592341e-09 1.43985228e-09]
[1.28618329e-09 1.47597017e-09 1.43339476e-09]
[1.28243295e-09 1.47647271e-09 1.41123341e-09]
[1.25330628e-09 1.47499016e-09 1.43249381e-09]
[1.27981223e-09 1.47373968e-09 1.44367657e-09]
[1.28904263e-09 1.47268316e-09 1.44275580e-09]
[1.28915604e-09 1.47279315e-09 1.44041087e-09]
[1.28660494e-09 1.47402410e-09 1.43480090e-09]
[1.28448695e-09 1.47517413e-09 1.41178475e-09]
[1.24929112e-09 1.46489359e-09 1.43333554e-09]
[1.27602587e-09 1.46528394e-09 1.44374717e-09]
[1.28576497e-09 1.46565884e-09 1.44341843e-09]
[1.28651029e-09 1.46678667e-09 1.44202285e-09]
[1.28495902e-09 1.46836049e-09 1.43664337e-09]
[1.28467380e-09 1.46866372e-09 1.41167017e-09]
[1.27086260e-09 1.44292167e-09 1.44466489e-09]
[1.28229484e-09 1.44319398e-09 1.44457587e-09]
[1.28460322e-09 1.44361297e-09 1.44346522e-09]
[1.28482399e-09 1.44325828e-09 1.43708507e-09]
[1.23988213e-09 1.53558302e-09 1.48492418e-09]
[1.26036934e-09 1.52518758e-09 1.45613110e-09]
[1.25833267e-09 1.51921086e-09 1.43965727e-09]
[1.25715910e-09 1.51777639e-09 1.43344665e-09]
[1.23911917e-09 1.52126290e-09 1.49834545e-09]
[1.29190096e-09 1.50957238e-09 1.47436318e-09]
[1.30322009e-09 1.50091433e-09 1.44940356e-09]
[1.29727129e-09 1.49656451e-09 1.43740928e-09]
[1.29582040e-09 1.49603516e-09 1.43467528e-09]
[1.31297546e-09 1.49801437e-09 1.42263144e-09]
[1.25898559e-09 1.49077294e-09 1.48872122e-09]
[1.30232218e-09 1.48301554e-09 1.46650271e-09]
[1.30904596e-09 1.47790437e-09 1.44508852e-09]
[1.30182685e-09 1.47595339e-09 1.43662687e-09]
[1.30131550e-09 1.47689936e-09 1.43668323e-09]
[1.32167100e-09 1.48006992e-09 1.42616222e-09]
[1.25673071e-09 1.47286516e-09 1.48363430e-09]
[1.29581040e-09 1.47004987e-09 1.46281071e-09]
[1.30101103e-09 1.46863947e-09 1.44368431e-09]
[1.29378607e-09 1.46913901e-09 1.43763735e-09]
[1.29478742e-09 1.47184905e-09 1.44000102e-09]
[1.31939312e-09 1.47649639e-09 1.43091048e-09]
[1.25581265e-09 1.46534774e-09 1.48360712e-09]
[1.29454379e-09 1.46677389e-09 1.46312070e-09]
[1.30038721e-09 1.46854388e-09 1.44505761e-09]
[1.29442088e-09 1.47141915e-09 1.44063269e-09]
[1.29841432e-09 1.47592562e-09 1.44484906e-09]
[1.32959972e-09 1.48141239e-09 1.43639943e-09]
[1.31252946e-09 1.45420733e-09 1.46636539e-09]
[1.32149499e-09 1.45798890e-09 1.44872823e-09]
[1.31942801e-09 1.46244740e-09 1.44536430e-09]
[1.32972157e-09 1.46749871e-09 1.45038605e-09]
[1.40054572e-09 1.52877011e-09 1.49524210e-09]
[1.38075103e-09 1.51266404e-09 1.43431919e-09]
[1.34299578e-09 1.50672679e-09 1.42102842e-09]
[1.32846495e-09 1.50757934e-09 1.44343931e-09]
[1.37863262e-09 1.46603758e-09 1.47967302e-09]
[1.35546565e-09 1.45850863e-09 1.42789095e-09]
[1.31878605e-09 1.45648670e-09 1.42073733e-09]
[1.30622830e-09 1.45855389e-09 1.44754225e-09]
[1.33944246e-09 1.45259732e-09 1.47368553e-09]
[1.31646457e-09 1.45103094e-09 1.42608839e-09]
[1.27977950e-09 1.45144489e-09 1.42189683e-09]
[1.26702465e-09 1.45530847e-09 1.45291906e-09]
[1.32561857e-09 1.47577227e-09 1.47476129e-09]
[1.30344958e-09 1.47912610e-09 1.42784376e-09]
[1.26568046e-09 1.48342534e-09 1.42568983e-09]
[1.25350405e-09 1.49210325e-09 1.46219303e-09]]
Finally, we can plot the combined panels and their resulting field
from opmcoils.panels import plot_combined_panels
plot_combined_panels(panels, currents, target_points)

Total running time of the script: (0 minutes 24.480 seconds)