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

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
parent 9229ec98
No related branches found
No related tags found
No related merge requests found
Showing
with 910 additions and 387 deletions
......@@ -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
......
......@@ -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]'))
......@@ -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)
......
......@@ -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)
......
......@@ -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()
......@@ -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
......@@ -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'
......
......@@ -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':
......
......@@ -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()
......
......@@ -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__":
......
......@@ -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')
......@@ -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'
......
This diff is collapsed.
This diff is collapsed.
......@@ -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'
......
......@@ -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)
......
......@@ -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'),
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment