Skip to content
Snippets Groups Projects
Commit 0afb984a authored by Jan Caron's avatar Jan Caron
Browse files

Found a way to use a src folder (PYRAMID as project, FZ-Jülich as workspace)

Removed old scripts (AnalyticSolution and DataLoader)
Added several template testcases
parent e758722a
No related branches found
No related tags found
No related merge requests found
Showing
with 716 additions and 438 deletions
# -*- coding: utf-8 -*-
"""
Created on Wed Mar 20 10:24:40 2013
@author: Jan
"""
'''IMPORT'''
from pylab import *
import numpy as np
from numpy import pi
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
#from matplotlib.ticker import FormatStrFormatter
'''CONSTANTS'''
PHI_0 = 2067.83 # magnetic flux in T*nm²
'''INPUT VARIABLES'''
b0 = 1.0 #in T
v0 = 0
Vacc = 30000
xDim, yDim = 160, 160
res = 10 #in nm
beta = 300.0/360.0 * 2*pi
x0 = res*xDim*0.5
y0 = res*yDim*0.5
R = res*xDim*0.2
'''CREATE COORDINATE GRIDS'''
x = np.linspace(res/2,xDim*res-res/2,num=xDim)
y = np.linspace(res/2,yDim*res-res/2,num=yDim)
xx, yy = np.meshgrid(x,y)
'''COMPUTATION MAGNETIC PHASE SHIFT (REAL SPACE) DISC'''
coeff = - pi * res * b0 / ( 2 * PHI_0 )
def phiMag(x,y):
r = np.sqrt((x-x0) ** 2 + (y-y0) ** 2)
result = coeff * ((y-y0) * np.cos(beta) - (x-x0) * np.sin(beta))
in_or_out = 1 * (r < R) + (R / r) ** 2 * (r > R)
result *= in_or_out
return result
phaseMag = phiMag(xx, yy)
def plot_phase(func, name):
fig = plt.figure()
ax = fig.add_subplot(111, aspect='equal')
plt.pcolormesh(func, cmap='Greys')
ticks = ax.get_xticks() * res
ax.set_xticklabels(ticks.astype(int))
ticks = ax.get_yticks() * res
ax.set_yticklabels(ticks.astype(int))
ax.set_title('Analytical Solution' + name)
ax.set_xlabel('x-axis [nm]')
ax.set_ylabel('y-axis [nm]')
plt.colorbar()
plt.show()
plot_phase(phaseMag, ' Disc - Phase')
plot_phase(cos(16*phaseMag), ' Disc - Cos(Phase)')
\ No newline at end of file
# -*- coding: utf-8 -*-
"""
Created on Wed Mar 20 10:24:40 2013
@author: Jan
"""
'''IMPORT'''
from pylab import *
import numpy as np
from numpy import pi
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
#from matplotlib.ticker import FormatStrFormatter
'''CONSTANTS'''
PHI_0 = 2067.83 # magnetic flux in T*nm²
'''INPUT VARIABLES'''
b0 = 1.0 #in T
v0 = 0
Vacc = 30000
xDim, yDim = 160, 160
res = 10 #in nm
beta = 300.0/360.0 * 2*pi
x0 = res*xDim*0.5
y0 = res*yDim*0.5
Lx = res*xDim*0.2
Ly = res*yDim*0.4
'''CREATE COORDINATE GRIDS'''
x = np.linspace(res/2,xDim*res-res/2,num=xDim)
y = np.linspace(res/2,yDim*res-res/2,num=yDim)
#xx, yy = np.meshgrid(x,y)
'''COMPUTATION MAGNETIC PHASE SHIFT (REAL SPACE) SLAB'''
def F0(x,y):
a = np.log( x**2 + y**2 )
b = np.arctan( x / y ) # atan or atan2?
return x*a - 2*x + 2*y*b
coeff = b0 * res / ( 4 * PHI_0 )
def phiMag(x,y):
return coeff * ( - np.cos(beta) * ( F0(x-x0-Lx/2,y-y0-Ly/2)-F0(x-x0+Lx/2,y-y0-Ly/2)
-F0(x-x0-Lx/2,y-y0+Ly/2)+F0(x-x0+Lx/2,y-y0+Ly/2) )
+ np.sin(beta) * ( F0(y-y0-Ly/2,x-x0-Lx/2)-F0(y-y0+Ly/2,x-x0-Lx/2)
-F0(y-y0-Ly/2,x-x0+Lx/2)+F0(y-y0+Ly/2,x-x0+Lx/2) ) )
def F0_Cos_1(x,y):
return coeff * np.cos(beta) * F0(x-x0-Lx/2,y-y0-Ly/2)
def F0_Cos_2(x,y):
return coeff * np.cos(beta) * F0(x-x0+Lx/2,y-y0-Ly/2)
def F0_Cos_3(x,y):
return coeff * np.cos(beta) * F0(x-x0-Lx/2,y-y0+Ly/2)
def F0_Cos_4(x,y):
return coeff * np.cos(beta) * F0(x-x0+Lx/2,y-y0+Ly/2)
def F0_Sin_1(x,y):
return coeff * np.sin(beta) * F0(y-y0-Ly/2,x-x0-Lx/2)
def F0_Sin_2(x,y):
return coeff * np.sin(beta) * F0(y-y0+Ly/2,x-x0-Lx/2)
def F0_Sin_3(x,y):
return coeff * np.sin(beta) * F0(y-y0-Ly/2,x-x0+Lx/2)
def F0_Sin_4(x,y):
return coeff * np.sin(beta) * F0(y-y0+Ly/2,x-x0+Lx/2)
def phiMag1(x,y):
return coeff * ( - 0*np.cos(beta) + 1*( F0(x-x0-Lx/2,y-y0-Ly/2)-F0(x-x0+Lx/2,y-y0-Ly/2)) )
def phiMag2(x,y):
return coeff * ( - 0*np.cos(beta) + 1*(-F0(x-x0-Lx/2,y-y0+Ly/2)+F0(x-x0+Lx/2,y-y0+Ly/2) ) )
def phiMag3(x,y):
return coeff * ( + 0*np.sin(beta) + 1*( F0(y-y0-Ly/2,x-x0-Lx/2)-F0(y-y0+Ly/2,x-x0-Lx/2) ) )
def phiMag4(x,y):
return coeff * ( + 0*np.sin(beta) + 1*(-F0(y-y0-Ly/2,x-x0+Lx/2)+F0(y-y0+Ly/2,x-x0+Lx/2) ) )
def Test(x,y):
return ( abs(x-x0)<Lx/2 and abs(y-y0)<Ly/2 )
xx, yy = np.meshgrid(x,y)
phaseMag = phiMag(xx, yy)
phase_F0_Cos_1 = F0_Cos_1(xx, yy)
phase_F0_Cos_2 = F0_Cos_2(xx, yy)
phase_F0_Cos_3 = F0_Cos_3(xx, yy)
phase_F0_Cos_4 = F0_Cos_4(xx, yy)
phase_F0_Sin_1 = F0_Sin_1(xx, yy)
phase_F0_Sin_2 = F0_Sin_2(xx, yy)
phase_F0_Sin_3 = F0_Sin_3(xx, yy)
phase_F0_Sin_4 = F0_Sin_4(xx, yy)
sinphase_F0_Cos_1 = np.sin(phase_F0_Cos_1)
sinphase_F0_Cos_2 = np.sin(phase_F0_Cos_2)
sinphase_F0_Cos_3 = np.sin(phase_F0_Cos_3)
sinphase_F0_Cos_4 = np.sin(phase_F0_Cos_4)
sinphase_F0_Sin_1 = np.sin(phase_F0_Sin_1)
sinphase_F0_Sin_2 = np.sin(phase_F0_Sin_2)
sinphase_F0_Sin_3 = np.sin(phase_F0_Sin_3)
sinphase_F0_Sin_4 = np.sin(phase_F0_Sin_4)
phase_F0_Cos_Complete = (phase_F0_Cos_1 + phase_F0_Cos_2
+ phase_F0_Cos_3 + phase_F0_Cos_4)
phase_F0_Sin_Complete = (phase_F0_Sin_1 + phase_F0_Sin_2
+ phase_F0_Sin_3 + phase_F0_Sin_4)
sinphase_F0_Cos_Complete = (sinphase_F0_Cos_1 + sinphase_F0_Cos_2
+ sinphase_F0_Cos_3 + sinphase_F0_Cos_4)
sinphase_F0_Sin_Complete = (sinphase_F0_Sin_1 + sinphase_F0_Sin_2
+ sinphase_F0_Sin_3 + sinphase_F0_Sin_4)
phaseMag1 = phiMag1(xx, yy)
phaseMag2 = phiMag2(xx, yy)
phaseMag3 = phiMag3(xx, yy)
phaseMag4 = phiMag4(xx, yy)
def plot_phase(func, name):
fig = plt.figure()
ax = fig.add_subplot(111, aspect='equal')
plt.pcolormesh(func, cmap='jet')
ticks = ax.get_xticks() * res
ax.set_xticklabels(ticks.astype(int))
ticks = ax.get_yticks() * res
ax.set_yticklabels(ticks.astype(int))
ax.set_title('Analytical Solution' + name)
ax.set_xlabel('x-axis [nm]')
ax.set_ylabel('y-axis [nm]')
plt.colorbar()
plt.show()
'''PLOT'''
fig = plt.figure()
ax = fig.add_subplot(111, aspect='equal')
plt.pcolormesh(np.cos(16*phaseMag), cmap='Greys')
ticks = ax.get_xticks()*res
ax.set_xticklabels(ticks.astype(int))
ticks = ax.get_yticks()*res
ax.set_yticklabels(ticks.astype(int))
ax.set_title('Analytical Solution')
ax.set_xlabel('x-axis [nm]')
ax.set_ylabel('y-axis [nm]')
plt.colorbar()
plt.show()
'''PLOT F0s'''
plot_phase(phase_F0_Cos_Complete, 'F0_Cos_Complete')
plot_phase(phase_F0_Sin_Complete, 'F0_Sin_Complete')
plot_phase(sinphase_F0_Cos_Complete, 'Sin_F0_Cos_Complete')
plot_phase(sinphase_F0_Sin_Complete, 'Sin_F0_Sin_Complete')
#plot_phase(phase_F0_Cos_1, 'F0_Cos_1')
#plot_phase(phase_F0_Cos_2, 'F0_Cos_2')
#plot_phase(phase_F0_Cos_3, 'F0_Cos_3')
#plot_phase(phase_F0_Cos_4, 'F0_Cos_4')
#plot_phase(phase_F0_Sin_1, 'F0_Sin_1')
#plot_phase(phase_F0_Sin_2, 'F0_Sin_2')
#plot_phase(phase_F0_Sin_3, 'F0_Sin_3')
#plot_phase(phase_F0_Sin_4, 'F0_Sin_4')
#plot_phase(phase_F0_Cos_1-phase_F0_Cos_3, 'F0_Cos_1-3')
#plot_phase(phase_F0_Cos_2-phase_F0_Cos_4, 'F0_Cos_2-4')
#plot_phase(phase_F0_Sin_1-phase_F0_Sin_3, 'F0_Sin_1-3')
#plot_phase(phase_F0_Sin_2-phase_F0_Sin_4, 'F0_Sin_2-4')
#plot_phase(phase_F0_Cos_1-phase_F0_Cos_3 + phase_F0_Cos_2-phase_F0_Cos_4,
# 'F0_Cos_Complete')
#plot_phase(phase_F0_Sin_1-phase_F0_Sin_3 + phase_F0_Sin_2-phase_F0_Sin_4,
# 'F0_Sin_Complete')
# plot_phase(phase_F0_Sin_1-phase_F0_Sin_3 + phase_F0_Sin_2-phase_F0_Sin_4,
# 'F0_Sin_Complete')
x = np.linspace(-50,50,100)
y = np.linspace(-50,50,100)
xx, yy = np.meshgrid(x,y)
Arc2 = np.arctan2(yy,xx)
Arc = np.arctan(yy/xx)
\ No newline at end of file
# -*- coding: utf-8 -*-
"""
Created on Wed Mar 20 10:24:40 2013
@author: Jan
"""
'''PROBLEM: Sphere is 3D, current model is just 2D'''
'''IMPORT'''
from pylab import *
import numpy as np
from numpy import pi
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
#from matplotlib.ticker import FormatStrFormatter
'''CONSTANTS'''
PHI_0 = 2067.83 # magnetic flux in T*nm²
'''INPUT VARIABLES'''
b0 = 1.0 #in T
v0 = 0
Vacc = 30000
xDim, yDim = 160, 160
res = 10 #in nm
beta = 300.0/360.0 * 2*pi
x0 = res*xDim*0.5
y0 = res*yDim*0.5
R = res*xDim*0.2
'''CREATE COORDINATE GRIDS'''
x = np.linspace(res/2,xDim*res-res/2,num=xDim)
y = np.linspace(res/2,yDim*res-res/2,num=yDim)
xx, yy = np.meshgrid(x,y)
'''COMPUTATION MAGNETIC PHASE SHIFT (REAL SPACE) DISC'''
def F0(x,y):
a = np.log( x**2 + y**2 )
b = np.arctan2( x, y ) # atan or atan2?
return x*a - 2*x + 2*y*b
coeff = - 2/3 * pi * R**3 * b0 / PHI_0 * res/R
def phiMag(x,y):
r = np.sqrt((x-x0) ** 2 + (y-y0) ** 2)
result = coeff / r**2 * ((y-y0) * np.cos(beta) - (x-x0) * np.sin(beta))
in_or_out = 1 * (r > R) + (1 - (1-(r/R)**2)**(3/2)) * (r < R)
result *= in_or_out
return result
phaseMag = phiMag(xx, yy)
def plot_phase(func, name):
fig = plt.figure()
ax = fig.add_subplot(111, aspect='equal')
plt.pcolormesh(func, cmap='Greys')
ticks = ax.get_xticks() * res
ax.set_xticklabels(ticks.astype(int))
ticks = ax.get_yticks() * res
ax.set_yticklabels(ticks.astype(int))
ax.set_title('Analytical Solution' + name)
ax.set_xlabel('x-axis [nm]')
ax.set_ylabel('y-axis [nm]')
plt.colorbar()
plt.show()
plot_phase(phaseMag, ' Sphere - Phase')
plot_phase(cos(16*phaseMag), ' Sphere - Cos(Phase)')
\ No newline at end of file
# -*- coding: utf-8 -*-
"""
Created on Wed Mar 20 10:24:40 2013
@author: Jan
"""
'''IMPORT'''
import numpy as np
from numpy import pi, e
import matplotlib.pyplot as plt
import math as ma
'''CONSTANTS'''
PHI_0 = 2067.83
'''INPUT VARIABLES'''
b0 = 1.0
v0 = 0
Vacc = 30000
scale=1E-7
padFactor = 2
filename = 'output.txt'
'''READ DATA'''
data = np.genfromtxt(filename, skip_header=2)
xDim, yDim, zDim = np.genfromtxt(filename, dtype=int, skip_header=1, skip_footer=len(data[:,0]))
res = (data[1,0] - data[0,0]) / scale
xLen, yLen, zLen = [data[-1,i]/scale+res/2 for i in range(3)]
xMag, yMag, zMag = [data[:,i].reshape(zDim,yDim,xDim).mean(0)*zLen for i in range(3,6)]
#Reshape in Python and Igor is different, Python fills rows first, Igor columns!
#TODO interpolation (redefine xDim,yDim,zDim) thickness ramp
'''COMPUTATION MAGNETIC PHASE SHIFT (REAL SPACE) SLAB'''
# def F0(x,y):
# a = np.log( x**2 + y**2 )
# b = np.arctan( x / y )
# return x*a - 2*x + 2*y*b
#
# coeff = b0 * res / ( 4 * PHI_0 )
#
# def phiMag(x,y):
# return coeff * ( - np.cos(beta) * ( F0(x-x0-Lx/2,y-y0-Ly/2)
# -F0(x-x0+Lx/2,y-y0-Ly/2)
# -F0(x-x0-Lx/2,y-y0+Ly/2)
# +F0(x-x0+Lx/2,y-y0+Ly/2) )
# + np.sin(beta) * ( F0(y-y0-Ly/2,x-x0-Lx/2)
# -F0(y-y0+Ly/2,x-x0-Lx/2)
# -F0(y-y0-Ly/2,x-x0+Lx/2)
# +F0(y-y0+Ly/2,x-x0+Lx/2) ) )
#
# return phiMag(xx, yy)
def F(n,m):
a = np.log( res**2/4 * ( (2*n-1)**2 + (2*m-1)**2 ) )
b = np.arctan( (2*n-1) / (2*m-1) )
return res * ( (n-1/2)*a - (2*n-1) + (2*m-1)*b )
coeff = b0 / ( 4 * PHI_0 )
beta = np.arctan2(yMag, xMag)
absMag = np.sqrt(xMag**2 + yMag**2)
def phi_ij(i,j,p,q):
return absMag[j,i] * ( - np.cos(beta[j,i]) * (F(p-i,q-j)-F(p-i+1,q-j)
-F(p-i,q-j+1)+F(p-i+1,q-j+1))
+ np.sin(beta[j,i]) * (F(q-j,p-i)-F(q-j+1,p-i)
-F(q-j,p-i+1)+F(q-j+1,p-i+1)) )
phaseMag = np.zeros((yDim,xDim))
for q in range(yDim):
for p in range(xDim):
for j in range(yDim):
for i in range(xDim):
phaseMag[q,p] += phi_ij(i,j,p,q)
phaseMag *= coeff
#TODO Electrostatic Component
'''PLOT'''
fig = plt.figure()
ax = fig.add_subplot(111, aspect='equal')
plt.pcolormesh(phaseMag, cmap='gray')
ticks = ax.get_xticks()*res
ax.set_xticklabels(ticks.astype(int))
ticks = ax.get_yticks()*res
ax.set_yticklabels(ticks.astype(int))
ax.set_title('Real Space Approach')
ax.set_xlabel('x-axis [nm]')
ax.set_ylabel('y-axis [nm]')
plt.colorbar()
plt.show()
\ No newline at end of file
# -*- coding: utf-8 -*-
"""
Created on Wed Apr 03 11:15:38 2013
@author: Jan
"""
import numpy as np
import matplotlib.pyplot as plt
import pyramid.magcreator as mc
import pyramid.dataloader as dl
import pyramid.phasemap as pm
import pyramid.holoimage as hi
import pyramid.analytic as an
import time
import pdb, traceback, sys
from numpy import pi
def phase_from_mag():
'''Calculate and display the phase map from a given magnetization.
Arguments:
None
Returns:
None
'''
'''INPUT'''
# TODO: Input via GUI
filename = '../output/output.txt'
b_0 = 10.0 # in T
v_0 = 0 # TODO: units?
v_acc = 30000 # in V
padding = 20
density = 100
dim = (50, 50) # in px (y,x)
res = 1.0 # in nm
beta = pi/4
plot_mag_distr = True
# Slab:
shape_fun = mc.slab
center = (24, 24) # in px (y,x) index starts with 0!
width = (25, 25) # in px (y,x)
params = (center, width)
# # Disc:
# shape_fun = mc.disc
# center = (4, 4) # in px (y,x)
# radius = 2.5
# params = (center, radius)
# # Filament:
# shape_fun = mc.filament
# pos = 5
# x_or_y = 'y'
# params = (pos, x_or_y)
# # Alternating Filaments:
# shape_fun = mc.alternating_filaments
# spacing = 5
# x_or_y = 'y'
# params = (spacing, x_or_y)
# # Single Pixel:
# shape_fun = mc.single_pixel
# pixel = (5, 5)
# params = pixel
# '''CREATE LOGO'''
# mc.create_logo(128, res, beta, filename, plot_mag_distr)
# mag_data = dl.MagDataLLG(filename)
# phase= pm.real_space_slab(mag_data, b_0)
# holo = hi.holo_image(phase, mag_data.res, density)
# hi.display_holo(holo, '')
'''CREATE MAGNETIC DISTRIBUTION'''
mc.create_hom_mag(dim, res, beta, shape_fun, params,
filename, plot_mag_distr)
'''LOAD MAGNETIC DISTRIBUTION'''
mag_data = dl.MagDataLLG(filename)
# TODO: get it to work:
phase_el = pm.phase_elec(mag_data, v_0=1, v_acc=200000)
phi_cos_real_slab = np.zeros((2*dim[0]-1, 2*dim[1]-1))
pm.real_space_slab(mag_data, b_0, pixel_map=phi_cos_real_slab)
pm.display_phase(phi_cos_real_slab, res, 'Phase of one Pixel-Slab (Cos - Part)')
phi_cos_real_disc = np.zeros((2*dim[0]-1, 2*dim[1]-1))
pm.real_space_disc(mag_data, b_0, pixel_map=phi_cos_real_disc)
pm.display_phase(phi_cos_real_disc, res, 'Phase of one Pixel-Disc (Cos - Part)')
phi_cos_diff = phi_cos_real_slab - phi_cos_real_disc
pm.display_phase(phi_cos_diff, mag_data.res, 'Difference: One Pixel Slab - Disc')
'''NUMERICAL SOLUTION'''
# numerical solution Fourier Space:
tic = time.clock()
phase_fft = pm.fourier_space(mag_data, b_0, padding)
toc = time.clock()
print 'Time for Fourier Space Approach: ' + str(toc - tic)
holo_fft = hi.holo_image(phase_fft, mag_data.res, density)
display_combined(phase_fft, mag_data.res, holo_fft,
'Fourier Space Approach')
# numerical solution Real Space (Slab):
jacobi = np.zeros((2*dim[0]*dim[1], dim[0]*dim[1]))
tic = time.clock()
phase_real_slab = pm.real_space_slab(mag_data, b_0, jacobi=None)
toc = time.clock()
np.savetxt('../output/jacobi.npy', jacobi)
print 'Time for Real Space Approach (Slab): ' + str(toc - tic)
holo_real_slab = hi.holo_image(phase_real_slab, mag_data.res, density)
display_combined(phase_real_slab, mag_data.res, holo_real_slab,
'Real Space Approach (Slab)')
# numerical solution Real Space (Disc):
tic = time.clock()
phase_real_disc = pm.real_space_disc(mag_data, b_0)
toc = time.clock()
print 'Time for Real Space Approach (Disc): ' + str(toc - tic)
holo_real_disc = hi.holo_image(phase_real_disc, mag_data.res, density)
display_combined(phase_real_disc, mag_data.res, holo_real_disc,
'Real Space Approach (Disc)')
'''ANALYTIC SOLUTION'''
# analytic solution slab:
phase = an.phasemap_slab(dim, res, beta, center, width, b_0)
holo = hi.holo_image(phase, res, density)
display_combined(phase, res, holo, 'Analytic Solution - Slab')
# # analytic solution disc:
# phase = an.phasemap_disc(dim, res, beta, center, radius, b_0)
# holo = hi.holo_image(phase, res, density)
# display_combined(phase, res, holo, 'Analytic Solution - Disc')
# # analytic solution sphere:
# phase = an.phasemap_sphere(dim, res, beta, center, radius, b_0)
# holo = hi.holo_image(phase, res, density)
# display_combined(phase, res, holo, 'Analytic Solution - Sphere')
'''DIFFERENCES'''
diff_fft_to_ana = phase_fft - phase
diff_real_slab_to_ana = phase_real_slab - phase
diff_real_disc_to_ana = phase_real_disc - phase
diff_slab_to_disc = phase_real_disc - phase_real_slab
pm.display_phase(diff_fft_to_ana, res, 'Difference: FFT - Analytic')
pm.display_phase(diff_real_slab_to_ana, res, 'Difference: Slab - Analytic')
pm.display_phase(diff_real_disc_to_ana, res, 'Difference: Disc - Analytic')
pm.display_phase(diff_slab_to_disc, res, 'Difference: Disc - Slab')
# TODO: Delete
# import pdb; pdb.set_trace()
def display_combined(phase, res, holo, title):
fig = plt.figure(figsize=(14, 7))
fig.suptitle(title, fontsize=20)
holo_axis = fig.add_subplot(1,2,1, aspect='equal')
hi.display_holo(holo, 'Holography Image', holo_axis)
phase_axis = fig.add_subplot(1,2,2, aspect='equal')
pm.display_phase(phase, res, 'Phasemap', phase_axis)
if __name__ == "__main__":
try:
phase_from_mag()
except:
type, value, tb = sys.exc_info()
traceback.print_exc()
pdb.post_mortem(tb)
\ No newline at end of file
# -*- coding: utf-8 -*-
"""
Created on Wed Apr 03 11:15:38 2013
@author: Jan
"""
import pyramid.magcreator as mc
import pyramid.dataloader as dl
import pyramid.phasemap as pm
import pyramid.holoimage as hi
import pdb, traceback, sys
from numpy import pi
def create_logo():
'''Calculate and display the phase map from a given magnetization.
Arguments:
None
Returns:
None
'''
filename = '../output/logo_magnetization.txt'
b_0 = 1.0 # in T
res = 10.0 # in nm
beta = pi/2
density = 10
mc.create_logo(128, res, beta, filename)
mag_data = dl.MagDataLLG(filename)
phase= pm.real_space_slab(mag_data, b_0)
holo = hi.holo_image(phase, mag_data.res, density)
hi.display_holo(holo, '')
if __name__ == "__main__":
try:
create_logo()
except:
type, value, tb = sys.exc_info()
traceback.print_exc()
pdb.post_mortem(tb)
\ No newline at end of file
# -*- coding: utf-8 -*-
"""
Created on Wed Apr 03 11:15:38 2013
@author: Jan
"""
import numpy as np
import matplotlib.pyplot as plt
import pyramid.magcreator as mc
import pyramid.dataloader as dl
import pyramid.phasemap as pm
import pyramid.holoimage as hi
import pyramid.analytic as an
import time
import pdb, traceback, sys
from numpy import pi
def phase_from_mag():
'''Calculate and display the phase map from a given magnetization.
Arguments:
None
Returns:
None
'''
'''INPUT'''
# TODO: Input via GUI
filename = '../output/output.txt'
b_0 = 10.0 # in T
v_0 = 0 # TODO: units?
v_acc = 30000 # in V
padding = 20
density = 100
dim = (50, 50) # in px (y,x)
res = 1.0 # in nm
beta = pi/4
plot_mag_distr = True
# Slab:
shape_fun = mc.slab
center = (24, 24) # in px (y,x) index starts with 0!
width = (25, 25) # in px (y,x)
params = (center, width)
# # Disc:
# shape_fun = mc.disc
# center = (4, 4) # in px (y,x)
# radius = 2.5
# params = (center, radius)
# # Filament:
# shape_fun = mc.filament
# pos = 5
# x_or_y = 'y'
# params = (pos, x_or_y)
# # Alternating Filaments:
# shape_fun = mc.alternating_filaments
# spacing = 5
# x_or_y = 'y'
# params = (spacing, x_or_y)
# # Single Pixel:
# shape_fun = mc.single_pixel
# pixel = (5, 5)
# params = pixel
# '''CREATE LOGO'''
# mc.create_logo(128, res, beta, filename, plot_mag_distr)
# mag_data = dl.MagDataLLG(filename)
# phase= pm.real_space_slab(mag_data, b_0)
# holo = hi.holo_image(phase, mag_data.res, density)
# hi.display_holo(holo, '')
'''CREATE MAGNETIC DISTRIBUTION'''
mc.create_hom_mag(dim, res, beta, shape_fun, params,
filename, plot_mag_distr)
'''LOAD MAGNETIC DISTRIBUTION'''
mag_data = dl.MagDataLLG(filename)
# TODO: get it to work:
phase_el = pm.phase_elec(mag_data, v_0=1, v_acc=200000)
phi_cos_real_slab = np.zeros((2*dim[0]-1, 2*dim[1]-1))
pm.real_space_slab(mag_data, b_0, pixel_map=phi_cos_real_slab)
pm.display_phase(phi_cos_real_slab, res, 'Phase of one Pixel-Slab (Cos - Part)')
phi_cos_real_disc = np.zeros((2*dim[0]-1, 2*dim[1]-1))
pm.real_space_disc(mag_data, b_0, pixel_map=phi_cos_real_disc)
pm.display_phase(phi_cos_real_disc, res, 'Phase of one Pixel-Disc (Cos - Part)')
phi_cos_diff = phi_cos_real_slab - phi_cos_real_disc
pm.display_phase(phi_cos_diff, mag_data.res, 'Difference: One Pixel Slab - Disc')
'''NUMERICAL SOLUTION'''
# numerical solution Fourier Space:
tic = time.clock()
phase_fft = pm.fourier_space(mag_data, b_0, padding)
toc = time.clock()
print 'Time for Fourier Space Approach: ' + str(toc - tic)
holo_fft = hi.holo_image(phase_fft, mag_data.res, density)
display_combined(phase_fft, mag_data.res, holo_fft,
'Fourier Space Approach')
# numerical solution Real Space (Slab):
jacobi = np.zeros((2*dim[0]*dim[1], dim[0]*dim[1]))
tic = time.clock()
phase_real_slab = pm.real_space_slab(mag_data, b_0, jacobi=None)
toc = time.clock()
np.savetxt('../output/jacobi.npy', jacobi)
print 'Time for Real Space Approach (Slab): ' + str(toc - tic)
holo_real_slab = hi.holo_image(phase_real_slab, mag_data.res, density)
display_combined(phase_real_slab, mag_data.res, holo_real_slab,
'Real Space Approach (Slab)')
# numerical solution Real Space (Disc):
tic = time.clock()
phase_real_disc = pm.real_space_disc(mag_data, b_0)
toc = time.clock()
print 'Time for Real Space Approach (Disc): ' + str(toc - tic)
holo_real_disc = hi.holo_image(phase_real_disc, mag_data.res, density)
display_combined(phase_real_disc, mag_data.res, holo_real_disc,
'Real Space Approach (Disc)')
'''ANALYTIC SOLUTION'''
# analytic solution slab:
phase = an.phasemap_slab(dim, res, beta, center, width, b_0)
holo = hi.holo_image(phase, res, density)
display_combined(phase, res, holo, 'Analytic Solution - Slab')
# # analytic solution disc:
# phase = an.phasemap_disc(dim, res, beta, center, radius, b_0)
# holo = hi.holo_image(phase, res, density)
# display_combined(phase, res, holo, 'Analytic Solution - Disc')
# # analytic solution sphere:
# phase = an.phasemap_sphere(dim, res, beta, center, radius, b_0)
# holo = hi.holo_image(phase, res, density)
# display_combined(phase, res, holo, 'Analytic Solution - Sphere')
'''DIFFERENCES'''
diff_fft_to_ana = phase_fft - phase
diff_real_slab_to_ana = phase_real_slab - phase
diff_real_disc_to_ana = phase_real_disc - phase
diff_slab_to_disc = phase_real_disc - phase_real_slab
pm.display_phase(diff_fft_to_ana, res, 'Difference: FFT - Analytic')
pm.display_phase(diff_real_slab_to_ana, res, 'Difference: Slab - Analytic')
pm.display_phase(diff_real_disc_to_ana, res, 'Difference: Disc - Analytic')
pm.display_phase(diff_slab_to_disc, res, 'Difference: Disc - Slab')
# TODO: Delete
# import pdb; pdb.set_trace()
def display_combined(phase, res, holo, title):
fig = plt.figure(figsize=(14, 7))
fig.suptitle(title, fontsize=20)
holo_axis = fig.add_subplot(1,2,1, aspect='equal')
hi.display_holo(holo, 'Holography Image', holo_axis)
phase_axis = fig.add_subplot(1,2,2, aspect='equal')
pm.display_phase(phase, res, 'Phasemap', phase_axis)
if __name__ == "__main__":
try:
phase_from_mag()
except:
type, value, tb = sys.exc_info()
traceback.print_exc()
pdb.post_mortem(tb)
\ No newline at end of file
# -*- coding: utf-8 -*-
"""
Created on Wed Apr 03 11:15:38 2013
@author: Jan
"""
import numpy as np
import matplotlib.pyplot as plt
import pyramid.magcreator as mc
import pyramid.dataloader as dl
import pyramid.phasemap as pm
import pyramid.holoimage as hi
import pyramid.analytic as an
import time
import pdb, traceback, sys
from numpy import pi
def phase_from_mag():
'''Calculate and display the phase map from a given magnetization.
Arguments:
None
Returns:
None
'''
'''INPUT'''
# TODO: Input via GUI
filename = '../output/output.txt'
b_0 = 1.0 # in T
v_0 = 0 # TODO: units?
v_acc = 30000 # in V
padding = 20
density = 100
dim = (50, 50) # in px (y,x)
res = 1.0 # in nm
beta = pi/4
plot_mag_distr = True
# Slab:
shape_fun = mc.slab
center = (24, 24) # in px (y,x) index starts with 0!
width = (25, 25) # in px (y,x)
params = (center, width)
# # Disc:
# shape_fun = mc.disc
# center = (4, 4) # in px (y,x)
# radius = 2.5
# params = (center, radius)
# # Filament:
# shape_fun = mc.filament
# pos = 5
# x_or_y = 'y'
# params = (pos, x_or_y)
# # Alternating Filaments:
# shape_fun = mc.alternating_filaments
# spacing = 5
# x_or_y = 'y'
# params = (spacing, x_or_y)
# # Single Pixel:
# shape_fun = mc.single_pixel
# pixel = (5, 5)
# params = pixel
# '''CREATE LOGO'''
# mc.create_logo(128, res, beta, filename, plot_mag_distr)
# mag_data = dl.MagDataLLG(filename)
# phase= pm.real_space_slab(mag_data, b_0)
# holo = hi.holo_image(phase, mag_data.res, density)
# hi.display_holo(holo, '')
'''CREATE MAGNETIC DISTRIBUTION'''
mc.create_hom_mag(dim, res, beta, shape_fun, params,
filename, plot_mag_distr)
'''LOAD MAGNETIC DISTRIBUTION'''
mag_data = dl.MagDataLLG(filename)
# TODO: get it to work:
phase_el = pm.phase_elec(mag_data, v_0=1, v_acc=200000)
phi_cos_real_slab = np.zeros((2*dim[0]-1, 2*dim[1]-1))
pm.real_space_slab(mag_data, b_0, pixel_map=phi_cos_real_slab)
pm.display_phase(phi_cos_real_slab, res, 'Phase of one Pixel-Slab (Cos - Part)')
phi_cos_real_disc = np.zeros((2*dim[0]-1, 2*dim[1]-1))
pm.real_space_disc(mag_data, b_0, pixel_map=phi_cos_real_disc)
pm.display_phase(phi_cos_real_disc, res, 'Phase of one Pixel-Disc (Cos - Part)')
phi_cos_diff = phi_cos_real_slab - phi_cos_real_disc
pm.display_phase(phi_cos_diff, mag_data.res, 'Difference: One Pixel Slab - Disc')
'''NUMERICAL SOLUTION'''
# numerical solution Fourier Space:
tic = time.clock()
phase_fft = pm.fourier_space(mag_data, b_0, padding)
toc = time.clock()
print 'Time for Fourier Space Approach: ' + str(toc - tic)
holo_fft = hi.holo_image(phase_fft, mag_data.res, density)
display_combined(phase_fft, mag_data.res, holo_fft,
'Fourier Space Approach')
# numerical solution Real Space (Slab):
jacobi = np.zeros((2*dim[0]*dim[1], dim[0]*dim[1]))
tic = time.clock()
phase_real_slab = pm.real_space_slab(mag_data, b_0, jacobi=None)
toc = time.clock()
np.savetxt('../output/jacobi.npy', jacobi)
print 'Time for Real Space Approach (Slab): ' + str(toc - tic)
holo_real_slab = hi.holo_image(phase_real_slab, mag_data.res, density)
display_combined(phase_real_slab, mag_data.res, holo_real_slab,
'Real Space Approach (Slab)')
# numerical solution Real Space (Disc):
tic = time.clock()
phase_real_disc = pm.real_space_disc(mag_data, b_0)
toc = time.clock()
print 'Time for Real Space Approach (Disc): ' + str(toc - tic)
holo_real_disc = hi.holo_image(phase_real_disc, mag_data.res, density)
display_combined(phase_real_disc, mag_data.res, holo_real_disc,
'Real Space Approach (Disc)')
'''ANALYTIC SOLUTION'''
# analytic solution slab:
phase = an.phasemap_slab(dim, res, beta, center, width, b_0)
holo = hi.holo_image(phase, res, density)
display_combined(phase, res, holo, 'Analytic Solution - Slab')
# # analytic solution disc:
# phase = an.phasemap_disc(dim, res, beta, center, radius, b_0)
# holo = hi.holo_image(phase, res, density)
# display_combined(phase, res, holo, 'Analytic Solution - Disc')
# # analytic solution sphere:
# phase = an.phasemap_sphere(dim, res, beta, center, radius, b_0)
# holo = hi.holo_image(phase, res, density)
# display_combined(phase, res, holo, 'Analytic Solution - Sphere')
'''DIFFERENCES'''
diff_fft_to_ana = phase_fft - phase
diff_real_slab_to_ana = phase_real_slab - phase
diff_real_disc_to_ana = phase_real_disc - phase
diff_slab_to_disc = phase_real_disc - phase_real_slab
pm.display_phase(diff_fft_to_ana, res, 'Difference: FFT - Analytic')
pm.display_phase(diff_real_slab_to_ana, res, 'Difference: Slab - Analytic')
pm.display_phase(diff_real_disc_to_ana, res, 'Difference: Disc - Analytic')
pm.display_phase(diff_slab_to_disc, res, 'Difference: Disc - Slab')
# TODO: Delete
# import pdb; pdb.set_trace()
def display_combined(phase, res, holo, title):
fig = plt.figure(figsize=(14, 7))
fig.suptitle(title, fontsize=20)
holo_axis = fig.add_subplot(1,2,1, aspect='equal')
hi.display_holo(holo, 'Holography Image', holo_axis)
phase_axis = fig.add_subplot(1,2,2, aspect='equal')
pm.display_phase(phase, res, 'Phasemap', phase_axis)
if __name__ == "__main__":
try:
phase_from_mag()
except:
type, value, tb = sys.exc_info()
traceback.print_exc()
pdb.post_mortem(tb)
\ No newline at end of file
......@@ -28,15 +28,15 @@ def phase_from_mag():
'''INPUT'''
# TODO: Input via GUI
filename = 'output.txt'
b_0 = 10.0 # in T
filename = '../output/output.txt'
b_0 = 1.0 # in T
v_0 = 0 # TODO: units?
v_acc = 30000 # in V
padding = 20
density = 100
density = 10
dim = (50, 50) # in px (y,x)
res = 1.0 # in nm
res = 10.0 # in nm
beta = pi/4
plot_mag_distr = True
......@@ -105,11 +105,11 @@ def phase_from_mag():
display_combined(phase_fft, mag_data.res, holo_fft,
'Fourier Space Approach')
# numerical solution Real Space (Slab):
# jacobi = np.zeros((2*dim[0]*dim[1], dim[0]*dim[1]))
jacobi = np.zeros((2*dim[0]*dim[1], dim[0]*dim[1]))
tic = time.clock()
phase_real_slab = pm.real_space_slab(mag_data, b_0, jacobi=None)
toc = time.clock()
# np.savetxt('jacobi.npy', jacobi)
np.savetxt('../output/jacobi.npy', jacobi)
print 'Time for Real Space Approach (Slab): ' + str(toc - tic)
holo_real_slab = hi.holo_image(phase_real_slab, mag_data.res, density)
display_combined(phase_real_slab, mag_data.res, holo_real_slab,
......
File moved
File moved
File moved
File moved
......@@ -168,7 +168,7 @@ def create_logo(edge, res, beta = pi/2, filename='logo.txt', plot_mag_distr=Fals
y_mag = np.array(np.ones(dim)) * np.sin(beta) * shape_mag
z_mag = np.array(np.zeros(dim))
if (True):
if (plot_mag_distr):
fig = plt.figure()
fig.add_subplot(111, aspect='equal')
plt.quiver(x_mag, y_mag, pivot='middle', angles='xy', scale_units='xy',
......
......@@ -71,6 +71,8 @@ def real_space_slab(mag_data, b_0=1, v_0=0, v_acc=30000,
the phasemap as a 2 dimensional array
'''
# TODO: combine with disc and sphere approach, pixel field as function
# TODO: Expand docstring!
# TODO: Delete
......
# -*- coding: utf-8 -*-
"""
Created on Wed Apr 24 07:10:28 2013
@author: Jan
"""
# py.test
import unittest
class TestSuite(unittest.TestCase):
def setUp(self):
pass
def tearDown(self):
pass
def test(self):
self.assertTrue(True)
def test_almost(self):
self.assertAlmostEqual(0, 0.01, places=1)
if __name__ == '__main__':
suite = unittest.TestLoader().loadTestsFromTestCase(TestSuite)
unittest.TextTestRunner(verbosity=2).run(suite)
\ No newline at end of file
# -*- coding: utf-8 -*-
"""
Created on Wed Apr 24 07:10:28 2013
@author: Jan
"""
# py.test
import unittest
class TestSuite(unittest.TestCase):
def setUp(self):
pass
def tearDown(self):
pass
def test(self):
self.assertTrue(True)
def test_almost(self):
self.assertAlmostEqual(0, 0.01, places=1)
if __name__ == '__main__':
suite = unittest.TestLoader().loadTestsFromTestCase(TestSuite)
unittest.TextTestRunner(verbosity=2).run(suite)
\ No newline at end of file
# -*- coding: utf-8 -*-
"""
Created on Wed Apr 24 07:10:28 2013
@author: Jan
"""
# py.test
import unittest
class TestSuite(unittest.TestCase):
def setUp(self):
pass
def tearDown(self):
pass
def test(self):
self.assertTrue(True)
def test_almost(self):
self.assertAlmostEqual(0, 0.01, places=1)
if __name__ == '__main__':
suite = unittest.TestLoader().loadTestsFromTestCase(TestSuite)
unittest.TextTestRunner(verbosity=2).run(suite)
\ No newline at end of file
# -*- coding: utf-8 -*-
"""
Created on Wed Apr 24 07:10:28 2013
@author: Jan
"""
# py.test
import unittest
class TestSuite(unittest.TestCase):
def setUp(self):
pass
def tearDown(self):
pass
def test(self):
self.assertTrue(True)
def test_almost(self):
self.assertAlmostEqual(0, 0.01, places=1)
if __name__ == '__main__':
suite = unittest.TestLoader().loadTestsFromTestCase(TestSuite)
unittest.TextTestRunner(verbosity=2).run(suite)
\ No newline at end of file
# -*- coding: utf-8 -*-
"""
Created on Wed Apr 24 07:10:28 2013
@author: Jan
"""
# py.test
import unittest
import numpy as np
class TestSuite(unittest.TestCase):
def setUp(self):
pass
def tearDown(self):
pass
def test(self):
self.assertTrue(True)
def test_almost(self):
self.assertAlmostEqual(0, 0.01, places=1)
np.testing.assert_array_almost_equal()
if __name__ == '__main__':
suite = unittest.TestLoader().loadTestsFromTestCase(TestSuite)
unittest.TextTestRunner(verbosity=2).run(suite)
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment