Example #1
0
def stray_field_calc_thick(mx,
                           my,
                           mz,
                           Ms,
                           t,
                           sim_size,
                           z,
                           windowData=False,
                           windowPower=1 / 2):
    pi = np.pi
    mlen = len(mx)
    hlen = mlen / 2
    res = sim_size / mlen
    fieldPrefactor = (4 * pi * 1.0e-7) * Ms

    # Mx = np.multiply(mx, 1/(res**2))
    if windowData:
        mx = fi.window_image(mx, windowPower)
        my = fi.window_image(my, windowPower)
        mz = fi.window_image(mz, windowPower)
    fmxs = np.fft.fft2(mx)
    fmys = np.fft.fft2(my)
    fmzs = np.fft.fft2(mz)

    fmx = np.fft.fftshift(fmxs)
    fmy = np.fft.fftshift(fmys)
    fmz = np.fft.fftshift(fmzs)

    kxv = 2 * pi * np.linspace(
        -mlen / (2 * sim_size), mlen / (2 * sim_size), mlen, endpoint=False)
    kyv = 2 * pi * np.linspace(
        -mlen / (2 * sim_size), mlen / (2 * sim_size), mlen, endpoint=False)
    kx, ky = np.meshgrid(kxv, kyv)

    k = np.sqrt(kx**2 + ky**2)

    alpha = np.divide(np.exp(-k * z), k + 1e-10) * (1 - np.exp(-k * t)) / 2

    Hzk = alpha * k * fmz - 1j * alpha * (kx * fmx + ky * fmy)

    surface_cdk = fmz
    volume_cdk = -1j * (kx * fmx + ky * fmy)

    Hxk = -1j * np.divide(kx, k + (1e-10)) * Hzk
    Hyk = -1j * np.divide(ky, k + (1e-10)) * Hzk

    meffk = surface_cdk + np.divide(volume_cdk, k + (1e-10))

    volume_cd = np.real(np.fft.ifft2(np.fft.ifftshift(volume_cdk)))
    surface_cd = np.real(np.fft.ifft2(np.fft.ifftshift(fmz)))
    meff = np.real(np.fft.ifft2(np.fft.ifftshift(meffk)))

    Hx = fieldPrefactor * np.real(np.fft.ifft2(np.fft.ifftshift(Hxk)))
    Hy = fieldPrefactor * np.real(np.fft.ifft2(np.fft.ifftshift(Hyk)))
    Hz = fieldPrefactor * np.real(np.fft.ifft2(np.fft.ifftshift(Hzk)))

    return [Hx, Hy, Hz], surface_cd, volume_cd, meff
Example #2
0
def stray_field_calc_fast(mx,my,mz,Mst,sim_size,z,windowData=False,windowPower=1/2):
    pi = np.pi
    mlen = len(mx)
    hlen = mlen/2
    res = sim_size/mlen
    fieldPrefactor = (4*pi*1.0e-7)*Mst/2

    if windowData:
        mx = fi.window_image(mx,windowPower)
        my = fi.window_image(my,windowPower)
        mz = fi.window_image(mz,windowPower)
    fmxs = np.fft.fft2(mx, norm="ortho")
    fmys = np.fft.fft2(my, norm="ortho")
    fmzs = np.fft.fft2(mz, norm="ortho")

    fmx = np.fft.fftshift(fmxs)
    fmy = np.fft.fftshift(fmys)
    fmz = np.fft.fftshift(fmzs)

    surface_cdk = fmz

    volume_cdk = np.zeros_like(fmx)
    meffk = np.zeros_like(fmx)

    kxv = 2*pi*np.linspace(-mlen/(2*sim_size), mlen/(2*sim_size), mlen, endpoint=False)
    kyv = 2*pi*np.linspace(-mlen/(2*sim_size), mlen/(2*sim_size), mlen, endpoint=False)
    kx, ky = np.meshgrid(kxv, kyv)

    k = np.sqrt(kx**2 + ky**2)

    volume_cdk = -1j*(kx*fmx + ky*fmy)

    Hxk = np.zeros_like(fmx)
    Hyk = np.zeros_like(fmx)
    Hzk = np.zeros_like(fmx)

    Hzk = np.exp(-k*z) * k * (surface_cdk + np.divide(volume_cdk, k+(1e-10)))
    Hxk = -1j * np.divide(kx, k+(1e-10)) * Hzk
    Hyk = -1j * np.divide(ky, k+(1e-10)) * Hzk
    meffk = surface_cdk+np.divide(volume_cdk, k+(1e-10))

    surface_cd = Mst*np.real(np.fft.ifft2(np.fft.ifftshift(surface_cdk), norm="ortho"))
    volume_cd = Mst*np.real(np.fft.ifft2(np.fft.ifftshift(np.divide(volume_cdk,k+(1e-10))), norm="ortho"))
    meff = np.real(np.fft.ifft2(np.fft.ifftshift(meffk), norm="ortho"))

    Hx = fieldPrefactor*np.real(np.fft.ifft2(np.fft.ifftshift(Hxk), norm="ortho"))
    Hy = fieldPrefactor*np.real(np.fft.ifft2(np.fft.ifftshift(Hyk), norm="ortho"))
    Hz = fieldPrefactor*np.real(np.fft.ifft2(np.fft.ifftshift(Hzk), norm="ortho"))

    return [Hx, Hy, Hz], surface_cd, volume_cd, meff#, [Hxk, Hyk, Hzk]
    x0 = params[2]
    wid = params[3]

    y = c + (a / 2) * np.tanh((x - x0) / wid)
    return y


