From 4d230fd8b4eb4c3de4af2379d2b944aa708b1061 Mon Sep 17 00:00:00 2001
From: Jan Caron <j.caron@fz-juelich.de>
Date: Wed, 10 Jul 2013 16:20:13 +0200
Subject: [PATCH] Added scripts to create and compare vortices and one to setup
 interactive mode

---
 pyramid/magcreator.py                | 27 +++++++++
 scripts/compare_method_errors_res.py | 12 +++-
 scripts/compare_vortices.py          | 87 ++++++++++++++++++++++++++++
 scripts/create_vortex.py             | 54 +++++++++++++++++
 scripts/interactive_setup.py         | 14 +++++
 5 files changed, 192 insertions(+), 2 deletions(-)
 create mode 100644 scripts/compare_vortices.py
 create mode 100644 scripts/create_vortex.py
 create mode 100644 scripts/interactive_setup.py

diff --git a/pyramid/magcreator.py b/pyramid/magcreator.py
index 658e2ce..e2db43d 100644
--- a/pyramid/magcreator.py
+++ b/pyramid/magcreator.py
@@ -217,3 +217,30 @@ def create_mag_dist_comb(mag_shape_list, phi_list, theta_list=None, magnitude_li
         y_mag += mag_object[1]
         x_mag += mag_object[2]
     return z_mag, y_mag, x_mag
+
+
+def create_mag_dist_vortex(mag_shape, center=None, magnitude=1):
+    '''Create a 3-dimensional magnetic distribution of a homogeneous magnetized object.
+    Arguments:
+        mag_shape - the magnetic shapes (numpy arrays, see Shapes.* for examples)
+        phi       - the azimuthal angle, describing the direction of the magnetized object
+        theta     - the polar angle, describing the direction of the magnetized object
+                    (optional, is set to pi/2 if not specified -> z-component is zero)
+        magnitude - the relative magnitudes for the magnetic shape (optional, one if not specified)
+    Returns:
+        the 3D magnetic distribution as a MagData object (see pyramid.magdata for reference)
+
+    '''
+    dim = np.shape(mag_shape)
+    assert len(dim) == 3, 'Magnetic shapes must describe 3-dimensional distributions!'
+    if center is None:
+        center = (int(dim[1]/2)-0.5, int(dim[2]/2)-0.5)  # center has to be between (!) two pixels
+    assert len(center) == 2, 'Vortex center has to be defined in 2D!'
+    x = np.linspace(-center[1], dim[2]-1-center[1], dim[2])
+    y = np.linspace(-center[0], dim[1]-1-center[0], dim[1])
+    xx, yy = np.meshgrid(x, y)
+    phi = np.arctan2(yy, xx) - pi/2
+    z_mag = np.zeros(dim)
+    y_mag = -np.ones(dim) * np.sin(phi) * mag_shape * magnitude
+    x_mag = -np.ones(dim) * np.cos(phi) * mag_shape * magnitude
+    return z_mag, y_mag, x_mag
\ No newline at end of file
diff --git a/scripts/compare_method_errors_res.py b/scripts/compare_method_errors_res.py
index 6fcc589..92bc9a3 100644
--- a/scripts/compare_method_errors_res.py
+++ b/scripts/compare_method_errors_res.py
@@ -37,7 +37,8 @@ def compare_method_errors_res():
     
     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), (1, 128, 128), (1, 256, 256), (1, 512, 512)]
+    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
     
     
@@ -69,23 +70,27 @@ def compare_method_errors_res():
     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_w_real_d[0, :] = res_list
     data_disc_real_d[0, :] = res_list
-
+    data_vort_real_d[0, :] = res_list
         
     
     
@@ -117,6 +122,9 @@ def compare_method_errors_res():
         phase_ana_disc = an.phase_mag_disc(dim, res, phi, center, radius, height, b_0)
         mag_data_disc = MagData(res, mc.create_mag_dist(mag_shape_disc, phi))
         projection_disc = pj.simple_axis_projection(mag_data_disc)
+        # Vortex:
+        center_vortex = (center[1], center[2])
+        
         
         '''FOURIER UNPADDED'''
         padding = 0
