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

Further Changes of the project structure

jacobi matrix now contains the derivatives instead of descriptive strings
parent fe551d76
No related branches found
No related tags found
No related merge requests found
File moved
...@@ -35,7 +35,7 @@ def phase_from_mag(): ...@@ -35,7 +35,7 @@ def phase_from_mag():
padding = 20 padding = 20
density = 100 density = 100
dim = (3, 3) # in px (y,x) dim = (50, 50) # in px (y,x)
res = 1.0 # in nm res = 1.0 # in nm
beta = pi/4 beta = pi/4
...@@ -43,8 +43,8 @@ def phase_from_mag(): ...@@ -43,8 +43,8 @@ def phase_from_mag():
# Slab: # Slab:
shape_fun = mc.slab shape_fun = mc.slab
center = (2, 2) # in px (y,x) index starts with 0! center = (24, 24) # in px (y,x) index starts with 0!
width = (1, 1) # in px (y,x) width = (25, 25) # in px (y,x)
params = (center, width) params = (center, width)
# # Disc: # # Disc:
# shape_fun = mc.disc # shape_fun = mc.disc
...@@ -105,13 +105,11 @@ def phase_from_mag(): ...@@ -105,13 +105,11 @@ def phase_from_mag():
display_combined(phase_fft, mag_data.res, holo_fft, display_combined(phase_fft, mag_data.res, holo_fft,
'Fourier Space Approach') 'Fourier Space Approach')
# numerical solution Real Space (Slab): # numerical solution Real Space (Slab):
jacobi = np.chararray((2*dim[0]*dim[1], dim[0]*dim[1]), itemsize=10) # jacobi = np.zeros((2*dim[0]*dim[1], dim[0]*dim[1]))
tic = time.clock() tic = time.clock()
phase_real_slab = pm.real_space_slab(mag_data, b_0, jacobi=jacobi) phase_real_slab = pm.real_space_slab(mag_data, b_0, jacobi=None)
toc = time.clock() toc = time.clock()
np.save('jacobi.npy', jacobi) # np.savetxt('jacobi.npy', jacobi)
jacobi = np.load('jacobi.npy')
enter_pdb # <- raises error
print 'Time for Real Space Approach (Slab): ' + str(toc - tic) print 'Time for Real Space Approach (Slab): ' + str(toc - tic)
holo_real_slab = hi.holo_image(phase_real_slab, mag_data.res, density) holo_real_slab = hi.holo_image(phase_real_slab, mag_data.res, density)
display_combined(phase_real_slab, mag_data.res, holo_real_slab, display_combined(phase_real_slab, mag_data.res, holo_real_slab,
......
File moved
File moved
File moved
File moved
File moved
...@@ -96,27 +96,16 @@ def real_space_slab(mag_data, b_0=1, v_0=0, v_acc=30000, ...@@ -96,27 +96,16 @@ def real_space_slab(mag_data, b_0=1, v_0=0, v_acc=30000,
-F_h(n-0.5, m+0.5) + F_h(n+0.5, m+0.5) ) -F_h(n-0.5, m+0.5) + F_h(n+0.5, m+0.5) )
def phi_mag(i, j): # TODO: rename def phi_mag(i, j): # TODO: rename
return mag[j,i]*(np.cos(beta[j,i])*phi_cos[y_dim-1-j:(2*y_dim-1)-j, return (np.cos(beta[j,i])*phi_cos[y_dim-1-j:(2*y_dim-1)-j,
x_dim-1-i:(2*x_dim-1)-i] x_dim-1-i:(2*x_dim-1)-i]
-np.sin(beta[j,i])*phi_sin[y_dim-1-j:(2*y_dim-1)-j, -np.sin(beta[j,i])*phi_sin[y_dim-1-j:(2*y_dim-1)-j,
x_dim-1-i:(2*x_dim-1)-i]) x_dim-1-i:(2*x_dim-1)-i])
Y = np.chararray((y_dim,x_dim)) def phi_mag_deriv(i, j): # TODO: rename
Y[:] = 'y' return -(np.sin(beta[j,i])*phi_cos[y_dim-1-j:(2*y_dim-1)-j,
Div = np.chararray((y_dim,x_dim)) x_dim-1-i:(2*x_dim-1)-i]
Div[:] = '/' + np.cos(beta[j,i])*phi_sin[y_dim-1-j:(2*y_dim-1)-j,
Index = np.chararray((y_dim,x_dim), itemsize=3) x_dim-1-i:(2*x_dim-1)-i])
Index[:] = np.array(range(y_dim*x_dim),dtype='|S3').reshape((y_dim,x_dim))
Mag = np.chararray((y_dim,x_dim))
Mag[:] = 'm'
Beta = np.chararray((y_dim,x_dim))
Beta[:] = 'b'
def phi_del_mag(i, j): # TODO: rename
return Y + Index + Div + Mag + (i+x_dim*j).astype('|S5')
def phi_del_beta(i, j): # TODO: rename
return Y + Index + Div + Beta + (i+x_dim*j).astype('|S5')
'''CREATE COORDINATE GRIDS''' '''CREATE COORDINATE GRIDS'''
x = np.linspace(0,(x_dim-1),num=x_dim) x = np.linspace(0,(x_dim-1),num=x_dim)
...@@ -139,14 +128,15 @@ def real_space_slab(mag_data, b_0=1, v_0=0, v_acc=30000, ...@@ -139,14 +128,15 @@ def real_space_slab(mag_data, b_0=1, v_0=0, v_acc=30000,
# TODO: only iterate over pixels that have a magn. > threshold (first >0) # TODO: only iterate over pixels that have a magn. > threshold (first >0)
# import pdb; pdb.set_trace()
for j in range(y_dim): for j in range(y_dim):
for i in range(x_dim): for i in range(x_dim):
phase += phi_mag(i, j) if (mag[j, i] != 0): # TODO: same result with or without?
if jacobi is not None: phi_mag_cache = phi_mag(i, j)
jacobi[i+x_dim*j] = phi_del_mag(i, j).reshape(-1) phase += mag[j,i] * phi_mag_cache
jacobi[y_dim*x_dim+i+x_dim*j] = phi_del_beta(i, j).reshape(-1) if jacobi is not None:
jacobi[i+x_dim*j] = phi_mag_cache.reshape(-1)
jacobi[x_dim*y_dim+i+x_dim*j] = (mag[j,i]*phi_mag_deriv(i, j)).reshape(-1)
return phase return phase
...@@ -211,7 +201,8 @@ def real_space_disc(mag_data, b_0=1, v_0=0, v_acc=30000, ...@@ -211,7 +201,8 @@ def real_space_disc(mag_data, b_0=1, v_0=0, v_acc=30000,
# TODO: only iterate over pixels that have a magn. > threshold (first >0) # TODO: only iterate over pixels that have a magn. > threshold (first >0)
for j in range(y_dim): for j in range(y_dim):
for i in range(x_dim): for i in range(x_dim):
phase += phi_mag(i, j) # if (mag[j, i] != 0): # TODO: same result with or without?
phase += phi_mag(i, j)
return phase return phase
......
File moved
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