#---------------- RECONSTRUCTION ---------------------------------
#-----------------------------------------------------------------

datas = np.multiply(ffmask, data[0])
datas0 = np.add(datas, -np.cos(theta) * zfield)
datas0filter = signal.wiener(datas0, 3)
datas0filter = signal.medfilt(datas0filter, 5)

wimdata = fi.window_image(datas0)
wimdatafilter = fi.window_image(datas0filter, power=1 / 2)

recon_data = vr.vector_reconstruction(wimdatafilter,
                                      data[1],
                                      theta,
                                      thetaError,
                                      phi,
                                      height,
                                      scanL,
                                      kcutoff=1)

bxdata = recon_data[0]
bydata = recon_data[1]
bzdata = recon_data[2] + zfield
mdata = recon_data[3]
               np.exp(-2 * pi * (h + t) / l)) * np.sin(2 * pi * x / l)
    bz = B0 * (np.exp(-2 * pi * h / l) -
               np.exp(-2 * pi * (h + t) / l)) * np.cos(2 * pi * x / l)

    return bx, bz


x = np.linspace(-size / 2, size / 2, res, endpoint=False)
y = x
xx, yy = np.meshgrid(x, y)

my = np.sin(2 * pi * xx / l)
mz = np.cos(2 * pi * xx / l)
mx = np.zeros_like(my)

mwx = fi.window_image(mx, power=1 / 20)
mwy = fi.window_image(my, power=1 / 20)
mwz = fi.window_image(mz, power=1 / 20)
h, _, _, _ = sfct.stray_field_calc_thick(mx, my, mz, Ms, t, size, height)

flen = len(h[0])

fx = np.linspace(-size / 2, size / 2, flen, endpoint=False)

bx, bz = helix_field(fx, height)

plt.close('all')

fig1, ax1 = plt.subplots()
plt.plot(fx, h[0][int(flen / 2), :])
plt.plot(fx, bx)
Example #5
0
def vector_m_reconstruction(scannum,
                            kcutoff=1,
                            mask=True,
                            printError=False,
                            material='ta'):

    path = '/Users/alec/UCSB/cofeb_analysis_data/' + material + '/'
    scan_path = path + str(scannum) + '/'
    scan_params_path = scan_path + 'scan_parameters.json'
    material_params_path = path + 'material_parameters.json'
    with open(scan_params_path, 'r') as fread:
        scan_params = json.load(fread)
    with open(material_params_path, 'r') as fread:
        material_params = json.load(fread)

    Ms = material_params['Ms']
    t = material_params['t']
    DWWidth = material_params['DWWidth']

    phi = scan_params['phi']
    theta = scan_params['theta']
    thetaError = scan_params['thetaError']
    height = scan_params['height']
    heightError = scan_params['heightError']
    scanSize = scan_params['scanSize']
    xres = scan_params['xres']
    yres = scan_params['yres']
    xcenter = scan_params['xcenter']
    ycenter = scan_params['ycenter']
    zfield = scan_params['zfield'] * (1e4)  # convert to G

    data = lscan.load_ff('/Users/alec/UCSB/scan_data/' + str(scannum) +
                         '-esrdata/fitdata.txt',
                         xres,
                         yres,
                         Dgs=2870,
                         maxfgrad=20,
                         fieldangle=True,
                         printNVCalcError=printError)
    misc.imsave(
        '/Users/alec/UCSB/scan_images/full-field/ff' + str(scannum) + '.png',
        data[0])

    np.savetxt(scan_path + '/fail_index.txt', data[7])

    #---------------- RECONSTRUCTION ---------------------------------
    #-----------------------------------------------------------------

    datas = data[0]

    if (mask):
        ffmask = ndimage.imread('/Users/alec/UCSB/scan_images/full-field/ff' +
                                str(scannum) + 'mask.png',
                                flatten=True)
        ffmask = np.multiply(np.add(np.multiply(ffmask, 1 / 255), -0.5), -2)
        datas = np.multiply(ffmask, datas)

    datas0 = np.add(datas, -np.cos(theta) * zfield)

    wimdata = fi.window_image(datas0, power=1 / 10)

    recon_data = vr.vector_reconstruction(wimdata,
                                          data[1],
                                          theta,
                                          thetaError,
                                          phi,
                                          height,
                                          scanSize,
                                          t,
                                          kcutoff=kcutoff)

    bxdata = recon_data[0]
    bydata = recon_data[1]
    bzdata = recon_data[2] + zfield
    mdata = recon_data[3]
    Vdata = recon_data[4]
    bzdataError = recon_data[5]

    np.savetxt(scan_path + 'bNV.txt', data[0], delimiter=',')
    np.savetxt(scan_path + 'bNVError.txt', data[1], delimiter=',')
    np.savetxt(scan_path + 'bz.txt', bzdata, delimiter=',')
    np.savetxt(scan_path + 'bzError.txt', bzdataError, delimiter=',')
    np.savetxt(scan_path + 'bx.txt', bxdata, delimiter=',')
    np.savetxt(scan_path + 'by.txt', bydata, delimiter=',')
    np.savetxt(scan_path + 'mdata.txt', mdata, delimiter=',')
    np.savetxt(scan_path + 'V.txt', Vdata, delimiter=',')