diff --git a/scripts/compare_vortices.py b/scripts/compare_vortices.py
new file mode 100644
index 0000000..76dca66
--- /dev/null
+++ b/scripts/compare_vortices.py
@@ -0,0 +1,87 @@
+# -*- coding: utf-8 -*-
+"""Create the Pyramid-Logo."""
+
+
+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.holoimage   as hi
+from pyramid.magdata  import MagData
+from pyramid.phasemap import PhaseMap
+
+
+def compare_vortices():
+    '''Calculate and display the Pyramid-Logo.
+    Arguments:
+        None
+    Returns:
+        None
+    
+    '''
+    # Input parameters:  
+    dim_list = [(1, 512, 512), (1, 256, 256), (1, 128, 128), (1, 64, 64), (1, 32, 32), (1, 16, 16)]
+    res_list = [2., 4., 8., 16., 32., 64.]  # in nm
+    density = 10
+    height = 1
+    
+    x = []
+    y = []
+    
+    # Starting magnetic distribution:
+    dim_start = (1, 2*dim_list[0][1], 2*dim_list[0][2])
+    res_start = res_list[0] / 2
+    print 'dim_start = ', dim_start
+    print 'res_start = ', res_start
+    center = (0, dim_start[1]/2 - 0.5, dim_start[2]/2 - 0.5)
+    radius = 0.25 * dim_start[1]
+    mag_shape = mc.Shapes.disc(dim_start, center, radius, height)
+    mag_data = MagData(res_start, mc.create_mag_dist_vortex(mag_shape))
+    #mag_data.quiver_plot()
+    
+    for i, (dim, res) in enumerate(zip(dim_list, res_list)):
+        # Create coarser grid for the magnetization:
+        z_mag = mag_data.magnitude[0].reshape(1, dim[1], 2, dim[1], 2)
+        y_mag = mag_data.magnitude[1].reshape(1, dim[1], 2, dim[1], 2)
+        x_mag = mag_data.magnitude[2].reshape(1, dim[1], 2, dim[1], 2)
+        print 'dim = ', dim
+        print 'res = ', res
+        magnitude = (z_mag.mean(axis=4).mean(axis=2) / 2,
+                     y_mag.mean(axis=4).mean(axis=2) / 2,
+                     x_mag.mean(axis=4).mean(axis=2) / 2)
+        mag_data = MagData(res, magnitude)
+        print np.shape(mag_data.magnitude[0])
+        #mag_data.quiver_plot()
+        projection = pj.simple_axis_projection(mag_data)
+        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, :]/pi)
+        fig = plt.figure()
+        fig.add_subplot(1, 1, 1)
+        plt.plot(x[i], y[i])
+#    
+    # Plot:
+    fig = plt.figure()
+    axis = fig.add_subplot(1, 1, 1)
+    axis.plot(x[0], y[0], 'k',
+              x[1], y[1], 'r',
+              x[2], y[2], 'm',
+              x[3], y[3], 'y',
+              x[4], y[4], 'c',
+              x[5], y[5], 'g',
+              x[6], y[6], 'b')
+    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
diff --git a/scripts/create_vortex.py b/scripts/create_vortex.py
new file mode 100644
index 0000000..93c25c8
--- /dev/null
+++ b/scripts/create_vortex.py
@@ -0,0 +1,54 @@
+# -*- coding: utf-8 -*-
+"""Create the Pyramid-Logo."""
+
+
+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.holoimage   as hi
+from pyramid.magdata  import MagData
+from pyramid.phasemap import PhaseMap
+
+
+def create_vortex():
+    '''Calculate and display the Pyramid-Logo.
+    Arguments:
+        None
+    Returns:
+        None
+    
+    '''
+    # Input parameters:  
+    filename = '../output/mag_dist_vortex.txt'
+    res = 10.0  # in nm
+    density = 1
+    dim = (1, 128, 128)
+    center = (0, int(dim[1]/2)-0.5, int(dim[2]/2)-0.5)
+    radius = 0.25 * dim[1]
+    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.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'))    
+    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
diff --git a/scripts/interactive_setup.py b/scripts/interactive_setup.py
new file mode 100644
index 0000000..660e4f5
--- /dev/null
+++ b/scripts/interactive_setup.py
@@ -0,0 +1,14 @@
+# -*- coding: utf-8 -*-
+"""Imports pyramid package and sets working directory to output directory"""
+
+import pyramid.analytic as an
+import pyramid.holoimage as hi
+import pyramid.magcreator as mc
+import pyramid.phasemapper as pm
+import pyramid.projector as pj
+import pyramid.reconstructor as rc
+from pyramid.magdata import MagData
+from pyramid.phasemap import PhaseMap
+
+import os
+os.chdir('C:\Users\Jan\PhD Thesis\Pyramid\output')
\ No newline at end of file
-- 
GitLab