'returns the magnetic field for the current loop calculated
from eqns (1) and (2) in Phys Rev A Vol. 35, N 4, pp. 1535-1546; 1987.
return:
B is a vector for the B field at point r in inverse units of
(mu I) / (2 pi d)
for I in amps and d in meters and mu = 4 pi * 10^-7 we get Tesla'

def mk_B_field(self):

    (n, l, m) = self.base_vectors()
    R = self.radius
    r0 = self.position
    r = np.c_[(np.ravel(self.app.X), np.ravel(self.app.Y), np.ravel(self.app.Z))]
    trans = np.vstack((l, m, n))
    r -= r0
    r = np.dot(r, linalg.inv(trans))
    x = r[:, 0]
    y = r[:, 1]
    z = r[:, 2]
    rho = np.sqrt(((x ** 2) + (y ** 2)))
    theta = np.arctan((x / y))
    E = special.ellipe((((4 * R) * rho) / (((R + rho) ** 2) + (z ** 2))))
    K = special.ellipk((((4 * R) * rho) / (((R + rho) ** 2) + (z ** 2))))
    Bz = ((1 / np.sqrt((((R + rho) ** 2) + (z ** 2)))) * (K + ((E * (((R ** 2) - (rho ** 2)) - (z ** 2))) / (((R - rho) ** 2) + (z ** 2)))))
    Brho = ((z / (rho * np.sqrt((((R + rho) ** 2) + (z ** 2))))) * ((- K) + ((E * (((R ** 2) + (rho ** 2)) + (z ** 2))) / (((R - rho) ** 2) + (z ** 2)))))
    Brho[np.isnan(Brho)] = 0
    B = np.c_[((np.cos(theta) * Brho), (np.sin(theta) * Brho), Bz)]
    B = np.dot(B, trans)
    (Bx, By, Bz) = B.T
    Bx = np.reshape(Bx, self.app.X.shape)
    By = np.reshape(By, self.app.X.shape)
    Bz = np.reshape(Bz, self.app.X.shape)
    Bnorm = np.sqrt((((Bx ** 2) + (By ** 2)) + (Bz ** 2)))
    Bmax = (10 * np.median(Bnorm))
    Bx[(Bnorm > Bmax)] = np.NAN
    By[(Bnorm > Bmax)] = np.NAN
    Bz[(Bnorm > Bmax)] = np.NAN
    Bnorm[(Bnorm > Bmax)] = np.NAN
    self.Bx = Bx
    self.By = By
    self.Bz = Bz
    self.Bnorm = Bnorm