Example #6
0
def stray_field_calc(mx, my, mz, Mst, sim_size, z, windowData=False):
    pi = np.pi
    mlen = len(mx)
    hlen = mlen / 2
    res = sim_size / mlen
    fieldPrefactor = (4 * pi * 1.0e-7) * Mst / 2

    # Mx = np.multiply(mx, 1/(res**2))
    if windowData:
        mx = fi.window_image(mx, windowPower)
        my = fi.window_image(my, windowPower)
        mz = fi.window_image(mz, windowPower)
    fmxs = np.fft.fft2(mx, norm="ortho")
    fmys = np.fft.fft2(my, norm="ortho")
    fmzs = np.fft.fft2(mz, norm="ortho")

    fmx = np.fft.fftshift(fmxs)
    fmy = np.fft.fftshift(fmys)
    fmz = np.fft.fftshift(fmzs)

    surface_cdk = fmz

    volume_cdk = np.zeros_like(fmx)
    meffk = np.zeros_like(fmx)

    for j in range(0, mlen):
        ky = 2 * pi * (j - hlen) / sim_size
        for i in range(0, mlen):
            kx = 2 * pi * (i - hlen) / sim_size
            volume_cdk[j][i] = -1j * (kx * fmx[j, i] + ky * fmy[j, i])

    Hxk = np.zeros_like(fmx)
    Hyk = np.zeros_like(fmx)
    Hzk = np.zeros_like(fmx)

    for j in range(0, mlen):
        ky = 2 * pi * (j - hlen) / sim_size
        for i in range(0, mlen):
            kx = 2 * pi * (i - hlen) / sim_size
            k = np.sqrt(kx**2 + ky**2)
            if (k == 0):
                Hzk[j, i] = 0
                Hxk[j][i] = 0
                Hyk[j][i] = 0
            else:
                Hzk[j][i] = np.exp(-k * z) * k * (surface_cdk[j, i] +
                                                  (volume_cdk[j][i]) / k)
                Hxk[j][i] = -1j * (kx / k) * Hzk[j, i]
                Hyk[j][i] = -1j * (ky / k) * Hzk[j, i]
                meffk[j][i] = surface_cdk[j, i] + (volume_cdk[j][i]) / k

    surface_cd = np.real(
        np.fft.ifft2(np.fft.ifftshift(surface_cdk), norm="ortho"))
    volume_cd = np.real(
        np.fft.ifft2(np.fft.ifftshift(volume_cdk), norm="ortho"))
    meff = np.real(np.fft.ifft2(np.fft.ifftshift(meffk), norm="ortho"))

    Hx = fieldPrefactor * np.real(
        np.fft.ifft2(np.fft.ifftshift(Hxk), norm="ortho"))
    Hy = fieldPrefactor * np.real(
        np.fft.ifft2(np.fft.ifftshift(Hyk), norm="ortho"))
    Hz = fieldPrefactor * np.real(
        np.fft.ifft2(np.fft.ifftshift(Hzk), norm="ortho"))

    return surface_cd, volume_cd, meff, [Hxk, Hyk, Hzk], [Hx, Hy, Hz]
