From 975e30c27737e2aa6b83c0b99a98d60a484decdb Mon Sep 17 00:00:00 2001 From: Jan Caron <j.caron@fz-juelich.de> Date: Tue, 13 Aug 2013 16:16:08 +0200 Subject: [PATCH] Final version of paper scripts holoimage: changed colorwheel (now without axes) magcreator: create_vortex now also allows a 3D-center (2D is extracted) magdata: new methods: get_mask() and scale_down() phasemap: changed plotting defaults (new kwargs) phasemapper: started on electrical contribution --- pyramid/analytic.py | 12 +- pyramid/holoimage.py | 40 +- pyramid/magcreator.py | 10 +- pyramid/magdata.py | 77 ++- pyramid/phasemap.py | 69 ++- pyramid/phasemapper.py | 37 +- .../compare_method_errors_fourier_padding.py | 2 +- scripts/compare_methods.py | 16 +- scripts/compare_pixel_fields.py | 6 +- scripts/create_logo.py | 3 +- scripts/interactive_setup.py | 2 +- .../ch5-0-evaluation_and_comparison.py | 23 +- .../paper 1/ch5-1-evaluation_real_space.py | 318 ++++++----- .../paper 1/ch5-2-evaluation_fourier_space.py | 535 +++++++++++++++--- .../paper 1/ch5-3-comparison_of_methods.py | 136 ++--- scripts/reconstruct_random_pixels.py | 9 +- setup.py | 2 +- 17 files changed, 910 insertions(+), 387 deletions(-) diff --git a/pyramid/analytic.py b/pyramid/analytic.py index 246c7a8..89337ce 100644 --- a/pyramid/analytic.py +++ b/pyramid/analytic.py @@ -12,7 +12,7 @@ PHI_0 = -2067.83 # magnetic flux in T*nm² def phase_mag_slab(dim, res, phi, center, width, b_0=1): - '''Get the analytic solution for a phase map of a slab of specified dimensions + '''Get the analytic solution for a phase map of a slab of specified dimensions. Arguments: dim - the dimensions of the grid, shape(z, y, x) res - the resolution of the grid (grid spacing) in nm @@ -40,8 +40,8 @@ def phase_mag_slab(dim, res, phi, center, width, b_0=1): + F0(y-y0+Ly/2, x-x0+Lx/2))) # Process input parameters: z_dim, y_dim, x_dim = dim - y0 = res * (center[1] + 0.5) # y0, x0 have to be in the center of a pixel, - x0 = res * (center[2] + 0.5) # hence: cellindex + 0.5 + y0 = res * (center[1] + 0.5) # y0, x0 define the center of a pixel, + x0 = res * (center[2] + 0.5) # hence: (cellindex + 0.5) * resolution Lz, Ly, Lx = res * width[0], res * width[1], res * width[2] coeff = b_0 / (4*PHI_0) # Create grid: @@ -53,7 +53,7 @@ def phase_mag_slab(dim, res, phi, center, width, b_0=1): def phase_mag_disc(dim, res, phi, center, radius, height, b_0=1): - '''Get the analytic solution for a phase map of a disc of specified dimensions + '''Get the analytic solution for a phase map of a disc of specified dimensions. Arguments: dim - the dimensions of the grid, shape(z, y, x) res - the resolution of the grid (grid spacing) in nm @@ -89,7 +89,7 @@ def phase_mag_disc(dim, res, phi, center, radius, height, b_0=1): def phase_mag_sphere(dim, res, phi, center, radius, b_0=1): - '''Get the analytic solution for a phase map of a sphere of specified dimensions + '''Get the analytic solution for a phase map of a sphere of specified dimensions. Arguments: dim - the dimensions of the grid, shape(z, y, x) res - the resolution of the grid (grid spacing) in nm @@ -123,7 +123,7 @@ def phase_mag_sphere(dim, res, phi, center, radius, b_0=1): def phase_mag_vortex(dim, res, center, radius, height, b_0=1): - '''Get the analytic solution for a phase map of a sharp vortex disc of specified dimensions + '''Get the analytic solution for a phase map of a sharp vortex disc of specified dimensions. Arguments: dim - the dimensions of the grid, shape(z, y, x) res - the resolution of the grid (grid spacing) in nm diff --git a/pyramid/holoimage.py b/pyramid/holoimage.py index b44e91d..cea6f96 100644 --- a/pyramid/holoimage.py +++ b/pyramid/holoimage.py @@ -8,6 +8,7 @@ import matplotlib.pyplot as plt from pyramid.phasemap import PhaseMap from numpy import pi from PIL import Image +from matplotlib.ticker import NullLocator CDICT = {'red': [(0.00, 1.0, 0.0), @@ -76,20 +77,20 @@ def make_color_wheel(): rgb = (255.999 * color_wheel_magnitude.T * rgba[:, :, :3].T).T.astype(np.uint8) color_wheel = Image.fromarray(rgb) # Plot the color wheel: - fig = plt.figure() - ax = fig.add_subplot(111, aspect='equal') - ax.imshow(color_wheel) - ax.set_title('Color Wheel') - ax.set_xlabel('x-axis') - ax.set_ylabel('y-axis') + fig = plt.figure(figsize=(4, 4)) + axis = fig.add_subplot(1, 1, 1, aspect='equal') + axis.imshow(color_wheel, origin='lower') + axis.xaxis.set_major_locator(NullLocator()) + axis.yaxis.set_major_locator(NullLocator()) -def display(holo_image, title='Holography Image', axis=None): +def display(holo_image, title='Holography Image', axis=None, interpolation='none'): '''Display the color coded holography image resulting from a given phase map. Arguments: - holo_image - holography image created with the holo_image function of this module - title - the title of the plot (default: 'Holography Image') - axis - the axis on which to display the plot (default: None, a new figure is created) + holo_image - holography image created with the holo_image function of this module + title - the title of the plot (default: 'Holography Image') + axis - the axis on which to display the plot (default: None, creates new figure) + interpolation - defines the interpolation method (default: 'none') Returns: None @@ -99,13 +100,17 @@ def display(holo_image, title='Holography Image', axis=None): fig = plt.figure() axis = fig.add_subplot(1, 1, 1, aspect='equal') # Plot the image and set axes: - axis.imshow(holo_image, interpolation='none') + axis.imshow(holo_image, origin='lower', interpolation=interpolation) + # Set the title and the axes labels: axis.set_title(title) - axis.set_xlabel('x-axis') - axis.set_ylabel('y-axis') + plt.tick_params(axis='both', which='major', labelsize=14) + axis.set_title(title, fontsize=18) + axis.set_xlabel('x-axis [px]', fontsize=15) + axis.set_ylabel('y-axis [px]', fontsize=15) -def display_combined(phase_map, density, title='Combined Plot'): +def display_combined(phase_map, density, title='Combined Plot', interpolation='none', + labels=('x-axis [nm]', 'y-axis [nm]', 'phase [rad]')):# TODO DOCSTRING '''Display a given phase map and the resulting color coded holography image in one plot. Arguments: phase_map - the PhaseMap object from which the holography image is calculated @@ -116,11 +121,12 @@ def display_combined(phase_map, density, title='Combined Plot'): ''' # Create combined plot and set title: - fig = plt.figure(figsize=(14, 7)) + fig = plt.figure(figsize=(16, 7)) fig.suptitle(title, fontsize=20) # Plot holography image: holo_axis = fig.add_subplot(1, 2, 1, aspect='equal') - display(holo_image(phase_map, density), axis=holo_axis) + display(holo_image(phase_map, density), axis=holo_axis, interpolation=interpolation) # Plot phase map: phase_axis = fig.add_subplot(1, 2, 2, aspect='equal') - phase_map.display(axis=phase_axis) + fig.subplots_adjust(right=0.85) + phase_map.display(axis=phase_axis, labels=('x-axis [nm]', 'y-axis [nm]', 'phase [mrad]')) diff --git a/pyramid/magcreator.py b/pyramid/magcreator.py index 0a389e5..7eef6d5 100644 --- a/pyramid/magcreator.py +++ b/pyramid/magcreator.py @@ -223,9 +223,9 @@ 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) + center - the vortex center, given in 2D (x,y) or 3D (x,y,z), where z is discarded + (optional, is set to the center of the field of view if not specified, always + between two pixels!) 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) @@ -235,7 +235,9 @@ def create_mag_dist_vortex(mag_shape, center=None, magnitude=1): 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!' + if len(center) == 3: # if a 3D-center is given, just take the x and y components + center = (center[1], center[2]) + assert len(center) == 2, 'Vortex center has to be defined in 3D or 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) diff --git a/pyramid/magdata.py b/pyramid/magdata.py index 61221c7..1d172b0 100644 --- a/pyramid/magdata.py +++ b/pyramid/magdata.py @@ -5,6 +5,7 @@ import numpy as np import tables.netcdf3 as nc import matplotlib.pyplot as plt +from matplotlib.ticker import MaxNLocator class MagData: @@ -30,18 +31,42 @@ class MagData: self.magnitude = magnitude def get_vector(self, mask): - # TODO: Implement! + # TODO: DOCSTRING! return np.concatenate([self.magnitude[2][mask], self.magnitude[1][mask], self.magnitude[0][mask]]) def set_vector(self, mask, vector): - # TODO: Implement! + # TODO: DOCSTRING! assert np.size(vector) % 3 == 0, 'Vector has to contain all 3 components for every pixel!' count = np.size(vector)/3 self.magnitude[2][mask] = vector[:count] # x-component self.magnitude[1][mask] = vector[count:2*count] # y-component self.magnitude[0][mask] = vector[2*count:] # z-component + + def get_mask(self, threshold=0): + # TODO: DOCSTRING! + z_mask = abs(self.magnitude[0]) > threshold + x_mask = abs(self.magnitude[1]) > threshold + y_mask = abs(self.magnitude[2]) > threshold + return np.logical_or(np.logical_or(x_mask, y_mask), z_mask) + + def scale_down(self, n=1): + # TODO: DOCSTRING! + # Starting magnetic distribution: + assert n >= 0 and isinstance(n, (int, long)), 'n must be a positive integer!' + assert self.dim[0] % 2**n == 0 and self.dim[1] % 2**n == 0 and self.dim[2] % 2**n == 0, \ + 'For downscaling, every dimension must be a multiple of 2!' + for t in range(n): + # Create coarser grid for the magnetization: + z_mag = self.magnitude[0].reshape(self.dim[0]/2, 2, self.dim[1]/2, 2, self.dim[2]/2, 2) + y_mag = self.magnitude[1].reshape(self.dim[0]/2, 2, self.dim[1]/2, 2, self.dim[2]/2, 2) + x_mag = self.magnitude[2].reshape(self.dim[0]/2, 2, self.dim[1]/2, 2, self.dim[2]/2, 2) + self.dim = (self.dim[0]/2, self.dim[1]/2, self.dim[2]/2) + self.res = self.res * 2 + self.magnitude = (z_mag.mean(axis=5).mean(axis=3).mean(axis=1), + y_mag.mean(axis=5).mean(axis=3).mean(axis=1), + x_mag.mean(axis=5).mean(axis=3).mean(axis=1)) @classmethod def load_from_llg(cls, filename): @@ -130,30 +155,57 @@ class MagData: print f f.close() - def quiver_plot(self, axis='z', ax_slice=0): + def quiver_plot(self, title='Magnetic Distribution)', proj_axis='z', ax_slice=None, + filename=None, axis=None): # TODO!! '''Plot a slice of the magnetization as a quiver plot. Arguments: axis - the axis from which a slice is plotted ('x', 'y' or 'z'), default = 'z' - ax_slice - the slice-index of the specified axis + ax_slice - the slice-index of the specified axis (optional, if not specified, is + set to the center of the specified axis) + filename - filename, specifying the location where the image is saved (optional, if + not specified, image is shown instead) Returns: None ''' - assert axis == 'z' or axis == 'y' or axis == 'x', 'Axis has to be x, y or z (as string).' - if axis == 'z': # Slice of the xy-plane with z = ax_slice + assert proj_axis == 'z' or proj_axis == 'y' or proj_axis == 'x', \ + 'Axis has to be x, y or z (as string).' + if proj_axis == 'z': # Slice of the xy-plane with z = ax_slice + if ax_slice is None: + ax_slice = int(self.dim[0]/2) mag_slice_u = self.magnitude[2][ax_slice, ...] mag_slice_v = self.magnitude[1][ax_slice, ...] - elif axis == 'y': # Slice of the xz-plane with y = ax_slice + u_label = 'x [px]' + v_label = 'y [px]' + elif proj_axis == 'y': # Slice of the xz-plane with y = ax_slice + if ax_slice is None: + ax_slice = int(self.dim[1]/2) mag_slice_u = self.magnitude[2][:, ax_slice, :] mag_slice_v = self.magnitude[0][:, ax_slice, :] - elif axis == 'x': # Slice of the yz-plane with x = ax_slice + u_label = 'x [px]' + v_label = 'z [px]' + elif proj_axis == 'x': # Slice of the yz-plane with x = ax_slice + if ax_slice is None: + ax_slice = int(self.dim[2]/2) mag_slice_u = self.magnitude[1][..., ax_slice] mag_slice_v = self.magnitude[0][..., ax_slice] - # Plot the magnetization vectors: - fig = plt.figure() - fig.add_subplot(111, aspect='equal') - plt.quiver(mag_slice_u, mag_slice_v, pivot='middle', angles='xy', scale_units='xy', + u_label = 'y [px]' + v_label = 'z [px]' + # If no axis is specified, a new figure is created: + if axis is None: + fig = plt.figure(figsize=(8.5, 7)) + axis = fig.add_subplot(1, 1, 1, aspect='equal') + axis.quiver(mag_slice_u, mag_slice_v, pivot='middle', angles='xy', scale_units='xy', scale=1, headwidth=6, headlength=7) + axis.set_xlim(0, np.shape(mag_slice_u)[1]) + axis.set_ylim(0, np.shape(mag_slice_u)[0]) + axis.set_title(title, fontsize=18) + axis.set_xlabel(u_label, fontsize=15) + axis.set_ylabel(v_label, fontsize=15) + axis.tick_params(axis='both', which='major', labelsize=14) + axis.xaxis.set_major_locator(MaxNLocator(nbins=8, integer=True)) + axis.yaxis.set_major_locator(MaxNLocator(nbins=8, integer=True)) + plt.show() def quiver_plot3d(self): '''3D-Quiver-Plot of the magnetization as vectors. @@ -178,6 +230,7 @@ class MagData: y_mag = np.reshape(self.magnitude[1], (-1)) z_mag = np.reshape(self.magnitude[0], (-1)) # Plot them as vectors: + mlab.figure() plot = mlab.quiver3d(xx, yy, zz, x_mag, y_mag, z_mag, mode='arrow', scale_factor=10.0) mlab.outline(plot) mlab.axes(plot) diff --git a/pyramid/phasemap.py b/pyramid/phasemap.py index 12dea2f..f2b5a04 100644 --- a/pyramid/phasemap.py +++ b/pyramid/phasemap.py @@ -88,7 +88,8 @@ class PhaseMap: phase[:] = self.phase f.close() - def display(self, title='Phase Map', axis=None, cmap='gray'): + def display(self, title='Phase Map', labels=('x-axis [nm]', 'y-axis [nm]', 'phase [rad]'), + cmap='RdBu', limit=None, norm=None, axis=None): '''Display the phasemap as a colormesh. Arguments: title - the title of the plot (default: 'Phase Map') @@ -97,23 +98,65 @@ class PhaseMap: Returns: None - ''' + ''' # TODO: Docstring! + + # TODO: ALWAYS CENTERED around 0 + if limit is None: + limit = np.max(np.abs(self.phase)) + # If no axis is specified, a new figure is created: if axis is None: - fig = plt.figure() + fig = plt.figure(figsize=(8.5, 7)) axis = fig.add_subplot(1, 1, 1, aspect='equal') - im = plt.pcolormesh(self.phase, cmap=cmap) + # Plot the phasemap: + im = axis.pcolormesh(self.phase, cmap=cmap, vmin=-limit, vmax=limit, norm=norm) # Set the axes ticks and labels: - ticks = axis.get_xticks()*self.res + axis.set_xlim(0, np.shape(self.phase)[1]) + axis.set_ylim(0, np.shape(self.phase)[0]) + ticks = (axis.get_xticks()*self.res).astype(int) axis.set_xticklabels(ticks) - ticks = axis.get_yticks()*self.res + ticks = (axis.get_yticks()*self.res).astype(int) + axis.tick_params(axis='both', which='major', labelsize=14) axis.set_yticklabels(ticks) - axis.set_title(title) - axis.set_xlabel('x-axis [nm]') - axis.set_ylabel('y-axis [nm]') - # Plot the phase map: + axis.set_title(title, fontsize=18) + axis.set_xlabel(labels[0], fontsize=15) + axis.set_ylabel(labels[1], fontsize=15) + # Add colorbar: fig = plt.gcf() - fig.subplots_adjust(right=0.85) - cbar_ax = fig.add_axes([0.9, 0.15, 0.02, 0.7]) - fig.colorbar(im, cax=cbar_ax) + fig.subplots_adjust(right=0.8) + cbar_ax = fig.add_axes([0.82, 0.15, 0.02, 0.7]) + cbar = fig.colorbar(im, cax=cbar_ax) + cbar.ax.tick_params(labelsize=14) + cbar.set_label(labels[2], fontsize=15) + + plt.show() + + def display3d(self, title='Phase Map', labels=('x-axis [nm]', 'y-axis [nm]', 'phase [rad]'), + cmap='RdBu', limit=None, norm=None, axis=None): + '''Display the phasemap as a colormesh. + Arguments: + title - the title of the plot (default: 'Phase Map') + axis - the axis on which to display the plot (default: None, a new figure is created) + cmap - the colormap which is used for the plot (default: 'gray') + Returns: + None + + ''' # TODO: Docstring! + + from mpl_toolkits.mplot3d import Axes3D + + fig = plt.figure() + ax = Axes3D(fig)#.gca(projection='3d') + + u = range(self.dim[1]) + v = range(self.dim[0]) + uu, vv = np.meshgrid(u, v) + ax.plot_surface(uu, vv, self.phase, rstride=4, cstride=4, alpha=0.7, cmap='RdBu', + linewidth=0, antialiased=False) + ax.contourf(uu, vv, self.phase, 15, zdir='z', offset=np.min(self.phase), cmap='RdBu') + ax.view_init(45, -135) + ax.set_xlabel('x-axis [px]') + ax.set_ylabel('y-axis [px]') + ax.set_zlabel('phase [mrad]') + plt.show() diff --git a/pyramid/phasemapper.py b/pyramid/phasemapper.py index 2d53f97..61cffa1 100644 --- a/pyramid/phasemapper.py +++ b/pyramid/phasemapper.py @@ -4,7 +4,8 @@ import numpy as np import numcore -import time + +from numpy import pi # Physical constants PHI_0 = -2067.83 # magnetic flux in T*nm² @@ -248,20 +249,20 @@ def phase_mag_real_alt(res, projection, method, b_0=1, jacobi=None): # TODO: Mo return phase -#def phase_elec(mag_data, v_0=0, v_acc=30000): -# # TODO: Docstring -# -# res = mag_data.res -# z_dim, y_dim, x_dim = mag_data.dim -# z_mag, y_mag, x_mag = mag_data.magnitude -# -# phase = np.logical_or(x_mag, y_mag, z_mag) -# -# lam = H_BAR / np.sqrt(2 * M_E * v_acc * (1 + Q_E*v_acc / (2*M_E*C**2))) -# -# Ce = (2*pi*Q_E/lam * (Q_E*v_acc + M_E*C**2) / -# (Q_E*v_acc * (Q_E*v_acc + 2*M_E*C**2))) -# -# phase *= res * v_0 * Ce -# -# return phase +def phase_elec(mag_data, v_0=1, v_acc=30000): + # TODO: Docstring + + res = mag_data.res + z_dim, y_dim, x_dim = mag_data.dim + z_mag, y_mag, x_mag = mag_data.magnitude + + phase = np.logical_or(x_mag, y_mag, z_mag) + + lam = H_BAR / np.sqrt(2 * M_E * v_acc * (1 + Q_E*v_acc / (2*M_E*C**2))) + + Ce = (2*pi*Q_E/lam * (Q_E*v_acc + M_E*C**2) / + (Q_E*v_acc * (Q_E*v_acc + 2*M_E*C**2))) + + phase *= res * v_0 * Ce + + return phase diff --git a/scripts/compare_method_errors_fourier_padding.py b/scripts/compare_method_errors_fourier_padding.py index 9c0db37..e393d4a 100644 --- a/scripts/compare_method_errors_fourier_padding.py +++ b/scripts/compare_method_errors_fourier_padding.py @@ -36,7 +36,7 @@ def phase_from_mag(): b_0 = 1 # in T res = 10.0 # in nm dim = (1, 128, 128) - phi = -pi/4 + phi = -pi/2 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' diff --git a/scripts/compare_methods.py b/scripts/compare_methods.py index ae92cf4..e6677fd 100644 --- a/scripts/compare_methods.py +++ b/scripts/compare_methods.py @@ -31,20 +31,20 @@ def compare_methods(): b_0 = 1 # in T res = 10.0 # in nm phi = pi/4 - padding = 20 - density = 10 - dim = (1, 128, 128) # in px (z, y, x) + padding = 12 + density = 1 + dim = (16, 128, 128) # in px (z, y, x) # Create magnetic shape: - geometry = 'slab' + geometry = 'disc' 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) + center = (dim[0]/2-0.5, dim[1]/2-0.5, dim[2]/2.-0.5) # in px (z, y, x) index starts with 0! + width = (dim[0]/2, 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! + center = (dim[0]/2-0.5, 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 + height = dim[0]/2 # 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': diff --git a/scripts/compare_pixel_fields.py b/scripts/compare_pixel_fields.py index fff98b2..c3bd985 100644 --- a/scripts/compare_pixel_fields.py +++ b/scripts/compare_pixel_fields.py @@ -26,10 +26,11 @@ def compare_pixel_fields(): # Input parameters: res = 10.0 # in nm phi = pi/2 # in rad - dim = (1, 11, 11) - pixel = (0, 5, 5) + dim = (1, 5, 5) + pixel = (0, 2, 2) # 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)) + mag_data.save_to_llg('../output/mag_dist_single_pixel.txt') projection = pj.simple_axis_projection(mag_data) phase_map_slab = PhaseMap(res, pm.phase_mag_real(res, projection, 'slab')) phase_map_slab.display('Phase of one Pixel (Slab)') @@ -38,7 +39,6 @@ def compare_pixel_fields(): 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() diff --git a/scripts/create_logo.py b/scripts/create_logo.py index 8fcc493..bf763f0 100644 --- a/scripts/create_logo.py +++ b/scripts/create_logo.py @@ -41,9 +41,10 @@ def create_logo(): 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)) + mag_data.quiver_plot() projection = pj.simple_axis_projection(mag_data) phase_map = PhaseMap(res, pm.phase_mag_real(res, projection, 'slab')) - hi.display(hi.holo_image(phase_map, density), 'PYRAMID - LOGO') + hi.display(hi.holo_image(phase_map, density), 'PYRAMID - LOGO', interpolation='bilinear') if __name__ == "__main__": diff --git a/scripts/interactive_setup.py b/scripts/interactive_setup.py index a7293d0..1235112 100644 --- a/scripts/interactive_setup.py +++ b/scripts/interactive_setup.py @@ -11,4 +11,4 @@ from pyramid.magdata import MagData from pyramid.phasemap import PhaseMap import os -os.chdir('C:\Users\Jan\Daten\PhD Thesis\Pyramid\output') +os.chdir('C:\Users\Jan\Home\PhD Thesis\Pyramid\output') diff --git a/scripts/paper 1/ch5-0-evaluation_and_comparison.py b/scripts/paper 1/ch5-0-evaluation_and_comparison.py index c01d0d9..f9f6773 100644 --- a/scripts/paper 1/ch5-0-evaluation_and_comparison.py +++ b/scripts/paper 1/ch5-0-evaluation_and_comparison.py @@ -57,17 +57,20 @@ def run(): mag_data_vort.quiver_plot3d() print '--SHELVE MAGNETIC DISTRIBUTIONS' data_shelve[key] = (mag_data_disc, mag_data_vort) - - print '--PLOT/SAVE HOMOG. MAGN. DISC' - # Plot and save MagData (Disc): - mag_data_disc.quiver_plot('Homog. magn. disc') - plt.savefig(directory + '/ch5-0-mag_data_disc.png', bbox_inches='tight') - - print '--PLOT/SAVE VORTEX STATE DISC' - # Plot and save MagData (Vortex): - mag_data_vort.quiver_plot('Vortex state disc') - plt.savefig(directory + '/ch5-0-mag_data_vort.png', bbox_inches='tight') + print '--PLOT/SAVE MAGNETIC DISTRIBUTIONS' + fig, axes = plt.subplots(1, 2, figsize=(16, 7)) + fig.suptitle('Magnetic Distributions', fontsize=20) + # Plot MagData (Disc): + mag_data_disc.quiver_plot('Homog. magn. disc', axis = axes[0]) + axes[0].set_aspect('equal') + # Plot MagData (Disc): + mag_data_vort.quiver_plot('Vortex state disc', axis = axes[1]) + axes[1].set_aspect('equal') + # Save Plots: + plt.figtext(0.15, 0.15, 'a)', fontsize=30) + plt.figtext(0.57, 0.15, 'b)', fontsize=30) + plt.savefig(directory + '/ch5-0-magnetic_distributions.png', bbox_inches='tight') ############################################################################################### print 'CLOSING SHELVE\n' diff --git a/scripts/paper 1/ch5-1-evaluation_real_space.py b/scripts/paper 1/ch5-1-evaluation_real_space.py index 0cb4305..430b9b3 100644 --- a/scripts/paper 1/ch5-1-evaluation_real_space.py +++ b/scripts/paper 1/ch5-1-evaluation_real_space.py @@ -56,53 +56,54 @@ def run(): # Get analytic solution: phase_ana_disc = an.phase_mag_disc(dim, res, phi, center, radius, height) phase_ana_vort = an.phase_mag_vortex(dim, res, center, radius, height) - phase_map_ana_disc = PhaseMap(res, phase_ana_disc) - phase_map_ana_vort = PhaseMap(res, phase_ana_vort) + phase_map_ana_disc = PhaseMap(res, phase_ana_disc*1E3) # in mrad -> *1000 + phase_map_ana_vort = PhaseMap(res, phase_ana_vort*1E3) # in mrad -> *1000 print '--PLOT/SAVE ANALYTIC SOLUTIONS' - hi.display_combined(phase_map_ana_disc, 100, 'Analytic solution: hom. magn. disc', 'bilinear') + hi.display_combined(phase_map_ana_disc, 0.1, 'Analytic solution: hom. magn. disc', 'bilinear', + labels=('x-axis [nm]', 'y-axis [nm]', 'phase [mrad]')) axis = plt.gcf().add_subplot(1, 2, 2, aspect='equal') axis.axhline(y=512, linewidth=3, linestyle='--', color='r') + plt.figtext(0.15, 0.2, 'a)', fontsize=30, color='w') + plt.figtext(0.52, 0.2, 'b)', fontsize=30) plt.savefig(directory + '/ch5-1-analytic_solution_disc.png', bbox_inches='tight') - hi.display_combined(phase_map_ana_vort, 100, 'Analytic solution: Vortex state', 'bilinear') + hi.display_combined(phase_map_ana_vort, 0.1, 'Analytic solution: vortex state', 'bilinear', + labels=('x-axis [nm]', 'y-axis [nm]', 'phase [mrad]')) axis = plt.gcf().add_subplot(1, 2, 2, aspect='equal') axis.axhline(y=512, linewidth=3, linestyle='--', color='r') + plt.figtext(0.15, 0.2, 'c)', fontsize=30, color='w') + plt.figtext(0.52, 0.2, 'd)', fontsize=30) plt.savefig(directory + '/ch5-1-analytic_solution_vort.png', bbox_inches='tight') # Get colorwheel: hi.make_color_wheel() + plt.figtext(0.15, 0.14, 'e)', fontsize=30, color='w') plt.savefig(directory + '/ch5-1-colorwheel.png', bbox_inches='tight') ############################################################################################### - print 'CH5-1 PHASE SLICES REAL SPACE' # TODO: Verschieben + print 'CH5-1 PHASE SLICES REAL SPACE' # Input parameters: res = 0.25 # in nm phi = pi/2 - density = 20 + density = 0.1 # Because phase is in mrad -> amplification by 100 (0.001 * 100 = 0.1) dim = (64, 512, 512) # in px (z, y, x) # Create magnetic shape: center = (dim[0]/2-0.5, 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 = dim[0]/2 # in px - key = 'ch5-1-phase_slice_mag_dist' + key = 'ch5-1-phase_slices_real' if key in data_shelve: print '--LOAD MAGNETIC DISTRIBUTION' - mag_shape = data_shelve[key] + (x_d, y_d, dy_d, x_v, y_v, dy_v) = data_shelve[key] else: print '--CREATE MAGNETIC DISTRIBUTION' mag_shape = mc.Shapes.disc(dim, center, radius, height) - print '--SAVE MAGNETIC DISTRIBUTION' - data_shelve[key] = mag_shape - - key = 'ch5-1-phase_slice_disc' - if key in data_shelve: - print '--LOAD PHASE SLICES HOMOG. MAGN. DISC' - (x, y) = data_shelve[key] - else: + print '--CREATE PHASE SLICES HOMOG. MAGN. DISC' # Arrays for plotting: - x = [] - y = [] + x_d = [] + y_d = [] + dy_d = [] # Analytic solution: L = dim[1] * res # in px/nm Lz = 0.5 * dim[0] * res # in px/nm @@ -110,74 +111,35 @@ def run(): x0 = L / 2 # in px/nm def F_disc(x): - coeff = - pi * Lz / (2*PHI_0) + coeff = - pi * Lz / (2*PHI_0) * 1E3 # in mrad -> *1000 result = coeff * (- (x - x0) * np.sin(phi)) result *= np.where(np.abs(x - x0) <= R, 1, (R / (x - x0)) ** 2) return result - x.append(np.linspace(0, L, 5000)) - y.append(F_disc(x[0])) - # Create and plot MagData (Disc): + x_d.append(np.linspace(0, L, 5000)) + y_d.append(F_disc(x_d[0])) + dy_d.append(np.zeros_like(x_d[0])) + # Create MagData (Disc): mag_data_disc = MagData(res, mc.create_mag_dist(mag_shape, phi)) for i in range(5): mag_data_disc.scale_down() print '----res =', mag_data_disc.res, 'nm', 'dim =', mag_data_disc.dim projection = pj.simple_axis_projection(mag_data_disc) phase_map = PhaseMap(mag_data_disc.res, - pm.phase_mag_real(mag_data_disc.res, projection, 'slab')) - hi.display_combined(phase_map, density, 'Disc, res = {}'.format(res)) - x.append(np.linspace(0, mag_data_disc.dim[1]*mag_data_disc.res, mag_data_disc.dim[1])) - y.append(phase_map.phase[int(mag_data_disc.dim[1]/2), :]) - # Shelve x and y: - print '--SAVE PHASE SLICES HOMOG. MAGN. DISC' - data_shelve[key] = (x, y) - - print '--PLOT/SAVE PHASE SLICES HOMOG. MAGN. DISC' - # Plot phase slices: - fig = plt.figure() - axis = fig.add_subplot(1, 1, 1) - axis.plot(x[0], y[0], 'k', label='analytic') - axis.plot(x[1], y[1], 'r', label='0.5 nm') - axis.plot(x[2], y[2], 'm', label='1 nm') - axis.plot(x[3], y[3], 'y', label='2 nm') - axis.plot(x[4], y[4], 'g', label='4 nm') - axis.plot(x[5], y[5], 'c', label='8 nm') - plt.tick_params(axis='both', which='major', labelsize=14) - axis.set_title('DISC', fontsize=18) - axis.set_xlabel('x [nm]', fontsize=15) - axis.set_ylabel('phase [rad]', fontsize=15) - axis.set_xlim(0, 128) - axis.set_ylim(-0.22, 0.22) - axis.legend() - # Plot Zoombox and Arrow: - rect1 = Rectangle((23.5, 0.16), 15, 0.04, fc='w', ec='k') - axis.add_patch(rect1) - plt.arrow(32.5, 0.16, 0.0, -0.16, length_includes_head=True, - head_width=2, head_length=0.02, fc='k', ec='k') - # Plot zoom inset: - ins_axis = plt.axes([0.2, 0.2, 0.3, 0.3]) - ins_axis.plot(x[0], y[0], 'k', label='analytic') - ins_axis.plot(x[1], y[1], 'r', label='0.5 nm') - ins_axis.plot(x[2], y[2], 'm', label='1 nm') - ins_axis.plot(x[3], y[3], 'y', label='2 nm') - ins_axis.plot(x[4], y[4], 'g', label='4 nm') - ins_axis.plot(x[5], y[5], 'c', label='8 nm') - plt.tick_params(axis='both', which='major', labelsize=14) - ins_axis.set_xlim(23.5, 38.5) - ins_axis.set_ylim(0.16, 0.2) - ins_axis.xaxis.set_major_locator(MaxNLocator(nbins=4, integer= True)) - ins_axis.yaxis.set_major_locator(MaxNLocator(nbins=3)) - plt.show() - plt.savefig(directory + '/ch5-1-disc_slice_comparison.png', bbox_inches='tight') - - key = 'ch5-1-phase_slice_vort' - if key in data_shelve: - print '--LOAD PHASE SLICES VORTEX STATE DISC' - (x, y) = data_shelve[key] - else: + pm.phase_mag_real(mag_data_disc.res, projection, 'slab') * 1E3) + hi.display_combined(phase_map, density, 'Disc, res = {} nm'.format(mag_data_disc.res), + labels=('x-axis [nm]', 'y-axis [nm]', 'phase [mrad]')) + x_d.append(np.linspace(mag_data_disc.res * 0.5, + mag_data_disc.res * (mag_data_disc.dim[1]-0.5), + mag_data_disc.dim[1])) + slice_pos = int(mag_data_disc.dim[1]/2) + y_d.append(phase_map.phase[slice_pos, :]) + dy_d.append(phase_map.phase[slice_pos, :] - F_disc(x_d[-1])) + print '--CREATE PHASE SLICES VORTEX STATE DISC' - x = [] - y = [] + x_v = [] + y_v = [] + dy_v = [] # Analytic solution: L = dim[1] * res # in px/nm Lz = 0.5 * dim[0] * res # in px/nm @@ -185,63 +147,149 @@ def run(): x0 = L / 2 # in px/nm def F_vort(x): - coeff = pi*Lz/PHI_0 + coeff = pi*Lz/PHI_0 * 1E3 # in mrad -> *1000 result = coeff * np.where(np.abs(x - x0) <= R, (np.abs(x-x0)-R), 0) return result - x.append(np.linspace(0, L, 5001)) - y.append(F_vort(x[0])) - # Create and plot MagData (Vortex): + x_v.append(np.linspace(0, L, 5001)) + y_v.append(F_vort(x_v[0])) + dy_v.append(np.zeros_like(x_v[0])) + # Create MagData (Vortex): mag_data_vort = MagData(res, mc.create_mag_dist_vortex(mag_shape)) for i in range(5): mag_data_vort.scale_down() - print '----i =', i, 'dim =', mag_data_vort.dim, 'res =', mag_data_vort.res, 'nm' + print '----res =', mag_data_vort.res, 'nm', 'dim =', mag_data_vort.dim projection = pj.simple_axis_projection(mag_data_vort) phase_map = PhaseMap(mag_data_vort.res, - pm.phase_mag_real(mag_data_vort.res, projection, 'slab')) - hi.display_combined(phase_map, density, 'Disc, res = {}'.format(res)) - x.append(np.linspace(0, mag_data_vort.dim[1]*mag_data_vort.res, mag_data_vort.dim[1])) - y.append(phase_map.phase[int(mag_data_vort.dim[1]/2), :]) - # Shelve x and y: - print '--SAVE PHASE SLICES VORTEX STATE DISC' - data_shelve[key] = (x, y) + pm.phase_mag_real(mag_data_vort.res, projection, 'slab') * 1E3) + hi.display_combined(phase_map, density, 'Disc, res = {} nm'.format(mag_data_vort.res), + labels=('x-axis [nm]', 'y-axis [nm]', 'phase [mrad]')) + x_v.append(np.linspace(mag_data_vort.res * 0.5, + mag_data_vort.res * (mag_data_vort.dim[1]-0.5), + mag_data_vort.dim[1])) + slice_pos = int(mag_data_vort.dim[1]/2) + y_v.append(phase_map.phase[int(mag_data_vort.dim[1]/2), :]) + dy_v.append(phase_map.phase[slice_pos, :] - F_vort(x_v[-1])) + + # Shelve x, y and dy: + print '--SAVE PHASE SLICES' + data_shelve[key] = (x_d, y_d, dy_d, x_v, y_v, dy_v) + + # Create figure: + fig, axes = plt.subplots(1, 2, figsize=(16, 7)) + fig.suptitle('Central phase slices', fontsize=20) + + print '--PLOT/SAVE PHASE SLICES HOMOG. MAGN. DISC' + # Plot phase slices: + axes[0].plot(x_d[0], y_d[0], '-k', linewidth=1.5, label='analytic') + axes[0].plot(x_d[1], y_d[1], '-r', linewidth=1.5, label='0.5 nm') + axes[0].plot(x_d[2], y_d[2], '-m', linewidth=1.5, label='1 nm') + axes[0].plot(x_d[3], y_d[3], '-y', linewidth=1.5, label='2 nm') + axes[0].plot(x_d[4], y_d[4], '-g', linewidth=1.5, label='4 nm') + axes[0].plot(x_d[5], y_d[5], '-c', linewidth=1.5, label='8 nm') + axes[0].tick_params(axis='both', which='major', labelsize=14) + axes[0].set_title('Homog. magn. disc', fontsize=18) + axes[0].set_xlabel('x [nm]', fontsize=15) + axes[0].set_ylabel('phase [mrad]', fontsize=15) + axes[0].set_xlim(0, 128) + axes[0].set_ylim(-220, 220) + # Plot Zoombox and Arrow: + zoom = (23.5, 160, 15, 40) + rect = Rectangle((zoom[0], zoom[1]), zoom[2], zoom[3], fc='w', ec='k') + axes[0].add_patch(rect) + axes[0].arrow(zoom[0]+zoom[2], zoom[1]+zoom[3]/2, 36, 0, length_includes_head=True, + head_width=10, head_length=4, fc='k', ec='k') + # Plot zoom inset: + ins_axis_d = plt.axes([0.33, 0.57, 0.14, 0.3]) + ins_axis_d.plot(x_d[0], y_d[0], '-k', linewidth=1.5, label='analytic') + ins_axis_d.plot(x_d[1], y_d[1], '-r', linewidth=1.5, label='0.5 nm') + ins_axis_d.plot(x_d[2], y_d[2], '-m', linewidth=1.5, label='1 nm') + ins_axis_d.plot(x_d[3], y_d[3], '-y', linewidth=1.5, label='2 nm') + ins_axis_d.plot(x_d[4], y_d[4], '-g', linewidth=1.5, label='4 nm') + ins_axis_d.plot(x_d[5], y_d[5], '-c', linewidth=1.5, label='8 nm') + ins_axis_d.tick_params(axis='both', which='major', labelsize=14) + ins_axis_d.set_xlim(zoom[0], zoom[0]+zoom[2]) + ins_axis_d.set_ylim(zoom[1], zoom[1]+zoom[3]) + ins_axis_d.xaxis.set_major_locator(MaxNLocator(nbins=4, integer= True)) + ins_axis_d.yaxis.set_major_locator(MaxNLocator(nbins=3)) print '--PLOT/SAVE PHASE SLICES VORTEX STATE DISC' - # Plot: - fig = plt.figure() - axis = fig.add_subplot(1, 1, 1) - axis.plot(x[0], y[0], 'k', label='analytic') - axis.plot(x[1], y[1], 'r', label='0.5 nm') - axis.plot(x[2], y[2], 'm', label='1 nm') - axis.plot(x[3], y[3], 'y', label='2 nm') - axis.plot(x[4], y[4], 'g', label='4 nm') - axis.plot(x[5], y[5], 'c', label='8 nm') - plt.tick_params(axis='both', which='major', labelsize=14) - axis.set_title('VORTEX', fontsize=18) - axis.set_xlabel('x [nm]', fontsize=15) - axis.set_ylabel('phase [rad]', fontsize=15) - axis.set_xlim(0, 128) - axis.legend() + # Plot phase slices: + axes[1].plot(x_v[0], y_v[0], '-k', linewidth=1.5, label='analytic') + axes[1].plot(x_v[1], y_v[1], '-r', linewidth=1.5, label='0.5 nm') + axes[1].plot(x_v[2], y_v[2], '-m', linewidth=1.5, label='1 nm') + axes[1].plot(x_v[3], y_v[3], '-y', linewidth=1.5, label='2 nm') + axes[1].plot(x_v[4], y_v[4], '-g', linewidth=1.5, label='4 nm') + axes[1].plot(x_v[5], y_v[5], '-c', linewidth=1.5, label='8 nm') + axes[1].tick_params(axis='both', which='major', labelsize=14) + axes[1].set_title('Vortex state disc', fontsize=18) + axes[1].set_xlabel('x [nm]', fontsize=15) + axes[1].set_ylabel('phase [mrad]', fontsize=15) + axes[1].set_xlim(0, 128) + axes[1].yaxis.set_major_locator(MaxNLocator(nbins=6)) + axes[1].legend() # Plot Zoombox and Arrow: - zoom = (59, 0.34, 10, 0.055) - rect1 = Rectangle((zoom[0], zoom[1]), zoom[2], zoom[3], fc='w', ec='k') - axis.add_patch(rect1) - plt.arrow(zoom[0]+zoom[2]/2, zoom[1], 0, -0.19, length_includes_head=True, - head_width=2, head_length=0.02, fc='k', ec='k') + zoom = (59, 340, 10, 55) + rect = Rectangle((zoom[0], zoom[1]), zoom[2], zoom[3], fc='w', ec='k') + axes[1].add_patch(rect) + axes[1].arrow(zoom[0]+zoom[2]/2, zoom[1], 0, -193, length_includes_head=True, + head_width=2, head_length=20, fc='k', ec='k') # Plot zoom inset: - ins_axis = plt.axes([0.47, 0.15, 0.15, 0.3]) - ins_axis.plot(x[0], y[0], 'k', label='analytic') - ins_axis.plot(x[1], y[1], 'r', label='0.5 nm') - ins_axis.plot(x[2], y[2], 'm', label='1 nm') - ins_axis.plot(x[3], y[3], 'y', label='2 nm') - ins_axis.plot(x[4], y[4], 'g', label='4 nm') - ins_axis.plot(x[5], y[5], 'c', label='8 nm') - plt.tick_params(axis='both', which='major', labelsize=14) - ins_axis.set_xlim(zoom[0], zoom[0]+zoom[2]) - ins_axis.set_ylim(zoom[1], zoom[1]+zoom[3]) - ins_axis.xaxis.set_major_locator(MaxNLocator(nbins=4, integer= True)) - ins_axis.yaxis.set_major_locator(MaxNLocator(nbins=4)) - plt.savefig(directory + '/ch5-1-vortex_slice_comparison.png', bbox_inches='tight') + ins_axis_v = plt.axes([0.695, 0.15, 0.075, 0.3]) + ins_axis_v.plot(x_v[0], y_v[0], '-k', linewidth=1.5, label='analytic') + ins_axis_v.plot(x_v[1], y_v[1], '-r', linewidth=1.5, label='0.5 nm') + ins_axis_v.plot(x_v[2], y_v[2], '-m', linewidth=1.5, label='1 nm') + ins_axis_v.plot(x_v[3], y_v[3], '-y', linewidth=1.5, label='2 nm') + ins_axis_v.plot(x_v[4], y_v[4], '-g', linewidth=1.5, label='4 nm') + ins_axis_v.plot(x_v[5], y_v[5], '-c', linewidth=1.5, label='8 nm') + ins_axis_v.tick_params(axis='both', which='major', labelsize=14) + ins_axis_v.set_xlim(zoom[0], zoom[0]+zoom[2]) + ins_axis_v.set_ylim(zoom[1], zoom[1]+zoom[3]) + ins_axis_v.xaxis.set_major_locator(MaxNLocator(nbins=4, integer= True)) + ins_axis_v.yaxis.set_major_locator(MaxNLocator(nbins=4)) + + plt.show() + plt.figtext(0.15, 0.13, 'a)', fontsize=30) + plt.figtext(0.57, 0.13, 'b)', fontsize=30) + plt.savefig(directory + '/ch5-1-phase_slice_comparison.png', bbox_inches='tight') + + # Create figure: + fig, axes = plt.subplots(1, 2, figsize=(16, 7)) + fig.suptitle('Central phase slice errors', fontsize=20) + + print '--PLOT/SAVE PHASE SLICE ERRORS HOMOG. MAGN. DISC' + # Plot phase slices: + axes[0].plot(x_d[0], dy_d[0], '-k', linewidth=1.5, label='analytic') + axes[0].plot(x_d[1], dy_d[1], '-r', linewidth=1.5, label='0.5 nm') + axes[0].plot(x_d[2], dy_d[2], '-m', linewidth=1.5, label='1 nm') + axes[0].plot(x_d[3], dy_d[3], '-y', linewidth=1.5, label='2 nm') + axes[0].plot(x_d[4], dy_d[4], '-g', linewidth=1.5, label='4 nm') + axes[0].plot(x_d[5], dy_d[5], '-c', linewidth=1.5, label='8 nm') + axes[0].tick_params(axis='both', which='major', labelsize=14) + axes[0].set_title('Homog. magn. disc', fontsize=18) + axes[0].set_xlabel('x [nm]', fontsize=15) + axes[0].set_ylabel('phase [mrad]', fontsize=15) + axes[0].set_xlim(0, 128) + + print '--PLOT/SAVE PHASE SLICE ERRORS VORTEX STATE DISC' + # Plot phase slices: + axes[1].plot(x_v[0], dy_v[0], '-k', linewidth=1.5, label='analytic') + axes[1].plot(x_v[1], dy_v[1], '-r', linewidth=1.5, label='0.5 nm') + axes[1].plot(x_v[2], dy_v[2], '-m', linewidth=1.5, label='1 nm') + axes[1].plot(x_v[3], dy_v[3], '-y', linewidth=1.5, label='2 nm') + axes[1].plot(x_v[4], dy_v[4], '-g', linewidth=1.5, label='4 nm') + axes[1].plot(x_v[5], dy_v[5], '-c', linewidth=1.5, label='8 nm') + axes[1].tick_params(axis='both', which='major', labelsize=14) + axes[1].set_title('Vortex state disc', fontsize=18) + axes[1].set_xlabel('x [nm]', fontsize=15) + axes[1].set_ylabel('phase [mrad]', fontsize=15) + axes[1].set_xlim(0, 128) + axes[1].legend(loc=4) + + plt.show() + plt.figtext(0.15, 0.13, 'a)', fontsize=30) + plt.figtext(0.57, 0.13, 'b)', fontsize=30) + plt.savefig(directory + '/ch5-1-phase_slice_errors.png', bbox_inches='tight') ############################################################################################### print 'CH5-1 PHASE DIFFERENCES REAL SPACE' @@ -277,7 +325,7 @@ def run(): # Shelve magnetic distributions: data_shelve[key] = (mag_data_disc, mag_data_vort) - print '--PLOT/SAVE PHASE DIFFERENCES' + print '--CALCULATE PHASE DIFFERENCES' # Create projections along z-axis: projection_disc = pj.simple_axis_projection(mag_data_disc) projection_vort = pj.simple_axis_projection(mag_data_vort) @@ -287,22 +335,32 @@ def run(): # Create norm for the plots: bounds = np.array([-3, -0.5, -0.25, -0.1, 0, 0.1, 0.25, 0.5, 3]) norm = BoundaryNorm(bounds, RdBu.N) - # Disc: + # Calculations (Disc): phase_num_disc = pm.phase_mag_real(res, projection_disc, 'slab') phase_diff_disc = PhaseMap(res, (phase_num_disc-phase_ana_disc)*1E3) # in mrad -> *1000) RMS_disc = np.sqrt(np.mean(phase_diff_disc.phase**2)) - phase_diff_disc.display('Deviation (homog. magn. disc), RMS = {:3.2f} mrad'.format(RMS_disc), - labels=('x-axis [nm]', 'y-axis [nm]', '$\Delta$phase [mrad]'), - limit=np.max(bounds), norm=norm) - plt.savefig(directory + '/ch5-1-disc_phase_diff.png', bbox_inches='tight') - # Vortex: + # Calculations (Vortex): phase_num_vort = pm.phase_mag_real(res, projection_vort, 'slab') phase_diff_vort = PhaseMap(res, (phase_num_vort-phase_ana_vort)*1E3) # in mrad -> *1000 RMS_vort = np.sqrt(np.mean(phase_diff_vort.phase**2)) - phase_diff_vort.display('Deviation (vortex state disc), RMS = {:3.2f} mrad'.format(RMS_vort), + + print '--PLOT/SAVE PHASE DIFFERENCES' + fig, axes = plt.subplots(1, 2, figsize=(16, 7)) + fig.suptitle('Difference of the real space approach from the analytical solution', fontsize=20) + # Plot MagData (Disc): + phase_diff_disc.display('Homog. magn. disc, RMS = {:3.2f} mrad'.format(RMS_disc), + labels=('x-axis [nm]', 'y-axis [nm]', '$\Delta$phase [mrad]'), + limit=np.max(bounds), norm=norm, axis=axes[0]) + axes[0].set_aspect('equal') + # Plot MagData (Disc): + phase_diff_vort.display('Vortex state disc, RMS = {:3.2f} mrad'.format(RMS_vort), labels=('x-axis [nm]', 'y-axis [nm]', '$\Delta$phase [mrad]'), - limit=np.max(bounds), norm=norm) - plt.savefig(directory + '/ch5-1-vortex_phase_diff.png', bbox_inches='tight') + limit=np.max(bounds), norm=norm, axis=axes[1]) + axes[1].set_aspect('equal') + # Save Plots: + plt.figtext(0.15, 0.2, 'a)', fontsize=30) + plt.figtext(0.52, 0.2, 'b)', fontsize=30) + plt.savefig(directory + '/ch5-1-phase_differences.png', bbox_inches='tight') ############################################################################################### print 'CLOSING SHELVE\n' diff --git a/scripts/paper 1/ch5-2-evaluation_fourier_space.py b/scripts/paper 1/ch5-2-evaluation_fourier_space.py index 7b7e05f..b103fd9 100644 --- a/scripts/paper 1/ch5-2-evaluation_fourier_space.py +++ b/scripts/paper 1/ch5-2-evaluation_fourier_space.py @@ -1,3 +1,4 @@ +# -*- coding: utf-8 -*- """Compare the different methods to create phase maps.""" @@ -16,6 +17,7 @@ import pyramid.magcreator as mc import pyramid.projector as pj import pyramid.phasemapper as pm import pyramid.analytic as an +import pyramid.holoimage as hi from pyramid.magdata import MagData from pyramid.phasemap import PhaseMap @@ -23,6 +25,10 @@ import matplotlib.pyplot as plt from matplotlib.colors import BoundaryNorm from matplotlib.ticker import MaxNLocator from matplotlib.cm import RdBu +from matplotlib.patches import Rectangle + + +PHI_0 = -2067.83 # magnetic flux in T*nm² def run(): @@ -34,6 +40,359 @@ def run(): os.makedirs(directory) data_shelve = shelve.open(directory + '/paper_1_shelve') + ############################################################################################### + print 'CH5-1 PHASE SLICES FOURIER SPACE' + + # Input parameters: + res = 0.25 # in nm + phi = pi/2 + density = 0.1 # Because phase is in mrad -> amplification by 100 (0.001 * 100 = 0.1) + dim = (64, 512, 512) # in px (z, y, x) + # Create magnetic shape: + center = (dim[0]/2-0.5, 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 = dim[0]/2 # in px + + key = 'ch5-2-phase_slices_fourier' + if key in data_shelve: + print '--LOAD MAGNETIC DISTRIBUTION' + (x_d, y_d0, y_d10, dy_d0, dy_d10, x_v, y_v0, y_v10, dy_v0, dy_v10) = data_shelve[key] + else: + print '--CREATE MAGNETIC DISTRIBUTION' + mag_shape = mc.Shapes.disc(dim, center, radius, height) + + print '--CREATE PHASE SLICES HOMOG. MAGN. DISC' + # Arrays for plotting: + x_d = [] + y_d0 = [] + y_d10 = [] + dy_d0 = [] + dy_d10 = [] + # Analytic solution: + L = dim[1] * res # in px/nm + Lz = 0.5 * dim[0] * res # in px/nm + R = 0.25 * L # in px/nm + x0 = L / 2 # in px/nm + + def F_disc(x): + coeff = - pi * Lz / (2*PHI_0) * 1E3 # in mrad -> *1000 + result = coeff * (- (x - x0) * np.sin(phi)) + result *= np.where(np.abs(x - x0) <= R, 1, (R / (x - x0)) ** 2) + return result + + x_d.append(np.linspace(0, L, 5000)) + y_d0.append(F_disc(x_d[0])) + y_d10.append(F_disc(x_d[0])) + dy_d0.append(np.zeros_like(x_d[0])) + dy_d10.append(np.zeros_like(x_d[0])) + # Create MagData (Disc): + mag_data_disc = MagData(res, mc.create_mag_dist(mag_shape, phi)) + for i in range(5): + mag_data_disc.scale_down() + print '----res =', mag_data_disc.res, 'nm', 'dim =', mag_data_disc.dim + projection = pj.simple_axis_projection(mag_data_disc) + phase_map0 = PhaseMap(mag_data_disc.res, + pm.phase_mag_fourier(mag_data_disc.res, projection, + padding=0) * 1E3) + phase_map10 = PhaseMap(mag_data_disc.res, + pm.phase_mag_fourier(mag_data_disc.res, projection, + padding=10) * 1E3) + hi.display_combined(phase_map0, density, 'Disc, res = {} nm'.format(mag_data_disc.res), + labels=('x-axis [nm]', 'y-axis [nm]', 'phase [mrad]')) + hi.display_combined(phase_map10, density, 'Disc, res = {} nm'.format(mag_data_disc.res), + labels=('x-axis [nm]', 'y-axis [nm]', 'phase [mrad]')) + x_d.append(np.linspace(mag_data_disc.res * 0.5, + mag_data_disc.res * (mag_data_disc.dim[1]-0.5), + mag_data_disc.dim[1])) + slice_pos = int(mag_data_disc.dim[1]/2) + y_d0.append(phase_map0.phase[slice_pos, :]) + y_d10.append(phase_map10.phase[slice_pos, :]) + dy_d0.append(phase_map0.phase[slice_pos, :] - F_disc(x_d[-1])) + dy_d10.append(phase_map10.phase[slice_pos, :] - F_disc(x_d[-1])) + + print '--CREATE PHASE SLICES VORTEX STATE DISC' + x_v = [] + y_v0 = [] + y_v10 = [] + dy_v0 = [] + dy_v10 = [] + # Analytic solution: + L = dim[1] * res # in px/nm + Lz = 0.5 * dim[0] * res # in px/nm + R = 0.25 * L # in px/nm + x0 = L / 2 # in px/nm + + def F_vort(x): + coeff = pi*Lz/PHI_0 * 1E3 # in mrad -> *1000 + result = coeff * np.where(np.abs(x - x0) <= R, (np.abs(x-x0)-R), 0) + return result + + x_v.append(np.linspace(0, L, 5000)) + y_v0.append(F_vort(x_v[0])) + y_v10.append(F_vort(x_v[0])) + dy_v0.append(np.zeros_like(x_v[0])) + dy_v10.append(np.zeros_like(x_v[0])) + # Create MagData (Vortex): + mag_data_vort = MagData(res, mc.create_mag_dist_vortex(mag_shape)) + for i in range(5): + mag_data_vort.scale_down() + print '----res =', mag_data_vort.res, 'nm', 'dim =', mag_data_vort.dim + projection = pj.simple_axis_projection(mag_data_vort) + phase_map0 = PhaseMap(mag_data_vort.res, + pm.phase_mag_fourier(mag_data_vort.res, projection, + padding=0) * 1E3) + phase_map10 = PhaseMap(mag_data_vort.res, + pm.phase_mag_fourier(mag_data_vort.res, projection, + padding=10) * 1E3) + hi.display_combined(phase_map0, density, 'Disc, res = {} nm'.format(mag_data_vort.res), + labels=('x-axis [nm]', 'y-axis [nm]', 'phase [mrad]')) + hi.display_combined(phase_map10, density, 'Disc, res = {} nm'.format(mag_data_vort.res), + labels=('x-axis [nm]', 'y-axis [nm]', 'phase [mrad]')) + x_v.append(np.linspace(mag_data_vort.res * 0.5, + mag_data_vort.res * (mag_data_vort.dim[1]-0.5), + mag_data_vort.dim[1])) + slice_pos = int(mag_data_vort.dim[1]/2) + y_v0.append(phase_map0.phase[slice_pos, :]) + y_v10.append(phase_map10.phase[slice_pos, :]) + dy_v0.append(phase_map0.phase[slice_pos, :] - F_vort(x_v[-1])) + dy_v10.append(phase_map10.phase[slice_pos, :] - F_vort(x_v[-1])) + + # Shelve x, y and dy: + print '--SAVE PHASE SLICES' + data_shelve[key] = (x_d, y_d0, y_d10, dy_d0, dy_d10, x_v, y_v0, y_v10, dy_v0, dy_v10) + + # Create figure: + fig, axes = plt.subplots(1, 2, figsize=(16, 7)) + fig.suptitle('Central phase slices (padding = 0)', fontsize=20) + + print '--PLOT/SAVE PHASE SLICES HOMOG. MAGN. DISC PADDING = 0' + # Plot phase slices: + axes[0].plot(x_d[0], y_d0[0], '-k', linewidth=1.5, label='analytic') + axes[0].plot(x_d[1], y_d0[1], '-r', linewidth=1.5, label='0.5 nm') + axes[0].plot(x_d[2], y_d0[2], '-m', linewidth=1.5, label='1 nm') + axes[0].plot(x_d[3], y_d0[3], '-y', linewidth=1.5, label='2 nm') + axes[0].plot(x_d[4], y_d0[4], '-g', linewidth=1.5, label='4 nm') + axes[0].plot(x_d[5], y_d0[5], '-c', linewidth=1.5, label='8 nm') + axes[0].tick_params(axis='both', which='major', labelsize=14) + axes[0].set_title('Homog. magn. disc', fontsize=18) + axes[0].set_xlabel('x [nm]', fontsize=15) + axes[0].set_ylabel('phase [mrad]', fontsize=15) + axes[0].set_xlim(0, 128) + axes[0].set_ylim(-220, 220) + # Plot Zoombox and Arrow: + zoom = (23.5, 160, 15, 40) + rect = Rectangle((zoom[0], zoom[1]), zoom[2], zoom[3], fc='w', ec='k') + axes[0].add_patch(rect) + axes[0].arrow(zoom[0]+zoom[2], zoom[1]+zoom[3]/2, 36, 0, length_includes_head=True, + head_width=10, head_length=4, fc='k', ec='k') + # Plot zoom inset: + ins_axis_d = plt.axes([0.33, 0.57, 0.14, 0.3]) + ins_axis_d.plot(x_d[0], y_d0[0], '-k', linewidth=1.5, label='analytic') + ins_axis_d.plot(x_d[1], y_d0[1], '-r', linewidth=1.5, label='0.5 nm') + ins_axis_d.plot(x_d[2], y_d0[2], '-m', linewidth=1.5, label='1 nm') + ins_axis_d.plot(x_d[3], y_d0[3], '-y', linewidth=1.5, label='2 nm') + ins_axis_d.plot(x_d[4], y_d0[4], '-g', linewidth=1.5, label='4 nm') + ins_axis_d.plot(x_d[5], y_d0[5], '-c', linewidth=1.5, label='8 nm') + ins_axis_d.tick_params(axis='both', which='major', labelsize=14) + ins_axis_d.set_xlim(zoom[0], zoom[0]+zoom[2]) + ins_axis_d.set_ylim(zoom[1], zoom[1]+zoom[3]) + ins_axis_d.xaxis.set_major_locator(MaxNLocator(nbins=4, integer= True)) + ins_axis_d.yaxis.set_major_locator(MaxNLocator(nbins=3)) + + print '--PLOT/SAVE PHASE SLICES VORTEX STATE DISC PADDING = 0' + # Plot phase slices: + axes[1].plot(x_v[0], y_v0[0], '-k', linewidth=1.5, label='analytic') + axes[1].plot(x_v[1], y_v0[1], '-r', linewidth=1.5, label='0.5 nm') + axes[1].plot(x_v[2], y_v0[2], '-m', linewidth=1.5, label='1 nm') + axes[1].plot(x_v[3], y_v0[3], '-y', linewidth=1.5, label='2 nm') + axes[1].plot(x_v[4], y_v0[4], '-g', linewidth=1.5, label='4 nm') + axes[1].plot(x_v[5], y_v0[5], '-c', linewidth=1.5, label='8 nm') + axes[1].tick_params(axis='both', which='major', labelsize=14) + axes[1].set_title('Vortex state disc', fontsize=18) + axes[1].set_xlabel('x [nm]', fontsize=15) + axes[1].set_ylabel('phase [mrad]', fontsize=15) + axes[1].set_xlim(0, 128) + axes[1].yaxis.set_major_locator(MaxNLocator(nbins=6)) + axes[1].legend() + # Plot Zoombox and Arrow: + zoom = (59, 340, 10, 55) + rect = Rectangle((zoom[0], zoom[1]), zoom[2], zoom[3], fc='w', ec='k') + axes[1].add_patch(rect) + axes[1].arrow(zoom[0]+zoom[2]/2, zoom[1], 0, -193, length_includes_head=True, + head_width=2, head_length=20, fc='k', ec='k') + # Plot zoom inset: + ins_axis_v = plt.axes([0.695, 0.15, 0.075, 0.3]) + ins_axis_v.plot(x_v[0], y_v0[0], '-k', linewidth=1.5, label='analytic') + ins_axis_v.plot(x_v[1], y_v0[1], '-r', linewidth=1.5, label='0.5 nm') + ins_axis_v.plot(x_v[2], y_v0[2], '-m', linewidth=1.5, label='1 nm') + ins_axis_v.plot(x_v[3], y_v0[3], '-y', linewidth=1.5, label='2 nm') + ins_axis_v.plot(x_v[4], y_v0[4], '-g', linewidth=1.5, label='4 nm') + ins_axis_v.plot(x_v[5], y_v0[5], '-c', linewidth=1.5, label='8 nm') + ins_axis_v.tick_params(axis='both', which='major', labelsize=14) + ins_axis_v.set_xlim(zoom[0], zoom[0]+zoom[2]) + ins_axis_v.set_ylim(zoom[1], zoom[1]+zoom[3]) + ins_axis_v.xaxis.set_major_locator(MaxNLocator(nbins=4, integer= True)) + ins_axis_v.yaxis.set_major_locator(MaxNLocator(nbins=4)) + + plt.show() + plt.figtext(0.15, 0.13, 'a)', fontsize=30) + plt.figtext(0.57, 0.13, 'b)', fontsize=30) + plt.savefig(directory + '/ch5-1-phase_slice_padding_0.png', bbox_inches='tight') + + # Create figure: + fig, axes = plt.subplots(1, 2, figsize=(16, 7)) + fig.suptitle('Central phase slices (padding = 10)', fontsize=20) + + print '--PLOT/SAVE PHASE SLICES HOMOG. MAGN. DISC PADDING = 10' + # Plot phase slices: + axes[0].plot(x_d[0], y_d10[0], '-k', linewidth=1.5, label='analytic') + axes[0].plot(x_d[1], y_d10[1], '-r', linewidth=1.5, label='0.5 nm') + axes[0].plot(x_d[2], y_d10[2], '-m', linewidth=1.5, label='1 nm') + axes[0].plot(x_d[3], y_d10[3], '-y', linewidth=1.5, label='2 nm') + axes[0].plot(x_d[4], y_d10[4], '-g', linewidth=1.5, label='4 nm') + axes[0].plot(x_d[5], y_d10[5], '-c', linewidth=1.5, label='8 nm') + axes[0].tick_params(axis='both', which='major', labelsize=14) + axes[0].set_title('Homog. magn. disc', fontsize=18) + axes[0].set_xlabel('x [nm]', fontsize=15) + axes[0].set_ylabel('phase [mrad]', fontsize=15) + axes[0].set_xlim(0, 128) + axes[0].set_ylim(-220, 220) + # Plot Zoombox and Arrow: + zoom = (23.5, 160, 15, 40) + rect = Rectangle((zoom[0], zoom[1]), zoom[2], zoom[3], fc='w', ec='k') + axes[0].add_patch(rect) + axes[0].arrow(zoom[0]+zoom[2], zoom[1]+zoom[3]/2, 36, 0, length_includes_head=True, + head_width=10, head_length=4, fc='k', ec='k') + # Plot zoom inset: + ins_axis_d = plt.axes([0.33, 0.57, 0.14, 0.3]) + ins_axis_d.plot(x_d[0], y_d10[0], '-k', linewidth=1.5, label='analytic') + ins_axis_d.plot(x_d[1], y_d10[1], '-r', linewidth=1.5, label='0.5 nm') + ins_axis_d.plot(x_d[2], y_d10[2], '-m', linewidth=1.5, label='1 nm') + ins_axis_d.plot(x_d[3], y_d10[3], '-y', linewidth=1.5, label='2 nm') + ins_axis_d.plot(x_d[4], y_d10[4], '-g', linewidth=1.5, label='4 nm') + ins_axis_d.plot(x_d[5], y_d10[5], '-c', linewidth=1.5, label='8 nm') + ins_axis_d.tick_params(axis='both', which='major', labelsize=14) + ins_axis_d.set_xlim(zoom[0], zoom[0]+zoom[2]) + ins_axis_d.set_ylim(zoom[1], zoom[1]+zoom[3]) + ins_axis_d.xaxis.set_major_locator(MaxNLocator(nbins=4, integer= True)) + ins_axis_d.yaxis.set_major_locator(MaxNLocator(nbins=3)) + + print '--PLOT/SAVE PHASE SLICES VORTEX STATE DISC PADDING = 10' + # Plot phase slices: + axes[1].plot(x_v[0], y_v10[0], '-k', linewidth=1.5, label='analytic') + axes[1].plot(x_v[1], y_v10[1], '-r', linewidth=1.5, label='0.5 nm') + axes[1].plot(x_v[2], y_v10[2], '-m', linewidth=1.5, label='1 nm') + axes[1].plot(x_v[3], y_v10[3], '-y', linewidth=1.5, label='2 nm') + axes[1].plot(x_v[4], y_v10[4], '-g', linewidth=1.5, label='4 nm') + axes[1].plot(x_v[5], y_v10[5], '-c', linewidth=1.5, label='8 nm') + axes[1].tick_params(axis='both', which='major', labelsize=14) + axes[1].set_title('Vortex state disc', fontsize=18) + axes[1].set_xlabel('x [nm]', fontsize=15) + axes[1].set_ylabel('phase [mrad]', fontsize=15) + axes[1].set_xlim(0, 128) + axes[1].yaxis.set_major_locator(MaxNLocator(nbins=6)) + axes[1].legend() + # Plot Zoombox and Arrow: + zoom = (59, 340, 10, 55) + rect = Rectangle((zoom[0], zoom[1]), zoom[2], zoom[3], fc='w', ec='k') + axes[1].add_patch(rect) + axes[1].arrow(zoom[0]+zoom[2]/2, zoom[1], 0, -193, length_includes_head=True, + head_width=2, head_length=20, fc='k', ec='k') + # Plot zoom inset: + ins_axis_v = plt.axes([0.695, 0.15, 0.075, 0.3]) + ins_axis_v.plot(x_v[0], y_v10[0], '-k', linewidth=1.5, label='analytic') + ins_axis_v.plot(x_v[1], y_v10[1], '-r', linewidth=1.5, label='0.5 nm') + ins_axis_v.plot(x_v[2], y_v10[2], '-m', linewidth=1.5, label='1 nm') + ins_axis_v.plot(x_v[3], y_v10[3], '-y', linewidth=1.5, label='2 nm') + ins_axis_v.plot(x_v[4], y_v10[4], '-g', linewidth=1.5, label='4 nm') + ins_axis_v.plot(x_v[5], y_v10[5], '-c', linewidth=1.5, label='8 nm') + ins_axis_v.tick_params(axis='both', which='major', labelsize=14) + ins_axis_v.set_xlim(zoom[0], zoom[0]+zoom[2]) + ins_axis_v.set_ylim(zoom[1], zoom[1]+zoom[3]) + ins_axis_v.xaxis.set_major_locator(MaxNLocator(nbins=4, integer= True)) + ins_axis_v.yaxis.set_major_locator(MaxNLocator(nbins=4)) + + plt.show() + plt.figtext(0.15, 0.13, 'a)', fontsize=30) + plt.figtext(0.57, 0.13, 'b)', fontsize=30) + plt.savefig(directory + '/ch5-1-phase_slice_padding_10.png', bbox_inches='tight') + + # Create figure: + fig, axes = plt.subplots(1, 2, figsize=(16, 7)) + fig.suptitle('Central phase slice errors (padding = 0)', fontsize=20) + + print '--PLOT/SAVE PHASE SLICE ERRORS HOMOG. MAGN. DISC PADDING = 0' + # Plot phase slices: + axes[0].plot(x_d[0], dy_d0[0], '-k', linewidth=1.5, label='analytic') + axes[0].plot(x_d[1], dy_d0[1], '-r', linewidth=1.5, label='0.5 nm') + axes[0].plot(x_d[2], dy_d0[2], '-m', linewidth=1.5, label='1 nm') + axes[0].plot(x_d[3], dy_d0[3], '-y', linewidth=1.5, label='2 nm') + axes[0].plot(x_d[4], dy_d0[4], '-g', linewidth=1.5, label='4 nm') + axes[0].plot(x_d[5], dy_d0[5], '-c', linewidth=1.5, label='8 nm') + axes[0].tick_params(axis='both', which='major', labelsize=14) + axes[0].set_title('Homog. magn. disc', fontsize=18) + axes[0].set_xlabel('x [nm]', fontsize=15) + axes[0].set_ylabel('phase [mrad]', fontsize=15) + axes[0].set_xlim(0, 128) + + print '--PLOT/SAVE PHASE SLICE ERRORS VORTEX STATE DISC PADDING = 0' + # Plot phase slices: + axes[1].plot(x_v[0], dy_v0[0], '-k', linewidth=1.5, label='analytic') + axes[1].plot(x_v[1], dy_v0[1], '-r', linewidth=1.5, label='0.5 nm') + axes[1].plot(x_v[2], dy_v0[2], '-m', linewidth=1.5, label='1 nm') + axes[1].plot(x_v[3], dy_v0[3], '-y', linewidth=1.5, label='2 nm') + axes[1].plot(x_v[4], dy_v0[4], '-g', linewidth=1.5, label='4 nm') + axes[1].plot(x_v[5], dy_v0[5], '-c', linewidth=1.5, label='8 nm') + axes[1].tick_params(axis='both', which='major', labelsize=14) + axes[1].set_title('Vortex state disc', fontsize=18) + axes[1].set_xlabel('x [nm]', fontsize=15) + axes[1].set_ylabel('phase [mrad]', fontsize=15) + axes[1].set_xlim(0, 128) + axes[1].legend(loc=4) + + plt.show() + plt.figtext(0.15, 0.13, 'c)', fontsize=30) + plt.figtext(0.57, 0.13, 'd)', fontsize=30) + plt.savefig(directory + '/ch5-1-phase_slice_errors_padding_0.png', bbox_inches='tight') + + # Create figure: + fig, axes = plt.subplots(1, 2, figsize=(16, 7)) + fig.suptitle('Central phase slice errors (padding = 10)', fontsize=20) + + print '--PLOT/SAVE PHASE SLICE ERRORS HOMOG. MAGN. DISC PADDING = 10' + # Plot phase slices: + axes[0].plot(x_d[0], dy_d10[0], '-k', linewidth=1.5, label='analytic') + axes[0].plot(x_d[1], dy_d10[1], '-r', linewidth=1.5, label='0.5 nm') + axes[0].plot(x_d[2], dy_d10[2], '-m', linewidth=1.5, label='1 nm') + axes[0].plot(x_d[3], dy_d10[3], '-y', linewidth=1.5, label='2 nm') + axes[0].plot(x_d[4], dy_d10[4], '-g', linewidth=1.5, label='4 nm') + axes[0].plot(x_d[5], dy_d10[5], '-c', linewidth=1.5, label='8 nm') + axes[0].tick_params(axis='both', which='major', labelsize=14) + axes[0].set_title('Homog. magn. disc', fontsize=18) + axes[0].set_xlabel('x [nm]', fontsize=15) + axes[0].set_ylabel('phase [mrad]', fontsize=15) + axes[0].set_xlim(0, 128) + + print '--PLOT/SAVE PHASE SLICE ERRORS VORTEX STATE DISC PADDING = 10' + # Plot phase slices: + axes[1].plot(x_v[0], dy_v10[0], '-k', linewidth=1.5, label='analytic') + axes[1].plot(x_v[1], dy_v10[1], '-r', linewidth=1.5, label='0.5 nm') + axes[1].plot(x_v[2], dy_v10[2], '-m', linewidth=1.5, label='1 nm') + axes[1].plot(x_v[3], dy_v10[3], '-y', linewidth=1.5, label='2 nm') + axes[1].plot(x_v[4], dy_v10[4], '-g', linewidth=1.5, label='4 nm') + axes[1].plot(x_v[5], dy_v10[5], '-c', linewidth=1.5, label='8 nm') + axes[1].tick_params(axis='both', which='major', labelsize=14) + axes[1].set_title('Vortex state disc', fontsize=18) + axes[1].set_xlabel('x [nm]', fontsize=15) + axes[1].set_ylabel('phase [mrad]', fontsize=15) + axes[1].set_xlim(0, 128) + axes[1].legend(loc=4) + + plt.show() + plt.figtext(0.15, 0.13, 'c)', fontsize=30) + plt.figtext(0.57, 0.13, 'd)', fontsize=30) + plt.savefig(directory + '/ch5-1-phase_slice_errors_padding_10.png', bbox_inches='tight') + ############################################################################################### print 'CH5-2 PHASE DIFFERENCES FOURIER SPACE' @@ -75,6 +434,10 @@ def run(): # Get analytic solutions: phase_ana_disc = an.phase_mag_disc(dim, res, phi, center, radius, height) phase_ana_vort = an.phase_mag_vortex(dim, res, center, radius, height) + + # Create figure: + fig, axes = plt.subplots(1, 2, figsize=(16, 7)) + fig.suptitle('Difference of the real space approach from the analytical solution', fontsize=20) # Create norm for the plots: bounds = np.array([-100, -50, -25, -5, 0, 5, 25, 50, 100]) norm = BoundaryNorm(bounds, RdBu.N) @@ -82,21 +445,29 @@ def run(): phase_num_disc = pm.phase_mag_fourier(res, projection_disc, padding=0) phase_diff_disc = PhaseMap(res, (phase_num_disc-phase_ana_disc)*1E3) # in mrad -> *1000) RMS_disc = np.sqrt(np.mean(phase_diff_disc.phase**2)) - phase_diff_disc.display('Deviation (homog. magn. disc), RMS = {:3.2f} mrad'.format(RMS_disc), - labels=('x-axis [nm]', 'y-axis [nm]', - '$\Delta$phase [mrad] (padding = 0)'), + phase_diff_disc.display('Homog. magn. disc, RMS = {:3.2f} mrad'.format(RMS_disc), + axis=axes[0], labels=('x-axis [nm]', 'y-axis [nm]', + '$\Delta$phase [mrad] (padding = 0)'), limit=np.max(bounds), norm=norm) - plt.savefig(directory + '/ch5-2-disc_phase_diff_no_padding.png', bbox_inches='tight') + axes[0].set_aspect('equal') # Vortex: phase_num_vort = pm.phase_mag_fourier(res, projection_vort, padding=0) phase_diff_vort = PhaseMap(res, (phase_num_vort-phase_ana_vort)*1E3) # in mrad -> *1000 RMS_vort = np.sqrt(np.mean(phase_diff_vort.phase**2)) - phase_diff_vort.display('Deviation (vortex state disc), RMS = {:3.2f} mrad'.format(RMS_vort), - labels=('x-axis [nm]', 'y-axis [nm]', - '$\Delta$phase [mrad] (padding = 0)'), + phase_diff_vort.display('Vortex state disc, RMS = {:3.2f} mrad'.format(RMS_vort), + axis=axes[1], labels=('x-axis [nm]', 'y-axis [nm]', + '$\Delta$phase [mrad] (padding = 0)'), limit=np.max(bounds), norm=norm) - plt.savefig(directory + '/ch5-2-vortex_phase_diff_no_padding.png', bbox_inches='tight') + axes[1].set_aspect('equal') + + plt.show() + plt.figtext(0.15, 0.2, 'a)', fontsize=30) + plt.figtext(0.52, 0.2, 'b)', fontsize=30) + plt.savefig(directory + '/ch5-2-fourier_phase_differe_no_padding.png', bbox_inches='tight') + # Create figure: + fig, axes = plt.subplots(1, 2, figsize=(16, 7)) + fig.suptitle('Difference of the real space approach from the analytical solution', fontsize=20) # Create norm for the plots: bounds = np.array([-3, -0.5, -0.25, -0.1, 0, 0.1, 0.25, 0.5, 3]) norm = BoundaryNorm(bounds, RdBu.N) @@ -104,20 +475,25 @@ def run(): phase_num_disc = pm.phase_mag_fourier(res, projection_disc, padding=10) phase_diff_disc = PhaseMap(res, (phase_num_disc-phase_ana_disc)*1E3) # in mrad -> *1000) RMS_disc = np.sqrt(np.mean(phase_diff_disc.phase**2)) - phase_diff_disc.display('Deviation (homog. magn. disc), RMS = {:3.2f} mrad'.format(RMS_disc), - labels=('x-axis [nm]', 'y-axis [nm]', - '$\Delta$phase [mrad] (padding = 10)'), + phase_diff_disc.display('Homog. magn. disc, RMS = {:3.2f} mrad'.format(RMS_disc), + axis=axes[0], labels=('x-axis [nm]', 'y-axis [nm]', + '$\Delta$phase [mrad] (padding = 10)'), limit=np.max(bounds), norm=norm) - plt.savefig(directory + '/ch5-2-disc_phase_diff_padding_10.png', bbox_inches='tight') + axes[0].set_aspect('equal') # Vortex: phase_num_vort = pm.phase_mag_fourier(res, projection_vort, padding=10) phase_diff_vort = PhaseMap(res, (phase_num_vort-phase_ana_vort)*1E3) # in mrad -> *1000 RMS_vort = np.sqrt(np.mean(phase_diff_vort.phase**2)) - phase_diff_vort.display('Deviation (vortex state disc), RMS = {:3.2f} mrad'.format(RMS_vort), - labels=('x-axis [nm]', 'y-axis [nm]', - '$\Delta$phase [mrad] (padding = 10)'), + phase_diff_vort.display('Vortex state disc, RMS = {:3.2f} mrad'.format(RMS_vort), + axis=axes[1], labels=('x-axis [nm]', 'y-axis [nm]', + '$\Delta$phase [mrad] (padding = 10)'), limit=np.max(bounds), norm=norm) - plt.savefig(directory + '/ch5-2-vortex_phase_diff_padding_10.png', bbox_inches='tight') + axes[1].set_aspect('equal') + + plt.show() + plt.figtext(0.15, 0.2, 'c)', fontsize=30) + plt.figtext(0.52, 0.2, 'd)', fontsize=30) + plt.savefig(directory + '/ch5-2-fourier_phase_differe_padding_10.png', bbox_inches='tight') ############################################################################################### print 'CH5-2 FOURIER PADDING VARIATION' @@ -183,42 +559,41 @@ def run(): data_shelve[key] = data_disc[:, i] print '--PLOT/SAVE PADDING SERIES OF HOMOG. MAGN. DISC' + # Create figure: + fig, axes = plt.subplots(1, 2, figsize=(16, 7)) + fig.suptitle('Variation of the padding (homog. magn. disc)', fontsize=20) # Plot RMS against padding: - fig = plt.figure() - axis = fig.add_subplot(1, 1, 1) - axis.axhline(y=0.18, linestyle='--', color='g', label='RMS [mrad] (real space)') - axis.plot(data_disc[0], data_disc[1], 'go-', label='RMS [mrad] (Fourier space)') - axis.set_title('Variation of the Padding (homog. magn. disc)', fontsize=18) - axis.set_xlabel('padding', fontsize=15) - axis.set_ylabel('RMS [mrad]', fontsize=15) - axis.set_xlim(-0.5, 16.5) - axis.set_ylim(-5, 45) - axis.xaxis.set_major_locator(MaxNLocator(nbins=10, integer= True)) - axis.legend() - plt.tick_params(axis='both', which='major', labelsize=14) + axes[0].axhline(y=0.18, linestyle='--', color='g', label='RMS [mrad] (real space)') + axes[0].plot(data_disc[0], data_disc[1], 'go-', label='RMS [mrad] (Fourier space)') + axes[0].set_xlabel('padding', fontsize=15) + axes[0].set_ylabel('RMS [mrad]', fontsize=15) + axes[0].set_xlim(-0.5, 16.5) + axes[0].set_ylim(-5, 45) + axes[0].xaxis.set_major_locator(MaxNLocator(nbins=10, integer= True)) + axes[0].tick_params(axis='both', which='major', labelsize=14) + axes[0].legend() # Plot zoom inset: - ins_axis = plt.axes([0.3, 0.3, 0.55, 0.4]) - ins_axis.axhline(y=0.18, linestyle='--', color='g') - ins_axis.plot(data_disc[0], data_disc[1], 'go-') - ins_axis.set_yscale('log') - ins_axis.set_xlim(5.5, 16.5) - ins_axis.set_ylim(0.1, 1.1) - plt.tick_params(axis='both', which='major', labelsize=14) - plt.savefig(directory + '/ch5-2-disc_padding_RMS.png', bbox_inches='tight') + ins_axis_d = plt.axes([0.2, 0.35, 0.25, 0.4]) + ins_axis_d.axhline(y=0.18, linestyle='--', color='g') + ins_axis_d.plot(data_disc[0], data_disc[1], 'go-') + ins_axis_d.set_yscale('log') + ins_axis_d.set_xlim(5.5, 16.5) + ins_axis_d.set_ylim(0.1, 1.1) + ins_axis_d.tick_params(axis='both', which='major', labelsize=14) # Plot duration against padding: - fig = plt.figure() - axis = fig.add_subplot(1, 1, 1) - axis.plot(data_disc[0], data_disc[2], 'bo-') - axis.set_title('Variation of the Padding (homog. magn. disc)', fontsize=18) - axis.set_xlabel('padding', fontsize=15) - axis.set_ylabel('duration [s]', fontsize=15) - axis.set_xlim(-0.5, 16.5) - axis.set_ylim(-0.05, 1.5) - axis.xaxis.set_major_locator(MaxNLocator(nbins=10, integer= True)) - axis.yaxis.set_major_locator(MaxNLocator(nbins=10)) - plt.tick_params(axis='both', which='major', labelsize=14) - plt.savefig(directory + '/ch5-2-disc_padding_duration.png', bbox_inches='tight') - + axes[1].plot(data_disc[0], data_disc[2], 'bo-') + axes[1].set_xlabel('padding', fontsize=15) + axes[1].set_ylabel('duration [s]', fontsize=15) + axes[1].set_xlim(-0.5, 16.5) + axes[1].set_ylim(-0.05, 1.5) + axes[1].xaxis.set_major_locator(MaxNLocator(nbins=10, integer= True)) + axes[1].yaxis.set_major_locator(MaxNLocator(nbins=10)) + axes[1].tick_params(axis='both', which='major', labelsize=14) + + plt.show() + plt.figtext(0.15, 0.13, 'a)', fontsize=30) + plt.figtext(0.57, 0.17, 'b)', fontsize=30) + plt.savefig(directory + '/ch5-2-disc_padding_variation.png', bbox_inches='tight') print '--LOAD/CREATE PADDING SERIES OF VORTEX STATE DISC' data_vort = np.zeros((3, len(padding_list))) @@ -240,39 +615,41 @@ def run(): data_shelve[key] = data_vort[:, i] print '--PLOT/SAVE PADDING SERIES OF VORTEX STATE DISC' + # Create figure: + fig, axes = plt.subplots(1, 2, figsize=(16, 7)) + fig.suptitle('Variation of the padding (Vortex state disc)', fontsize=20) # Plot RMS against padding: - fig = plt.figure() - axis = fig.add_subplot(1, 1, 1) - axis.axhline(y=0.22, linestyle='--', color='g', label='RMS [mrad] (real space)') - axis.plot(data_vort[0], data_vort[1], 'go-', label='RMS [mrad] (Fourier space)') - axis.set_title('Variation of the Padding (vortex state disc)', fontsize=18) - axis.set_xlabel('padding', fontsize=15) - axis.set_ylabel('RMS [mrad]', fontsize=15) - axis.set_xlim(-0.5, 16.5) - axis.set_ylim(-5, 45) - plt.tick_params(axis='both', which='major', labelsize=14) - axis.xaxis.set_major_locator(MaxNLocator(nbins=10, integer= True)) - axis.legend() + axes[0].axhline(y=0.22, linestyle='--', color='g', label='RMS [mrad] (real space)') + axes[0].plot(data_vort[0], data_vort[1], 'go-', label='RMS [mrad] (Fourier space)') + axes[0].set_xlabel('padding', fontsize=15) + axes[0].set_ylabel('RMS [mrad]', fontsize=15) + axes[0].set_xlim(-0.5, 16.5) + axes[0].set_ylim(-5, 45) + axes[0].tick_params(axis='both', which='major', labelsize=14) + axes[0].xaxis.set_major_locator(MaxNLocator(nbins=10, integer= True)) + axes[0].legend() # Plot zoom inset: - ins_axis = plt.axes([0.3, 0.3, 0.55, 0.4]) - ins_axis.axhline(y=0.22, linestyle='--', color='g') - ins_axis.plot(data_vort[0], data_vort[1], 'go-') - ins_axis.set_yscale('log') - ins_axis.set_xlim(5.5, 16.5) - ins_axis.set_ylim(0.1, 1.1) - plt.tick_params(axis='both', which='major', labelsize=14) - plt.savefig(directory + '/ch5-2-vortex_padding_RMS.png', bbox_inches='tight') + ins_axis_v = plt.axes([0.2, 0.35, 0.25, 0.4]) + ins_axis_v.axhline(y=0.22, linestyle='--', color='g') + ins_axis_v.plot(data_vort[0], data_vort[1], 'go-') + ins_axis_v.set_yscale('log') + ins_axis_v.set_xlim(5.5, 16.5) + ins_axis_v.set_ylim(0.1, 1.1) + ins_axis_v.tick_params(axis='both', which='major', labelsize=14) # Plot duration against padding: - fig = plt.figure() - axis = fig.add_subplot(1, 1, 1) - axis.plot(data_vort[0], data_vort[2], 'bo-') - axis.set_title('Variation of the Padding (vortex state disc)', fontsize=18) - axis.set_xlabel('padding', fontsize=15) - axis.set_ylabel('duration [s]', fontsize=15) - axis.set_xlim(-0.5, 16.5) - axis.set_ylim(-0.05, 1.5) - plt.tick_params(axis='both', which='major', labelsize=14) - plt.savefig(directory + '/ch5-2-vortex_padding_duration.png', bbox_inches='tight') + axes[1].plot(data_vort[0], data_vort[2], 'bo-') + axes[1].set_xlabel('padding', fontsize=15) + axes[1].set_ylabel('duration [s]', fontsize=15) + axes[1].set_xlim(-0.5, 16.5) + axes[1].set_ylim(-0.05, 1.5) + axes[1].xaxis.set_major_locator(MaxNLocator(nbins=10, integer= True)) + axes[1].yaxis.set_major_locator(MaxNLocator(nbins=10)) + axes[1].tick_params(axis='both', which='major', labelsize=14) + + plt.show() + plt.figtext(0.15, 0.13, 'c)', fontsize=30) + plt.figtext(0.57, 0.17, 'd)', fontsize=30) + plt.savefig(directory + '/ch5-2-vortex_padding_variation.png', bbox_inches='tight') ############################################################################################### print 'CLOSING SHELVE\n' diff --git a/scripts/paper 1/ch5-3-comparison_of_methods.py b/scripts/paper 1/ch5-3-comparison_of_methods.py index 0b592a3..d5b886a 100644 --- a/scripts/paper 1/ch5-3-comparison_of_methods.py +++ b/scripts/paper 1/ch5-3-comparison_of_methods.py @@ -10,7 +10,9 @@ import sys import os import numpy as np from numpy import pi + import matplotlib.pyplot as plt +from matplotlib.ticker import IndexLocator import pyramid.magcreator as mc import pyramid.projector as pj @@ -180,91 +182,75 @@ def run(): print '--PLOT/SAVE METHOD DATA' - # row and column sharing - fig, axes = plt.subplots(2, 2, sharex='col', sharey='row', figsize=(16, 7)) -# ax1.plot(x, y) -# ax1.set_title('Sharing x per column, y per row') -# ax2.scatter(x, y) -# ax3.scatter(x, 2 * y ** 2 - 1, color='r') -# ax4.plot(x, 2 * y ** 2 - 1, color='r') - - - - # Plot duration against res (disc): -# fig = plt.figure() -# axis = fig.add_subplot(1, 1, 1) - plt.tick_params(axis='both', which='major', labelsize=14) + # Plot using shared rows and colums: + fig, axes = plt.subplots(2, 2, sharex='col', sharey='row', figsize=(12, 8)) + fig.tight_layout(rect=(0.05, 0.05, 0.95, 0.95)) + fig.suptitle('Method Comparison', fontsize=20) + + # Plot duration against res (disc) [top/left]: axes[1, 0].set_yscale('log') - axes[1, 0].plot(data_disc_fourier0[0], data_disc_fourier0[1], '--b+', label='Fourier padding=0') - axes[1, 0].plot(data_disc_fourier1[0], data_disc_fourier1[1], '--bx', label='Fourier padding=1') - axes[1, 0].plot(data_disc_fourier10[0], data_disc_fourier10[1], '--b*', label='Fourier padding=10') - axes[1, 0].plot(data_disc_real_s[0], data_disc_real_s[1], '--rs', label='Real space (slab)') - axes[1, 0].plot(data_disc_real_d[0], data_disc_real_d[1], '--ro', label='Real space (disc)') - axes[1, 0].set_title('Variation of the resolution (disc)', fontsize=18) -# axes[1, 0].set_xlabel('res [nm]', fontsize=15) -# axes[1, 0].set_ylabel('RMS [mrad]', fontsize=15) -# axes[1, 0].set_xlim(-0.5, 16.5) -# axes[1, 0].legend(loc=4) -# plt.tick_params(axis='both', which='major', labelsize=14) -# plt.savefig(directory + '/ch5-3-disc_RMS_against_res.png', bbox_inches='tight') - # Plot RMS against res (disc): -# fig = plt.figure() -# axis = fig.add_subplot(1, 1, 1) + axes[1, 0].plot(data_disc_fourier0[0], data_disc_fourier0[1], ':bs') + axes[1, 0].plot(data_disc_fourier1[0], data_disc_fourier1[1], ':bo') + axes[1, 0].plot(data_disc_fourier10[0], data_disc_fourier10[1], ':b^') + axes[1, 0].plot(data_disc_real_s[0], data_disc_real_s[1], '--rs') + axes[1, 0].plot(data_disc_real_d[0], data_disc_real_d[1], '--ro') + axes[1, 0].set_xlabel('res [nm]', fontsize=15) + axes[1, 0].set_ylabel('RMS [mrad]', fontsize=15) + axes[1, 0].set_xlim(-0.5, 16.5) + axes[1, 0].tick_params(axis='both', which='major', labelsize=14) + axes[1, 0].xaxis.set_major_locator(IndexLocator(base=4, offset=-0.5)) + + # Plot RMS against res (disc) [bottom/left]: + plt.tick_params(axis='both', which='major', labelsize=14) axes[0, 0].set_yscale('log') - axes[0, 0].plot(data_disc_fourier0[0], data_disc_fourier0[2], '--b+', label='Fourier padding=0') - axes[0, 0].plot(data_disc_fourier1[0], data_disc_fourier1[2], '--bx', label='Fourier padding=1') - axes[0, 0].plot(data_disc_fourier10[0], data_disc_fourier10[2], '--b*', label='Fourier padding=10') - axes[0, 0].plot(data_disc_real_s[0], data_disc_real_s[2], '--rs', label='Real space (slab)') - axes[0, 0].plot(data_disc_real_d[0], data_disc_real_d[2], '--ro', label='Real space (disc)') - axes[0, 0].set_title('Variation of the resolution (disc)', fontsize=18) -# axes[0, 0].set_xlabel('res [nm]', fontsize=15) + axes[0, 0].plot(data_disc_fourier0[0], data_disc_fourier0[2], ':bs') + axes[0, 0].plot(data_disc_fourier1[0], data_disc_fourier1[2], ':bo') + axes[0, 0].plot(data_disc_fourier10[0], data_disc_fourier10[2], ':b^') + axes[0, 0].plot(data_disc_real_s[0], data_disc_real_s[2], '--rs') + axes[0, 0].plot(data_disc_real_d[0], data_disc_real_d[2], '--ro') + axes[0, 0].set_title('Homog. magn. disc', fontsize=18) axes[0, 0].set_ylabel('duration [s]', fontsize=15) -# axes[0, 0].set_xlim(-0.5, 16.5) -# axes[0, 0].legend(loc=1) -# plt.tick_params(axis='both', which='major', labelsize=14) -# plt.savefig(directory + '/ch5-3-disc_duration_against_res.png', bbox_inches='tight') + axes[0, 0].set_xlim(-0.5, 16.5) + axes[0, 0].tick_params(axis='both', which='major', labelsize=14) + axes[0, 0].xaxis.set_major_locator(IndexLocator(base=4, offset=-0.5)) - # Plot duration against res (vortex): -# fig = plt.figure() -# axis = fig.add_subplot(1, 1, 1) + # Plot duration against res (vortex) [top/right]: axes[1, 1].set_yscale('log') - axes[1, 1].plot(data_vort_fourier0[0], data_vort_fourier0[1], '--b+', label='Fourier padding=0') - axes[1, 1].plot(data_vort_fourier1[0], data_vort_fourier1[1], '--bx', label='Fourier padding=1') - axes[1, 1].plot(data_vort_fourier10[0], data_vort_fourier10[1], '--b*', label='Fourier padding=10') - axes[1, 1].plot(data_vort_real_s[0], data_vort_real_s[1], '--rs', label='Real space (slab)') - axes[1, 1].plot(data_vort_real_d[0], data_vort_real_d[1], '--ro', label='Real space (disc)') -# axes[1, 1].set_title('Variation of the resolution (vortex)', fontsize=18) + axes[1, 1].plot(data_vort_fourier0[0], data_vort_fourier0[1], ':bs') + axes[1, 1].plot(data_vort_fourier1[0], data_vort_fourier1[1], ':bo') + axes[1, 1].plot(data_vort_fourier10[0], data_vort_fourier10[1], ':b^') + axes[1, 1].plot(data_vort_real_s[0], data_vort_real_s[1], '--rs') + axes[1, 1].plot(data_vort_real_d[0], data_vort_real_d[1], '--ro') axes[1, 1].set_xlabel('res [nm]', fontsize=15) -# axes[1, 1].set_ylabel('RMS [mrad]', fontsize=15) axes[1, 1].set_xlim(-0.5, 16.5) -# axes[1, 1].legend(loc=4) -# plt.tick_params(axis='both', which='major', labelsize=14) -# plt.savefig(directory + '/ch5-3-vortex_RMS_against_res.png', bbox_inches='tight') - # Plot RMS against res (vort): -# fig = plt.figure() -# axis = fig.add_subplot(1, 1, 1) + axes[1, 1].tick_params(axis='both', which='major', labelsize=14) + axes[1, 1].xaxis.set_major_locator(IndexLocator(base=4, offset=-0.5)) + + # Plot RMS against res (vortex) [bottom/right]: axes[0, 1].set_yscale('log') - axes[0, 1].plot(data_vort_fourier0[0], data_vort_fourier0[2], '--b+', label='Fourier padding=0') - axes[0, 1].plot(data_vort_fourier1[0], data_vort_fourier1[2], '--bx', label='Fourier padding=1') - axes[0, 1].plot(data_vort_fourier10[0], data_vort_fourier10[2], '--b*', label='Fourier padding=10') - axes[0, 1].plot(data_vort_real_s[0], data_vort_real_s[2], '--rs', label='Real space (slab)') - axes[0, 1].plot(data_vort_real_d[0], data_vort_real_d[2], '--ro', label='Real space (disc)') - axes[0, 1].set_title('Variation of the resolution (vortex)', fontsize=18) -# axes[0, 1].set_xlabel('res [nm]', fontsize=15) -# axes[0, 1].set_ylabel('duration [s]', fontsize=15) + axes[0, 1].plot(data_vort_fourier0[0], data_vort_fourier0[2], ':bs', + label='Fourier padding=0') + axes[0, 1].plot(data_vort_fourier1[0], data_vort_fourier1[2], ':bo', + label='Fourier padding=1') + axes[0, 1].plot(data_vort_fourier10[0], data_vort_fourier10[2], ':b^', + label='Fourier padding=10') + axes[0, 1].plot(data_vort_real_s[0], data_vort_real_s[2], '--rs', + label='Real space (slab)') + axes[0, 1].plot(data_vort_real_d[0], data_vort_real_d[2], '--ro', + label='Real space (disc)') + axes[0, 1].set_title('Vortex state disc', fontsize=18) axes[0, 1].set_xlim(-0.5, 16.5) + axes[0, 1].tick_params(axis='both', which='major', labelsize=14) + axes[0, 1].xaxis.set_major_locator(IndexLocator(base=4, offset=-0.5)) axes[0, 1].legend(loc=1) -# plt.tick_params(axis='both', which='major', labelsize=14) - plt.savefig(directory + '/ch5-3-vortex_duration_against_res.png', bbox_inches='tight') - - - - - - - - - + + # Save figure as .png: + plt.show() + plt.figtext(0.45, 0.85, 'a)', fontsize=30) + plt.figtext(0.57, 0.85, 'b)', fontsize=30) + plt.figtext(0.45, 0.15, 'c)', fontsize=30) + plt.figtext(0.57, 0.15, 'd)', fontsize=30) + plt.savefig(directory + '/ch5-3-method comparison.png', bbox_inches='tight') ############################################################################################### print 'CLOSING SHELVE\n' diff --git a/scripts/reconstruct_random_pixels.py b/scripts/reconstruct_random_pixels.py index a09bb09..c4d62a6 100644 --- a/scripts/reconstruct_random_pixels.py +++ b/scripts/reconstruct_random_pixels.py @@ -32,7 +32,6 @@ def reconstruct_random_distribution(): 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) @@ -51,15 +50,9 @@ def reconstruct_random_distribution(): projection = pj.simple_axis_projection(mag_data) phase_map = PhaseMap(res, pm.phase_mag_real(res, projection, 'slab', b_0)) hi.display_combined(phase_map, 10, 'Generated Distribution') - # Get the locations of the magnetized pixels (mask): - z_mag, y_mag, x_mag = mag_data.magnitude - z_mask = abs(z_mag) > threshold - 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) + mag_data_rec = rc.reconstruct_simple_leastsq(phase_map, mag_data.get_mask(), b_0) # Display the reconstructed phase map and holography image: projection_rec = pj.simple_axis_projection(mag_data_rec) diff --git a/setup.py b/setup.py index 9efd3c4..9d9a4ea 100644 --- a/setup.py +++ b/setup.py @@ -57,7 +57,7 @@ setup( packages = find_packages(exclude=['tests']), include_dirs = [numpy.get_include()], - requires = ['numpy', 'matplotlib'], + requires = ['numpy', 'matplotlib', 'mayavi'], scripts = get_files('scripts'), -- GitLab