diff --git a/.hgignore b/.hgignore index 133aa8076c825f084a541fe1c365dbbb24679377..ed3c92e729c95397a5cd7df76dcec24d9fb82b02 100644 --- a/.hgignore +++ b/.hgignore @@ -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 diff --git a/pyramid/numcore/initpyximport.py b/pyramid/numcore/initpyximport.py deleted file mode 100644 index cec853089d77e8f17939f511a390e5397e9b02cd..0000000000000000000000000000000000000000 --- a/pyramid/numcore/initpyximport.py +++ /dev/null @@ -1,32 +0,0 @@ -# -*- 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) diff --git a/scripts/compare_discs.py b/scripts/compare_discs.py index f544e61e38181c05e139e41a9c229e17f3f743cc..15e031d2cebced6332a0036309db78fe8a1ed88e 100644 --- a/scripts/compare_discs.py +++ b/scripts/compare_discs.py @@ -1,18 +1,20 @@ +#! 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) diff --git a/scripts/compare_method_errors.py b/scripts/compare_method_errors.py deleted file mode 100644 index 41bfc5d6b0ea34e81890c7f980f208a3829ef0cd..0000000000000000000000000000000000000000 --- a/scripts/compare_method_errors.py +++ /dev/null @@ -1,102 +0,0 @@ -# -*- 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 diff --git a/scripts/compare_method_errors_fourier_padding.py b/scripts/compare_method_errors_fourier_padding.py index f6f7cc4b93fe096abada409975abe37a89f0b6d0..9c0db3771309e14335c1306f50accba79665ba5c 100644 --- a/scripts/compare_method_errors_fourier_padding.py +++ b/scripts/compare_method_errors_fourier_padding.py @@ -1,18 +1,21 @@ +#! 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) diff --git a/scripts/compare_method_errors_res.py b/scripts/compare_method_errors_res.py index 796d0a04ed362979a424f66d6f8196356cfe2f80..7221cd70c9bba24058e6762fe1eaa0cd75bc4cbb 100644 --- a/scripts/compare_method_errors_res.py +++ b/scripts/compare_method_errors_res.py @@ -1,18 +1,21 @@ +#! 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 import shelve @@ -22,28 +25,21 @@ def compare_method_errors_res(): None Returns: None - + ''' # Create / Open databank: data_shelve = shelve.open('../output/method_errors_shelve') - - - - - - - + '''VARY DIMENSIONS FOR ALL APPROACHES''' - - b_0 = 1 # in T + + b_0 = 1 # in T phi = -pi/4 - dim_list = [(1, 4, 4), (1, 8, 8), (1, 16, 16), (1, 32, 32), (1, 64, 64), + dim_list = [(1, 4, 4), (1, 8, 8), (1, 16, 16), (1, 32, 32), (1, 64, 64), (1, 128, 128), (1, 256, 256), (1, 512, 512)] res_list = [64., 32., 16., 8., 4., 2., 1., 0.5, 0.25] # in nm - - + '''CREATE DATA ARRAYS''' - + data_sl_p_fourier0 = np.zeros((3, len(res_list))) data_sl_w_fourier0 = np.zeros((3, len(res_list))) data_disc_fourier0 = np.zeros((3, len(res_list))) @@ -64,56 +60,53 @@ def compare_method_errors_res(): data_disc_real_s = np.zeros((3, len(res_list))) data_vort_real_s = np.zeros((3, len(res_list))) - data_sl_p_real_d= np.zeros((3, len(res_list))) + data_sl_p_real_d = np.zeros((3, len(res_list))) data_sl_w_real_d = np.zeros((3, len(res_list))) data_disc_real_d = np.zeros((3, len(res_list))) data_vort_real_d = np.zeros((3, len(res_list))) - '''CREATE DATA ARRAYS''' - + data_sl_p_fourier0[0, :] = res_list data_sl_w_fourier0[0, :] = res_list data_disc_fourier0[0, :] = res_list data_vort_fourier0[0, :] = res_list - + data_sl_p_fourier1[0, :] = res_list data_sl_w_fourier1[0, :] = res_list data_disc_fourier1[0, :] = res_list data_vort_fourier1[0, :] = res_list - + data_sl_p_fourier20[0, :] = res_list data_sl_w_fourier20[0, :] = res_list data_disc_fourier20[0, :] = res_list data_vort_fourier20[0, :] = res_list - + data_sl_p_real_s[0, :] = res_list data_sl_w_real_s[0, :] = res_list data_disc_real_s[0, :] = res_list data_vort_real_s[0, :] = res_list - - data_sl_p_real_d[0, :]= res_list + + data_sl_p_real_d[0, :] = res_list data_sl_w_real_d[0, :] = res_list data_disc_real_d[0, :] = res_list data_vort_real_d[0, :] = res_list - - - + for i, (dim, res) in enumerate(zip(dim_list, res_list)): - - print 'i =', i, ' dim =', str(dim) - + + print 'i =', i, ' dim =', str(dim) + '''ANALYTIC SOLUTIONS''' # Slab (perfectly aligned): 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_sl_p = mc.Shapes.slab(dim, center, width) phase_ana_sl_p = an.phase_mag_slab(dim, res, phi, center, width, b_0) mag_data_sl_p = MagData(res, mc.create_mag_dist(mag_shape_sl_p, phi)) projection_sl_p = pj.simple_axis_projection(mag_data_sl_p) # Slab (worst case): center = (0, dim[1]/2, dim[2]/2) # 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_sl_w = mc.Shapes.slab(dim, center, width) phase_ana_sl_w = an.phase_mag_slab(dim, res, phi, center, width, b_0) mag_data_sl_w = MagData(res, mc.create_mag_dist(mag_shape_sl_w, phi)) @@ -121,7 +114,7 @@ def compare_method_errors_res(): # Disc: print center 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_disc = mc.Shapes.disc(dim, center, radius, height) phase_ana_disc = an.phase_mag_disc(dim, res, phi, center, radius, height, b_0) @@ -133,14 +126,14 @@ def compare_method_errors_res(): phase_ana_vort = an.phase_mag_vortex(dim, res, center, radius, height, b_0) mag_data_vort = MagData(res, mc.create_mag_dist_vortex(mag_shape_vort, center_vortex)) projection_vort = pj.simple_axis_projection(mag_data_vort) - + '''FOURIER UNPADDED''' padding = 0 # Slab (perfectly aligned): - key = ', '.join(['Resolution->RMS|duration', 'Fourier', 'padding={}'.format(padding), + key = ', '.join(['Resolution->RMS|duration', 'Fourier', 'padding={}'.format(padding), 'B0={}'.format(b_0), 'res={}'.format(res), 'dim={}'.format(dim), 'phi={}'.format(phi), 'geometry=sl_p']) - if data_shelve.has_key(key): + if key in data_shelve: data_sl_p_fourier0[:, i] = data_shelve[key] else: start_time = time.time() @@ -150,10 +143,10 @@ def compare_method_errors_res(): data_sl_p_fourier0[1, i] = np.std(phase_diff) data_shelve[key] = data_sl_p_fourier0[:, i] # Slab (worst case): - key = ', '.join(['Resolution->RMS|duration', 'Fourier', 'padding={}'.format(padding), + key = ', '.join(['Resolution->RMS|duration', 'Fourier', 'padding={}'.format(padding), 'B0={}'.format(b_0), 'res={}'.format(res), 'dim={}'.format(dim), 'phi={}'.format(phi), 'geometry=sl_w']) - if data_shelve.has_key(key): + if key in data_shelve: data_sl_w_fourier0[:, i] = data_shelve[key] else: start_time = time.time() @@ -163,10 +156,10 @@ def compare_method_errors_res(): data_sl_w_fourier0[1, i] = np.std(phase_diff) data_shelve[key] = data_sl_w_fourier0[:, i] # Disc: - key = ', '.join(['Resolution->RMS|duration', 'Fourier', 'padding={}'.format(padding), + key = ', '.join(['Resolution->RMS|duration', 'Fourier', 'padding={}'.format(padding), 'B0={}'.format(b_0), 'res={}'.format(res), 'dim={}'.format(dim), 'phi={}'.format(phi), 'geometry=disc']) - if data_shelve.has_key(key): + if key in data_shelve: data_disc_fourier0[:, i] = data_shelve[key] else: start_time = time.time() @@ -176,10 +169,10 @@ def compare_method_errors_res(): data_disc_fourier0[1, i] = np.std(phase_diff) data_shelve[key] = data_disc_fourier0[:, i] # Vortex: - key = ', '.join(['Resolution->RMS|duration', 'Fourier', 'padding={}'.format(padding), + key = ', '.join(['Resolution->RMS|duration', 'Fourier', 'padding={}'.format(padding), 'B0={}'.format(b_0), 'res={}'.format(res), 'dim={}'.format(dim), 'phi={}'.format(phi), 'geometry=vortex']) - if data_shelve.has_key(key): + if key in data_shelve: data_vort_fourier0[:, i] = data_shelve[key] else: start_time = time.time() @@ -188,15 +181,14 @@ def compare_method_errors_res(): phase_diff = phase_ana_vort - phase_num data_vort_fourier0[1, i] = np.std(phase_diff) data_shelve[key] = data_vort_fourier0[:, i] - - + '''FOURIER PADDED ONCE''' padding = 1 # Slab (perfectly aligned): - key = ', '.join(['Resolution->RMS|duration', 'Fourier', 'padding={}'.format(padding), + key = ', '.join(['Resolution->RMS|duration', 'Fourier', 'padding={}'.format(padding), 'B0={}'.format(b_0), 'res={}'.format(res), 'dim={}'.format(dim), 'phi={}'.format(phi), 'geometry=sl_p']) - if data_shelve.has_key(key): + if key in data_shelve: data_sl_p_fourier1[:, i] = data_shelve[key] else: start_time = time.time() @@ -206,10 +198,10 @@ def compare_method_errors_res(): data_sl_p_fourier1[1, i] = np.std(phase_diff) data_shelve[key] = data_sl_p_fourier1[:, i] # Slab (worst case): - key = ', '.join(['Resolution->RMS|duration', 'Fourier', 'padding={}'.format(padding), + key = ', '.join(['Resolution->RMS|duration', 'Fourier', 'padding={}'.format(padding), 'B0={}'.format(b_0), 'res={}'.format(res), 'dim={}'.format(dim), 'phi={}'.format(phi), 'geometry=sl_w']) - if data_shelve.has_key(key): + if key in data_shelve: data_sl_w_fourier1[:, i] = data_shelve[key] else: start_time = time.time() @@ -219,10 +211,10 @@ def compare_method_errors_res(): data_sl_w_fourier1[1, i] = np.std(phase_diff) data_shelve[key] = data_sl_w_fourier1[:, i] # Disc: - key = ', '.join(['Resolution->RMS|duration', 'Fourier', 'padding={}'.format(padding), + key = ', '.join(['Resolution->RMS|duration', 'Fourier', 'padding={}'.format(padding), 'B0={}'.format(b_0), 'res={}'.format(res), 'dim={}'.format(dim), 'phi={}'.format(phi), 'geometry=disc']) - if data_shelve.has_key(key): + if key in data_shelve: data_disc_fourier1[:, i] = data_shelve[key] else: start_time = time.time() @@ -232,10 +224,10 @@ def compare_method_errors_res(): data_disc_fourier1[1, i] = np.std(phase_diff) data_shelve[key] = data_disc_fourier1[:, i] # Vortex: - key = ', '.join(['Resolution->RMS|duration', 'Fourier', 'padding={}'.format(padding), + key = ', '.join(['Resolution->RMS|duration', 'Fourier', 'padding={}'.format(padding), 'B0={}'.format(b_0), 'res={}'.format(res), 'dim={}'.format(dim), 'phi={}'.format(phi), 'geometry=vortex']) - if data_shelve.has_key(key): + if key in data_shelve: data_vort_fourier1[:, i] = data_shelve[key] else: start_time = time.time() @@ -244,16 +236,15 @@ def compare_method_errors_res(): phase_diff = phase_ana_vort - phase_num data_vort_fourier1[1, i] = np.std(phase_diff) data_shelve[key] = data_vort_fourier1[:, i] - - + '''FOURIER PADDED 20''' if dim[1] <= 128: padding = 20 # Slab (perfectly aligned): - key = ', '.join(['Resolution->RMS|duration', 'Fourier', 'padding={}'.format(padding), + key = ', '.join(['Resolution->RMS|duration', 'Fourier', 'padding={}'.format(padding), 'B0={}'.format(b_0), 'res={}'.format(res), 'dim={}'.format(dim), 'phi={}'.format(phi), 'geometry=sl_p']) - if data_shelve.has_key(key): + if key in data_shelve: data_sl_p_fourier20[:, i] = data_shelve[key] else: start_time = time.time() @@ -263,10 +254,10 @@ def compare_method_errors_res(): data_sl_p_fourier20[1, i] = np.std(phase_diff) data_shelve[key] = data_sl_p_fourier20[:, i] # Slab (worst case): - key = ', '.join(['Resolution->RMS|duration', 'Fourier', 'padding={}'.format(padding), + key = ', '.join(['Resolution->RMS|duration', 'Fourier', 'padding={}'.format(padding), 'B0={}'.format(b_0), 'res={}'.format(res), 'dim={}'.format(dim), 'phi={}'.format(phi), 'geometry=sl_w']) - if data_shelve.has_key(key): + if key in data_shelve: data_sl_w_fourier20[:, i] = data_shelve[key] else: start_time = time.time() @@ -276,10 +267,10 @@ def compare_method_errors_res(): data_sl_w_fourier20[1, i] = np.std(phase_diff) data_shelve[key] = data_sl_w_fourier20[:, i] # Disc: - key = ', '.join(['Resolution->RMS|duration', 'Fourier', 'padding={}'.format(padding), + key = ', '.join(['Resolution->RMS|duration', 'Fourier', 'padding={}'.format(padding), 'B0={}'.format(b_0), 'res={}'.format(res), 'dim={}'.format(dim), 'phi={}'.format(phi), 'geometry=disc']) - if data_shelve.has_key(key): + if key in data_shelve: data_disc_fourier20[:, i] = data_shelve[key] else: start_time = time.time() @@ -289,10 +280,10 @@ def compare_method_errors_res(): data_disc_fourier20[1, i] = np.std(phase_diff) data_shelve[key] = data_disc_fourier20[:, i] # Vortex: - key = ', '.join(['Resolution->RMS|duration', 'Fourier', 'padding={}'.format(padding), + key = ', '.join(['Resolution->RMS|duration', 'Fourier', 'padding={}'.format(padding), 'B0={}'.format(b_0), 'res={}'.format(res), 'dim={}'.format(dim), 'phi={}'.format(phi), 'geometry=vortex']) - if data_shelve.has_key(key): + if key in data_shelve: data_vort_fourier20[:, i] = data_shelve[key] else: start_time = time.time() @@ -301,14 +292,14 @@ def compare_method_errors_res(): phase_diff = phase_ana_vort - phase_num data_vort_fourier20[1, i] = np.std(phase_diff) data_shelve[key] = data_vort_fourier20[:, i] - + '''REAL SLAB''' method = 'slab' # Slab (perfectly aligned): - key = ', '.join(['Resolution->RMS|duration', 'Real', 'method={}'.format(method), + key = ', '.join(['Resolution->RMS|duration', 'Real', 'method={}'.format(method), 'B0={}'.format(b_0), 'res={}'.format(res), 'dim={}'.format(dim), 'phi={}'.format(phi), 'geometry=sl_p']) - if data_shelve.has_key(key): + if key in data_shelve: data_sl_p_real_s[:, i] = data_shelve[key] else: start_time = time.time() @@ -318,10 +309,10 @@ def compare_method_errors_res(): data_sl_p_real_s[1, i] = np.std(phase_diff) data_shelve[key] = data_sl_p_real_s[:, i] # Slab (worst case): - key = ', '.join(['Resolution->RMS|duration', 'Real', 'method={}'.format(method), + key = ', '.join(['Resolution->RMS|duration', 'Real', 'method={}'.format(method), 'B0={}'.format(b_0), 'res={}'.format(res), 'dim={}'.format(dim), 'phi={}'.format(phi), 'geometry=sl_w']) - if data_shelve.has_key(key): + if key in data_shelve: data_sl_w_real_s[:, i] = data_shelve[key] else: start_time = time.time() @@ -331,10 +322,10 @@ def compare_method_errors_res(): data_sl_w_real_s[1, i] = np.std(phase_diff) data_shelve[key] = data_sl_w_real_s[:, i] # Disc: - key = ', '.join(['Resolution->RMS|duration', 'Real', 'method={}'.format(method), + key = ', '.join(['Resolution->RMS|duration', 'Real', 'method={}'.format(method), 'B0={}'.format(b_0), 'res={}'.format(res), 'dim={}'.format(dim), 'phi={}'.format(phi), 'geometry=disc']) - if data_shelve.has_key(key): + if key in data_shelve: data_disc_real_s[:, i] = data_shelve[key] else: start_time = time.time() @@ -344,10 +335,10 @@ def compare_method_errors_res(): data_disc_real_s[1, i] = np.std(phase_diff) data_shelve[key] = data_disc_real_s[:, i] # Vortex: - key = ', '.join(['Resolution->RMS|duration', 'Real', 'method={}'.format(method), + key = ', '.join(['Resolution->RMS|duration', 'Real', 'method={}'.format(method), 'B0={}'.format(b_0), 'res={}'.format(res), 'dim={}'.format(dim), 'phi={}'.format(phi), 'geometry=vortex']) - if data_shelve.has_key(key): + if key in data_shelve: data_disc_real_s[:, i] = data_shelve[key] else: start_time = time.time() @@ -356,14 +347,14 @@ def compare_method_errors_res(): phase_diff = phase_ana_vort - phase_num data_vort_real_s[1, i] = np.std(phase_diff) data_shelve[key] = data_vort_real_s[:, i] - + '''REAL DISC''' method = 'disc' # Slab (perfectly aligned): - key = ', '.join(['Resolution->RMS|duration', 'Real', 'method={}'.format(method), + key = ', '.join(['Resolution->RMS|duration', 'Real', 'method={}'.format(method), 'B0={}'.format(b_0), 'res={}'.format(res), 'dim={}'.format(dim), 'phi={}'.format(phi), 'geometry=sl_p']) - if data_shelve.has_key(key): + if key in data_shelve: data_sl_p_real_d[:, i] = data_shelve[key] else: start_time = time.time() @@ -373,10 +364,10 @@ def compare_method_errors_res(): data_sl_p_real_d[1, i] = np.std(phase_diff) data_shelve[key] = data_sl_p_real_d[:, i] # Slab (worst case): - key = ', '.join(['Resolution->RMS|duration', 'Real', 'method={}'.format(method), + key = ', '.join(['Resolution->RMS|duration', 'Real', 'method={}'.format(method), 'B0={}'.format(b_0), 'res={}'.format(res), 'dim={}'.format(dim), 'phi={}'.format(phi), 'geometry=sl_w']) - if data_shelve.has_key(key): + if key in data_shelve: data_sl_w_real_d[:, i] = data_shelve[key] else: start_time = time.time() @@ -386,10 +377,10 @@ def compare_method_errors_res(): data_sl_w_real_d[1, i] = np.std(phase_diff) data_shelve[key] = data_sl_w_real_d[:, i] # Disc: - key = ', '.join(['Resolution->RMS|duration', 'Real', 'method={}'.format(method), + key = ', '.join(['Resolution->RMS|duration', 'Real', 'method={}'.format(method), 'B0={}'.format(b_0), 'res={}'.format(res), 'dim={}'.format(dim), 'phi={}'.format(phi), 'geometry=disc']) - if data_shelve.has_key(key): + if key in data_shelve: data_disc_real_d[:, i] = data_shelve[key] else: start_time = time.time() @@ -399,10 +390,10 @@ def compare_method_errors_res(): data_disc_real_d[1, i] = np.std(phase_diff) data_shelve[key] = data_disc_real_d[:, i] # Vortex: - key = ', '.join(['Resolution->RMS|duration', 'Real', 'method={}'.format(method), + key = ', '.join(['Resolution->RMS|duration', 'Real', 'method={}'.format(method), 'B0={}'.format(b_0), 'res={}'.format(res), 'dim={}'.format(dim), 'phi={}'.format(phi), 'geometry=vortex']) - if data_shelve.has_key(key): + if key in data_shelve: data_vort_real_d[:, i] = data_shelve[key] else: start_time = time.time() @@ -411,7 +402,7 @@ def compare_method_errors_res(): phase_diff = phase_ana_vort - phase_num data_vort_real_d[1, i] = np.std(phase_diff) data_shelve[key] = data_vort_real_d[:, i] - + # Plot duration against res (perfect slab): fig = plt.figure() axis = fig.add_subplot(1, 1, 1) @@ -440,12 +431,12 @@ def compare_method_errors_res(): axis.set_ylabel('duration [s]') # Save to file: data_sl_p = np.concatenate((data_sl_p_fourier0, - data_sl_p_fourier1[1:,:], - data_sl_p_fourier20[1:,:], - data_sl_p_real_s[1:,:], - data_sl_p_real_d[1:,:])) + data_sl_p_fourier1[1:, :], + data_sl_p_fourier20[1:, :], + data_sl_p_real_s[1:, :], + data_sl_p_real_d[1:, :])) np.savetxt('../output/data_slab_perfect.txt', data_sl_p.T) - + # Plot duration against res (worst case slab): fig = plt.figure() axis = fig.add_subplot(1, 1, 1) @@ -474,12 +465,12 @@ def compare_method_errors_res(): axis.set_ylabel('duration [s]') # Save to file: data_sl_w = np.concatenate((data_sl_w_fourier0, - data_sl_w_fourier1[1:,:], - data_sl_w_fourier20[1:,:], - data_sl_w_real_s[1:,:], - data_sl_w_real_d[1:,:])) + data_sl_w_fourier1[1:, :], + data_sl_w_fourier20[1:, :], + data_sl_w_real_s[1:, :], + data_sl_w_real_d[1:, :])) np.savetxt('../output/data_slab_worstcase.txt', data_sl_w.T) - + # Plot duration against res (disc): fig = plt.figure() axis = fig.add_subplot(1, 1, 1) @@ -508,12 +499,12 @@ def compare_method_errors_res(): axis.set_ylabel('duration [s]') # Save to file: data_disc = np.concatenate((data_disc_fourier0, - data_disc_fourier1[1:,:], - data_disc_fourier20[1:,:], - data_disc_real_s[1:,:], - data_disc_real_d[1:,:])) + data_disc_fourier1[1:, :], + data_disc_fourier20[1:, :], + data_disc_real_s[1:, :], + data_disc_real_d[1:, :])) np.savetxt('../output/data_disc.txt', data_disc.T) - + # Plot duration against res (vortex): fig = plt.figure() axis = fig.add_subplot(1, 1, 1) @@ -542,20 +533,19 @@ def compare_method_errors_res(): axis.set_ylabel('duration [s]') # Save to file: data_vort = np.concatenate((data_vort_fourier0, - data_vort_fourier1[1:,:], - data_vort_fourier20[1:,:], - data_vort_real_s[1:,:], - data_vort_real_d[1:,:])) + data_vort_fourier1[1:, :], + data_vort_fourier20[1:, :], + data_vort_real_s[1:, :], + data_vort_real_d[1:, :])) np.savetxt('../output/data_vortex.txt', data_vort.T) - + data_shelve.close() - - + if __name__ == "__main__": try: compare_method_errors_res() except: type, value, tb = sys.exc_info() traceback.print_exc() - pdb.post_mortem(tb) \ No newline at end of file + pdb.post_mortem(tb) diff --git a/scripts/compare_methods.py b/scripts/compare_methods.py index 7327b7ffa5d73377945156a2afb9cd267dff20c2..ae92cf4b6c1756db7d04341cae8607a92b04af53 100644 --- a/scripts/compare_methods.py +++ b/scripts/compare_methods.py @@ -1,18 +1,21 @@ +#! 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) diff --git a/scripts/compare_pixel_fields.py b/scripts/compare_pixel_fields.py index 12175953a70fbdbf4415250761db54073c92e1ea..fff98b28bb152a76c76e89d77e871b88bd09371e 100644 --- a/scripts/compare_pixel_fields.py +++ b/scripts/compare_pixel_fields.py @@ -1,14 +1,17 @@ +#! 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) diff --git a/scripts/compare_vortices.py b/scripts/compare_vortices.py index 2c89820857230511b180f769d3fadbf3cb57399a..7c01f3876d86520f4b59a67ddb5378d3864dcf36 100644 --- a/scripts/compare_vortices.py +++ b/scripts/compare_vortices.py @@ -1,17 +1,20 @@ +#! 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) diff --git a/scripts/create_alternating_filaments.py b/scripts/create_alternating_filaments.py index 684f58ee945bd52674b78b2302479aed4fae9ffa..a07706a346188f07da2c9dcba5d24d8f73d634c7 100644 --- a/scripts/create_alternating_filaments.py +++ b/scripts/create_alternating_filaments.py @@ -1,8 +1,11 @@ +#! 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) diff --git a/scripts/create_logo.py b/scripts/create_logo.py index a83af16d0b9534122481234ca318c8c19b071915..8fcc4930a5a42ac0afe262d7dcdd97d209045fb6 100644 --- a/scripts/create_logo.py +++ b/scripts/create_logo.py @@ -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) diff --git a/scripts/create_multiple_samples.py b/scripts/create_multiple_samples.py index bddaa8111fe7eae26d36793ed6aed32d404daf7d..c353aed9ba9201c02b15d62a0d0c407cb61672f5 100644 --- a/scripts/create_multiple_samples.py +++ b/scripts/create_multiple_samples.py @@ -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) diff --git a/scripts/create_random_pixels.py b/scripts/create_random_pixels.py index 8a9224d98a02883a294fa560a11ea419d3b8916d..a52e68683e46cb946188032e7830711a182704b4 100644 --- a/scripts/create_random_pixels.py +++ b/scripts/create_random_pixels.py @@ -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) diff --git a/scripts/create_random_slabs.py b/scripts/create_random_slabs.py index d36e49eb9c5a805400320a8d8b3780c19a0fab5f..03960f26720fc9b50ed8bc72cd83ecba50e73f51 100644 --- a/scripts/create_random_slabs.py +++ b/scripts/create_random_slabs.py @@ -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) diff --git a/scripts/create_sample.py b/scripts/create_sample.py index 5a567c068dbebc02fe02dd1702b83bdbdbe89c43..1ee772e3fdecac8bc286bc7cf9db571c2f35c6df 100644 --- a/scripts/create_sample.py +++ b/scripts/create_sample.py @@ -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) diff --git a/scripts/create_vortex.py b/scripts/create_vortex.py index 93c25c8b0d0966d503d28fe59df5032d68c567f2..4fa8ad66bcc796cdf5e1379c3faed651fa9424a9 100644 --- a/scripts/create_vortex.py +++ b/scripts/create_vortex.py @@ -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) diff --git a/scripts/get_jacobi.py b/scripts/get_jacobi.py index 66ece51f5ac9f3bdb8c894aad4c51a024e30db3d..779fb4af368e6abb19a4d8f09ea190a3041082cb 100644 --- a/scripts/get_jacobi.py +++ b/scripts/get_jacobi.py @@ -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) diff --git a/scripts/get_revision.py b/scripts/get_revision.py deleted file mode 100644 index 62af71cc512738a8650187cd1baebaee717d2160..0000000000000000000000000000000000000000 --- a/scripts/get_revision.py +++ /dev/null @@ -1,14 +0,0 @@ -# -*- 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 diff --git a/scripts/gui/__init__.py b/scripts/gui/__init__.py index 636ccd22c73910e269e8396169625504d8bde056..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 100644 --- a/scripts/gui/__init__.py +++ b/scripts/gui/__init__.py @@ -1,7 +0,0 @@ -# -*- coding: utf-8 -*- -""" -Created on Tue May 21 14:29:25 2013 - -@author: Jan -""" - diff --git a/scripts/gui_create_logo.py b/scripts/gui_create_logo.py index 4e684aef1824b733e92ad88d2c95778a88ef0be1..45432c2bf786ec291133fbcb00b5733dbcbb4f2a 100644 --- a/scripts/gui_create_logo.py +++ b/scripts/gui_create_logo.py @@ -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_()) diff --git a/scripts/interactive_setup.py b/scripts/interactive_setup.py index 5c4ebd4bf98b68324eef5e3cfd704cf4e545782d..a7293d092f024e149c6b36407f5a16d8fdc1f25b 100644 --- a/scripts/interactive_setup.py +++ b/scripts/interactive_setup.py @@ -12,4 +12,3 @@ from pyramid.phasemap import PhaseMap import os os.chdir('C:\Users\Jan\Daten\PhD Thesis\Pyramid\output') -# TODO: Path not hard-coded!!! \ No newline at end of file diff --git a/scripts/reconstruct_random_pixels.py b/scripts/reconstruct_random_pixels.py index 1cf7c705e9c9f424f5969da75034c6a567b8b700..a09bb09c65ffd2b94b81cb3e2e076b35aa455035 100644 --- a/scripts/reconstruct_random_pixels.py +++ b/scripts/reconstruct_random_pixels.py @@ -1,8 +1,11 @@ # -*- coding: utf-8 -*- """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 @@ -26,19 +29,19 @@ def reconstruct_random_distribution(): # Input parameters: n_pixel = 5 dim = (1, 16, 16) - b_0 = 1 # in T - res = 10.0 # in nm + b_0 = 1 # in T + res = 10.0 # in nm rnd.seed(18) threshold = 0 # Create lists for magnetic objects: mag_shape_list = np.zeros((n_pixel,) + dim) - phi_list = np.zeros(n_pixel) + phi_list = np.zeros(n_pixel) magnitude_list = np.zeros(n_pixel) for i in range(n_pixel): 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() + mag_shape_list[i, ...] = mc.Shapes.pixel(dim, pixel) + phi_list[i] = 2 * pi * rnd.random() magnitude_list[i] = rnd.random() # Create magnetic distribution: magnitude = mc.create_mag_dist_comb(mag_shape_list, phi_list, magnitude_list) @@ -54,7 +57,7 @@ def reconstruct_random_distribution(): x_mask = abs(x_mag) > threshold y_mask = abs(y_mag) > threshold mask = np.logical_or(np.logical_or(x_mask, y_mask), z_mask) - + # Reconstruct the magnetic distribution: mag_data_rec = rc.reconstruct_simple_leastsq(phase_map, mask, b_0) diff --git a/setup.py b/setup.py index d90599684b12b69e2766e7a9bc60aff708fe5b1a..18e670b541e3f46237c7373f3802c5ce9a5e8006 100644 --- a/setup.py +++ b/setup.py @@ -1,41 +1,51 @@ # -*- coding: utf-8 -*- -""" -Created on Fri May 03 10:27:04 2013 - -@author: Jan -""" - - -# Build extensions: 'python setup.py build_ext -i clean' -# Install package: 'python setup.py install clean' +"""Setup for testing, building, distributing and installing the 'Pyramid'-package""" import numpy - import os import sys import sysconfig -#import glob - -#from distutils.core import setup +import subprocess from distutils.command.build import build -#from distutils.extension import Extension - from Cython.Distutils import build_ext +from setuptools import setup +from setuptools import find_packages +from setuptools.extension import Extension -from setuptools import setup, find_packages -from setuptools.extension import Extension +class custom_build(build): + '''Custom build command''' + + def make_hgrevision(self, target): + output = subprocess.Popen(["hg", "id", "-i"], stdout=subprocess.PIPE).communicate()[0] + hgrevision_cc = file(str(target), "w") + hgrevision_cc.write('HG_Revision = "{0}"\n'.format(output.strip())) + hgrevision_cc.close() + + def run(self): + build.run(self) + print 'creating hg_revision.txt' + self.make_hgrevision(os.path.join('build', get_build_path('lib'), 'hg_revision.txt')) -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() +def get_build_path(dname): + '''Returns the name of a distutils build directory''' + path = "{dirname}.{platform}-{version[0]}.{version[1]}" + return path.format(dirname=dname, platform=sysconfig.get_platform(), version=sys.version_info) -print '\n------------------------------------------------------------------------------' + +def get_files(rootdir): + '''Returns a list of .py-files inside rootdir''' + filepaths = [] + for root, dirs, files in os.walk(rootdir): + for filename in files: + if filename.endswith('.py'): + filepaths.append(os.path.join(root, filename)) + return filepaths + + +print '\n-------------------------------------------------------------------------------' setup( name = 'Pyramid', @@ -44,21 +54,23 @@ setup( author = 'Jan Caron', author_email = 'j.caron@fz-juelich.de', - packages = find_packages(exclude=['test']),#['pyramid', 'pyramid.numcore', 'test', 'scripts'], + packages = find_packages(exclude=['tests']), include_dirs = [numpy.get_include()], requires = ['numpy', 'matplotlib'], - - scripts = ['scripts/create_logo.py'], - test_suite = 'test', - - cmdclass = {'build_ext': build_ext}, + + scripts = get_files('scripts'), + + test_suite = 'tests', + + cmdclass = {'build_ext': build_ext, 'build': custom_build}, + ext_package = 'pyramid/numcore', ext_modules = [ - Extension('phase_mag_real', ['pyramid/numcore/phase_mag_real.pyx'], + Extension('phase_mag_real', ['pyramid/numcore/phase_mag_real.pyx'], include_dirs = [numpy.get_include(), numpy.get_numarray_include()], - extra_compile_args=["-march=native", "-mtune=native"] + extra_compile_args=['-march=native', '-mtune=native'] ) ] ) -print '------------------------------------------------------------------------------\n' +print '-------------------------------------------------------------------------------\n' diff --git a/tests/__init__.py b/tests/__init__.py index 3827142a682f0c22c20c6f4c2f979e07e898f7dc..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -1,26 +0,0 @@ -import unittest -from test_compliance import TestCaseCompliance -from test_magcreator import TestCaseMagCreator -from test_magdata import TestCaseMagData -from test_projector import TestCaseProjector -from test_phasemapper import TestCasePhaseMapper -from test_phasemap import TestCasePhaseMap -from test_holoimage import TestCaseHoloImage -from test_analytic import TestCaseAnalytic -from test_reconstructor import TestCaseReconstructor - - -def load_suite(): - - loader = unittest.TestLoader() - suite = unittest.TestSuite() - suite.addTest(loader.loadTestsFromTestCase(TestCaseCompliance)) - suite.addTest(loader.loadTestsFromTestCase(TestCaseMagCreator)) - suite.addTest(loader.loadTestsFromTestCase(TestCaseMagData)) - suite.addTest(loader.loadTestsFromTestCase(TestCaseProjector)) - suite.addTest(loader.loadTestsFromTestCase(TestCasePhaseMapper)) - suite.addTest(loader.loadTestsFromTestCase(TestCasePhaseMap)) - suite.addTest(loader.loadTestsFromTestCase(TestCaseHoloImage)) - suite.addTest(loader.loadTestsFromTestCase(TestCaseAnalytic)) - suite.addTest(loader.loadTestsFromTestCase(TestCaseReconstructor)) - return suite diff --git a/tests/test_compliance.py b/tests/test_compliance.py index a78ca8499d6705c79ace45b4fea055c46edc922d..ad9188fdd12d4b3e74398e468004fe2143154545 100644 --- a/tests/test_compliance.py +++ b/tests/test_compliance.py @@ -10,9 +10,7 @@ import pep8 class TestCaseCompliance(unittest.TestCase): - """ - Class for checking compliance of pyjurassic. - """ # TODO: Docstring + """Class for checking compliance of pyramid.""" # TODO: Docstring def setUp(self): pass @@ -24,15 +22,16 @@ class TestCaseCompliance(unittest.TestCase): filepaths = [] for root, dirs, files in os.walk(rootdir): for filename in files: - if filename.endswith('.py') or filename.endswith('.pyx'): + if ((filename.endswith('.py') or filename.endswith('.pyx')) + and root != os.path.join('scripts', 'gui')): filepaths.append(os.path.join(root, filename)) return filepaths def test_pep8(self): # TODO: Docstring files = self.get_files_to_check('pyramid') \ - + self.get_files_to_check('scripts') \ - + self.get_files_to_check('test') + + self.get_files_to_check('scripts') \ + + self.get_files_to_check('tests') ignores = ('E226', 'E128') pep8.MAX_LINE_LENGTH = 99 pep8style = pep8.StyleGuide(quiet=False) @@ -48,6 +47,8 @@ class TestCaseCompliance(unittest.TestCase): result = pep8style.check_files(files) if result.total_errors == 0: print 'No Warnings or Errors detected!' + else: + print '\n{} Warnings and Errors detected!'.format(result.total_errors) sys.stdout = stdout_buffer error_message = 'Found %s Errors and Warnings!' % result.total_errors