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

PEP8 Compliance for scripts and tests

setup.py: Final cleanup
deleted initpyximport, compare_method_errors and get_revision (now in setup.py)
parent ee36c1d6
No related branches found
No related tags found
No related merge requests found
Showing
with 354 additions and 489 deletions
......@@ -8,4 +8,5 @@ syntax: glob
*.so
*.os
output*
build*
\ No newline at end of file
build*
Pyramid.egg-info*
\ No newline at end of file
# -*- coding: utf-8 -*-
"""Script to initialize Cythons pyximport to ensure compatibility with MinGW compiler and NumPy."""
import os
import numpy
import pyximport
if os.name == 'nt':
if 'CPATH' in os.environ:
os.environ['CPATH'] = os.environ['CPATH'] + numpy.get_include()
else:
os.environ['CPATH'] = numpy.get_include()
# # XXX: assuming that MinGW is installed in C:\MinGW (default)
# # for PythonXY the default is C:\MinGW-xy
# if os.environ.has_key('PATH'):
# os.environ['PATH'] = os.environ['PATH'] + ';C:\MinGW\bin'
# else:
# os.environ['PATH'] = 'C:\MinGW\bin'
mingw_setup_args = {'options': {'build_ext': {'compiler': 'mingw32'}}}
pyximport.install(setup_args=mingw_setup_args, inplace=True)
elif os.name == 'posix':
if 'CFLAGS' in os.environ:
os.environ['CFLAGS'] = os.environ['CFLAGS'] + ' -I' + numpy.get_include()
else:
os.environ['CFLAGS'] = ' -I' + numpy.get_include()
pyximport.install(inplace=True)
#! python
# -*- coding: utf-8 -*-
"""Create the Pyramid-Logo."""
import pdb, traceback, sys
import pdb
import traceback
import sys
import numpy as np
from numpy import pi
import matplotlib.pyplot as plt
import pyramid.magcreator as mc
import pyramid.projector as pj
import pyramid.magcreator as mc
import pyramid.projector as pj
import pyramid.phasemapper as pm
import pyramid.holoimage as hi
import pyramid.analytic as an
from pyramid.magdata import MagData
import pyramid.holoimage as hi
from pyramid.magdata import MagData
from pyramid.phasemap import PhaseMap
......@@ -20,22 +22,22 @@ PHI_0 = -2067.83 # magnetic flux in T*nm²
def compare_vortices():
''' DOCSTRING
'''
# Input parameters:
''' DOCSTRING''' # TODO: Docstring!
# Input parameters:
dim_list = [(16, 256, 256), (8, 128, 128), (4, 64, 64), (2, 32, 32), (1, 16, 16)]
res_list = [1., 2., 4., 8., 16.] # in nm
density = 20
phi = pi/2
x = []
y = []
# Analytic solution:
L = dim_list[0][1] # in px/nm
Lz = 0.5 * dim_list[0][0] # in px/nm
R = 0.25 * L # in px/nm
x0 = L / 2 # in px/nm
def F(x):
coeff = - pi * Lz / (2*PHI_0)
result = coeff * (- (x - x0) * np.sin(phi))
......@@ -43,16 +45,16 @@ def compare_vortices():
return result
x_an = np.linspace(0, L, 1000)
y_an = F(x_an)
# Starting magnetic distribution:
dim_start = (2*dim_list[0][0], 2*dim_list[0][1], 2*dim_list[0][2])
res_start = res_list[0] / 2
center = (dim_start[0]/2 - 0.5, dim_start[1]/2 - 0.5, dim_start[2]/2 - 0.5)
radius = 0.25 * dim_start[1]
height = 0.5* dim_start[0]
height = 0.5 * dim_start[0]
mag_shape = mc.Shapes.disc(dim_start, center, radius, height)
mag_data = MagData(res_start, mc.create_mag_dist(mag_shape, phi))
for i, (dim, res) in enumerate(zip(dim_list, res_list)):
# Create coarser grid for the magnetization:
print 'dim = ', dim, 'res = ', res
......@@ -64,7 +66,7 @@ def compare_vortices():
x_mag.mean(axis=5).mean(axis=3).mean(axis=1))
mag_data = MagData(res, magnitude)
projection = pj.simple_axis_projection(mag_data)
phase_map = PhaseMap(res, pm.phase_mag_real(res, projection, 'slab'))
phase_map = PhaseMap(res, pm.phase_mag_real(res, projection, 'slab'))
hi.display_combined(phase_map, density, 'Vortex State, res = {}'.format(res))
x.append(np.linspace(0, dim[1]*res, dim[1]))
y.append(phase_map.phase[dim[1]/2, :])
......@@ -80,12 +82,12 @@ def compare_vortices():
x_an, y_an, 'k')
axis.set_xlabel('x [nm]')
axis.set_ylabel('phase')
if __name__ == "__main__":
try:
compare_vortices()
except:
type, value, tb = sys.exc_info()
traceback.print_exc()
pdb.post_mortem(tb)
\ No newline at end of file
pdb.post_mortem(tb)
# -*- coding: utf-8 -*-
"""Compare the different methods to create phase maps."""
import time
import pdb, traceback, sys
import numpy as np
from numpy import pi
import matplotlib.pyplot as plt
import pyramid.magcreator as mc
import pyramid.projector as pj
import pyramid.phasemapper as pm
import pyramid.analytic as an
from pyramid.magdata import MagData
from pyramid.phasemap import PhaseMap
import shelve
def phase_from_mag():
'''Calculate and display the phase map from a given magnetization.
Arguments:
None
Returns:
None
'''
# Create / Open databank:
data_shelve = shelve.open('../output/method_errors_shelve')
'''FOURIER PADDING->RMS|DURATION'''
# Parameters:
b_0 = 1 # in T
res = 1.0 # in nm
dim = (16, 256, 256)
phi = -pi/4
padding_list = [0, 0.25, 0.5, 0.75, 1, 1.5, 2, 3, 4,5, 6,7, 8,9, 10, 11]#, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22]
geometry = 'disc'
# Create magnetic shape:
if geometry == 'slab':
center = (0, dim[1]/2-0.5, dim[2]/2-0.5) # in px (z, y, x) index starts with 0!
width = (1, dim[1]/2, dim[2]/2) # in px (z, y, x)
mag_shape = mc.Shapes.slab(dim, center, width)
phase_ana = an.phase_mag_slab(dim, res, phi, center, width, b_0)
elif geometry == 'disc':
center = (0, dim[1]/2-0.5, dim[2]/2-0.5) # in px (z, y, x) index starts with 0!
radius = dim[1]/4 # in px
height = 8 # in px
mag_shape = mc.Shapes.disc(dim, center, radius, height)
phase_ana = an.phase_mag_disc(dim, res, phi, center, radius, b_0)
# Project the magnetization data:
mag_data = MagData(res, mc.create_mag_dist(mag_shape, phi))
projection = pj.simple_axis_projection(mag_data)
# Create data:
data = np.zeros((3, len(padding_list)))
data[0, :] = padding_list
for (i, padding) in enumerate(padding_list):
print 'padding =', padding_list[i]
# Key:
key = ', '.join(['Padding->RMS|duration', 'Fourier', 'padding={}'.format(padding_list[i]),
'B0={}'.format(b_0), 'res={}'.format(res), 'dim={}'.format(dim),
'phi={}'.format(phi), 'geometry={}'.format(geometry)])
if data_shelve.has_key(key):
data[:, i] = data_shelve[key]
else:
start_time = time.time()
phase_num = pm.phase_mag_fourier(res, projection, b_0, padding_list[i])
data[2, i] = time.time() - start_time
phase_diff = phase_ana - phase_num
PhaseMap(res, phase_diff).display()
data[1, i] = np.std(phase_diff)
data_shelve[key] = data[:, i]
# Plot duration against padding:
fig = plt.figure()
axis = fig.add_subplot(1, 1, 1)
# axis.set_xscale('log')
# axis.set_yscale('log')
axis.plot(data[0], data[1])
axis.set_title('Fourier Space Approach: Variation of the Padding')
axis.set_xlabel('padding')
axis.set_ylabel('RMS')
# Plot RMS against padding:
fig = plt.figure()
axis = fig.add_subplot(1, 1, 1)
# axis.set_xscale('log')
# axis.set_yscale('log')
axis.plot(data[0], data[2])
axis.set_title('Fourier Space Approach: Variation of the Padding')
axis.set_xlabel('padding')
axis.set_ylabel('duration [s]')
data_shelve.close()
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
#! python
# -*- coding: utf-8 -*-
"""Compare the different methods to create phase maps."""
import time
import pdb, traceback, sys
import pdb
import traceback
import sys
import numpy as np
from numpy import pi
import matplotlib.pyplot as plt
import pyramid.magcreator as mc
import pyramid.projector as pj
import pyramid.magcreator as mc
import pyramid.projector as pj
import pyramid.phasemapper as pm
import pyramid.analytic as an
from pyramid.magdata import MagData
import pyramid.analytic as an
from pyramid.magdata import MagData
from pyramid.phasemap import PhaseMap
import shelve
......@@ -23,33 +26,34 @@ def phase_from_mag():
None
Returns:
None
'''
# Create / Open databank:
data_shelve = shelve.open('../output/method_errors_shelve')
'''FOURIER PADDING->RMS|DURATION'''
# Parameters:
b_0 = 1 # in T
b_0 = 1 # in T
res = 10.0 # in nm
dim = (1, 128, 128)
dim = (1, 128, 128)
phi = -pi/4
padding_list = [0, 0.25, 0.5, 0.75, 1, 1.5, 2, 3, 4,5, 6,7, 8,9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22]
padding_list = [0, 0.25, 0.5, 0.75, 1, 1.5, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
16, 17, 18, 19, 20, 21, 22]
geometry = 'disc'
# Create magnetic shape:
if geometry == 'slab':
center = (0, dim[1]/2-0.5, dim[2]/2-0.5) # in px (z, y, x) index starts with 0!
width = (1, dim[1]/2, dim[2]/2) # in px (z, y, x)
width = (1, dim[1]/2, dim[2]/2) # in px (z, y, x)
mag_shape = mc.Shapes.slab(dim, center, width)
phase_ana = an.phase_mag_slab(dim, res, phi, center, width, b_0)
elif geometry == 'disc':
center = (0, dim[1]/2-0.5, dim[2]/2-0.5) # in px (z, y, x) index starts with 0!
radius = dim[1]/4 # in px
height = 1 # in px
radius = dim[1] / 4 # in px
height = 1 # in px
mag_shape = mc.Shapes.disc(dim, center, radius, height)
phase_ana = an.phase_mag_disc(dim, res, phi, center, radius, b_0)
# Project the magnetization data:
mag_data = MagData(res, mc.create_mag_dist(mag_shape, phi))
# Project the magnetization data:
mag_data = MagData(res, mc.create_mag_dist(mag_shape, phi))
projection = pj.simple_axis_projection(mag_data)
# Create data:
data = np.zeros((3, len(padding_list)))
......@@ -57,10 +61,10 @@ def phase_from_mag():
for (i, padding) in enumerate(padding_list):
print 'padding =', padding_list[i]
# Key:
key = ', '.join(['Padding->RMS|duration', 'Fourier', 'padding={}'.format(padding_list[i]),
key = ', '.join(['Padding->RMS|duration', 'Fourier', 'padding={}'.format(padding_list[i]),
'B0={}'.format(b_0), 'res={}'.format(res), 'dim={}'.format(dim),
'phi={}'.format(phi), 'geometry={}'.format(geometry)])
if data_shelve.has_key(key):
if key in data_shelve:
data[:, i] = data_shelve[key]
else:
start_time = time.time()
......@@ -69,7 +73,7 @@ def phase_from_mag():
phase_diff = phase_ana - phase_num
PhaseMap(res, phase_diff).display()
data[1, i] = np.std(phase_diff)
data_shelve[key] = data[:, i]
data_shelve[key] = data[:, i]
# Plot duration against padding:
fig = plt.figure()
axis = fig.add_subplot(1, 1, 1)
......@@ -85,15 +89,14 @@ def phase_from_mag():
axis.set_title('Fourier Space Approach: Variation of the Padding')
axis.set_xlabel('padding')
axis.set_ylabel('duration [s]')
# Close shelve:
data_shelve.close()
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
pdb.post_mortem(tb)
This diff is collapsed.
#! python
# -*- coding: utf-8 -*-
"""Compare the different methods to create phase maps."""
import time
import pdb, traceback, sys
import pdb
import traceback
import sys
import numpy as np
from numpy import pi
import pyramid.magcreator as mc
import pyramid.projector as pj
import pyramid.magcreator as mc
import pyramid.projector as pj
import pyramid.phasemapper as pm
import pyramid.holoimage as hi
import pyramid.analytic as an
from pyramid.magdata import MagData
import pyramid.holoimage as hi
import pyramid.analytic as an
from pyramid.magdata import MagData
from pyramid.phasemap import PhaseMap
......@@ -22,7 +25,7 @@ def compare_methods():
None
Returns:
None
'''
# Input parameters:
b_0 = 1 # in T
......@@ -30,61 +33,61 @@ def compare_methods():
phi = pi/4
padding = 20
density = 10
dim = (1, 128, 128) # in px (z, y, x)
dim = (1, 128, 128) # in px (z, y, x)
# Create magnetic shape:
geometry = 'slab'
geometry = 'slab'
if geometry == 'slab':
center = (0, dim[1]/2., dim[2]/2.) # in px (z, y, x) index starts with 0!
width = (1, dim[1]/2.-0.5, dim[2]/2.-0.5) # in px (z, y, x)
width = (1, dim[1]/2.-0.5, dim[2]/2.-0.5) # in px (z, y, x)
mag_shape = mc.Shapes.slab(dim, center, width)
phase_ana = an.phase_mag_slab(dim, res, phi, center, width, b_0)
elif geometry == 'disc':
center = (0, dim[1]/2.-0.5, dim[2]/2.-0.5) # in px (z, y, x) index starts with 0!
radius = dim[1]/4 # in px
radius = dim[1]/4 # in px
height = 1 # in px
mag_shape = mc.Shapes.disc(dim, center, radius, height)
phase_ana = an.phase_mag_disc(dim, res, phi, center, radius, height, b_0)
elif geometry == 'sphere':
center = (50, 50, 50) # in px (z, y, x) index starts with 0!
radius = 25 # in px
radius = 25 # in px
mag_shape = mc.Shapes.sphere(dim, center, radius)
phase_ana = an.phase_mag_sphere(dim, res, phi, center, radius, b_0)
# Project the magnetization data:
# Project the magnetization data:
mag_data = MagData(res, mc.create_mag_dist(mag_shape, phi))
mag_data.quiver_plot(ax_slice=int(center[0]))
projection = pj.simple_axis_projection(mag_data)
# Construct phase maps:
phase_map_ana = PhaseMap(res, phase_ana)
phase_map_ana = PhaseMap(res, phase_ana)
start_time = time.time()
phase_map_fft = PhaseMap(res, pm.phase_mag_fourier(res, projection, b_0, padding))
phase_map_fft = PhaseMap(res, pm.phase_mag_fourier(res, projection, b_0, padding))
print 'Time for Fourier space approach: ', time.time() - start_time
start_time = time.time()
start_time = time.time()
phase_map_slab = PhaseMap(res, pm.phase_mag_real(res, projection, 'slab', b_0))
print 'Time for real space approach (Slab):', time.time() - start_time
start_time = time.time()
phase_map_disc = PhaseMap(res, pm.phase_mag_real(res, projection, 'disc', b_0))
print 'Time for real space approach (Disc):', time.time() - start_time
# Display the combinated plots with phasemap and holography image:
hi.display_combined(phase_map_ana, density, 'Analytic Solution')
hi.display_combined(phase_map_fft, density, 'Fourier Space')
hi.display_combined(phase_map_ana, density, 'Analytic Solution')
hi.display_combined(phase_map_fft, density, 'Fourier Space')
hi.display_combined(phase_map_slab, density, 'Real Space (Slab)')
hi.display_combined(phase_map_disc, density, 'Real Space (Disc)')
# Plot differences to the analytic solution:
phase_map_diff_fft = PhaseMap(res, phase_map_ana.phase-phase_map_fft.phase)
phase_map_diff_fft = PhaseMap(res, phase_map_ana.phase-phase_map_fft.phase)
phase_map_diff_slab = PhaseMap(res, phase_map_ana.phase-phase_map_slab.phase)
phase_map_diff_disc = PhaseMap(res, phase_map_ana.phase-phase_map_disc.phase)
RMS_fft = np.std(phase_map_diff_fft.phase)
RMS_fft = np.std(phase_map_diff_fft.phase)
RMS_slab = np.std(phase_map_diff_slab.phase)
RMS_disc = np.std(phase_map_diff_disc.phase)
phase_map_diff_fft.display('Fourier Space (RMS = {:3.2e})'.format(RMS_fft))
phase_map_diff_slab.display('Real Space (Slab) (RMS = {:3.2e})'.format(RMS_slab))
phase_map_diff_disc.display('Real Space (Disc) (RMS = {:3.2e})'.format(RMS_disc))
if __name__ == "__main__":
try:
compare_methods()
except:
type, value, tb = sys.exc_info()
traceback.print_exc()
pdb.post_mortem(tb)
\ No newline at end of file
pdb.post_mortem(tb)
#! python
# -*- coding: utf-8 -*-
"""Compare the phase map of one pixel for different real space approaches."""
import pdb, traceback, sys
import pdb
import traceback
import sys
from numpy import pi
import pyramid.magcreator as mc
import pyramid.projector as pj
import pyramid.magcreator as mc
import pyramid.projector as pj
import pyramid.phasemapper as pm
from pyramid.magdata import MagData
from pyramid.magdata import MagData
from pyramid.phasemap import PhaseMap
......@@ -18,28 +21,28 @@ def compare_pixel_fields():
None
Returns:
None
'''
# Input parameters:
# Input parameters:
res = 10.0 # in nm
phi = pi/2 # in rad
dim = (1, 11, 11)
pixel = (0, 5, 5)
# Create magnetic data, project it, get the phase map and display the holography image:
mag_data = MagData(res, mc.create_mag_dist(mc.Shapes.pixel(dim, pixel), phi))
pixel = (0, 5, 5)
# Create magnetic data, project it, get the phase map and display the holography image:
mag_data = MagData(res, mc.create_mag_dist(mc.Shapes.pixel(dim, pixel), phi))
projection = pj.simple_axis_projection(mag_data)
phase_map_slab = PhaseMap(res, pm.phase_mag_real(res, projection, 'slab'))
phase_map_slab = PhaseMap(res, pm.phase_mag_real(res, projection, 'slab'))
phase_map_slab.display('Phase of one Pixel (Slab)')
phase_map_disc = PhaseMap(res, pm.phase_mag_real(res, projection, 'disc'))
phase_map_disc = PhaseMap(res, pm.phase_mag_real(res, projection, 'disc'))
phase_map_disc.display('Phase of one Pixel (Disc)')
phase_map_diff = PhaseMap(res, phase_map_disc.phase - phase_map_slab.phase)
phase_map_diff.display('Phase difference of one Pixel (Disc - Slab)')
if __name__ == "__main__":
try:
compare_pixel_fields()
except:
type, value, tb = sys.exc_info()
traceback.print_exc()
pdb.post_mortem(tb)
\ No newline at end of file
pdb.post_mortem(tb)
#! python
# -*- coding: utf-8 -*-
"""Create the Pyramid-Logo."""
import pdb, traceback, sys
import pdb
import traceback
import sys
import numpy as np
from numpy import pi
import matplotlib.pyplot as plt
import pyramid.magcreator as mc
import pyramid.projector as pj
import pyramid.magcreator as mc
import pyramid.projector as pj
import pyramid.phasemapper as pm
import pyramid.holoimage as hi
from pyramid.magdata import MagData
import pyramid.holoimage as hi
from pyramid.magdata import MagData
from pyramid.phasemap import PhaseMap
......@@ -24,37 +27,38 @@ def compare_vortices():
None
Returns:
None
'''
# Input parameters:
# Input parameters:
dim_list = [(16, 256, 256), (8, 128, 128), (4, 64, 64), (2, 32, 32), (1, 16, 16)]
res_list = [1., 2., 4., 8., 16.] # in nm
density = 20
x = []
y = []
# Starting magnetic distribution:
dim_start = (2*dim_list[0][0], 2*dim_list[0][1], 2*dim_list[0][2])
res_start = res_list[0] / 2
center = (dim_start[0]/2 - 0.5, dim_start[1]/2 - 0.5, dim_start[2]/2 - 0.5)
radius = 0.25 * dim_start[1]
height = 0.5* dim_start[0]
height = 0.5 * dim_start[0]
mag_shape = mc.Shapes.disc(dim_start, center, radius, height)
mag_data = MagData(res_start, mc.create_mag_dist_vortex(mag_shape))
# Analytic solution:
L = dim_list[0][1] # in px/nm
Lz = 0.5 * dim_list[0][0] # in px/nm
R = 0.25 * L # in px/nm
x0 = L / 2 # in px/nm
def F(x):
coeff = pi*Lz/PHI_0
result = coeff * np.where(np.abs(x - x0) <= R, (np.abs(x-x0)-R), 0)
return result
x_an = np.linspace(0, L, 1001)
y_an = F(x_an)
for i, (dim, res) in enumerate(zip(dim_list, res_list)):
# Create coarser grid for the magnetization:
print 'dim = ', dim, 'res = ', res
......@@ -67,7 +71,7 @@ def compare_vortices():
mag_data = MagData(res, magnitude)
#mag_data.quiver_plot()
projection = pj.simple_axis_projection(mag_data)
phase_map = PhaseMap(res, pm.phase_mag_real(res, projection, 'slab'))
phase_map = PhaseMap(res, pm.phase_mag_real(res, projection, 'slab'))
hi.display_combined(phase_map, density, 'Vortex State, res = {}'.format(res))
x.append(np.linspace(0, dim[1]*res, dim[1]))
y.append(phase_map.phase[dim[1]/2, :])
......@@ -79,16 +83,16 @@ def compare_vortices():
x[1], y[1], 'm',
x[2], y[2], 'y',
x[3], y[3], 'g',
x[4], y[4], 'c',#x[5], y[5], 'b',
x[4], y[4], 'c',
x_an, y_an, 'k')
axis.set_xlabel('x [nm]')
axis.set_ylabel('phase')
if __name__ == "__main__":
try:
compare_vortices()
except:
type, value, tb = sys.exc_info()
traceback.print_exc()
pdb.post_mortem(tb)
\ No newline at end of file
pdb.post_mortem(tb)
#! python
# -*- coding: utf-8 -*-
"""Create magnetic distribution of alternating filaments"""
import pdb, traceback, sys
import pdb
import traceback
import sys
import numpy as np
from numpy import pi
......@@ -16,28 +19,28 @@ def create_alternating_filaments():
None
Returns:
None
'''
# Input parameters:
filename = '../output/mag_dist_alt_filaments.txt'
filename = '../output/mag_dist_alt_filaments.txt'
dim = (1, 21, 21) # in px (z, y, x)
res = 10.0 # in nm
phi = pi/2
spacing = 5
phi = pi/2
spacing = 5
# Create lists for magnetic objects:
count = int((dim[1]-1) / spacing) + 1
mag_shape_list = np.zeros((count,) + dim)
phi_list = np.zeros(count)
for i in range(count):
phi_list = np.zeros(count)
for i in range(count):
pos = i * spacing
mag_shape_list[i] = mc.Shapes.filament(dim, (0, pos))
phi_list[i] = (1-2*(int(pos/spacing)%2)) * phi
phi_list[i] = (1-2*(int(pos/spacing) % 2)) * phi
# Create magnetic distribution
magnitude = mc.create_mag_dist_comb(mag_shape_list, phi_list)
magnitude = mc.create_mag_dist_comb(mag_shape_list, phi_list)
mag_data = MagData(res, magnitude)
mag_data.quiver_plot()
mag_data.save_to_llg(filename)
mag_data.save_to_llg(filename)
if __name__ == "__main__":
try:
......@@ -45,4 +48,4 @@ if __name__ == "__main__":
except:
type, value, tb = sys.exc_info()
traceback.print_exc()
pdb.post_mortem(tb)
\ No newline at end of file
pdb.post_mortem(tb)
......@@ -3,15 +3,17 @@
"""Create the Pyramid-Logo."""
import pdb, traceback, sys
import pdb
import traceback
import sys
import numpy as np
from numpy import pi
import pyramid.magcreator as mc
import pyramid.projector as pj
import pyramid.magcreator as mc
import pyramid.projector as pj
import pyramid.phasemapper as pm
import pyramid.holoimage as hi
from pyramid.magdata import MagData
import pyramid.holoimage as hi
from pyramid.magdata import MagData
from pyramid.phasemap import PhaseMap
......@@ -21,9 +23,9 @@ def create_logo():
None
Returns:
None
'''
# Input parameters:
# Input parameters:
res = 10.0 # in nm
phi = -pi/2 # in rad
density = 10
......@@ -32,22 +34,22 @@ def create_logo():
mag_shape = np.zeros(dim)
x = range(dim[2])
y = range(dim[1])
xx, yy = np.meshgrid(x, y)
xx, yy = np.meshgrid(x, y)
bottom = (yy >= 0.25*dim[1])
left = (yy <= 0.75/0.5 * dim[1]/dim[2] * xx)
right = np.fliplr(left)
mag_shape[0,...] = np.logical_and(np.logical_and(left, right), bottom)
# Create magnetic data, project it, get the phase map and display the holography image:
mag_data = MagData(res, mc.create_mag_dist(mag_shape, phi))
left = (yy <= 0.75/0.5 * dim[1]/dim[2] * xx)
right = np.fliplr(left)
mag_shape[0, ...] = np.logical_and(np.logical_and(left, right), bottom)
# Create magnetic data, project it, get the phase map and display the holography image:
mag_data = MagData(res, mc.create_mag_dist(mag_shape, phi))
projection = pj.simple_axis_projection(mag_data)
phase_map = PhaseMap(res, pm.phase_mag_real(res, projection, 'slab'))
phase_map = PhaseMap(res, pm.phase_mag_real(res, projection, 'slab'))
hi.display(hi.holo_image(phase_map, density), 'PYRAMID - LOGO')
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
pdb.post_mortem(tb)
......@@ -2,7 +2,9 @@
"""Create random magnetic distributions."""
import random as rnd
import pdb, traceback, sys
import pdb
import traceback
import sys
import numpy as np
from numpy import pi
......@@ -20,19 +22,19 @@ def create_multiple_samples():
None
Returns:
None
'''
filename = '../output/mag_dist_multiple_samples.txt'
'''
filename = '../output/mag_dist_multiple_samples.txt'
res = 10.0 # nm
dim = (64, 128, 128)
# Slab:
center = (32, 32, 32) # in px (z, y, x), index starts with 0!
width = (48, 48, 48) # in px (z, y, x)
width = (48, 48, 48) # in px (z, y, x)
mag_shape_slab = mc.Shapes.slab(dim, center, width)
# Disc:
center = (32, 32, 96) # in px (z, y, x), index starts with 0!
radius = 24 # in px
height = 24 # in px
height = 24 # in px
mag_shape_disc = mc.Shapes.disc(dim, center, radius, height)
# Sphere:
center = (32, 96, 64) # in px (z, y, x), index starts with 0!
......@@ -42,21 +44,20 @@ def create_multiple_samples():
mag_shape_list = [mag_shape_slab, mag_shape_disc, mag_shape_sphere]
phi_list = [pi/4, pi/2, pi]
# Create magnetic distribution:
magnitude = mc.create_mag_dist_comb(mag_shape_list, phi_list)
magnitude = mc.create_mag_dist_comb(mag_shape_list, phi_list)
mag_data = MagData(res, magnitude)
mag_data.quiver_plot('z', dim[0]/2)
mag_data.save_to_llg(filename)
projection = pj.simple_axis_projection(mag_data)
phase_map = PhaseMap(res, pm.phase_mag_real(res, projection, 'slab'))
phase_map = PhaseMap(res, pm.phase_mag_real(res, projection, 'slab'))
phase_map.display()
hi.display(hi.holo_image(phase_map, 0.5))
if __name__ == "__main__":
try:
create_multiple_samples()
except:
type, value, tb = sys.exc_info()
traceback.print_exc()
pdb.post_mortem(tb)
\ No newline at end of file
pdb.post_mortem(tb)
......@@ -2,7 +2,9 @@
"""Create random magnetic distributions."""
import random as rnd
import pdb, traceback, sys
import pdb
import traceback
import sys
import numpy as np
from numpy import pi
......@@ -20,36 +22,36 @@ def create_random_pixels():
None
Returns:
None
'''
# Input parameters:
count = 10
dim = (1, 128, 128)
res = 10 # in nm
dim = (1, 128, 128)
res = 10 # in nm
rnd.seed(12)
# Create lists for magnetic objects:
mag_shape_list = np.zeros((count,) + dim)
phi_list = np.zeros(count)
phi_list = np.zeros(count)
magnitude_list = np.zeros(count)
for i in range(count):
pixel = (rnd.randrange(dim[0]), rnd.randrange(dim[1]), rnd.randrange(dim[2]))
mag_shape_list[i,...] = mc.Shapes.pixel(dim, pixel)
phi_list[i] = 2*pi*rnd.random()
magnitude_list[i] = 1#rnd.random()
mag_shape_list[i, ...] = mc.Shapes.pixel(dim, pixel)
phi_list[i] = 2 * pi * rnd.random()
magnitude_list[i] = 1 # TODO: rnd.random()
# Create magnetic distribution:
magnitude = mc.create_mag_dist_comb(mag_shape_list, phi_list, magnitude_list)
magnitude = mc.create_mag_dist_comb(mag_shape_list, phi_list, magnitude_list)
mag_data = MagData(res, magnitude)
mag_data.quiver_plot()
mag_data.save_to_llg('../output/mag_dist_random_pixels.txt')
projection = pj.simple_axis_projection(mag_data)
phase_map = PhaseMap(res, pm.phase_mag_real(res, projection, 'slab'))
phase_map = PhaseMap(res, pm.phase_mag_real(res, projection, 'slab'))
hi.display(hi.holo_image(phase_map, 10))
if __name__ == "__main__":
try:
create_random_pixels()
except:
type, value, tb = sys.exc_info()
traceback.print_exc()
pdb.post_mortem(tb)
\ No newline at end of file
pdb.post_mortem(tb)
......@@ -2,7 +2,9 @@
"""Create random magnetic distributions."""
import random as rnd
import pdb, traceback, sys
import pdb
import traceback
import sys
import numpy as np
from numpy import pi
......@@ -20,40 +22,40 @@ def create_random_slabs():
None
Returns:
None
'''
# Input parameters:
count = 10
dim = (1, 128, 128)
res = 10 # in nm
dim = (1, 128, 128)
res = 10 # in nm
rnd.seed(42)
w_max = 10
# Create lists for magnetic objects:
mag_shape_list = np.zeros((count,) + dim)
phi_list = np.zeros(count)
phi_list = np.zeros(count)
magnitude_list = np.zeros(count)
for i in range(count):
width = (1, rnd.randint(1, w_max), rnd.randint(1, w_max))
width = (1, rnd.randint(1, w_max), rnd.randint(1, w_max))
center = (rnd.randrange(int(width[0]/2), dim[0]-int(width[0]/2)),
rnd.randrange(int(width[1]/2), dim[1]-int(width[1]/2)),
rnd.randrange(int(width[2]/2), dim[2]-int(width[2]/2)))
mag_shape_list[i,...] = mc.Shapes.slab(dim, center, width)
phi_list[i] = 2*pi*rnd.random()
magnitude_list[i] = 1#rnd.random()
mag_shape_list[i, ...] = mc.Shapes.slab(dim, center, width)
phi_list[i] = 2 * pi * rnd.random()
magnitude_list[i] = 1 # TODO: rnd.random()
# Create magnetic distribution:
magnitude = mc.create_mag_dist_comb(mag_shape_list, phi_list, magnitude_list)
magnitude = mc.create_mag_dist_comb(mag_shape_list, phi_list, magnitude_list)
mag_data = MagData(res, magnitude)
mag_data.quiver_plot()
mag_data.save_to_llg('../output/mag_dist_random_slabs.txt')
projection = pj.simple_axis_projection(mag_data)
phase_map = PhaseMap(res, pm.phase_mag_real(res, projection, 'slab'))
phase_map = PhaseMap(res, pm.phase_mag_real(res, projection, 'slab'))
hi.display(hi.holo_image(phase_map, 10))
if __name__ == "__main__":
try:
create_random_slabs()
except:
type, value, tb = sys.exc_info()
traceback.print_exc()
pdb.post_mortem(tb)
\ No newline at end of file
pdb.post_mortem(tb)
......@@ -2,7 +2,9 @@
"""Create magnetic distributions with simple geometries."""
import pdb, traceback, sys
import pdb
import traceback
import sys
from numpy import pi
import pyramid.magcreator as mc
......@@ -15,23 +17,23 @@ def create_sample():
None
Returns:
None
'''
# Input parameters:
key = 'slab'
filename = '../output/mag_dist_' + key + '.txt'
filename = '../output/mag_dist_' + key + '.txt'
dim = (1, 128, 128) # in px (z, y, x)
res = 10.0 # in nm
phi = pi/4
# Geometry parameters:
phi = pi/4
# Geometry parameters:
center = (0, 64, 64) # in px (z, y, x), index starts with 0!
width = (1, 50, 50) # in px (z, y, x)
width = (1, 50, 50) # in px (z, y, x)
radius = 25 # in px
height = 1 # in px
height = 1 # in px
pos = (0, 63) # in px (tuple of length 2)
pixel = (0, 63, 63) # in px (z, y, x), index starts with 0!
pixel = (0, 63, 63) # in px (z, y, x), index starts with 0!
# Determine the magnetic shape:
if key == 'slab':
if key == 'slab':
mag_shape = mc.Shapes.slab(dim, center, width)
elif key == 'disc':
mag_shape = mc.Shapes.disc(dim, center, radius, height)
......@@ -42,16 +44,16 @@ def create_sample():
elif key == 'pixel':
mag_shape = mc.Shapes.pixel(dim, pixel)
# Create magnetic distribution
magnitude = mc.create_mag_dist(mag_shape, phi)
magnitude = mc.create_mag_dist(mag_shape, phi)
mag_data = MagData(res, magnitude)
mag_data.quiver_plot()
mag_data.save_to_llg(filename)
if __name__ == "__main__":
try:
create_sample()
except:
type, value, tb = sys.exc_info()
traceback.print_exc()
pdb.post_mortem(tb)
\ No newline at end of file
pdb.post_mortem(tb)
......@@ -2,16 +2,16 @@
"""Create the Pyramid-Logo."""
import pdb, traceback, sys
import numpy as np
from numpy import pi
import pdb
import traceback
import sys
import matplotlib.pyplot as plt
import pyramid.magcreator as mc
import pyramid.projector as pj
import pyramid.magcreator as mc
import pyramid.projector as pj
import pyramid.phasemapper as pm
import pyramid.holoimage as hi
from pyramid.magdata import MagData
import pyramid.holoimage as hi
from pyramid.magdata import MagData
from pyramid.phasemap import PhaseMap
......@@ -21,9 +21,9 @@ def create_vortex():
None
Returns:
None
'''
# Input parameters:
# Input parameters:
filename = '../output/mag_dist_vortex.txt'
res = 10.0 # in nm
density = 1
......@@ -33,22 +33,23 @@ def create_vortex():
height = 1
# Create magnetic shape:
mag_shape = mc.Shapes.disc(dim, center, radius, height)
mag_data = MagData(res, mc.create_mag_dist_vortex(mag_shape))
mag_data = MagData(res, mc.create_mag_dist_vortex(mag_shape))
mag_data.quiver_plot()
mag_data.quiver_plot3d()
mag_data.save_to_llg(filename)
projection = pj.simple_axis_projection(mag_data)
phase_map = PhaseMap(res, pm.phase_mag_real(res, projection, 'slab'))
phase_map = PhaseMap(res, pm.phase_mag_real(res, projection, 'slab'))
hi.display_combined(phase_map, density, 'Vortex State')
phase_slice = phase_map.phase[dim[1]/2, :]
fig = plt.figure()
fig.add_subplot(111)
plt.plot(range(dim[1]), phase_slice)
if __name__ == "__main__":
try:
create_vortex()
except:
type, value, tb = sys.exc_info()
traceback.print_exc()
pdb.post_mortem(tb)
\ No newline at end of file
pdb.post_mortem(tb)
......@@ -5,14 +5,16 @@ Created on Wed Apr 03 11:15:38 2013
@author: Jan
"""
import time
import pdb
import traceback
import sys
import numpy as np
import pyramid.magcreator as mc
import pyramid.projector as pj
import pyramid.phasemapper as pm
from pyramid.magdata import MagData
from pyramid.phasemap import PhaseMap
import time
import pdb, traceback, sys
from numpy import pi
......@@ -22,20 +24,20 @@ def get_jacobi():
None
Returns:
None
'''
# TODO: Input via GUI
b_0 = 1.0 # in T
b_0 = 1.0 # in T
dim = (1, 3, 3) # in px (y,x)
res = 10.0 # in nm
phi = pi/4
phi = pi/4
center = (0, 1, 1) # in px (y,x) index starts with 0!
width = (0, 1, 1) # in px (y,x)
width = (0, 1, 1) # in px (y,x)
mag_data = MagData(res, mc.create_mag_dist(mc.Shapes.slab(dim, center, width), phi))
projection = pj.simple_axis_projection(mag_data)
'''NUMERICAL SOLUTION'''
# numerical solution Real Space (Slab):
jacobi = np.zeros((dim[2]*dim[1], 2*dim[2]*dim[1]))
......@@ -45,14 +47,14 @@ def get_jacobi():
phase_map.display()
np.savetxt('../output/jacobi.npy', jacobi)
print 'Time for Real Space Approach with Jacobi-Matrix (Slab): ' + str(toc - tic)
return jacobi
if __name__ == "__main__":
try:
jacobi = get_jacobi()
except:
type, value, tb = sys.exc_info()
traceback.print_exc()
pdb.post_mortem(tb)
\ No newline at end of file
pdb.post_mortem(tb)
# -*- coding: utf-8 -*-
"""
Created on Mon Jul 22 15:01:55 2013
@author: Jan
"""
def make_hgrevision(target, source, env):
import subprocess as sp
output = sp.Popen(["hg", "id", "-i"], stdout=sp.PIPE).communicate()[0]
hgrevision_cc = file(str(target[0]), "w")
hgrevision_cc.write('HG_Revision = "{0}"\n'.format(output.strip()))
hgrevision_cc.close()
\ No newline at end of file
# -*- coding: utf-8 -*-
"""
Created on Tue May 21 14:29:25 2013
@author: Jan
"""
......@@ -7,23 +7,23 @@ import numpy as np
from numpy import pi
from PyQt4 import QtCore, QtGui, uic
import pyramid.magcreator as mc
import pyramid.projector as pj
import pyramid.magcreator as mc
import pyramid.projector as pj
import pyramid.phasemapper as pm
import pyramid.holoimage as hi
from pyramid.magdata import MagData
import pyramid.holoimage as hi
from pyramid.magdata import MagData
from pyramid.phasemap import PhaseMap
from gui.create_logo import Ui_CreateLogoWidget
class Overlay(QtGui.QWidget):
def __init__(self, parent = None):
def __init__(self, parent=None):
QtGui.QWidget.__init__(self, parent)
palette = QtGui.QPalette(self.palette())
palette.setColor(palette.Background, QtCore.Qt.transparent)
self.setPalette(palette)
def paintEvent(self, event):
painter = QtGui.QPainter()
painter.begin(self)
......@@ -40,20 +40,21 @@ class Overlay(QtGui.QWidget):
self.height()/2 + 30 * np.sin(2 * pi * i / 6.0) - 10,
20, 20)
painter.end()
def showEvent(self, event):
self.timer = self.startTimer(50)
self.counter = 0
def hideEvent(self, event):
self.killTimer(self.timer)
def timerEvent(self, event):
self.counter += 1
self.update()
class CreateLogoWidget(QtGui.QWidget, Ui_CreateLogoWidget):
def __init__(self):
# Call parent constructor
QtGui.QWidget.__init__(self)
......@@ -68,7 +69,7 @@ class CreateLogoWidget(QtGui.QWidget, Ui_CreateLogoWidget):
self.overlay.hide()
# Show Widget:
self.show()
self.workerThread = WorkerThread()
def buttonPushed(self):
......@@ -76,19 +77,17 @@ class CreateLogoWidget(QtGui.QWidget, Ui_CreateLogoWidget):
x = self.xSpinBox.value()
y = self.ySpinBox.value()
create_logo((1, y, x), self.mplWidget.axes)
self.mplWidget.draw()
self.mplWidget.draw()
# self.workerThread.start()
self.overlay.hide()
def resizeEvent(self, event):
self.overlay.resize(event.size())
event.accept()
class WorkerThread(QtCore.QThread):
def __init__(self, parent=None):
QtCore.QThread.__init__(self)
......@@ -105,9 +104,9 @@ def create_logo(dim, axis):
None
Returns:
None
'''
# Input parameters:
# Input parameters:
res = 10.0 # in nm
phi = -pi/2 # in rad
density = 10
......@@ -115,19 +114,19 @@ def create_logo(dim, axis):
mag_shape = np.zeros(dim)
x = range(dim[2])
y = range(dim[1])
xx, yy = np.meshgrid(x, y)
xx, yy = np.meshgrid(x, y)
bottom = (yy >= 0.25*dim[1])
left = (yy <= 0.75/0.5 * dim[1]/dim[2] * xx)
right = np.fliplr(left)
mag_shape[0,...] = np.logical_and(np.logical_and(left, right), bottom)
# Create magnetic data, project it, get the phase map and display the holography image:
mag_data = MagData(res, mc.create_mag_dist(mag_shape, phi))
left = (yy <= 0.75/0.5 * dim[1]/dim[2] * xx)
right = np.fliplr(left)
mag_shape[0, ...] = np.logical_and(np.logical_and(left, right), bottom)
# Create magnetic data, project it, get the phase map and display the holography image:
mag_data = MagData(res, mc.create_mag_dist(mag_shape, phi))
projection = pj.simple_axis_projection(mag_data)
phase_map = PhaseMap(res, pm.phase_mag_real(res, projection, 'slab'))
phase_map = PhaseMap(res, pm.phase_mag_real(res, projection, 'slab'))
hi.display(hi.holo_image(phase_map, density), 'PYRAMID - LOGO', axis)
if __name__ == '__main__':
app = QtGui.QApplication(sys.argv)
gui = CreateLogoWidget()
sys.exit(app.exec_())
\ No newline at end of file
sys.exit(app.exec_())
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