Example #7
0
import fourier_image as fi

impath = '/Users/alec/UCSB/scan_images/irmn/domains1835.png'
domains = imread(impath, flatten=True)

scanvsize = 2
scansize = (5e-6) * scanvsize
slen = len(domains)
res = scansize / slen
res_difference = 2e-9
thickness = 0.911e-9
Ms = 1.044e6

domains = np.add(np.multiply(2 / 255, domains), -1)

wdomains = fi.window_image(domains)
fdomains = fft.fft2(wdomains)
fdomains = fft.fftshift(fdomains)

plt.close('all')

fig1, ax1 = plt.subplots()
im1 = plt.imshow(domains, cmap='Greys', interpolation='nearest')
fp.format_plot(plt, 400, 400, 450, 50)

fig1, ax1 = plt.subplots()
im1 = plt.imshow(np.log(np.abs(fdomains) + 1),
                 cmap='Greys',
                 interpolation='nearest')
fp.format_plot(plt, 400, 400, 450, 50)
Example #8
0
    h = args[0]
    x0 = 0
    bx = B0 * (h / (h**2 + (x - x0)**2))
    bz = -B0 * ((x - x0) / (h**2 + (x - x0)**2))

    return bx, bz


baspath = "/Users/alec/UCSB/cofeb_analysis_data/stray_field_test/"
filenames = ["medgex_test", "medgey_test", "medgez_test"]
numfiles = len(filenames)
m = []
for i in range(0, numfiles):
    m.append(np.transpose(np.loadtxt(baspath + filenames[i] + ".dat")))

mwx = fi.window_image(m[1])
mwy = fi.window_image(m[0])
mwz = fi.window_image(m[2])
h, _, _, _ = sfct.stray_field_calc_thick(mwx, mwy, mwz, Ms, t, size, height)

h[0] = (1e4) * h[0]
h[1] = (1e4) * h[1]
h[2] = (1e4) * h[2]

flen = len(h[0])

fx = np.linspace(-size / 2, size / 2, flen, endpoint=False)

bx, bz = edge_field(fx, height)

plt.close('all')
    a = params[1]
    x0 = params[2]
    wid = params[3]

    y = c+(a/pi)*np.arctan((x-x0)/wid)
    return y

#---------------- RECONSTRUCTION ---------------------------------
#-----------------------------------------------------------------

theta = 55.469*np.pi/180

datas = np.multiply(ffmask,data[0])
datas0 = np.add(datas,-np.cos(theta)*zfield)

wimdata = fi.window_image(datas0)

recon_data = vr.vector_reconstruction(wimdata, theta, phi, height, scanL)

bxdata = recon_data[0]
bydata = recon_data[1]
bzdata = recon_data[2]
meffdata = recon_data[3]

mzdataint = ndimage.interpolation.zoom(meffdata, 2, order=1)
minmz = np.min(mzdataint)
maxmz = np.max(mzdataint)

mzdataintnorm = np.multiply(np.add(mzdataint,-(maxmz+minmz)/2),1.999999/(maxmz-minmz))
mzdataintnorm = signal.wiener(mzdataintnorm)
Example #10
0
import matplotlib.pylab as pylab
from scipy import signal
import format_plot as fp
import fourier_image as fi

# mpl.rcParams['toolbar'] = 'None'

pi = np.pi
scannum = 1903
mgauge = 'neel_left'
path = '/Users/alec/UCSB/mathematica/magnetization_reconstruction/'
mz = np.loadtxt(path + 'mz_1760_' + mgauge + '_gauge.dat')[1:-1, 1:-1]
phi = np.loadtxt(path + 'phi_1760_' + mgauge + '_gauge.dat')
phiSeed = np.loadtxt(path + 'phiSeed_1760_' + mgauge + '_gauge.dat')
mr = np.sqrt(1 - mz**2)
mz = fi.window_image(mz, power=1 / 4)
mr = fi.window_image(mr, power=1 / 4)
mx = np.multiply(np.cos(phi), mr)
my = -np.multiply(np.sin(phi),
                  mr)  #negative to compensate for origin at image top

vec_space = 2
x = np.arange(0, len(mz[0]), vec_space)
y = x.copy()
mx_vec = mx[::vec_space, ::vec_space].copy()
my_vec = my[::vec_space, ::vec_space].copy()

plt.close('all')

fig1, ax1 = plt.subplots(figsize=(3, 3))
fig1.set_size_inches(4, 4)