Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • empyre/empyre
  • weber/empyre
  • wessels/empyre
  • bryan/empyre
4 results
Show changes
Showing
with 0 additions and 2038 deletions
# -*- coding: utf-8 -*-
"""Created on Tue Jan 28 15:15:08 2014 @author: Jan"""
import os
import numpy as np
from matplotlib.ticker import FuncFormatter
import pyramid
from pyramid.magdata import MagData
from pyramid.phasemapper import pm
import logging
import logging.config
LOGGING_CONF = os.path.join(os.path.dirname(os.path.realpath(pyramid.__file__)), 'logging.ini')
logging.config.fileConfig(LOGGING_CONF, disable_existing_loggers=False)
# Load data:
data = np.loadtxt('../../output/data from Edinburgh/long_grain_remapped_0p0035.txt', delimiter=',')
# Set parameters:
a = 1000 * (data[1, 2] - data[0, 2])
dim = len(np.unique(data[:, 2])), len(np.unique(data[:, 1])), len(np.unique(data[:, 0]))
# Set magnetization:
mag_vec = np.concatenate([data[:, 3], data[:, 4], data[:, 5]])
x_mag = np.reshape(data[:, 3], dim, order='F')
y_mag = np.reshape(data[:, 4], dim, order='F')
z_mag = np.reshape(data[:, 5], dim, order='F')
magnitude = np.array((x_mag, y_mag, z_mag))
mag_data = MagData(a, magnitude)
# Pad and upscale:
mag_data.pad(30, 20, 0)
mag_data.scale_up()
# Phasemapping:
phase_map = pm(mag_data)
# Plot:
phase_axis = phase_map.display_combined(gain=20, interpolation='bilinear',
grad_encode='bright')[0]
phase_axis.xaxis.set_major_formatter(FuncFormatter(lambda x, pos: '{:3.0f}'.format(x*mag_data.a)))
phase_axis.yaxis.set_major_formatter(FuncFormatter(lambda x, pos: '{:3.0f}'.format(x*mag_data.a)))
# -*- coding: utf-8 -*-
"""Created on Mon Aug 11 08:41:23 2014 @author: Jan"""
import os
import numpy as np
import pickle
import matplotlib.pyplot as plt
import pyramid
from pyramid.phasemap import PhaseMap
from pyramid.projector import SimpleProjector
from pyramid.phasemapper import pm
from pyramid.dataset import DataSet
from pyramid.regularisator import ZeroOrderRegularisator
import pyramid.reconstruction as rc
from time import clock
import logging
import logging.config
LOGGING_CONF = os.path.join(os.path.dirname(os.path.realpath(pyramid.__file__)), 'logging.ini')
logging.config.fileConfig(LOGGING_CONF, disable_existing_loggers=False)
###################################################################################################
threshold = 1
a = 1.0 # in nm
gain = 5
b_0 = 1
inter = 'none'
dim = (1,) + (64, 64)
dim_small = (64, 64)
smoothed_pictures = True
lam = 1E-4
order = 1
log = True
PATH = '../../output/joern/'
###################################################################################################
# Read in files:
phase_map = PhaseMap.load_from_netcdf4(PATH+'phase_map.nc')
#mask = np.genfromtxt('mask.txt', dtype=bool)
with open(PATH+'mask.pickle') as pf:
mask = pickle.load(pf)
# Setup:
data_set = DataSet(a, dim, b_0)
data_set.append(phase_map, SimpleProjector(dim))
regularisator = ZeroOrderRegularisator(lam)
# Reconstruct the magnetic distribution:
tic = clock()
mag_data_rec = rc.optimize_sparse_cg(data_set, regularisator, maxiter=100, verbosity=2)
# .optimize_simple_leastsq(phase_map, mask, b_0, lam=lam, order=order)
print 'reconstruction time:', clock() - tic
# Display the reconstructed phase map and holography image:
phase_map_rec = pm(mag_data_rec)
phase_map_rec.display_combined('Reconstr. Distribution', gain=gain, interpolation=inter)
# Plot the magnetization:
axis = (mag_data_rec*(1/mag_data_rec.magnitude.max())).quiver_plot()
axis.set_xlim(20, 45)
axis.set_ylim(20, 45)
# Display the Phase:
phase_diff = phase_map_rec-phase_map
phase_diff.display_phase('Difference')
# Get the average difference from the experimental results:
print 'Average difference:', np.average(phase_diff.phase)
# Plot holographic contour maps with overlayed magnetic distributions:
axis = phase_map_rec.display_holo('Magnetization Overlay', gain=0.1, interpolation=inter)
mag_data_rec.quiver_plot(axis=axis)
axis = plt.gca()
axis.set_xlim(20, 45)
axis.set_ylim(20, 45)
axis = phase_map_rec.display_holo('Magnetization Overlay', gain=0.1, interpolation=inter)
mag_data_rec.quiver_plot(axis=axis, log=log)
axis = plt.gca()
axis.set_xlim(20, 45)
axis.set_ylim(20, 45)
# -*- coding: utf-8 -*-
"""Created on Fri Jul 25 14:37:11 2014 @author: Jan"""
import os
import numpy as np
import matplotlib.pyplot as plt
from pylab import griddata
from tqdm import tqdm
import tables
import pyramid
from pyramid.magdata import MagData
from pyramid.projector import SimpleProjector
from pyramid.phasemapper import PhaseMapperRDFC
from pyramid.kernel import Kernel
import logging
import logging.config
LOGGING_CONF = os.path.join(os.path.dirname(os.path.realpath(pyramid.__file__)), 'logging.ini')
logging.config.fileConfig(LOGGING_CONF, disable_existing_loggers=False)
###################################################################################################
PATH = '../../output/'
dim = (16, 190, 220)
dim_uv = (300, 500)
a = 1.
b_0 = 1.1
dens_z = 4E3
dens_x = 1E2
lim_z = 22
lim_x = 0.35
###################################################################################################
# Build projectors and phasemapper:
projector_z = SimpleProjector(dim, axis='z', dim_uv=dim_uv)
projector_x = SimpleProjector(dim, axis='x', dim_uv=dim_uv)
pm_z = PhaseMapperRDFC(Kernel(a, projector_z.dim_uv, b_0))
pm_x = PhaseMapperRDFC(Kernel(a, projector_x.dim_uv, b_0))
# Read in hdf5-file and extract points:
h5file = tables.openFile(PATH+'dyn_0090mT_dyn.h5_dat.h5')
points = h5file.root.mesh.points.read()
# Plot point distribution in 2D and 3D:
axis = plt.figure().add_subplot(1, 1, 1, aspect='equal')
axis.scatter(points[:, 0], points[:, 1])
# Filling zeros:
iz_x = np.concatenate([np.linspace(-74, -37, 20),
np.linspace(-37, 37, 20),
np.linspace(37, 74, 20),
np.linspace(74, 37, 20),
np.linspace(37, -37, 20),
np.linspace(-37, -74, 20)])
iz_y = np.concatenate([np.linspace(0, 64, 20),
np.linspace(64, 64, 20),
np.linspace(64, 0, 20),
np.linspace(0, -64, 20),
np.linspace(-64, -64, 20),
np.linspace(-64, 0, 20)])
iz_z = np.zeros(len(iz_x))
# Set up grid:
xs = np.arange(-dim[2]/2, dim[2]/2)
ys = np.arange(-dim[1]/2, dim[1]/2)
zs = np.arange(-dim[0]/2, dim[0]/2)
xx, yy = np.meshgrid(xs, ys)
def calculate(t): # TODO: Somehow avoid memory error :-(...
print 't =', t
vectors = h5file.root.data.fields.m.read(field='m_CoFeb')[t, ...]
data = np.hstack((points, vectors))
# Create empty magnitude:
magnitude = np.zeros((3, len(zs), len(ys), len(xs)))
# Go over all z-slices:
for i, z in tqdm(enumerate(zs), total=len(zs)):
z_slice = data[np.abs(data[:, 2]-z) <= a/2., :]
weights = 1 - np.abs(z_slice[:, 2]-z)*2/a
for j in range(3): # For all 3 components!
grid_x = np.concatenate([z_slice[:, 0], iz_x])
grid_y = np.concatenate([z_slice[:, 1], iz_y])
grid_z = np.concatenate([weights*z_slice[:, 3+j], iz_z])
grid = griddata(grid_x, grid_y, grid_z, xx, yy)
magnitude[j, i, :, :] = grid.filled(fill_value=0)
# Create magnetic distribution and phase maps:
mag_data = MagData(a, magnitude)
phase_map_z = pm_z(projector_z(mag_data))
phase_map_x = pm_x(projector_x(mag_data))
phase_map_z.unit = 'mrad'
# Display phase maps and save them to png:
phase_map_z.display_combined(gain=dens_z, interpolation='bilinear', limit=lim_z)
plt.savefig(PATH+'rueffner/phase_map_z_t_'+str(t)+'.png')
phase_map_x.display_combined(gain=dens_x, interpolation='bilinear', limit=lim_x)
plt.savefig(PATH+'rueffner/phase_map_x_t_'+str(t)+'.png')
vectors, data, magnitude, z_slice, weights, grid_x, grid_y, grid_z, grid, mag_data, \
phase_map_z, phase_map_x = [None] * 12
# Close all plots to avoid clutter:
plt.close('all')
# Interpolation and phase calculation for all timesteps:
for t in np.arange(0, 1001, 5):
calculate(t)
# -*- coding: utf-8 -*-
"""
Created on Mon Oct 27 08:49:48 2014
@author: Jan
"""
from numpy import pi
import numpy as np
import pyramid.magcreator as mc
from pyramid.magdata import MagData
dim = (1, 32, 32)
center = (0, 16, 16)
width = (1, 8, 16)
mag_data = MagData(1, mc.create_mag_dist_homog(mc.Shapes.slab(dim, center, width), pi/6))
mag_data.quiver_plot()
mag_data.quiver_plot3d()
x, y, z = mag_data.magnitude[:, 0, ...]
x_rot = np.rot90(mag_data.magnitude[0, 0, ...]).copy()
y_rot = np.rot90(mag_data.magnitude[1, 0, ...]).copy()
#z_rot = np.rot90(mag_data.magnitude[2, 0, ...]).copy()
mag_data.magnitude[0, 0, ...] = -y_rot
mag_data.magnitude[1, 0, ...] = x_rot
mag_data.quiver_plot()
mag_data.quiver_plot3d()
# -*- coding: utf-8 -*-
"""Created on Thu Nov 07 16:47:52 2013 @author: Jan """
import os
import numpy as np
from numpy import pi
import pyramid
import pyramid.magcreator as mc
from pyramid.projector import SimpleProjector
from pyramid.phasemapper import PhaseMapperRDFC, PhaseMapperElectric
from pyramid.kernel import Kernel
from pyramid.magdata import MagData
import matplotlib.pyplot as plt
import logging
import logging.config
LOGGING_CONF = os.path.join(os.path.dirname(os.path.realpath(pyramid.__file__)), 'logging.ini')
logging.config.fileConfig(LOGGING_CONF, disable_existing_loggers=False)
# Set constants:
Q_E = 1 # 1.602176565e-19
EPSILON_0 = 1 # 8.8e-9
C_E = 1
def calculate_charge_batch(phase_map):
def calculate_charge(grad_y, grad_x, l, r, t, b):
left = np.sum(-grad_x[b:t, l])
top = np.sum(grad_y[t, l:r])
right = np.sum(grad_x[b:t, r])
bottom = np.sum(-grad_y[b, l:r])
integral = left + top + right + bottom
Q = -EPSILON_0/C_E * integral
return Q
grad_y, grad_x = np.gradient(phase_map.phase, phase_map.a, phase_map.a)
xi, yi = np.zeros(t-b), np.zeros(t-b)
for i, ti in enumerate(np.arange(b, t)):
xi[i] = ti
yi[i] = calculate_charge(grad_y, grad_x, l, r, ti, b)
return xi, yi
directory = '../../output/vadim/'
if not os.path.exists(directory):
os.makedirs(directory)
# Set parameters:
a = 1.0 # in nm
phi = pi/4
gain = 30
dim = (128, 128, 128) # in px (z, y, x)
v_0 = 1
v_acc = 300000
l = dim[2]/4.
r = dim[2]/4. + dim[2]/2.
b = dim[1]/4.
t = dim[1]/4. + dim[1]/2.
# 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 at 0!
radius = dim[1]/8 # in px
height = dim[0]/4 # in px
width = (dim[0]/4, dim[1]/4, dim[2]/4)
mag_shape_sphere = mc.Shapes.sphere(dim, center, radius)
mag_shape_disc = mc.Shapes.disc(dim, center, radius, height)
mag_shape_slab = mc.Shapes.slab(dim, center, (height, radius*2, radius*2))
mag_shape_ellipsoid = mc.Shapes.ellipsoid(dim, (center[0], 0*center[1], center[2]),
(radius*5, radius*10, radius*2))
# Create magnetization distributions:
mag_data_sphere = MagData(a, mc.create_mag_dist_homog(mag_shape_sphere, phi))
mag_data_disc = MagData(a, mc.create_mag_dist_homog(mag_shape_disc, phi))
mag_data_vortex = MagData(a, mc.create_mag_dist_vortex(mag_shape_disc))
mag_data_slab = MagData(a, mc.create_mag_dist_homog(mag_shape_slab, phi))
mag_data_ellipsoid = MagData(a, mc.create_mag_dist_homog(mag_shape_ellipsoid, phi))
# Create phasemapper:
projector = SimpleProjector(dim)
pm_mag = PhaseMapperRDFC(Kernel(a, projector.dim_uv))
pm_ele = PhaseMapperElectric(a, projector.dim_uv, v_0, v_acc)
# Magnetic phase map of a homogeneously magnetized disc:
phase_map_mag_disc = pm_mag(projector(mag_data_disc))
phase_map_mag_disc.save_to_txt(directory+'phase_map_mag_disc.txt')
axis, _ = phase_map_mag_disc.display_combined(gain=gain)
axis.axvline(l, b/dim[1], t/dim[1], linewidth=2, color='g')
axis.axvline(r, b/dim[1], t/dim[1], linewidth=2, color='g')
axis.axhline(b, l/dim[2], r/dim[2], linewidth=2, color='g')
axis.axhline(t, l/dim[2], r/dim[2], linewidth=2, color='g')
axis.arrow(l+(r-l)/2, b, 0, t-b, length_includes_head=True,
head_width=(r-l)/10, head_length=(r-l)/10, fc='g', ec='g')
plt.savefig(directory+'phase_map_mag_disc.png')
x, y = calculate_charge_batch(phase_map_mag_disc)
np.savetxt(directory+'charge_integral_mag_disc.txt', np.array([x, y]).T)
plt.figure()
plt.plot(x, y)
plt.savefig(directory+'charge_integral_mag_disc.png')
# Magnetic phase map of a vortex state disc:
phase_map_mag_vortex = pm_mag(projector(mag_data_vortex))
phase_map_mag_vortex.save_to_txt(directory+'phase_map_mag_vortex.txt')
axis, _ = phase_map_mag_vortex.display_combined(gain=gain)
axis.axvline(l, b/dim[1], t/dim[1], linewidth=2, color='g')
axis.axvline(r, b/dim[1], t/dim[1], linewidth=2, color='g')
axis.axhline(b, l/dim[2], r/dim[2], linewidth=2, color='g')
axis.axhline(t, l/dim[2], r/dim[2], linewidth=2, color='g')
axis.arrow(l+(r-l)/2, b, 0, t-b, length_includes_head=True,
head_width=(r-l)/10, head_length=(r-l)/10, fc='g', ec='g')
plt.savefig(directory+'phase_map_mag_vortex.png')
x, y = calculate_charge_batch(phase_map_mag_vortex)
np.savetxt(directory+'charge_integral_mag_vortex.txt', np.array([x, y]).T)
plt.figure()
plt.plot(x, y)
plt.savefig(directory+'charge_integral_mag_vortex.png')
# MIP phase of a slab:
phase_map_mip_slab = pm_ele(projector(mag_data_slab))
phase_map_mip_slab.save_to_txt(directory+'phase_map_mip_slab.txt')
axis, _ = phase_map_mip_slab.display_combined(gain=gain)
axis.axvline(l, b/dim[1], t/dim[1], linewidth=2, color='g')
axis.axvline(r, b/dim[1], t/dim[1], linewidth=2, color='g')
axis.axhline(b, l/dim[2], r/dim[2], linewidth=2, color='g')
axis.axhline(t, l/dim[2], r/dim[2], linewidth=2, color='g')
axis.arrow(l+(r-l)/2, b, 0, t-b, length_includes_head=True,
head_width=(r-l)/10, head_length=(r-l)/10, fc='g', ec='g')
plt.savefig(directory+'phase_map_mip_slab.png')
x, y = calculate_charge_batch(phase_map_mip_slab)
np.savetxt(directory+'charge_integral_mip_slab.txt', np.array([x, y]).T)
plt.figure()
plt.plot(x, y)
plt.savefig(directory+'charge_integral_mip_slab.png')
# MIP phase of a disc:
phase_map_mip_disc = pm_ele(projector(mag_data_disc))
phase_map_mip_disc.save_to_txt(directory+'phase_map_mip_disc.txt')
axis, _ = phase_map_mip_disc.display_combined(gain=gain)
axis.axvline(l, b/dim[1], t/dim[1], linewidth=2, color='g')
axis.axvline(r, b/dim[1], t/dim[1], linewidth=2, color='g')
axis.axhline(b, l/dim[2], r/dim[2], linewidth=2, color='g')
axis.axhline(t, l/dim[2], r/dim[2], linewidth=2, color='g')
axis.arrow(l+(r-l)/2, b, 0, t-b, length_includes_head=True,
head_width=(r-l)/10, head_length=(r-l)/10, fc='g', ec='g')
plt.savefig(directory+'phase_map_mip_disc.png')
x, y = calculate_charge_batch(phase_map_mip_disc)
np.savetxt(directory+'charge_integral_mip_disc.txt', np.array([x, y]).T)
plt.figure()
plt.plot(x, y)
plt.savefig(directory+'charge_integral_mip_disc.png')
# MIP phase of a sphere:
phase_map_mip_sphere = pm_ele(projector(mag_data_sphere))
phase_map_mip_sphere.save_to_txt(directory+'phase_map_mip_sphere.txt')
axis, _ = phase_map_mip_sphere.display_combined(gain=gain)
axis.axvline(l, b/dim[1], t/dim[1], linewidth=2, color='g')
axis.axvline(r, b/dim[1], t/dim[1], linewidth=2, color='g')
axis.axhline(b, l/dim[2], r/dim[2], linewidth=2, color='g')
axis.axhline(t, l/dim[2], r/dim[2], linewidth=2, color='g')
axis.arrow(l+(r-l)/2, b, 0, t-b, length_includes_head=True,
head_width=(r-l)/10, head_length=(r-l)/10, fc='g', ec='g')
plt.savefig(directory+'phase_map_mip_sphere.png')
x, y = calculate_charge_batch(phase_map_mip_sphere)
np.savetxt(directory+'charge_integral_mip_sphere.txt', np.array([x, y]).T)
plt.figure()
plt.plot(x, y)
plt.savefig(directory+'charge_integral_mip_sphere.png')
# MIP phase of an ellipsoid:
phase_map_mip_ellipsoid = pm_ele(projector(mag_data_ellipsoid))
phase_map_mip_ellipsoid.save_to_txt(directory+'phase_map_mip_ellipsoid.txt')
axis, _ = phase_map_mip_ellipsoid.display_combined(gain=gain)
axis.axvline(l, b/dim[1], t/dim[1], linewidth=2, color='g')
axis.axvline(r, b/dim[1], t/dim[1], linewidth=2, color='g')
axis.axhline(b, l/dim[2], r/dim[2], linewidth=2, color='g')
axis.axhline(t, l/dim[2], r/dim[2], linewidth=2, color='g')
axis.arrow(l+(r-l)/2, b, 0, t-b, length_includes_head=True,
head_width=(r-l)/10, head_length=(r-l)/10, fc='g', ec='g')
plt.savefig(directory+'phase_map_mip_ellipsoid.png')
x, y = calculate_charge_batch(phase_map_mip_ellipsoid)
np.savetxt(directory+'charge_integral_mip_ellipsoid.txt', np.array([x, y]).T)
plt.figure()
plt.plot(x, y)
plt.savefig(directory+'charge_integral_mip_ellipsoid.png')
# -*- coding: utf-8 -*-
"""Created on Fri Jan 24 11:17:11 2014 @author: Jan"""
import os
import numpy as np
from numpy import pi
import matplotlib.pyplot as plt
from matplotlib._pylab_helpers import Gcf
from pylab import griddata
import pickle
import vtk
from tqdm import tqdm
import pyramid
from pyramid.magdata import MagData
from pyramid.projector import YTiltProjector, XTiltProjector
from pyramid.kernel import Kernel
from pyramid.phasemapper import PhaseMapperRDFC
from pyramid.phasemap import PhaseMap
from pyramid.dataset import DataSet
import logging
import logging.config
LOGGING_CONF = os.path.join(os.path.dirname(os.path.realpath(pyramid.__file__)), 'logging.ini')
logging.config.fileConfig(LOGGING_CONF, disable_existing_loggers=False)
###################################################################################################
PATH = '../../output/vtk data/longtube_withcap/CoFeB_tube_cap_4nm'
b_0 = 1.54
force_calculation = False
count = 16
dim_uv_x = (500, 100)
dim_uv_y = (100, 500)
gain = 8
###################################################################################################
# Load vtk-data:
if force_calculation or not os.path.exists(PATH+'.pickle'):
# Setting up reader:
reader = vtk.vtkDataSetReader()
reader.SetFileName(PATH+'.vtk')
reader.ReadAllScalarsOn()
reader.ReadAllVectorsOn()
reader.Update()
# Getting output:
output = reader.GetOutput()
# Reading points and vectors:
size = output.GetNumberOfPoints()
vtk_points = output.GetPoints().GetData()
vtk_vectors = output.GetPointData().GetVectors()
# Converting points to numpy array:
point_array = np.zeros(vtk_points.GetSize())
vtk_points.ExportToVoidPointer(point_array)
point_array = np.reshape(point_array, (-1, 3))
# Converting vectors to numpy array:
vector_array = np.zeros(vtk_points.GetSize())
vtk_vectors.ExportToVoidPointer(vector_array)
vector_array = np.reshape(vector_array, (-1, 3))
# Combining data:
data = np.hstack((point_array, vector_array))
with open(PATH+'.pickle', 'w') as pf:
pickle.dump(data, pf)
else:
with open(PATH+'.pickle') as pf:
data = pickle.load(pf)
###################################################################################################
# Interpolate on regular grid:
if force_calculation or not os.path.exists(PATH+'.nc'):
# Determine the size of the object:
x_min, x_max = data[:, 0].min(), data[:, 0].max()
y_min, y_max = data[:, 1].min(), data[:, 1].max()
z_min, z_max = data[:, 2].min(), data[:, 2].max()
x_diff, y_diff, z_diff = np.ptp(data[:, 0]), np.ptp(data[:, 1]), np.ptp(data[:, 2])
x_cent, y_cent, z_cent = x_min+x_diff/2., y_min+y_diff/2., z_min+z_diff/2.
# Filling zeros:
iz_x = np.concatenate([np.linspace(-2.95, -2.95, 20),
np.linspace(-2.95, 0, 20),
np.linspace(0, 2.95, 20),
np.linspace(2.95, 2.95, 20),
np.linspace(2.95, 0, 20),
np.linspace(0, -2.95, 20), ])
iz_y = np.concatenate([np.linspace(-1.70, 1.70, 20),
np.linspace(1.70, 3.45, 20),
np.linspace(3.45, 1.70, 20),
np.linspace(1.70, -1.70, 20),
np.linspace(-1.70, -3.45, 20),
np.linspace(-3.45, -1.70, 20), ])
# Find unique z-slices:
zs_unique = np.unique(data[:, 2])
# Determine the grid spacing (in 1/10 nm):
a = (zs_unique[1] - zs_unique[0])
# Set actual z-slices:
zs = np.arange(z_min, z_max, a)
# Create regular grid:
xs = np.arange(x_cent-x_diff, x_cent+x_diff, a)
ys = np.arange(y_cent-y_diff, y_cent+y_diff, a)
xx, yy = np.meshgrid(xs, ys)
# Create empty magnitude:
magnitude = np.zeros((3, len(zs), len(ys), len(xs)))
# Go over all slices:
for i, z in tqdm(enumerate(zs), total=len(zs)):
z_slice = data[np.abs(data[:, 2]-z) <= a/2., :]
weights = 1 - np.abs(z_slice[:, 2]-z)*2/a
for j in range(3): # For all 3 components!
if z <= 0:
grid_x = np.concatenate([z_slice[:, 0], iz_x])
grid_y = np.concatenate([z_slice[:, 1], iz_y])
grid_z = np.concatenate([weights*z_slice[:, 3+j], np.zeros(len(iz_x))])
else:
grid_x = z_slice[:, 0]
grid_y = z_slice[:, 1]
grid_z = weights*z_slice[:, 3+j]
grid = griddata(grid_x, grid_y, grid_z, xx, yy)
magnitude[j, i, :, :] = grid.filled(fill_value=0)
a = a*10 # convert to nm
# Creating MagData object and save it as netcdf-file:
mag_data = MagData(a, np.pad(magnitude, ((0, 0), (0, 0), (0, 1), (0, 1)), mode='constant',
constant_values=0))
mag_data.save_to_netcdf4(PATH+'.nc')
else:
mag_data = MagData.load_from_netcdf4(PATH+'.nc')
###################################################################################################
mag_data_scaled = mag_data.copy()
mag_data_scaled.scale_down()
mag_data_scaled.save_to_netcdf4(PATH+'_scaled.nc')
# Create tilts and projectors:
tilts_full = np.linspace(-pi/2, pi/2, num=count/2, endpoint=False)
tilts_miss = np.linspace(-pi/3, pi/3, num=count/2, endpoint=False)
projectors_y = [YTiltProjector(mag_data_scaled.dim, tilt, dim_uv=dim_uv_y) for tilt in tilts_miss]
projectors_x = [XTiltProjector(mag_data_scaled.dim, tilt, dim_uv=dim_uv_x) for tilt in tilts_miss]
kernel_y = Kernel(mag_data_scaled.a, dim_uv_y, b_0)
kernel_x = Kernel(mag_data_scaled.a, dim_uv_x, b_0)
phase_maps_y = [PhaseMapperRDFC(kernel_y)(proj(mag_data_scaled)) for proj in projectors_y]
phase_maps_x = [PhaseMapperRDFC(kernel_x)(proj(mag_data_scaled)) for proj in projectors_x]
# Create data sets for x and y tilts:
data_set = DataSet(mag_data_scaled.a, mag_data_scaled.dim, b_0)
# Create and append phase maps and projectors:
for i in range(len(phase_maps_y)):
data_set.append(phase_maps_y[i], projectors_y[i])
data_set.append(phase_maps_x[i], projectors_x[i])
# Display phase maps:
data_set.display_combined(gain=gain, interpolation='bilinear')
# Save figures:
figures = [manager.canvas.figure for manager in Gcf.get_all_fig_managers()]
for i, figure in enumerate(figures):
figure.savefig(PATH+'_figure{}.png'.format(i))
plt.close('all')
###################################################################################################
# Close ups:
dim = (300, 72, 72)
dim_uv = (600, 150)
angles = [0, 20, 40, 60, -20, -40, -60]
# Turn magnetization around by 90° around z-axis:
for i in range(mag_data.magnitude.shape[1]):
x_rot = np.rot90(mag_data.magnitude[0, i, ...]).copy()
y_rot = np.rot90(mag_data.magnitude[1, i, ...]).copy()
z_rot = np.rot90(mag_data.magnitude[2, i, ...]).copy()
if i == 500:
# import pdb; pdb.set()
mag_data.quiver_plot(ax_slice=i)
plt.savefig(PATH+'_quiver_500_pre.png')
mag_data.magnitude[0, i, ...] = -y_rot
mag_data.magnitude[1, i, ...] = x_rot
mag_data.magnitude[2, i, ...] = z_rot
if i == 100:
mag_data.quiver_plot(ax_slice=i)
plt.savefig(PATH+'_quiver_500_post.png')
# Iterate over all angles:
for angle in angles:
angle_rad = angle * np.pi/180
shift = int(np.abs(80*np.sin(angle_rad)))
projector = XTiltProjector(dim, np.pi/2+angle_rad, dim_uv)
projector_scaled = XTiltProjector((dim[0]/2, dim[1]/2, dim[2]/2), np.pi/2+angle_rad,
(dim_uv[0]/2, dim_uv[1]/2))
# Tip:
mag_data_tip = MagData(mag_data.a, mag_data.magnitude[:, 608:, ...])
PM = PhaseMapperRDFC(Kernel(mag_data.a, projector.dim_uv))
phase_map_tip = PhaseMap(mag_data.a, PM(projector(mag_data_tip)).phase[350-shift:530-shift, :])
phase_map_tip.display_combined('Phase Map Nanowire Tip', gain=gain,
interpolation='bilinear')
plt.savefig(PATH+'_nanowire_tip_xtilt_{}.png'.format(angle))
mag_data_tip.scale_down()
mag_proj_tip = projector_scaled(mag_data_tip)
axis = mag_proj_tip.quiver_plot()
axis.set_xlim(17, 55)
axis.set_ylim(180-shift/2, 240-shift/2)
plt.savefig(PATH+'_nanowire_tip_mag_xtilt_{}.png'.format(angle))
axis = mag_proj_tip.quiver_plot(log=True)
axis.set_xlim(17, 55)
axis.set_ylim(180-shift/2, 240-shift/2)
plt.savefig(PATH+'_nanowire_tip_mag_log_xtilt_{}.png'.format(angle))
# Bottom:
mag_data_bot = MagData(mag_data.a, mag_data.magnitude[:, :300, ...])
PM = PhaseMapperRDFC(Kernel(mag_data.a, projector.dim_uv))
phase_map_tip = PhaseMap(mag_data.a, PM(projector(mag_data_bot)).phase[50+shift:225+shift, :])
phase_map_tip.display_combined('Phase Map Nanowire Bottom', gain=gain,
interpolation='bilinear')
plt.savefig(PATH+'_nanowire_bot_xtilt_{}_no_frame.png'.format(angle))
mag_data_bot.scale_down()
mag_proj_bot = projector_scaled(mag_data_bot)
axis = mag_proj_bot.quiver_plot()
axis.set_xlim(17, 55)
axis.set_ylim(50+shift/2, 110+shift/2)
plt.savefig(PATH+'_nanowire_bot_mag_xtilt_{}.png'.format(angle))
axis = mag_proj_bot.quiver_plot(log=True)
axis.set_xlim(17, 55)
axis.set_ylim(50+shift/2, 110+shift/2)
plt.savefig(PATH+'_nanowire_bot_mag_log_xtilt_{}.png'.format(angle))
# Close plots:
plt.close('all')
# -*- coding: utf-8 -*-
"""Created on Fri Jan 24 11:17:11 2014 @author: Jan"""
import os
import numpy as np
import matplotlib.pyplot as plt
from pylab import griddata
import pickle
import vtk
from tqdm import tqdm
import pyramid
from pyramid.magdata import MagData
from pyramid.phasemapper import pm
import logging
import logging.config
LOGGING_CONF = os.path.join(os.path.dirname(os.path.realpath(pyramid.__file__)), 'logging.ini')
logging.config.fileConfig(LOGGING_CONF, disable_existing_loggers=False)
###################################################################################################
PATH = '../../output/vtk data/tube_90x30x50_sat_edge_equil.gmr'
b_0 = 1.54
gain = 12
force_calculation = False
###################################################################################################
# Load vtk-data:
if force_calculation or not os.path.exists(PATH+'.pickle'):
# Setting up reader:
reader = vtk.vtkDataSetReader()
reader.SetFileName(PATH+'.vtk')
reader.ReadAllScalarsOn()
reader.ReadAllVectorsOn()
reader.Update()
# Getting output:
output = reader.GetOutput()
# Reading points and vectors:
size = output.GetNumberOfPoints()
vtk_points = output.GetPoints().GetData()
vtk_vectors = output.GetPointData().GetVectors()
# Converting points to numpy array:
point_array = np.zeros(vtk_points.GetSize())
vtk_points.ExportToVoidPointer(point_array)
point_array = np.reshape(point_array, (-1, 3))
# Converting vectors to numpy array:
vector_array = np.zeros(vtk_points.GetSize())
vtk_vectors.ExportToVoidPointer(vector_array)
vector_array = np.reshape(vector_array, (-1, 3))
# Combining data:
data = np.hstack((point_array, vector_array))
with open(PATH+'.pickle', 'w') as pf:
pickle.dump(data, pf)
else:
with open(PATH+'.pickle') as pf:
data = pickle.load(pf)
# Scatter plot of all x-y-coordinates
axis = plt.figure().add_subplot(1, 1, 1)
axis.scatter(data[:, 0], data[:, 1])
plt.show()
###################################################################################################
# Interpolate on regular grid:
if force_calculation or not os.path.exists(PATH+'.nc'):
# Find unique z-slices:
zs = np.unique(data[:, 2])
# Determine the grid spacing:
a = zs[1] - zs[0]
# Determine the size of object:
x_min, x_max = data[:, 0].min(), data[:, 0].max()
y_min, y_max = data[:, 1].min(), data[:, 1].max()
z_min, z_max = data[:, 2].min(), data[:, 2].max()
x_diff, y_diff, z_diff = np.ptp(data[:, 0]), np.ptp(data[:, 1]), np.ptp(data[:, 2])
x_cent, y_cent, z_cent = x_min+x_diff/2., y_min+y_diff/2., z_min+z_diff/2.
# Create regular grid
xs = np.arange(x_cent-x_diff, x_cent+x_diff, a)
ys = np.arange(y_cent-y_diff, y_cent+y_diff, a)
o, p = np.meshgrid(xs, ys)
# Create empty magnitude:
magnitude = np.zeros((3, len(zs), len(ys), len(xs)))
# WITH MASKING OF THE CENTER (SYMMETRIC):
iz_x = np.concatenate([np.linspace(-4.95, -4.95, 50),
np.linspace(-4.95, 0, 50),
np.linspace(0, 4.95, 50),
np.linspace(4.95, 4.95, 50),
np.linspace(-4.95, 0, 50),
np.linspace(0, 4.95, 50), ])
iz_y = np.concatenate([np.linspace(-2.88, 2.88, 50),
np.linspace(2.88, 5.7, 50),
np.linspace(5.7, 2.88, 50),
np.linspace(2.88, -2.88, 50),
np.linspace(-2.88, -5.7, 50),
np.linspace(-5.7, -2.88, 50), ])
for i, z in tqdm(enumerate(zs), total=len(zs)):
subdata = data[data[:, 2] == z, :]
for j in range(3): # For all 3 components!
gridded_subdata = griddata(np.concatenate([subdata[:, 0], iz_x]),
np.concatenate([subdata[:, 1], iz_y]),
np.concatenate([subdata[:, 3 + j], np.zeros(len(iz_x))]),
o, p)
magnitude[j, i, :, :] = gridded_subdata.filled(fill_value=0)
# # WITH MASKING OF THE CENTER (ASYMMETRIC):
# iz_x = np.concatenate([np.linspace(-5.88, -5.88, 50),
# np.linspace(-5.88, 0, 50),
# np.linspace(0, 5.88, 50),
# np.linspace(5.88, 5.88, 50),
# np.linspace(5.88, 0, 50),
# np.linspace(0, -5.88, 50),])
# iz_y = np.concatenate([np.linspace(-2.10, 4.50, 50),
# np.linspace(4.50, 7.90, 50),
# np.linspace(7.90, 4.50, 50),
# np.linspace(4.50, -2.10, 50),
# np.linspace(-2.10, -5.50, 50),
# np.linspace(-5.50, -2.10, 50), ])
# for i, z in tqdm(enumerate(zs), total=len(zs)):
# subdata = data[data[:, 2] == z, :]
# for j in range(3): # For all 3 components!
# gridded_subdata = griddata(np.concatenate([subdata[:, 0], iz_x]),
# np.concatenate([subdata[:, 1], iz_y]),
# np.concatenate([subdata[:, 3 + j], np.zeros(len(iz_x))]),
# o, p)
# magnitude[j, i, :, :] = gridded_subdata.filled(fill_value=0)
# # WITHOUT MASKING OF THE CENTER:
# for i, z in tqdm(enumerate(zs), total=len(zs)):
# subdata = data[data[:, 2] == z, :]
# for j in range(3): # For all 3 components!
# gridded_subdata = griddata(subdata[:, 0], subdata[:, 1], subdata[:, 3 + j], o, p)
# magnitude[j, i, :, :] = gridded_subdata.filled(fill_value=0)
# Creating MagData object:
mag_data = MagData(0.2*10, magnitude)
mag_data.save_to_netcdf4(PATH+'.nc')
else:
mag_data = MagData.load_from_netcdf4(PATH+'.nc')
mag_data.quiver_plot()
###################################################################################################
# Phasemapping:
phase_map = pm(mag_data)
(-phase_map).display_combined(title=r'Combined Plot (B$_0$={} T, Cos x {})'.format(b_0, gain),
gain=gain)
plt.savefig(PATH+'_{}T_cosx{}.png'.format(b_0, gain))
(-phase_map).display_combined(title=r'Combined Plot (B$_0$={} T, Cos x {})'.format(b_0, gain),
gain=gain, interpolation='bilinear')
plt.savefig(PATH+'_{}T_cosx{}_smooth.png'.format(b_0, gain))
# -*- coding: utf-8 -*-
"""
Created on Mon Aug 11 08:41:23 2014
@author: Jan
"""
import os
import numpy as np
from pyDM3reader import DM3lib as dm3
import matplotlib.pyplot as plt
import pyramid
from pyramid.phasemap import PhaseMap
from pyramid.phasemapper import pm
import pyramid.reconstruction as rc
from time import clock
import logging
import logging.config
LOGGING_CONF = os.path.join(os.path.dirname(os.path.realpath(pyramid.__file__)), 'logging.ini')
logging.config.fileConfig(LOGGING_CONF, disable_existing_loggers=False)
###################################################################################################
threshold = 1
a = 1.0 # in nm
gain = 5
b_0 = 1
inter = 'none'
dim_small = (64, 64)
smoothed_pictures = True
lam = 1E-4
order = 1
log = True
PATH = '../../output/zi-an/'
if not os.path.exists(PATH+'%.0e/'%lam):
os.makedirs(PATH+'%.0e/'%lam)
###################################################################################################
# Read in files:
if smoothed_pictures:
dm3_2_mag = dm3.DM3(PATH+'Output334_hw512.dm3').image
dm3_4_mag = dm3.DM3(PATH+'Output333_hw512.dm3').image
dm3_2_ele = dm3.DM3(PATH+'Output336.dm3').image
dm3_4_ele = dm3.DM3(PATH+'Output335.dm3').image
else:
dm3_2_mag = dm3.DM3(PATH+'18a_0102mag_ub140_62k_q3_pha_01_sb180_sc512_vf3_med5.dm3').image
dm3_4_mag = dm3.DM3(PATH+'07_0102mag60_q3_pha_01_sb280_sc512_vf3_med5.dm3').image
dm3_2_ele = dm3.DM3(PATH+'18a_0102ele_ub140_62k_q3_pha_01_sb180_sc512_vf3_med5.dm3').image
dm3_4_ele = dm3.DM3(PATH+'07_0102ele60_q3_pha_01_sb280_sc512_vf3_med5.dm3').image
# Construct phase maps and masks
phase_map_2 = PhaseMap(a, np.array(dm3_2_mag.resize(dim_small))-2.546)
phase_map_2.display_combined(gain=gain, interpolation=inter)
plt.savefig(PATH+'%.0e/phase_map_2part.png'%lam)
mask_2 = np.expand_dims(np.where(np.array(dm3_2_ele.resize(dim_small)) >= threshold,
True, False), axis=0)
phase_map_4 = PhaseMap(a, np.array(dm3_4_mag.resize(dim_small))+0.101)
phase_map_4.display_combined(gain=gain, interpolation=inter)
plt.savefig(PATH+'%.0e/phase_map_4part.png'%lam)
mask_4 = np.expand_dims(np.where(np.array(dm3_4_ele.resize(dim_small)) >= threshold,
True, False), axis=0)
# Reconstruct the magnetic distribution:
tic = clock()
mag_data_rec_2 = rc.optimize_simple_leastsq(phase_map_2, mask_2, b_0, lam=lam, order=order)
print '2 particle reconstruction time:', clock() - tic
tic = clock()
mag_data_rec_4 = rc.optimize_simple_leastsq(phase_map_4, mask_4, b_0, lam=lam, order=order)
print '4 particle reconstruction time:', clock() - tic
# Display the reconstructed phase map and holography image:
phase_map_rec_2 = pm(mag_data_rec_2)
phase_map_rec_2.display_combined('Reconstr. Distribution', gain=gain, interpolation=inter)
plt.savefig(PATH+'%.0e/phase_map_2part_rec.png'%lam)
phase_map_rec_4 = pm(mag_data_rec_4)
phase_map_rec_4.display_combined('Reconstr. Distribution', gain=gain, interpolation=inter)
plt.savefig(PATH+'%.0e/phase_map_4part_rec.png'%lam)
# Plot the magnetization:
axis = (mag_data_rec_2*(1/mag_data_rec_2.magnitude.max())).quiver_plot()
axis.set_xlim(20, 45)
axis.set_ylim(20, 45)
plt.savefig(PATH+'%.0e/mag_data_2part.png'%lam)
axis = (mag_data_rec_4*(1/mag_data_rec_4.magnitude.max())).quiver_plot()
axis.set_xlim(20, 45)
axis.set_ylim(20, 45)
plt.savefig(PATH+'%.0e/mag_data_4part.png'%lam)
# Display the Phase:
phase_diff_2 = phase_map_rec_2-phase_map_2
phase_diff_2.display_phase('Difference')
plt.savefig(PATH+'%.0e/phase_map_2part_diff.png'%lam)
phase_diff_4 = phase_map_rec_4-phase_map_4
phase_diff_4.display_phase('Difference')
plt.savefig(PATH+'%.0e/phase_map_4part_diff.png'%lam)
# Get the average difference from the experimental results:
print 'Average difference (2 cubes):', np.average(phase_diff_2.phase)
print 'Average difference (4 cubes):', np.average(phase_diff_4.phase)
# Plot holographic contour maps with overlayed magnetic distributions:
axis = phase_map_rec_2.display_holo('Magnetization Overlay', gain=0.1, interpolation=inter)
mag_data_rec_2.quiver_plot(axis=axis)
axis = plt.gca()
axis.set_xlim(20, 45)
axis.set_ylim(20, 45)
plt.savefig(PATH+'%.0e/phase_map_2part_holo.png'%lam)
axis = phase_map_rec_4.display_holo('Magnetization Overlay', gain=0.1, interpolation=inter)
mag_data_rec_4.quiver_plot(axis=axis)
axis = plt.gca()
axis.set_xlim(20, 45)
axis.set_ylim(20, 45)
plt.savefig(PATH+'%.0e/phase_map_4part_holo.png'%lam)
axis = phase_map_rec_2.display_holo('Magnetization Overlay', gain=0.1, interpolation=inter)
mag_data_rec_2.quiver_plot(axis=axis, log=log)
axis = plt.gca()
axis.set_xlim(20, 45)
axis.set_ylim(20, 45)
plt.savefig(PATH+'%.0e/phase_map_2part_holo_log.png'%lam)
axis = phase_map_rec_4.display_holo('Magnetization Overlay', gain=0.1, interpolation=inter)
mag_data_rec_4.quiver_plot(axis=axis, log=log)
axis = plt.gca()
axis.set_xlim(20, 45)
axis.set_ylim(20, 45)
plt.savefig(PATH+'%.0e/phase_map_4part_holo_log.png'%lam)
#! python
# -*- coding: utf-8 -*-
"""Create magnetic distribution of alternating filaments"""
import os
import numpy as np
from numpy import pi
import pyramid
import pyramid.magcreator as mc
from pyramid.magdata import MagData
from pyramid.phasemapper import pm
import logging
import logging.config
LOGGING_CONF = os.path.join(os.path.dirname(os.path.realpath(pyramid.__file__)), 'logging.ini')
logging.config.fileConfig(LOGGING_CONF, disable_existing_loggers=False)
directory = '../../output/magnetic distributions'
if not os.path.exists(directory):
os.makedirs(directory)
# Input parameters:
filename = directory + '/mag_dist_alt_filaments.txt'
dim = (1, 21, 21) # in px (z, y, x)
a = 10.0 # in nm
phi = pi/2
spacing = 5
# Create empty MagData object:
mag_data = MagData(a, np.zeros((3,)+dim))
count = int((dim[1]-1) / spacing) + 1
for i in range(count):
pos = i * spacing
mag_shape = mc.Shapes.filament(dim, (0, pos))
mag_data += MagData(a, mc.create_mag_dist_homog(mag_shape, phi))
phi *= -1 # Switch the angle
# Plot magnetic distribution
mag_data.quiver_plot()
mag_data.save_to_llg(filename)
pm(mag_data).display_phase()
#! python
# -*- coding: utf-8 -*-
"""Create a core-shell disc."""
import os
import numpy as np
import matplotlib.pyplot as plt
import pyramid
import pyramid.magcreator as mc
from pyramid.phasemapper import pm
from pyramid.magdata import MagData
import logging
import logging.config
LOGGING_CONF = os.path.join(os.path.dirname(os.path.realpath(pyramid.__file__)), 'logging.ini')
logging.config.fileConfig(LOGGING_CONF, disable_existing_loggers=False)
directory = '../../output/magnetic distributions'
if not os.path.exists(directory):
os.makedirs(directory)
# Input parameters:
filename = directory + '/mag_dist_core_shell_disc.txt'
a = 1.0 # in nm
dim = (32, 32, 32)
center = (dim[0]/2-0.5, int(dim[1]/2)-0.5, int(dim[2]/2)-0.5)
radius_core = dim[1]/8
radius_shell = dim[1]/4
height = dim[0]/2
# Create magnetic shape:
mag_shape_core = mc.Shapes.disc(dim, center, radius_core, height)
mag_shape_outer = mc.Shapes.disc(dim, center, radius_shell, height)
mag_shape_shell = np.logical_xor(mag_shape_outer, mag_shape_core)
mag_data = MagData(a, mc.create_mag_dist_vortex(mag_shape_shell, magnitude=0.75))
mag_data += MagData(a, mc.create_mag_dist_homog(mag_shape_core, phi=0, theta=0))
mag_data.quiver_plot('z-projection', proj_axis='z')
mag_data.quiver_plot('y-projection', proj_axis='y')
mag_data.save_to_llg(filename)
mag_data.quiver_plot3d()
phase_map_z = pm(mag_data)
phase_map_x = pm(mag_data)
phase_map_z.display_holo('Core-Shell structure (z-proj.)', gain=1E2)
phase_axis, holo_axis = phase_map_x.display_combined('Core-Shell structure (x-proj.)', gain=1E3)
phase_axis.set_xlabel('y [nm]')
phase_axis.set_ylabel('z [nm]')
holo_axis.set_xlabel('y-axis [px]')
holo_axis.set_ylabel('z-axis [px]')
phase_slice_z = phase_map_z.phase[dim[1]/2, :]
phase_slice_x = phase_map_x.phase[dim[0]/2, :]
fig = plt.figure()
fig.add_subplot(1, 1, 1)
plt.plot(range(dim[2]), phase_slice_z)
plt.title('Phase slice along x for z-projection')
fig = plt.figure()
fig.add_subplot(1, 1, 1)
plt.plot(range(dim[1]), phase_slice_x)
plt.title('Phase slice along y for x-projection')
#! python
# -*- coding: utf-8 -*-
"""Create a core-shell sphere."""
import os
import numpy as np
import matplotlib.pyplot as plt
import pyramid
import pyramid.magcreator as mc
from pyramid.phasemapper import pm
from pyramid.magdata import MagData
import logging
import logging.config
LOGGING_CONF = os.path.join(os.path.dirname(os.path.realpath(pyramid.__file__)), 'logging.ini')
logging.config.fileConfig(LOGGING_CONF, disable_existing_loggers=False)
directory = '../../output/magnetic distributions'
if not os.path.exists(directory):
os.makedirs(directory)
# Input parameters:
filename = directory + '/mag_dist_core_shell_sphere.txt'
a = 1.0 # in nm
dim = (32, 32, 32)
center = (dim[0]/2-0.5, int(dim[1]/2)-0.5, int(dim[2]/2)-0.5)
radius_core = dim[1]/8
radius_shell = dim[1]/4
# Create magnetic shape:
mag_shape_sphere = mc.Shapes.sphere(dim, center, radius_shell)
mag_shape_disc = mc.Shapes.disc(dim, center, radius_core, height=dim[0])
mag_shape_core = np.logical_and(mag_shape_sphere, mag_shape_disc)
mag_shape_shell = np.logical_and(mag_shape_sphere, np.logical_not(mag_shape_core))
mag_data = MagData(a, mc.create_mag_dist_vortex(mag_shape_shell, magnitude=0.75))
mag_data += MagData(a, mc.create_mag_dist_homog(mag_shape_core, phi=0, theta=0))
mag_data.quiver_plot('z-projection', proj_axis='z')
mag_data.quiver_plot('x-projection', proj_axis='x')
mag_data.save_to_llg(filename)
mag_data.quiver_plot3d()
phase_map_z = pm(mag_data)
phase_map_x = pm(mag_data)
phase_map_z.display_holo('Core-Shell structure (z-proj.)', gain=1E2)
phase_axis, holo_axis = phase_map_x.display_combined('Core-Shell structure (x-proj.)', gain=1E3)
phase_axis.set_xlabel('y [nm]')
phase_axis.set_ylabel('z [nm]')
holo_axis.set_xlabel('y-axis [px]')
holo_axis.set_ylabel('z-axis [px]')
phase_slice_z = phase_map_z.phase[dim[1]/2, :]
phase_slice_x = phase_map_x.phase[dim[0]/2, :]
fig = plt.figure()
fig.add_subplot(1, 1, 1)
plt.plot(range(dim[2]), phase_slice_z)
plt.title('Phase slice along x for z-projection')
fig = plt.figure()
fig.add_subplot(1, 1, 1)
plt.plot(range(dim[1]), phase_slice_x)
plt.title('Phase slice along y for x-projection')
#! python
# -*- coding: utf-8 -*-
"""Create the Pyramid-Logo."""
import os
import numpy as np
from numpy import pi
import pyramid
import pyramid.magcreator as mc
from pyramid.kernel import Kernel
from pyramid.phasemapper import PhaseMapperRDFC
from pyramid.magdata import MagData
from pyramid.projector import SimpleProjector
import logging
import logging.config
LOGGING_CONF = os.path.join(os.path.dirname(os.path.realpath(pyramid.__file__)), 'logging.ini')
logging.config.fileConfig(LOGGING_CONF, disable_existing_loggers=False)
# Input parameters:
a = 10.0 # in nm
phi = -pi/2 # in rad
gain = 10
dim = (1, 128, 128)
# Create magnetic shape:
mag_shape = np.zeros(dim)
x = range(dim[2])
y = range(dim[1])
xx, yy = np.meshgrid(x, y)
bottom = (yy >= 0.25*dim[1])
left = (yy <= 0.75/0.5 * dim[1]/dim[2] * xx)
right = np.fliplr(left)
mag_shape[0, ...] = np.logical_and(np.logical_and(left, right), bottom)
# Create magnetic data, project it, get the phase map and display the holography image:
mag_data = MagData(a, mc.create_mag_dist_homog(mag_shape, phi))
mag_data.quiver_plot()
projector = SimpleProjector(dim)
phase_map = PhaseMapperRDFC(Kernel(a, projector.dim_uv))(mag_data)
phase_map.display_holo('PYRAMID - LOGO', gain, interpolation='bilinear')
phase_map.display_combined()
#! python
# -*- coding: utf-8 -*-
"""Create multiple magnetic distributions."""
import os
from numpy import pi
import pyramid
import pyramid.magcreator as mc
from pyramid.magdata import MagData
from pyramid.phasemapper import pm
import logging
import logging.config
LOGGING_CONF = os.path.join(os.path.dirname(os.path.realpath(pyramid.__file__)), 'logging.ini')
logging.config.fileConfig(LOGGING_CONF, disable_existing_loggers=False)
directory = '../../output/magnetic distributions'
if not os.path.exists(directory):
os.makedirs(directory)
# Input parameters:
filename = directory + '/mag_dist_multiple_samples.txt'
a = 10.0 # nm
dim = (64, 128, 128)
# Slab:
center = (32, 32, 32) # in px (z, y, x), index starts with 0!
width = (48, 48, 48) # in px (z, y, x)
mag_shape_slab = mc.Shapes.slab(dim, center, width)
# Disc:
center = (32, 32, 96) # in px (z, y, x), index starts with 0!
radius = 24 # in px
height = 24 # in px
mag_shape_disc = mc.Shapes.disc(dim, center, radius, height)
# Sphere:
center = (32, 96, 64) # in px (z, y, x), index starts with 0!
radius = 24 # in px
mag_shape_sphere = mc.Shapes.sphere(dim, center, radius)
# Create empty MagData object and add magnetized objects:
mag_data = MagData(a, mc.create_mag_dist_homog(mag_shape_slab, pi/4))
mag_data += MagData(a, mc.create_mag_dist_homog(mag_shape_disc, pi/2))
mag_data += MagData(a, mc.create_mag_dist_homog(mag_shape_sphere, pi))
# Plot the magnetic distribution, phase map and holographic contour map:
mag_data.quiver_plot()
mag_data.save_to_llg(filename)
phase_map = pm(mag_data)
phase_map.display_combined(interpolation='bilinear')
#! python
# -*- coding: utf-8 -*-
"""Create random magnetic distributions."""
import random as rnd
import os
import numpy as np
from numpy import pi
import pyramid
import pyramid.magcreator as mc
from pyramid.magdata import MagData
from pyramid.phasemapper import pm
import logging
import logging.config
LOGGING_CONF = os.path.join(os.path.dirname(os.path.realpath(pyramid.__file__)), 'logging.ini')
logging.config.fileConfig(LOGGING_CONF, disable_existing_loggers=False)
directory = '../../output/magnetic distributions'
if not os.path.exists(directory):
os.makedirs(directory)
# Input parameters:
filename = directory + '/mag_dist_random_pixels.txt'
# Input parameters:
count = 10
dim = (1, 128, 128)
a = 10 # in nm
rnd.seed(12)
# Create empty MagData object and add pixels:
mag_data = MagData(a, np.zeros((3,)+dim))
for i in range(count):
pixel = (rnd.randrange(dim[0]), rnd.randrange(dim[1]), rnd.randrange(dim[2]))
mag_shape = mc.Shapes.pixel(dim, pixel)
phi = 2 * pi * rnd.random()
magnitude = 1
mag_data += MagData(a, mc.create_mag_dist_homog(mag_shape, phi, magnitude=magnitude))
# Plot magnetic distribution, phase map and holographic contour map:
mag_data.quiver_plot()
mag_data.save_to_llg(filename)
phase_map = pm(mag_data)
phase_map.display_combined()
#! python
# -*- coding: utf-8 -*-
"""Create random magnetic distributions."""
import random as rnd
import os
import numpy as np
from numpy import pi
import pyramid
import pyramid.magcreator as mc
from pyramid.magdata import MagData
from pyramid.phasemapper import pm
import logging
import logging.config
LOGGING_CONF = os.path.join(os.path.dirname(os.path.realpath(pyramid.__file__)), 'logging.ini')
logging.config.fileConfig(LOGGING_CONF, disable_existing_loggers=False)
directory = '../../output/magnetic distributions'
if not os.path.exists(directory):
os.makedirs(directory)
# Input parameters:
filename = directory + '/mag_dist_random_pixels.txt'
count = 10
dim = (1, 128, 128)
a = 10 # in nm
rnd.seed(42)
w_max = 10
# Create empty MagData object and add slabs:
mag_data = MagData(a, np.zeros((3,)+dim))
for i in range(count):
width = (1, rnd.randint(1, w_max), rnd.randint(1, w_max))
center = (rnd.randrange(int(width[0]/2), dim[0]-int(width[0]/2)),
rnd.randrange(int(width[1]/2), dim[1]-int(width[1]/2)),
rnd.randrange(int(width[2]/2), dim[2]-int(width[2]/2)))
mag_shape = mc.Shapes.slab(dim, center, width)
phi = 2 * pi * rnd.random()
magnitude = rnd.random()
mag_data += MagData(a, mc.create_mag_dist_homog(mag_shape, phi, magnitude=magnitude))
# Plot magnetic distribution, phase map and holographic contour map:
mag_data.quiver_plot()
mag_data.save_to_llg(filename)
phase_map = pm(mag_data)
phase_map.display_combined()
#! python
# -*- coding: utf-8 -*-
"""Create magnetic distributions with simple geometries."""
import os
from numpy import pi
import pyramid
import pyramid.magcreator as mc
from pyramid.magdata import MagData
from pyramid.phasemapper import pm
import logging
import logging.config
LOGGING_CONF = os.path.join(os.path.dirname(os.path.realpath(pyramid.__file__)), 'logging.ini')
logging.config.fileConfig(LOGGING_CONF, disable_existing_loggers=False)
directory = '../../output/magnetic distributions'
if not os.path.exists(directory):
os.makedirs(directory)
###################################################################################################
# Input parameters:
key = 'slab'
###################################################################################################
filename = directory + '/mag_dist_' + key + '.txt'
dim = (32, 32, 32) # in px (z, y, x)
a = 1.0 # in nm
phi = pi/4
# Geometry parameters:
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)
radius = dim[2]/4 # in px
height = dim[0]/2 # in px
pos = (0, dim[1]/2) # in px (tuple of length 2)
pixel = (0, 0, 1) # in px (z, y, x), index starts with 0!
# Determine the magnetic shape:
if key == 'slab':
mag_shape = mc.Shapes.slab(dim, center, width)
elif key == 'disc':
mag_shape = mc.Shapes.disc(dim, center, radius, height)
elif key == 'sphere':
mag_shape = mc.Shapes.sphere(dim, center, radius)
elif key == 'filament':
mag_shape = mc.Shapes.filament(dim, pos)
elif key == 'pixel':
mag_shape = mc.Shapes.pixel(dim, pixel)
# Create magnetic distribution
mag_data = MagData(a, mc.create_mag_dist_homog(mag_shape, phi, magnitude=0.75))
mag_data.save_to_llg(filename)
mag_data.quiver_plot()
mag_data.quiver_plot3d()
pm(mag_data).display_combined()
#! python
# -*- coding: utf-8 -*-
"""Create a magnetic vortex distribution."""
import os
import matplotlib.pyplot as plt
import pyramid
import pyramid.magcreator as mc
from pyramid.phasemapper import pm
from pyramid.magdata import MagData
import logging
import logging.config
LOGGING_CONF = os.path.join(os.path.dirname(os.path.realpath(pyramid.__file__)), 'logging.ini')
logging.config.fileConfig(LOGGING_CONF, disable_existing_loggers=False)
directory = '../../output/magnetic distributions'
if not os.path.exists(directory):
os.makedirs(directory)
# Input parameters:
filename = directory + '/mag_dist_vortex.txt'
a = 10.0 # in nm
# density = 1
dim = (32, 32, 32)
center = (int(dim[0]/2)-0.5, int(dim[1]/2)-0.5, int(dim[2]/2)-0.5)
print 'center', center
radius = 0.25 * dim[1]
height = dim[0]/4
# Create magnetic shape:
mag_shape = mc.Shapes.disc(dim, center, radius, height)
mag_data = MagData(a, mc.create_mag_dist_vortex(mag_shape, magnitude=0.75))
mag_data.quiver_plot()
mag_data.save_to_llg(filename)
phase_map = pm(mag_data)
phase_map.display_combined(gain=2)
phase_slice = phase_map.phase[dim[1]/2, :]
fig = plt.figure()
fig.add_subplot(111)
plt.plot(range(dim[1]), phase_slice)
mag_data.quiver_plot3d()
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'mag_slicer2.ui'
#
# Created: Sun Aug 31 20:39:52 2014
# by: PyQt4 UI code generator 4.9.6
#
# WARNING! All changes made in this file will be lost!
import sys
from PyQt4 import QtCore, QtGui
from matplotlibwidget import MatplotlibWidget
from pyramid.magdata import MagData
from pyramid.projector import SimpleProjector
from pyramid.phasemapper import PhaseMapperRDFC
from pyramid.kernel import Kernel
try:
_fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
def _fromUtf8(s):
return s
try:
_encoding = QtGui.QApplication.UnicodeUTF8
def _translate(context, text, disambig):
return QtGui.QApplication.translate(context, text, disambig, _encoding)
except AttributeError:
def _translate(context, text, disambig):
return QtGui.QApplication.translate(context, text, disambig)
class UI_MagSlicerMain(QtGui.QWidget):
def __init__(self, parent=None):
QtGui.QWidget.__init__(self, parent)
Form = self
self.setGeometry(100, 100, 1405, 550)
self.setWindowTitle('Mag Slicer')
###########################################################################################
self.verticalLayout = QtGui.QVBoxLayout(Form)
self.verticalLayout.setObjectName(_fromUtf8("verticalLayout"))
self.horizontalLayout = QtGui.QHBoxLayout()
self.horizontalLayout.setObjectName(_fromUtf8("horizontalLayout"))
self.pushButtonLoad = QtGui.QPushButton(Form)
self.pushButtonLoad.setObjectName(_fromUtf8("pushButtonLoad"))
self.horizontalLayout.addWidget(self.pushButtonLoad)
self.checkBoxScale = QtGui.QCheckBox(Form)
self.checkBoxScale.setChecked(True)
self.checkBoxScale.setTristate(False)
self.checkBoxScale.setObjectName(_fromUtf8("checkBoxScale"))
self.horizontalLayout.addWidget(self.checkBoxScale)
self.checkBoxLog = QtGui.QCheckBox(Form)
self.checkBoxLog.setObjectName(_fromUtf8("checkBoxLog"))
self.horizontalLayout.addWidget(self.checkBoxLog)
self.comboBoxSlice = QtGui.QComboBox(Form)
self.comboBoxSlice.setObjectName(_fromUtf8("comboBoxSlice"))
self.comboBoxSlice.addItem(_fromUtf8(""))
self.comboBoxSlice.addItem(_fromUtf8(""))
self.comboBoxSlice.addItem(_fromUtf8(""))
self.horizontalLayout.addWidget(self.comboBoxSlice)
self.labelSlice = QtGui.QLabel(Form)
self.labelSlice.setAlignment(QtCore.Qt.AlignRight | QtCore.Qt.AlignTrailing |
QtCore.Qt.AlignVCenter)
self.labelSlice.setObjectName(_fromUtf8("labelSlice"))
self.horizontalLayout.addWidget(self.labelSlice)
self.spinBoxSlice = QtGui.QSpinBox(Form)
self.spinBoxSlice.setAlignment(QtCore.Qt.AlignRight | QtCore.Qt.AlignTrailing |
QtCore.Qt.AlignVCenter)
self.spinBoxSlice.setMaximum(0)
self.spinBoxSlice.setProperty("value", 0)
self.spinBoxSlice.setObjectName(_fromUtf8("spinBoxSlice"))
self.horizontalLayout.addWidget(self.spinBoxSlice)
self.scrollBarSlice = QtGui.QScrollBar(Form)
sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Fixed)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.scrollBarSlice.sizePolicy().hasHeightForWidth())
self.scrollBarSlice.setSizePolicy(sizePolicy)
self.scrollBarSlice.setMinimumSize(QtCore.QSize(400, 0))
self.scrollBarSlice.setMaximum(0)
self.scrollBarSlice.setOrientation(QtCore.Qt.Horizontal)
self.scrollBarSlice.setObjectName(_fromUtf8("scrollBarSlice"))
self.horizontalLayout.addWidget(self.scrollBarSlice)
self.checkBoxSmooth = QtGui.QCheckBox(Form)
self.checkBoxSmooth.setChecked(True)
self.checkBoxSmooth.setObjectName(_fromUtf8("checkBoxSmooth"))
self.horizontalLayout.addWidget(self.checkBoxSmooth)
self.checkBoxAuto = QtGui.QCheckBox(Form)
self.checkBoxAuto.setChecked(True)
self.checkBoxAuto.setObjectName(_fromUtf8("checkBoxAuto"))
self.horizontalLayout.addWidget(self.checkBoxAuto)
self.labelGain = QtGui.QLabel(Form)
self.labelGain.setObjectName(_fromUtf8("labelGain"))
self.horizontalLayout.addWidget(self.labelGain)
self.spinBoxGain = QtGui.QDoubleSpinBox(Form)
self.spinBoxGain.setEnabled(False)
self.spinBoxGain.setMaximum(1000000.0)
self.spinBoxGain.setSingleStep(0.1)
self.spinBoxGain.setProperty("value", 1.0)
self.spinBoxGain.setObjectName(_fromUtf8("spinBoxGain"))
self.horizontalLayout.addWidget(self.spinBoxGain)
self.verticalLayout.addLayout(self.horizontalLayout)
self.horizontalLayoutPlots = QtGui.QHBoxLayout()
self.horizontalLayoutPlots.setSpacing(0)
self.horizontalLayoutPlots.setSizeConstraint(QtGui.QLayout.SetNoConstraint)
self.horizontalLayoutPlots.setObjectName(_fromUtf8("horizontalLayoutPlots"))
self.mplWidgetMag = MatplotlibWidget(Form)
sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Ignored, QtGui.QSizePolicy.Expanding)
sizePolicy.setHorizontalStretch(10)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.mplWidgetMag.sizePolicy().hasHeightForWidth())
self.mplWidgetMag.setSizePolicy(sizePolicy)
self.mplWidgetMag.setCursor(QtGui.QCursor(QtCore.Qt.ArrowCursor))
self.mplWidgetMag.setLayoutDirection(QtCore.Qt.LeftToRight)
self.mplWidgetMag.setAutoFillBackground(False)
self.mplWidgetMag.setObjectName(_fromUtf8("mplWidgetMag"))
self.horizontalLayoutPlots.addWidget(self.mplWidgetMag)
self.mplWidgetHolo = MatplotlibWidget(Form)
sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Ignored, QtGui.QSizePolicy.Expanding)
sizePolicy.setHorizontalStretch(10)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.mplWidgetHolo.sizePolicy().hasHeightForWidth())
self.mplWidgetHolo.setSizePolicy(sizePolicy)
self.mplWidgetHolo.setObjectName(_fromUtf8("mplWidgetHolo"))
self.horizontalLayoutPlots.addWidget(self.mplWidgetHolo)
self.mplWidgetPhase = MatplotlibWidget(Form)
self.mplWidgetPhase.setEnabled(True)
sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Ignored, QtGui.QSizePolicy.Expanding)
sizePolicy.setHorizontalStretch(10)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.mplWidgetPhase.sizePolicy().hasHeightForWidth())
self.mplWidgetPhase.setSizePolicy(sizePolicy)
self.mplWidgetPhase.setObjectName(_fromUtf8("mplWidgetPhase"))
self.horizontalLayoutPlots.addWidget(self.mplWidgetPhase)
self.verticalLayout.addLayout(self.horizontalLayoutPlots)
###########################################################################################
self.retranslateUi(Form)
self.connect(self.spinBoxSlice, QtCore.SIGNAL(_fromUtf8("editingFinished()")),
self.scrollBarSlice.setValue)
self.connect(self.scrollBarSlice, QtCore.SIGNAL(_fromUtf8("valueChanged(int)")),
self.spinBoxSlice.setValue)
self.connect(self.checkBoxAuto, QtCore.SIGNAL(_fromUtf8("toggled(bool)")),
self.spinBoxGain.setDisabled)
self.connect(self.checkBoxLog, QtCore.SIGNAL(_fromUtf8('clicked()')),
self.update_slice)
self.connect(self.checkBoxScale, QtCore.SIGNAL(_fromUtf8('clicked()')),
self.update_slice)
self.connect(self.spinBoxSlice, QtCore.SIGNAL(_fromUtf8('valueChanged(int)')),
self.update_slice)
self.connect(self.comboBoxSlice, QtCore.SIGNAL(_fromUtf8('currentIndexChanged(int)')),
self.update_phase)
self.connect(self.spinBoxGain, QtCore.SIGNAL(_fromUtf8('editingFinished()')),
self.update_phase)
self.connect(self.checkBoxAuto, QtCore.SIGNAL(_fromUtf8('toggled(bool)')),
self.update_phase)
self.connect(self.checkBoxSmooth, QtCore.SIGNAL(_fromUtf8('toggled(bool)')),
self.update_phase)
self.connect(self.pushButtonLoad, QtCore.SIGNAL(_fromUtf8('clicked()')),
self.load)
QtCore.QMetaObject.connectSlotsByName(Form)
self.mplWidgetMag.axes.set_visible(False)
self.mplWidgetHolo.axes.set_visible(False)
self.mplWidgetPhase.axes.set_visible(False)
self.mag_data_loaded = False
def retranslateUi(self, Form):
###########################################################################################
Form.setWindowTitle(_translate("Form", "Mag Slicer", None))
self.pushButtonLoad.setText(_translate("Form", "Laden", None))
self.checkBoxScale.setText(_translate("Form", "Scaled", None))
self.checkBoxLog.setText(_translate("Form", "Log", None))
self.comboBoxSlice.setItemText(0, _translate("Form", "xy-plane", None))
self.comboBoxSlice.setItemText(1, _translate("Form", "xz-plane", None))
self.comboBoxSlice.setItemText(2, _translate("Form", "zy-plane", None))
self.labelSlice.setText(_translate("Form", "Slice:", None))
self.checkBoxSmooth.setText(_translate("Form", "Smooth", None))
self.checkBoxAuto.setText(_translate("Form", "Auto", None))
self.labelGain.setText(_translate("Form", "Gain:", None))
###########################################################################################
def update_phase(self):
if self.mag_data_loaded:
mode_ind = self.comboBoxSlice.currentIndex()
if mode_ind == 0:
self.mode = 'z'
length = self.mag_data.dim[0] - 1
elif mode_ind == 1:
self.mode = 'y'
length = self.mag_data.dim[1] - 1
else:
self.mode = 'x'
length = self.mag_data.dim[2] - 1
if self.checkBoxAuto.isChecked():
gain = 'auto'
else:
gain = self.spinBoxGain.value()
self.projector = SimpleProjector(self.mag_data.dim, axis=self.mode)
self.spinBoxSlice.setMaximum(length)
self.scrollBarSlice.setMaximum(length)
self.spinBoxSlice.setValue(int(length/2.))
self.update_slice()
self.phase_mapper = PhaseMapperRDFC(Kernel(self.mag_data.a, self.projector.dim_uv))
self.phase_map = self.phase_mapper(self.projector(self.mag_data))
self.phase_map.display_phase(axis=self.mplWidgetPhase.axes, cbar=False, show=False)
if self.checkBoxSmooth.isChecked():
interpolation = 'bilinear'
else:
interpolation = 'none'
self.phase_map.display_holo(axis=self.mplWidgetHolo.axes, gain=gain,
interpolation=interpolation, show=False)
self.mplWidgetPhase.draw()
self.mplWidgetHolo.draw()
def update_slice(self):
if self.mag_data_loaded:
self.mag_data.quiver_plot(axis=self.mplWidgetMag.axes, proj_axis=self.mode,
ax_slice=self.spinBoxSlice.value(),
log=self.checkBoxLog.isChecked(),
scaled=self.checkBoxScale.isChecked(),
show=False)
self.mplWidgetMag.draw()
def load(self):
mag_file = QtGui.QFileDialog.getOpenFileName(self, 'Open Data File', '',
'NetCDF files (*.nc)')
self.mag_data = MagData.load_from_netcdf4(mag_file)
self.mag_data_loaded = True
self.mplWidgetMag.axes.set_visible(True)
self.mplWidgetHolo.axes.set_visible(True)
self.mplWidgetPhase.axes.set_visible(True)
self.comboBoxSlice.setCurrentIndex(0)
self.update_phase()
if __name__ == '__main__':
app = QtGui.QApplication(sys.argv)
widget = UI_MagSlicerMain()
widget.show()
sys.exit(app.exec_())
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Form</class>
<widget class="QWidget" name="Form">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>993</width>
<height>351</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="windowTitle">
<string>Mag Slicer</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QPushButton" name="pushButtonLoad">
<property name="text">
<string>Laden</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="checkBoxScale">
<property name="text">
<string>Scaled</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
<property name="tristate">
<bool>false</bool>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="checkBoxLog">
<property name="text">
<string>Log</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="comboBoxSlice">
<item>
<property name="text">
<string>xy-plane</string>
</property>
</item>
<item>
<property name="text">
<string>xz-plane</string>
</property>
</item>
<item>
<property name="text">
<string>zy-plane</string>
</property>
</item>
</widget>
</item>
<item>
<widget class="QLabel" name="labelSlice">
<property name="text">
<string>Slice:</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="spinBoxSlice">
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
<property name="maximum">
<number>0</number>
</property>
<property name="value">
<number>0</number>
</property>
</widget>
</item>
<item>
<widget class="QScrollBar" name="scrollBarSlice">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>400</width>
<height>0</height>
</size>
</property>
<property name="maximum">
<number>0</number>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="checkBoxSmooth">
<property name="text">
<string>Smooth</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="checkBoxAuto">
<property name="text">
<string>Auto</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="labelGain">
<property name="text">
<string>Gain:</string>
</property>
</widget>
</item>
<item>
<widget class="QDoubleSpinBox" name="spinBoxGain">
<property name="enabled">
<bool>false</bool>
</property>
<property name="maximum">
<double>1000000.000000000000000</double>
</property>
<property name="singleStep">
<double>0.100000000000000</double>
</property>
<property name="value">
<double>1.000000000000000</double>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayoutPlots">
<property name="spacing">
<number>0</number>
</property>
<property name="sizeConstraint">
<enum>QLayout::SetNoConstraint</enum>
</property>
<item>
<widget class="MatplotlibWidget" name="mplWidgetMag">
<property name="sizePolicy">
<sizepolicy hsizetype="Ignored" vsizetype="Expanding">
<horstretch>10</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="cursor">
<cursorShape>ArrowCursor</cursorShape>
</property>
<property name="layoutDirection">
<enum>Qt::LeftToRight</enum>
</property>
<property name="autoFillBackground">
<bool>false</bool>
</property>
</widget>
</item>
<item>
<widget class="MatplotlibWidget" name="mplWidgetHolo">
<property name="sizePolicy">
<sizepolicy hsizetype="Ignored" vsizetype="Expanding">
<horstretch>10</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item>
<widget class="MatplotlibWidget" name="mplWidgetPhase">
<property name="enabled">
<bool>true</bool>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Ignored" vsizetype="Expanding">
<horstretch>10</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>MatplotlibWidget</class>
<extends>QWidget</extends>
<header>matplotlibwidget</header>
</customwidget>
</customwidgets>
<resources/>
<connections>
<connection>
<sender>spinBoxSlice</sender>
<signal>valueChanged(int)</signal>
<receiver>scrollBarSlice</receiver>
<slot>setValue(int)</slot>
<hints>
<hint type="sourcelabel">
<x>335</x>
<y>18</y>
</hint>
<hint type="destinationlabel">
<x>380</x>
<y>17</y>
</hint>
</hints>
</connection>
<connection>
<sender>scrollBarSlice</sender>
<signal>valueChanged(int)</signal>
<receiver>spinBoxSlice</receiver>
<slot>setValue(int)</slot>
<hints>
<hint type="sourcelabel">
<x>364</x>
<y>27</y>
</hint>
<hint type="destinationlabel">
<x>321</x>
<y>29</y>
</hint>
</hints>
</connection>
<connection>
<sender>checkBoxAuto</sender>
<signal>toggled(bool)</signal>
<receiver>spinBoxGain</receiver>
<slot>setDisabled(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>761</x>
<y>18</y>
</hint>
<hint type="destinationlabel">
<x>870</x>
<y>14</y>
</hint>
</hints>
</connection>
</connections>
</ui>
# -*- coding: utf-8 -*-
"""Created on Mon Mar 17 14:28:10 2014 @author: Jan"""
import os
from numpy import pi
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.ticker import FuncFormatter
import pyramid
import pyramid.magcreator as mc
from pyramid.magdata import MagData
from pyramid.projector import YTiltProjector
from pyramid.phasemapper import PhaseMapperRDFC, pm
from pyramid.kernel import Kernel
from pyramid.dataset import DataSet
import logging
import logging.config
LOGGING_CONF = os.path.join(os.path.dirname(os.path.realpath(pyramid.__file__)), 'logging.ini')
logging.config.fileConfig(LOGGING_CONF, disable_existing_loggers=False)
###################################################################################################
print('Jan')
dim = (128, 128, 128)
center = (int(dim[0]/2), int(dim[1]/2), int(dim[2]/2))
radius = dim[0]/4.
a = 1.
magnitude = mc.create_mag_dist_homog(mc.Shapes.sphere(dim, center, radius), pi/4)
mag_data = MagData(a, magnitude)
phase_map = pm(mag_data)
axis = phase_map.display_phase()
axis.tick_params(axis='both', which='major', labelsize=18)
axis.set_title('Phase map', fontsize=24)
axis.set_xlabel('x [nm]', fontsize=18)
axis.set_ylabel('y [nm]', fontsize=18)
axis = phase_map.display_holo(gain=20, interpolation='bilinear')
axis.tick_params(axis='both', which='major', labelsize=18)
axis.set_title('Magnetic induction map', fontsize=24)
axis.set_xlabel('x [nm]', fontsize=18)
axis.set_ylabel('y [nm]', fontsize=18)
mag_data.scale_down(2)
mag_data.quiver_plot()
axis = plt.gca()
axis.tick_params(axis='both', which='major', labelsize=18)
axis.set_title('Magnetization distribution', fontsize=24)
axis.set_xlabel('x [nm]', fontsize=18)
axis.set_ylabel('y [nm]', fontsize=18)
phase_map.make_color_wheel()
shape_vort = mc.Shapes.disc((64, 64, 64), (31.5, 31.5, 31.5), 24, 10)
magnitude_vort = mc.create_mag_dist_vortex(shape_vort)
mag_vort = MagData(a, magnitude_vort)
mag_vort.scale_down(2)
mag_vort.quiver_plot()
###################################################################################################
print('Patrick')
a = 10.0 # nm
b_0 = 3 # T
dim = (128, 128, 128)
center = (int(dim[0]/2), int(dim[1]/2), int(dim[2]/2)) # in px (z, y, x), index starts with 0!
mag_data = MagData(a, mc.create_mag_dist_homog(mc.Shapes.ellipse(dim, center, (20., 60.), 5.), 0))
tilts = np.array([0., 60.])/180.*pi
data_set = DataSet(a, dim, b_0)
data_set.projectors = [YTiltProjector(mag_data.dim, tilt) for tilt in tilts]
phase_maps = data_set.create_phase_maps(mag_data)
axis = phase_maps[0].display_holo(gain=1, interpolation='bilinear')
axis.tick_params(axis='both', which='major', labelsize=18)
axis.set_title('Magnetic induction map', fontsize=24)
axis.xaxis.set_major_formatter(FuncFormatter(lambda x, pos: '{:g}'.format(x*a)))
axis.yaxis.set_major_formatter(FuncFormatter(lambda x, pos: '{:g}'.format(x*a)))
axis.set_xlabel('x [nm]', fontsize=18)
axis.set_ylabel('y [nm]', fontsize=18)
axis = phase_maps[0].display_phase(limit=17)
axis.tick_params(axis='both', which='major', labelsize=18)
axis.set_title('Phase map', fontsize=24)
axis.set_xlabel('x [nm]', fontsize=18)
axis.set_ylabel('y [nm]', fontsize=18)
axis = phase_maps[1].display_holo(gain=1, interpolation='bilinear')
axis.tick_params(axis='both', which='major', labelsize=18)
axis.set_title('Magnetic induction map', fontsize=24)
axis.xaxis.set_major_formatter(FuncFormatter(lambda x, pos: '{:g}'.format(x*a)))
axis.yaxis.set_major_formatter(FuncFormatter(lambda x, pos: '{:g}'.format(x*a)))
axis.set_xlabel('x [nm]', fontsize=18)
axis.set_ylabel('y [nm]', fontsize=18)
axis = phase_maps[1].display_phase(limit=17)
axis.tick_params(axis='both', which='major', labelsize=18)
axis.set_title('Phase map', fontsize=24)
axis.set_xlabel('x [nm]', fontsize=18)
axis.set_ylabel('y [nm]', fontsize=18)