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

Completed the restructuring of the package

scripts: changed scripts to work with the new syntax of the package
PhaseMag and MagData: added load and save options for NetCDF files
MagData: changed 3D-plotting to use mayavi (faster and better looking)
test: added more TestCases for various modules
phasemapper: added computation method to use mx and my (now standard)
compare_method_errors: first draft of script to compare the different errors
parent 9d34cde6
No related branches found
No related tags found
No related merge requests found
Showing
with 880 additions and 55 deletions
# -*- coding: utf-8 -*-
"""
Created on Wed Apr 24 07:10:28 2013
"""Testcase for the magdata module."""
@author: Jan
"""
# py.test
import unittest
import numpy as np
import pyramid.dataloader as dl
from numpy import pi
from pyramid.magdata import MagData
# py.test
# TODO: define test constants somewhere
# TODO: proper error messages
# TODO: Docstring
class TestCaseDataloader(unittest.TestCase):
class TestCaseMagData(unittest.TestCase):
def setUp(self):
self.filename = 'test_dataloader/test_data.txt'
self.mag_data = dl.MagDataLLG(self.filename)
pass
def tearDown(self):
self.filename = None
self.mag_data = None
pass
def test_filename(self):
def test_init(self):
magnitude = (np.zeros((1,1,1), np.zeros(1,1,1), np.zeros(1,1,1)))
magnitude = (np.zeros((1,1,1), np.zeros(1,1,1), np.zeros(1,1,1)))
self.assertRaises(AssertionError, MagData, 10.0, )
self.assertEqual(self.mag_data.filename, self.filename)
def test_resolution(self):
self.assertEqual(self.mag_data.res, 10.0)
......@@ -53,32 +50,24 @@ class TestCaseDataloader(unittest.TestCase):
np.testing.assert_array_almost_equal(y_mag, test_array, err_msg='y failure')
np.testing.assert_array_almost_equal(x_mag, test_array, err_msg='x failure')
def test_load_from_llg(self):
pass
#mc.create_hom_mag((3,5),10.0,pi/4,mc.slab,((1,2),(1,3)),'test.txt',plot_mag_distr=True)
# '{:7.6e}'
# scale = 1.0E-9 / 1.0E-2 #from cm to nm
# data = np.genfromtxt(filename, skip_header=2)
# x_dim, y_dim, z_dim = np.genfromtxt(filename, dtype=int,
# skip_header=1,
# skip_footer=len(data[:, 0]))
# res = (data[1, 0] - data[0, 0]) / scale
# x_len, y_len, z_len = [data[-1, i]/scale+res/2 for i in range(3)]
# x_mag, y_mag, z_mag = [data[:, i].reshape(z_dim, y_dim, x_dim).mean(0)
# *z_len for i in range(3,6)]
# #Reshape in Python and Igor is different,
# #Python fills rows first, Igor columns!
# self.filename = filename
# self.res = res
# self.dim = (x_dim, y_dim, z_dim)
# self.length = (x_len, y_len, z_len)
# self.magnitude = (x_mag, y_mag, z_mag)
# self.assertAlmostEqual(0, 0.01, places=1)
# mc.create_hom_mag((10,10),10.0,0,mc.slab,((4,4),(5,5)),'test.txt')
def test_save_to_llg(self):
pass
def test_load_from_netcdf(self):
pass
def test_save_to_netcdf(self):
pass
def test_quiver_plot(self):
pass
def test_quiver_plot3d(self):
pass
if __name__ == '__main__':
suite = unittest.TestLoader().loadTestsFromTestCase(TestCaseDataloader)
suite = unittest.TestLoader().loadTestsFromTestCase(TestCaseMagData)
unittest.TextTestRunner(verbosity=2).run(suite)
\ No newline at end of file
# -*- coding: utf-8 -*-
"""
Created on Wed Apr 24 07:10:28 2013
"""Testcase for the phasemap module."""
@author: Jan
"""
# py.test
import unittest
import numpy as np
from pyramid.phasemap import PhaseMap
class TestSuite(unittest.TestCase):
class TestCasePhaseMap(unittest.TestCase):
def setUp(self):
pass
def tearDown(self):
pass
def test(self):
self.assertTrue(True)
def test_almost(self):
self.assertAlmostEqual(0, 0.01, places=1)
np.testing.assert_array_almost_equal()
def test_template(self):
pass
def test_load_from_txt(self):
pass
def test_save_to_txt(self):
pass
def test_load_from_netcdf(self):
pass
def test_save_to_netcdf(self):
pass
def test_display(self):
pass
if __name__ == '__main__':
suite = unittest.TestLoader().loadTestsFromTestCase(TestSuite)
suite = unittest.TestLoader().loadTestsFromTestCase(TestCasePhaseMap)
unittest.TextTestRunner(verbosity=2).run(suite)
\ No newline at end of file
# -*- coding: utf-8 -*-
"""Testcase for the phasemapper module."""
import unittest
import pyramid.phasemapper as pm
class TestCasePhaseMapper(unittest.TestCase):
def setUp(self):
pass
def tearDown(self):
pass
def test_phase_mag_fourier(self):
pass
def test_phase_mag_real_slab(self):
pass
def test_phase_mag_real_disc(self):
pass
if __name__ == '__main__':
suite = unittest.TestLoader().loadTestsFromTestCase(TestCasePhaseMapper)
unittest.TextTestRunner(verbosity=2).run(suite)
\ No newline at end of file
# -*- coding: utf-8 -*-
"""Testcase for the projector module."""
import unittest
import numpy as np
from numpy import pi
import pyramid.projector as pj
import pyramid.magcreator as mc
from pyramid.magdata import MagData
class TestCaseProjector(unittest.TestCase):
def setUp(self):
self.mag_data = MagData.load_from_llg('test_projector/ref_mag_data.txt')
def tearDown(self):
self.mag_data = None
def test_simple_axis_projection(self):
z_proj_ref = (np.loadtxt('test_projector/ref_proj_z.txt'))
y_proj_ref = (np.loadtxt('test_projector/ref_proj_y.txt'))
x_proj_ref = (np.loadtxt('test_projector/ref_proj_x.txt'))
z_proj = pj.simple_axis_projection(self.mag_data, 'z')
y_proj = pj.simple_axis_projection(self.mag_data, 'y')
x_proj = pj.simple_axis_projection(self.mag_data, 'x')
np.testing.assert_equal(z_proj[0], z_proj_ref, 'Testmessage')
np.testing.assert_equal(z_proj[1], z_proj_ref, 'Testmessage')
np.testing.assert_equal(y_proj[0], y_proj_ref, 'Testmessage')
np.testing.assert_equal(y_proj[1], y_proj_ref, 'Testmessage')
np.testing.assert_equal(x_proj[0], x_proj_ref, 'Testmessage')
np.testing.assert_equal(x_proj[1], x_proj_ref, 'Testmessage')
if __name__ == '__main__':
suite = unittest.TestLoader().loadTestsFromTestCase(TestCaseProjector)
unittest.TextTestRunner(verbosity=2).run(suite)
\ No newline at end of file
LLGFileCreator: test_projector/ref_mag_data
7 6 5
5.000000e-07 5.000000e-07 5.000000e-07 0.000000e+00 0.000000e+00 0.000000e+00
1.500000e-06 5.000000e-07 5.000000e-07 0.000000e+00 0.000000e+00 0.000000e+00
2.500000e-06 5.000000e-07 5.000000e-07 0.000000e+00 0.000000e+00 0.000000e+00
3.500000e-06 5.000000e-07 5.000000e-07 0.000000e+00 0.000000e+00 0.000000e+00
4.500000e-06 5.000000e-07 5.000000e-07 0.000000e+00 0.000000e+00 0.000000e+00
5.500000e-06 5.000000e-07 5.000000e-07 0.000000e+00 0.000000e+00 0.000000e+00
6.500000e-06 5.000000e-07 5.000000e-07 0.000000e+00 0.000000e+00 0.000000e+00
5.000000e-07 1.500000e-06 5.000000e-07 0.000000e+00 0.000000e+00 0.000000e+00
1.500000e-06 1.500000e-06 5.000000e-07 0.000000e+00 0.000000e+00 0.000000e+00
2.500000e-06 1.500000e-06 5.000000e-07 0.000000e+00 0.000000e+00 0.000000e+00
3.500000e-06 1.500000e-06 5.000000e-07 0.000000e+00 0.000000e+00 0.000000e+00
4.500000e-06 1.500000e-06 5.000000e-07 0.000000e+00 0.000000e+00 0.000000e+00
5.500000e-06 1.500000e-06 5.000000e-07 0.000000e+00 0.000000e+00 0.000000e+00
6.500000e-06 1.500000e-06 5.000000e-07 0.000000e+00 0.000000e+00 0.000000e+00
5.000000e-07 2.500000e-06 5.000000e-07 0.000000e+00 0.000000e+00 0.000000e+00
1.500000e-06 2.500000e-06 5.000000e-07 0.000000e+00 0.000000e+00 0.000000e+00
2.500000e-06 2.500000e-06 5.000000e-07 0.000000e+00 0.000000e+00 0.000000e+00
3.500000e-06 2.500000e-06 5.000000e-07 0.000000e+00 0.000000e+00 0.000000e+00
4.500000e-06 2.500000e-06 5.000000e-07 0.000000e+00 0.000000e+00 0.000000e+00
5.500000e-06 2.500000e-06 5.000000e-07 0.000000e+00 0.000000e+00 0.000000e+00
6.500000e-06 2.500000e-06 5.000000e-07 0.000000e+00 0.000000e+00 0.000000e+00
5.000000e-07 3.500000e-06 5.000000e-07 0.000000e+00 0.000000e+00 0.000000e+00
1.500000e-06 3.500000e-06 5.000000e-07 0.000000e+00 0.000000e+00 0.000000e+00
2.500000e-06 3.500000e-06 5.000000e-07 0.000000e+00 0.000000e+00 0.000000e+00
3.500000e-06 3.500000e-06 5.000000e-07 0.000000e+00 0.000000e+00 0.000000e+00
4.500000e-06 3.500000e-06 5.000000e-07 1.000000e+00 1.000000e+00 1.000000e+00
5.500000e-06 3.500000e-06 5.000000e-07 0.000000e+00 0.000000e+00 0.000000e+00
6.500000e-06 3.500000e-06 5.000000e-07 0.000000e+00 0.000000e+00 0.000000e+00
5.000000e-07 4.500000e-06 5.000000e-07 0.000000e+00 0.000000e+00 0.000000e+00
1.500000e-06 4.500000e-06 5.000000e-07 0.000000e+00 0.000000e+00 0.000000e+00
2.500000e-06 4.500000e-06 5.000000e-07 0.000000e+00 0.000000e+00 0.000000e+00
3.500000e-06 4.500000e-06 5.000000e-07 0.000000e+00 0.000000e+00 0.000000e+00
4.500000e-06 4.500000e-06 5.000000e-07 0.000000e+00 0.000000e+00 0.000000e+00
5.500000e-06 4.500000e-06 5.000000e-07 0.000000e+00 0.000000e+00 0.000000e+00
6.500000e-06 4.500000e-06 5.000000e-07 0.000000e+00 0.000000e+00 0.000000e+00
5.000000e-07 5.500000e-06 5.000000e-07 0.000000e+00 0.000000e+00 0.000000e+00
1.500000e-06 5.500000e-06 5.000000e-07 0.000000e+00 0.000000e+00 0.000000e+00
2.500000e-06 5.500000e-06 5.000000e-07 0.000000e+00 0.000000e+00 0.000000e+00
3.500000e-06 5.500000e-06 5.000000e-07 0.000000e+00 0.000000e+00 0.000000e+00
4.500000e-06 5.500000e-06 5.000000e-07 0.000000e+00 0.000000e+00 0.000000e+00
5.500000e-06 5.500000e-06 5.000000e-07 0.000000e+00 0.000000e+00 0.000000e+00
6.500000e-06 5.500000e-06 5.000000e-07 0.000000e+00 0.000000e+00 0.000000e+00
5.000000e-07 5.000000e-07 1.500000e-06 0.000000e+00 0.000000e+00 0.000000e+00
1.500000e-06 5.000000e-07 1.500000e-06 0.000000e+00 0.000000e+00 0.000000e+00
2.500000e-06 5.000000e-07 1.500000e-06 0.000000e+00 0.000000e+00 0.000000e+00
3.500000e-06 5.000000e-07 1.500000e-06 0.000000e+00 0.000000e+00 0.000000e+00
4.500000e-06 5.000000e-07 1.500000e-06 0.000000e+00 0.000000e+00 0.000000e+00
5.500000e-06 5.000000e-07 1.500000e-06 0.000000e+00 0.000000e+00 0.000000e+00
6.500000e-06 5.000000e-07 1.500000e-06 0.000000e+00 0.000000e+00 0.000000e+00
5.000000e-07 1.500000e-06 1.500000e-06 0.000000e+00 0.000000e+00 0.000000e+00
1.500000e-06 1.500000e-06 1.500000e-06 0.000000e+00 0.000000e+00 0.000000e+00
2.500000e-06 1.500000e-06 1.500000e-06 0.000000e+00 0.000000e+00 0.000000e+00
3.500000e-06 1.500000e-06 1.500000e-06 0.000000e+00 0.000000e+00 0.000000e+00
4.500000e-06 1.500000e-06 1.500000e-06 0.000000e+00 0.000000e+00 0.000000e+00
5.500000e-06 1.500000e-06 1.500000e-06 0.000000e+00 0.000000e+00 0.000000e+00
6.500000e-06 1.500000e-06 1.500000e-06 0.000000e+00 0.000000e+00 0.000000e+00
5.000000e-07 2.500000e-06 1.500000e-06 0.000000e+00 0.000000e+00 0.000000e+00
1.500000e-06 2.500000e-06 1.500000e-06 0.000000e+00 0.000000e+00 0.000000e+00
2.500000e-06 2.500000e-06 1.500000e-06 0.000000e+00 0.000000e+00 0.000000e+00
3.500000e-06 2.500000e-06 1.500000e-06 1.000000e+00 1.000000e+00 1.000000e+00
4.500000e-06 2.500000e-06 1.500000e-06 1.000000e+00 1.000000e+00 1.000000e+00
5.500000e-06 2.500000e-06 1.500000e-06 1.000000e+00 1.000000e+00 1.000000e+00
6.500000e-06 2.500000e-06 1.500000e-06 0.000000e+00 0.000000e+00 0.000000e+00
5.000000e-07 3.500000e-06 1.500000e-06 0.000000e+00 0.000000e+00 0.000000e+00
1.500000e-06 3.500000e-06 1.500000e-06 0.000000e+00 0.000000e+00 0.000000e+00
2.500000e-06 3.500000e-06 1.500000e-06 0.000000e+00 0.000000e+00 0.000000e+00
3.500000e-06 3.500000e-06 1.500000e-06 1.000000e+00 1.000000e+00 1.000000e+00
4.500000e-06 3.500000e-06 1.500000e-06 1.000000e+00 1.000000e+00 1.000000e+00
5.500000e-06 3.500000e-06 1.500000e-06 1.000000e+00 1.000000e+00 1.000000e+00
6.500000e-06 3.500000e-06 1.500000e-06 0.000000e+00 0.000000e+00 0.000000e+00
5.000000e-07 4.500000e-06 1.500000e-06 0.000000e+00 0.000000e+00 0.000000e+00
1.500000e-06 4.500000e-06 1.500000e-06 0.000000e+00 0.000000e+00 0.000000e+00
2.500000e-06 4.500000e-06 1.500000e-06 0.000000e+00 0.000000e+00 0.000000e+00
3.500000e-06 4.500000e-06 1.500000e-06 1.000000e+00 1.000000e+00 1.000000e+00
4.500000e-06 4.500000e-06 1.500000e-06 1.000000e+00 1.000000e+00 1.000000e+00
5.500000e-06 4.500000e-06 1.500000e-06 1.000000e+00 1.000000e+00 1.000000e+00
6.500000e-06 4.500000e-06 1.500000e-06 0.000000e+00 0.000000e+00 0.000000e+00
5.000000e-07 5.500000e-06 1.500000e-06 0.000000e+00 0.000000e+00 0.000000e+00
1.500000e-06 5.500000e-06 1.500000e-06 0.000000e+00 0.000000e+00 0.000000e+00
2.500000e-06 5.500000e-06 1.500000e-06 0.000000e+00 0.000000e+00 0.000000e+00
3.500000e-06 5.500000e-06 1.500000e-06 0.000000e+00 0.000000e+00 0.000000e+00
4.500000e-06 5.500000e-06 1.500000e-06 0.000000e+00 0.000000e+00 0.000000e+00
5.500000e-06 5.500000e-06 1.500000e-06 0.000000e+00 0.000000e+00 0.000000e+00
6.500000e-06 5.500000e-06 1.500000e-06 0.000000e+00 0.000000e+00 0.000000e+00
5.000000e-07 5.000000e-07 2.500000e-06 0.000000e+00 0.000000e+00 0.000000e+00
1.500000e-06 5.000000e-07 2.500000e-06 0.000000e+00 0.000000e+00 0.000000e+00
2.500000e-06 5.000000e-07 2.500000e-06 0.000000e+00 0.000000e+00 0.000000e+00
3.500000e-06 5.000000e-07 2.500000e-06 0.000000e+00 0.000000e+00 0.000000e+00
4.500000e-06 5.000000e-07 2.500000e-06 0.000000e+00 0.000000e+00 0.000000e+00
5.500000e-06 5.000000e-07 2.500000e-06 0.000000e+00 0.000000e+00 0.000000e+00
6.500000e-06 5.000000e-07 2.500000e-06 0.000000e+00 0.000000e+00 0.000000e+00
5.000000e-07 1.500000e-06 2.500000e-06 0.000000e+00 0.000000e+00 0.000000e+00
1.500000e-06 1.500000e-06 2.500000e-06 0.000000e+00 0.000000e+00 0.000000e+00
2.500000e-06 1.500000e-06 2.500000e-06 0.000000e+00 0.000000e+00 0.000000e+00
3.500000e-06 1.500000e-06 2.500000e-06 0.000000e+00 0.000000e+00 0.000000e+00
4.500000e-06 1.500000e-06 2.500000e-06 1.000000e+00 1.000000e+00 1.000000e+00
5.500000e-06 1.500000e-06 2.500000e-06 0.000000e+00 0.000000e+00 0.000000e+00
6.500000e-06 1.500000e-06 2.500000e-06 0.000000e+00 0.000000e+00 0.000000e+00
5.000000e-07 2.500000e-06 2.500000e-06 0.000000e+00 0.000000e+00 0.000000e+00
1.500000e-06 2.500000e-06 2.500000e-06 0.000000e+00 0.000000e+00 0.000000e+00
2.500000e-06 2.500000e-06 2.500000e-06 0.000000e+00 0.000000e+00 0.000000e+00
3.500000e-06 2.500000e-06 2.500000e-06 1.000000e+00 1.000000e+00 1.000000e+00
4.500000e-06 2.500000e-06 2.500000e-06 1.000000e+00 1.000000e+00 1.000000e+00
5.500000e-06 2.500000e-06 2.500000e-06 1.000000e+00 1.000000e+00 1.000000e+00
6.500000e-06 2.500000e-06 2.500000e-06 0.000000e+00 0.000000e+00 0.000000e+00
5.000000e-07 3.500000e-06 2.500000e-06 0.000000e+00 0.000000e+00 0.000000e+00
1.500000e-06 3.500000e-06 2.500000e-06 0.000000e+00 0.000000e+00 0.000000e+00
2.500000e-06 3.500000e-06 2.500000e-06 1.000000e+00 1.000000e+00 1.000000e+00
3.500000e-06 3.500000e-06 2.500000e-06 1.000000e+00 1.000000e+00 1.000000e+00
4.500000e-06 3.500000e-06 2.500000e-06 1.000000e+00 1.000000e+00 1.000000e+00
5.500000e-06 3.500000e-06 2.500000e-06 1.000000e+00 1.000000e+00 1.000000e+00
6.500000e-06 3.500000e-06 2.500000e-06 1.000000e+00 1.000000e+00 1.000000e+00
5.000000e-07 4.500000e-06 2.500000e-06 0.000000e+00 0.000000e+00 0.000000e+00
1.500000e-06 4.500000e-06 2.500000e-06 0.000000e+00 0.000000e+00 0.000000e+00
2.500000e-06 4.500000e-06 2.500000e-06 0.000000e+00 0.000000e+00 0.000000e+00
3.500000e-06 4.500000e-06 2.500000e-06 1.000000e+00 1.000000e+00 1.000000e+00
4.500000e-06 4.500000e-06 2.500000e-06 1.000000e+00 1.000000e+00 1.000000e+00
5.500000e-06 4.500000e-06 2.500000e-06 1.000000e+00 1.000000e+00 1.000000e+00
6.500000e-06 4.500000e-06 2.500000e-06 0.000000e+00 0.000000e+00 0.000000e+00
5.000000e-07 5.500000e-06 2.500000e-06 0.000000e+00 0.000000e+00 0.000000e+00
1.500000e-06 5.500000e-06 2.500000e-06 0.000000e+00 0.000000e+00 0.000000e+00
2.500000e-06 5.500000e-06 2.500000e-06 0.000000e+00 0.000000e+00 0.000000e+00
3.500000e-06 5.500000e-06 2.500000e-06 0.000000e+00 0.000000e+00 0.000000e+00
4.500000e-06 5.500000e-06 2.500000e-06 1.000000e+00 1.000000e+00 1.000000e+00
5.500000e-06 5.500000e-06 2.500000e-06 0.000000e+00 0.000000e+00 0.000000e+00
6.500000e-06 5.500000e-06 2.500000e-06 0.000000e+00 0.000000e+00 0.000000e+00
5.000000e-07 5.000000e-07 3.500000e-06 0.000000e+00 0.000000e+00 0.000000e+00
1.500000e-06 5.000000e-07 3.500000e-06 0.000000e+00 0.000000e+00 0.000000e+00
2.500000e-06 5.000000e-07 3.500000e-06 0.000000e+00 0.000000e+00 0.000000e+00
3.500000e-06 5.000000e-07 3.500000e-06 0.000000e+00 0.000000e+00 0.000000e+00
4.500000e-06 5.000000e-07 3.500000e-06 0.000000e+00 0.000000e+00 0.000000e+00
5.500000e-06 5.000000e-07 3.500000e-06 0.000000e+00 0.000000e+00 0.000000e+00
6.500000e-06 5.000000e-07 3.500000e-06 0.000000e+00 0.000000e+00 0.000000e+00
5.000000e-07 1.500000e-06 3.500000e-06 0.000000e+00 0.000000e+00 0.000000e+00
1.500000e-06 1.500000e-06 3.500000e-06 0.000000e+00 0.000000e+00 0.000000e+00
2.500000e-06 1.500000e-06 3.500000e-06 0.000000e+00 0.000000e+00 0.000000e+00
3.500000e-06 1.500000e-06 3.500000e-06 0.000000e+00 0.000000e+00 0.000000e+00
4.500000e-06 1.500000e-06 3.500000e-06 0.000000e+00 0.000000e+00 0.000000e+00
5.500000e-06 1.500000e-06 3.500000e-06 0.000000e+00 0.000000e+00 0.000000e+00
6.500000e-06 1.500000e-06 3.500000e-06 0.000000e+00 0.000000e+00 0.000000e+00
5.000000e-07 2.500000e-06 3.500000e-06 0.000000e+00 0.000000e+00 0.000000e+00
1.500000e-06 2.500000e-06 3.500000e-06 0.000000e+00 0.000000e+00 0.000000e+00
2.500000e-06 2.500000e-06 3.500000e-06 0.000000e+00 0.000000e+00 0.000000e+00
3.500000e-06 2.500000e-06 3.500000e-06 1.000000e+00 1.000000e+00 1.000000e+00
4.500000e-06 2.500000e-06 3.500000e-06 1.000000e+00 1.000000e+00 1.000000e+00
5.500000e-06 2.500000e-06 3.500000e-06 1.000000e+00 1.000000e+00 1.000000e+00
6.500000e-06 2.500000e-06 3.500000e-06 0.000000e+00 0.000000e+00 0.000000e+00
5.000000e-07 3.500000e-06 3.500000e-06 0.000000e+00 0.000000e+00 0.000000e+00
1.500000e-06 3.500000e-06 3.500000e-06 0.000000e+00 0.000000e+00 0.000000e+00
2.500000e-06 3.500000e-06 3.500000e-06 0.000000e+00 0.000000e+00 0.000000e+00
3.500000e-06 3.500000e-06 3.500000e-06 1.000000e+00 1.000000e+00 1.000000e+00
4.500000e-06 3.500000e-06 3.500000e-06 1.000000e+00 1.000000e+00 1.000000e+00
5.500000e-06 3.500000e-06 3.500000e-06 1.000000e+00 1.000000e+00 1.000000e+00
6.500000e-06 3.500000e-06 3.500000e-06 0.000000e+00 0.000000e+00 0.000000e+00
5.000000e-07 4.500000e-06 3.500000e-06 0.000000e+00 0.000000e+00 0.000000e+00
1.500000e-06 4.500000e-06 3.500000e-06 0.000000e+00 0.000000e+00 0.000000e+00
2.500000e-06 4.500000e-06 3.500000e-06 0.000000e+00 0.000000e+00 0.000000e+00
3.500000e-06 4.500000e-06 3.500000e-06 1.000000e+00 1.000000e+00 1.000000e+00
4.500000e-06 4.500000e-06 3.500000e-06 1.000000e+00 1.000000e+00 1.000000e+00
5.500000e-06 4.500000e-06 3.500000e-06 1.000000e+00 1.000000e+00 1.000000e+00
6.500000e-06 4.500000e-06 3.500000e-06 0.000000e+00 0.000000e+00 0.000000e+00
5.000000e-07 5.500000e-06 3.500000e-06 0.000000e+00 0.000000e+00 0.000000e+00
1.500000e-06 5.500000e-06 3.500000e-06 0.000000e+00 0.000000e+00 0.000000e+00
2.500000e-06 5.500000e-06 3.500000e-06 0.000000e+00 0.000000e+00 0.000000e+00
3.500000e-06 5.500000e-06 3.500000e-06 0.000000e+00 0.000000e+00 0.000000e+00
4.500000e-06 5.500000e-06 3.500000e-06 0.000000e+00 0.000000e+00 0.000000e+00
5.500000e-06 5.500000e-06 3.500000e-06 0.000000e+00 0.000000e+00 0.000000e+00
6.500000e-06 5.500000e-06 3.500000e-06 0.000000e+00 0.000000e+00 0.000000e+00
5.000000e-07 5.000000e-07 4.500000e-06 0.000000e+00 0.000000e+00 0.000000e+00
1.500000e-06 5.000000e-07 4.500000e-06 0.000000e+00 0.000000e+00 0.000000e+00
2.500000e-06 5.000000e-07 4.500000e-06 0.000000e+00 0.000000e+00 0.000000e+00
3.500000e-06 5.000000e-07 4.500000e-06 0.000000e+00 0.000000e+00 0.000000e+00
4.500000e-06 5.000000e-07 4.500000e-06 0.000000e+00 0.000000e+00 0.000000e+00
5.500000e-06 5.000000e-07 4.500000e-06 0.000000e+00 0.000000e+00 0.000000e+00
6.500000e-06 5.000000e-07 4.500000e-06 0.000000e+00 0.000000e+00 0.000000e+00
5.000000e-07 1.500000e-06 4.500000e-06 0.000000e+00 0.000000e+00 0.000000e+00
1.500000e-06 1.500000e-06 4.500000e-06 0.000000e+00 0.000000e+00 0.000000e+00
2.500000e-06 1.500000e-06 4.500000e-06 0.000000e+00 0.000000e+00 0.000000e+00
3.500000e-06 1.500000e-06 4.500000e-06 0.000000e+00 0.000000e+00 0.000000e+00
4.500000e-06 1.500000e-06 4.500000e-06 0.000000e+00 0.000000e+00 0.000000e+00
5.500000e-06 1.500000e-06 4.500000e-06 0.000000e+00 0.000000e+00 0.000000e+00
6.500000e-06 1.500000e-06 4.500000e-06 0.000000e+00 0.000000e+00 0.000000e+00
5.000000e-07 2.500000e-06 4.500000e-06 0.000000e+00 0.000000e+00 0.000000e+00
1.500000e-06 2.500000e-06 4.500000e-06 0.000000e+00 0.000000e+00 0.000000e+00
2.500000e-06 2.500000e-06 4.500000e-06 0.000000e+00 0.000000e+00 0.000000e+00
3.500000e-06 2.500000e-06 4.500000e-06 0.000000e+00 0.000000e+00 0.000000e+00
4.500000e-06 2.500000e-06 4.500000e-06 0.000000e+00 0.000000e+00 0.000000e+00
5.500000e-06 2.500000e-06 4.500000e-06 0.000000e+00 0.000000e+00 0.000000e+00
6.500000e-06 2.500000e-06 4.500000e-06 0.000000e+00 0.000000e+00 0.000000e+00
5.000000e-07 3.500000e-06 4.500000e-06 0.000000e+00 0.000000e+00 0.000000e+00
1.500000e-06 3.500000e-06 4.500000e-06 0.000000e+00 0.000000e+00 0.000000e+00
2.500000e-06 3.500000e-06 4.500000e-06 0.000000e+00 0.000000e+00 0.000000e+00
3.500000e-06 3.500000e-06 4.500000e-06 0.000000e+00 0.000000e+00 0.000000e+00
4.500000e-06 3.500000e-06 4.500000e-06 1.000000e+00 1.000000e+00 1.000000e+00
5.500000e-06 3.500000e-06 4.500000e-06 0.000000e+00 0.000000e+00 0.000000e+00
6.500000e-06 3.500000e-06 4.500000e-06 0.000000e+00 0.000000e+00 0.000000e+00
5.000000e-07 4.500000e-06 4.500000e-06 0.000000e+00 0.000000e+00 0.000000e+00
1.500000e-06 4.500000e-06 4.500000e-06 0.000000e+00 0.000000e+00 0.000000e+00
2.500000e-06 4.500000e-06 4.500000e-06 0.000000e+00 0.000000e+00 0.000000e+00
3.500000e-06 4.500000e-06 4.500000e-06 0.000000e+00 0.000000e+00 0.000000e+00
4.500000e-06 4.500000e-06 4.500000e-06 0.000000e+00 0.000000e+00 0.000000e+00
5.500000e-06 4.500000e-06 4.500000e-06 0.000000e+00 0.000000e+00 0.000000e+00
6.500000e-06 4.500000e-06 4.500000e-06 0.000000e+00 0.000000e+00 0.000000e+00
5.000000e-07 5.500000e-06 4.500000e-06 0.000000e+00 0.000000e+00 0.000000e+00
1.500000e-06 5.500000e-06 4.500000e-06 0.000000e+00 0.000000e+00 0.000000e+00
2.500000e-06 5.500000e-06 4.500000e-06 0.000000e+00 0.000000e+00 0.000000e+00
3.500000e-06 5.500000e-06 4.500000e-06 0.000000e+00 0.000000e+00 0.000000e+00
4.500000e-06 5.500000e-06 4.500000e-06 0.000000e+00 0.000000e+00 0.000000e+00
5.500000e-06 5.500000e-06 4.500000e-06 0.000000e+00 0.000000e+00 0.000000e+00
6.500000e-06 5.500000e-06 4.500000e-06 0.000000e+00 0.000000e+00 0.000000e+00
\ No newline at end of file
0.000000000000000000e+00 0.000000000000000000e+00 0.000000000000000000e+00 1.000000000000000000e+00 0.000000000000000000e+00 0.000000000000000000e+00
0.000000000000000000e+00 0.000000000000000000e+00 3.000000000000000000e+00 3.000000000000000000e+00 3.000000000000000000e+00 0.000000000000000000e+00
0.000000000000000000e+00 1.000000000000000000e+00 3.000000000000000000e+00 5.000000000000000000e+00 3.000000000000000000e+00 1.000000000000000000e+00
0.000000000000000000e+00 0.000000000000000000e+00 3.000000000000000000e+00 3.000000000000000000e+00 3.000000000000000000e+00 0.000000000000000000e+00
0.000000000000000000e+00 0.000000000000000000e+00 0.000000000000000000e+00 1.000000000000000000e+00 0.000000000000000000e+00 0.000000000000000000e+00
0.000000000000000000e+00 0.000000000000000000e+00 0.000000000000000000e+00 0.000000000000000000e+00 1.000000000000000000e+00 0.000000000000000000e+00 0.000000000000000000e+00
0.000000000000000000e+00 0.000000000000000000e+00 0.000000000000000000e+00 3.000000000000000000e+00 3.000000000000000000e+00 3.000000000000000000e+00 0.000000000000000000e+00
0.000000000000000000e+00 0.000000000000000000e+00 1.000000000000000000e+00 3.000000000000000000e+00 5.000000000000000000e+00 3.000000000000000000e+00 1.000000000000000000e+00
0.000000000000000000e+00 0.000000000000000000e+00 0.000000000000000000e+00 3.000000000000000000e+00 3.000000000000000000e+00 3.000000000000000000e+00 0.000000000000000000e+00
0.000000000000000000e+00 0.000000000000000000e+00 0.000000000000000000e+00 0.000000000000000000e+00 1.000000000000000000e+00 0.000000000000000000e+00 0.000000000000000000e+00
0.000000000000000000e+00 0.000000000000000000e+00 0.000000000000000000e+00 0.000000000000000000e+00 0.000000000000000000e+00 0.000000000000000000e+00 0.000000000000000000e+00
0.000000000000000000e+00 0.000000000000000000e+00 0.000000000000000000e+00 0.000000000000000000e+00 1.000000000000000000e+00 0.000000000000000000e+00 0.000000000000000000e+00
0.000000000000000000e+00 0.000000000000000000e+00 0.000000000000000000e+00 3.000000000000000000e+00 3.000000000000000000e+00 3.000000000000000000e+00 0.000000000000000000e+00
0.000000000000000000e+00 0.000000000000000000e+00 1.000000000000000000e+00 3.000000000000000000e+00 5.000000000000000000e+00 3.000000000000000000e+00 1.000000000000000000e+00
0.000000000000000000e+00 0.000000000000000000e+00 0.000000000000000000e+00 3.000000000000000000e+00 3.000000000000000000e+00 3.000000000000000000e+00 0.000000000000000000e+00
0.000000000000000000e+00 0.000000000000000000e+00 0.000000000000000000e+00 0.000000000000000000e+00 1.000000000000000000e+00 0.000000000000000000e+00 0.000000000000000000e+00
# -*- coding: utf-8 -*-
"""Testcase for the reconstructor module."""
import unittest
import pyramid.reconstructor as rc
class TestCaseReconstructor(unittest.TestCase):
def setUp(self):
pass
def tearDown(self):
pass
def test_template(self):
pass
if __name__ == '__main__':
suite = unittest.TestLoader().loadTestsFromTestCase(TestCaseReconstructor)
unittest.TextTestRunner(verbosity=2).run(suite)
\ No newline at end of file
# -*- coding: utf-8 -*-
"""Compare the different methods to create phase maps."""
import time
import pdb, traceback, sys
import numpy as np
from numpy import pi
import matplotlib.pyplot as plt
import pyramid.magcreator as mc
import pyramid.projector as pj
import pyramid.phasemapper as pm
import pyramid.holoimage as hi
import pyramid.analytic as an
from pyramid.magdata import MagData
from pyramid.phasemap import PhaseMap
def phase_from_mag():
'''Calculate and display the phase map from a given magnetization.
Arguments:
None
Returns:
None
'''
# Input parameters:
b_0 = 1 # in T
res = 10.0 # in nm
beta = pi/4#np.linspace(0, 2*pi, endpoint=False, num=72)
padding = range(26)
dim = (1, 100, 100) # in px (z, y, x)
# Create magnetic shape:
geometry = 'slab'
if geometry == 'slab':
center = (0, 49, 49) # in px (z, y, x) index starts with 0!
width = (1, 50, 50) # in px (z, y, x)
mag_shape = mc.Shapes.slab(dim, center, width)
phase_ana = an.phase_mag_slab(dim, res, beta, center, width, b_0)
elif geometry == 'disc':
center = (0, 49, 49) # in px (z, y, x) index starts with 0!
radius = 25 # in px
height = 1 # in px
mag_shape = mc.Shapes.disc(dim, center, radius, height)
phase_ana = an.phase_mag_disc(dim, res, beta, center, radius, b_0)
# Project the magnetization data:
mag_data = MagData(res, mc.create_mag_dist(mag_shape, beta))
projection = pj.simple_axis_projection(mag_data)
# '''FOURIER'''
# #padding
# RMS = np.zeros(len(padding))
# duration = np.zeros(len(padding))
# for i in range(len(padding)):
# print 'padding =', padding[i]
# start_time = time.time()
# phase_num = pm.phase_mag_fourier(res, projection, b_0, padding[i])
# duration[i] = time.time() - start_time
# phase_diff = phase_ana - phase_num
# RMS[i] = np.std(phase_diff)
#
# fig = plt.figure()
# fig.add_subplot(111)
# plt.plot(padding, RMS)
#
# fig = plt.figure()
# fig.add_subplot(111)
# plt.plot(padding, duration)
'''REAL SLAB '''
beta = np.linspace(0, 2*pi, endpoint=False, num=72)
RMS = np.zeros(len(beta))
for i in range(len(beta)):
print 'beta =', round(360*beta[i]/(2*pi))
mag_data = MagData(res, mc.create_mag_dist(mag_shape, beta[i]))
projection = pj.simple_axis_projection(mag_data)
phase_num = pm.phase_mag_real(res, projection, 'slab', b_0)
phase_ana = an.phase_mag_slab(dim, res, beta[i], center, width, b_0)
phase_diff = phase_ana - phase_num
RMS[i] = np.std(phase_diff)
fig = plt.figure()
fig.add_subplot(111)
plt.plot(round(360*beta/(2*pi)), RMS)
# phase_map_slab = PhaseMap(res, pm.phase_mag_real(res, projection, 'slab', b_0))
# phase_map_disc = PhaseMap(res, pm.phase_mag_real(res, projection, 'disc', b_0))
# # Display the combinated plots with phasemap and holography image:
# hi.display_combined(phase_map_ana, density, 'Analytic Solution')
# hi.display_combined(phase_map_fft, density, 'Fourier Space')
# hi.display_combined(phase_map_slab, density, 'Real Space (Slab)')
# hi.display_combined(phase_map_disc, density, 'Real Space (Disc)')
#
# # Plot differences to the analytic solution:
#
# phase_map_diff_slab = PhaseMap(res, phase_map_ana.phase-phase_map_slab.phase)
# phase_map_diff_disc = PhaseMap(res, phase_map_ana.phase-phase_map_disc.phase)
#
# RMS_slab = phase_map_diff_slab.phase
# RMS_disc = phase_map_diff_disc.phase
if __name__ == "__main__":
try:
phase_from_mag()
except:
type, value, tb = sys.exc_info()
traceback.print_exc()
pdb.post_mortem(tb)
\ No newline at end of file
......@@ -30,27 +30,34 @@ def phase_from_mag():
beta = pi/4
padding = 20
density = 10
dim = (1, 50, 50) # in px (z, y, x)
dim = (1, 100, 100) # in px (z, y, x)
# Create magnetic shape:
geometry = 'slab'
if geometry == 'slab':
center = (0, 24, 24) # in px (z, y, x) index starts with 0!
width = (1, 25, 25) # in px (z, y, x)
center = (0, 49, 49) # in px (z, y, x) index starts with 0!
width = (1, 50, 50) # in px (z, y, x)
mag_shape = mc.Shapes.slab(dim, center, width)
phase_ana = an.phasemap_slab(dim, res, beta, center, width, b_0)
phase_ana = an.phase_mag_slab(dim, res, beta, center, width, b_0)
elif geometry == 'disc':
radius = 12.5 # in px
height = 1 # in px
center = (0, 49, 49) # in px (z, y, x) index starts with 0!
radius = 25 # in px
height = 1 # in px
mag_shape = mc.Shapes.disc(dim, center, radius, height)
phase_ana = an.phasemap_disc(dim, res, beta, center, radius, b_0)
phase_ana = an.phase_mag_disc(dim, res, beta, center, radius, b_0)
# Project the magnetization data:
mag_data = MagData(res, mc.create_mag_dist(mag_shape, beta))
projection = pj.simple_axis_projection(mag_data)
# Construct phase maps:
phase_map_ana = PhaseMap(res, phase_ana)
start_time = time.time()
phase_map_fft = PhaseMap(res, pm.phase_mag_fourier(res, projection, b_0, padding))
print 'Time for Fourier space approach: ', time.time() - start_time
start_time = time.time()
phase_map_slab = PhaseMap(res, pm.phase_mag_real(res, projection, 'slab', b_0))
print 'Time for real space approach (Slab):', time.time() - start_time
start_time = time.time()
phase_map_disc = PhaseMap(res, pm.phase_mag_real(res, projection, 'disc', b_0))
print 'Time for real space approach (Disc):', time.time() - start_time
# Display the combinated plots with phasemap and holography image:
hi.display_combined(phase_map_ana, density, 'Analytic Solution')
hi.display_combined(phase_map_fft, density, 'Fourier Space')
......@@ -65,12 +72,12 @@ def phase_from_mag():
phase_map_diff_fft = PhaseMap(res, phase_map_ana.phase-phase_map_fft.phase)
phase_map_diff_slab = PhaseMap(res, phase_map_ana.phase-phase_map_slab.phase)
phase_map_diff_disc = PhaseMap(res, phase_map_ana.phase-phase_map_disc.phase)
RMS_fft = phase_map_diff_fft.phase
RMS_slab = phase_map_diff_slab.phase
RMS_disc = phase_map_diff_disc.phase
phase_map_diff_fft.display('Fourier Space (RMS = {})'.format(np.std(RMS_fft)))
phase_map_diff_slab.display('Real Space (Slab) (RMS = {})'.format(np.std(RMS_slab)))
phase_map_diff_disc.display('Real Space (Disc) (RMS = {})'.format(np.std(RMS_disc)))
RMS_fft = np.std(phase_map_diff_fft.phase)
RMS_slab = np.std(phase_map_diff_slab.phase)
RMS_disc = np.std(phase_map_diff_disc.phase)
phase_map_diff_fft.display('Fourier Space (RMS = {:3.2e})'.format(RMS_fft))
phase_map_diff_slab.display('Real Space (Slab) (RMS = {:3.2e})'.format(RMS_slab))
phase_map_diff_disc.display('Real Space (Disc) (RMS = {:3.2e})'.format(RMS_disc))
if __name__ == "__main__":
......
......@@ -26,7 +26,7 @@ def compare_pixel_fields():
dim = (1, 11, 11)
pixel = (0, 5, 5)
# Create magnetic data, project it, get the phase map and display the holography image:
mag_data = MagData(res, mc.create_mag_dist(mc.Shapes.single_pixel(dim, pixel), beta))
mag_data = MagData(res, mc.create_mag_dist(mc.Shapes.pixel(dim, pixel), beta))
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)')
......
......@@ -8,10 +8,10 @@ from numpy import pi
import pyramid.magcreator as mc
from pyramid.magdata import MagData
#import pyramid.phasemapper as pm
#import pyramid.projector as pj
#import pyramid.holoimage as hi
#from pyramid.phasemap import PhaseMap
import pyramid.phasemapper as pm
import pyramid.projector as pj
import pyramid.holoimage as hi
from pyramid.phasemap import PhaseMap
def create_random_distribution():
......@@ -33,7 +33,7 @@ def create_random_distribution():
magnitude_list = np.zeros(count)
for i in range(count):
pixel = (rnd.randrange(dim[0]), rnd.randrange(dim[1]), rnd.randrange(dim[2]))
mag_shape_list[i,...] = mc.Shapes.single_pixel(dim, pixel)
mag_shape_list[i,...] = mc.Shapes.pixel(dim, pixel)
beta_list[i] = 2*pi*rnd.random()
magnitude_list[i] = 1#rnd.random()
# Create magnetic distribution
......@@ -41,9 +41,9 @@ def create_random_distribution():
mag_data = MagData(res, magnitude)
mag_data.quiver_plot()
mag_data.save_to_llg('../output/mag_dist_random_pixel.txt')
# 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, 10))
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, 10))
if __name__ == "__main__":
......
......@@ -40,7 +40,7 @@ def create_sample():
elif key == 'filament':
mag_shape = mc.Shapes.filament(dim, pos)
elif key == 'pixel':
mag_shape = mc.Shapes.single_pixel(dim, pixel)
mag_shape = mc.Shapes.pixel(dim, pixel)
# Create magnetic distribution
magnitude = mc.create_mag_dist(mag_shape, beta)
mag_data = MagData(res, magnitude)
......
......@@ -7,8 +7,9 @@ Created on Wed Apr 03 11:15:38 2013
import numpy as np
import pyramid.magcreator as mc
import pyramid.dataloader as dl
import pyramid.phasemap as pm
import pyramid.projector as pj
import pyramid.phasemapper as pm
from pyramid.magdata import MagData
import time
import pdb, traceback, sys
from numpy import pi
......@@ -23,33 +24,28 @@ def phase_from_mag():
'''
# TODO: Input via GUI
filename = '../output/output.txt'
b_0 = 1.0 # in T
dim = (3, 3) # in px (y,x)
dim = (1, 3, 3) # in px (y,x)
res = 10.0 # in nm
beta = pi/4
beta = 0*pi/4
center = (1, 1) # in px (y,x) index starts with 0!
width = (1, 1) # in px (y,x)
mag_shape = mc.slab(dim, center, width)
'''CREATE MAGNETIC DISTRIBUTION'''
mc.create_hom_mag(dim, res, beta, mag_shape, filename)
center = (0, 1, 1) # in px (y,x) index starts with 0!
width = (0, 1, 1) # in px (y,x)
mag_shape = mc.Shapes.slab(dim, center, width)
mag_data = MagData(res, mc.create_mag_dist(mag_shape, beta))
'''LOAD MAGNETIC DISTRIBUTION'''
mag_data = dl.MagDataLLG(filename)
projection = pj.simple_axis_projection(mag_data)
'''NUMERICAL SOLUTION'''
# numerical solution Real Space (Slab):
jacobi = np.zeros((dim[0]*dim[1], 2*dim[0]*dim[1]))
jacobi = np.zeros((dim[2]*dim[1], 2*dim[2]*dim[1]))
tic = time.clock()
pm.real_space(mag_data, 'slab', b_0, jacobi=jacobi)
pm.phase_mag_real(res, projection, 'slab', b_0, jacobi=jacobi)
toc = time.clock()
np.savetxt('../output/jacobi.npy', jacobi)
print 'Time for Real Space Approach with Jacobi-Matrix (Slab): ' + str(toc - tic)
return jacobi
......
# -*- coding: utf-8 -*-
"""
Created on Tue May 21 14:29:25 2013
@author: Jan
"""
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'create_logo.ui'
#
# Created: Tue May 21 14:29:03 2013
# by: PyQt4 UI code generator 4.9.5
#
# WARNING! All changes made in this file will be lost!
from PyQt4 import QtCore, QtGui
try:
_fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
_fromUtf8 = lambda s: s
class Ui_CreateLogoWidget(object):
def setupUi(self, CreateLogoWidget):
CreateLogoWidget.setObjectName(_fromUtf8("CreateLogoWidget"))
CreateLogoWidget.resize(520, 492)
self.verticalLayout_2 = QtGui.QVBoxLayout(CreateLogoWidget)
self.verticalLayout_2.setObjectName(_fromUtf8("verticalLayout_2"))
self.verticalLayout = QtGui.QVBoxLayout()
self.verticalLayout.setObjectName(_fromUtf8("verticalLayout"))
self.horizontalLayout = QtGui.QHBoxLayout()
self.horizontalLayout.setObjectName(_fromUtf8("horizontalLayout"))
self.xLabel = QtGui.QLabel(CreateLogoWidget)
self.xLabel.setAlignment(QtCore.Qt.AlignRight|QtCore.Qt.AlignTrailing|QtCore.Qt.AlignVCenter)
self.xLabel.setObjectName(_fromUtf8("xLabel"))
self.horizontalLayout.addWidget(self.xLabel)
self.xSpinBox = QtGui.QSpinBox(CreateLogoWidget)
self.xSpinBox.setAlignment(QtCore.Qt.AlignRight|QtCore.Qt.AlignTrailing|QtCore.Qt.AlignVCenter)
self.xSpinBox.setMaximum(512)
self.xSpinBox.setProperty("value", 128)
self.xSpinBox.setObjectName(_fromUtf8("xSpinBox"))
self.horizontalLayout.addWidget(self.xSpinBox)
self.yLabel = QtGui.QLabel(CreateLogoWidget)
self.yLabel.setAlignment(QtCore.Qt.AlignRight|QtCore.Qt.AlignTrailing|QtCore.Qt.AlignVCenter)
self.yLabel.setObjectName(_fromUtf8("yLabel"))
self.horizontalLayout.addWidget(self.yLabel)
self.ySpinBox = QtGui.QSpinBox(CreateLogoWidget)
self.ySpinBox.setAlignment(QtCore.Qt.AlignRight|QtCore.Qt.AlignTrailing|QtCore.Qt.AlignVCenter)
self.ySpinBox.setMaximum(512)
self.ySpinBox.setProperty("value", 128)
self.ySpinBox.setObjectName(_fromUtf8("ySpinBox"))
self.horizontalLayout.addWidget(self.ySpinBox)
self.logoPushButton = QtGui.QPushButton(CreateLogoWidget)
self.logoPushButton.setObjectName(_fromUtf8("logoPushButton"))
self.horizontalLayout.addWidget(self.logoPushButton)
self.verticalLayout.addLayout(self.horizontalLayout)
self.verticalLayout_2.addLayout(self.verticalLayout)
self.mplWidget = MatplotlibWidget(CreateLogoWidget)
self.mplWidget.setCursor(QtGui.QCursor(QtCore.Qt.ArrowCursor))
self.mplWidget.setLayoutDirection(QtCore.Qt.LeftToRight)
self.mplWidget.setAutoFillBackground(False)
self.mplWidget.setObjectName(_fromUtf8("mplWidget"))
self.verticalLayout_2.addWidget(self.mplWidget)
self.retranslateUi(CreateLogoWidget)
QtCore.QMetaObject.connectSlotsByName(CreateLogoWidget)
def retranslateUi(self, CreateLogoWidget):
CreateLogoWidget.setWindowTitle(QtGui.QApplication.translate("CreateLogoWidget", "Form", None, QtGui.QApplication.UnicodeUTF8))
self.xLabel.setText(QtGui.QApplication.translate("CreateLogoWidget", "X [px] :", None, QtGui.QApplication.UnicodeUTF8))
self.yLabel.setText(QtGui.QApplication.translate("CreateLogoWidget", "Y [px] :", None, QtGui.QApplication.UnicodeUTF8))
self.logoPushButton.setText(QtGui.QApplication.translate("CreateLogoWidget", "Create Logo", None, QtGui.QApplication.UnicodeUTF8))
from matplotlibwidget import MatplotlibWidget
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>CreateLogoWidget</class>
<widget class="QWidget" name="CreateLogoWidget">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>520</width>
<height>492</height>
</rect>
</property>
<property name="windowTitle">
<string>Create Pyramid Logo</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="xLabel">
<property name="text">
<string>X [px] :</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="xSpinBox">
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
<property name="maximum">
<number>512</number>
</property>
<property name="value">
<number>128</number>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="yLabel">
<property name="text">
<string>Y [px] :</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="ySpinBox">
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
<property name="maximum">
<number>512</number>
</property>
<property name="value">
<number>128</number>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="logoPushButton">
<property name="text">
<string>Create Logo</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</item>
<item>
<widget class="MatplotlibWidget" name="mplWidget">
<property name="cursor">
<cursorShape>ArrowCursor</cursorShape>
</property>
<property name="layoutDirection">
<enum>Qt::LeftToRight</enum>
</property>
<property name="autoFillBackground">
<bool>false</bool>
</property>
</widget>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>MatplotlibWidget</class>
<extends>QWidget</extends>
<header>matplotlibwidget</header>
</customwidget>
</customwidgets>
<resources/>
<connections/>
</ui>
# -*- coding: utf-8 -*-
"""Create the Pyramid-Logo via GUI-Input."""
import sys
import numpy as np
from numpy import pi
from PyQt4 import QtCore, QtGui, uic
import pyramid.magcreator as mc
import pyramid.projector as pj
import pyramid.phasemapper as pm
import pyramid.holoimage as hi
from pyramid.magdata import MagData
from pyramid.phasemap import PhaseMap
from gui.create_logo import Ui_CreateLogoWidget
class Overlay(QtGui.QWidget):
def __init__(self, parent = None):
QtGui.QWidget.__init__(self, parent)
palette = QtGui.QPalette(self.palette())
palette.setColor(palette.Background, QtCore.Qt.transparent)
self.setPalette(palette)
def paintEvent(self, event):
painter = QtGui.QPainter()
painter.begin(self)
painter.setRenderHint(QtGui.QPainter.Antialiasing)
painter.fillRect(event.rect(), QtGui.QBrush(QtGui.QColor(255, 255, 255, 127)))
painter.setPen(QtGui.QPen(QtCore.Qt.NoPen))
for i in range(6):
if (self.counter / 5) % 6 == i:
painter.setBrush(QtGui.QBrush(QtGui.QColor(127, 127 + (self.counter % 5)*32, 127)))
else:
painter.setBrush(QtGui.QBrush(QtGui.QColor(127, 127, 127)))
painter.drawEllipse(
self.width()/2 + 30 * np.cos(2 * pi * i / 6.0) - 10,
self.height()/2 + 30 * np.sin(2 * pi * i / 6.0) - 10,
20, 20)
painter.end()
def showEvent(self, event):
self.timer = self.startTimer(50)
self.counter = 0
def hideEvent(self, event):
self.killTimer(self.timer)
def timerEvent(self, event):
self.counter += 1
self.update()
class CreateLogoWidget(QtGui.QWidget, Ui_CreateLogoWidget):
def __init__(self):
# Call parent constructor
QtGui.QWidget.__init__(self)
self.setupUi(self)
self.ui = uic.loadUi('gui/create_logo.ui')
# self.setCentralWidget(self.ui)
# Connect Widgets with locally defined functions:
self.connect(self.logoPushButton, QtCore.SIGNAL('clicked()'), self.buttonPushed)
# Create overlay to indicate busy state:
self.overlay = Overlay(self)
# self.ui.overlay = Overlay(self.ui)
self.overlay.hide()
# Show Widget:
self.show()
self.workerThread = WorkerThread()
def buttonPushed(self):
self.overlay.show()
x = self.xSpinBox.value()
y = self.ySpinBox.value()
create_logo((1, y, x), self.mplWidget.axes)
self.mplWidget.draw()
# self.workerThread.start()
self.overlay.hide()
def resizeEvent(self, event):
self.overlay.resize(event.size())
event.accept()
class WorkerThread(QtCore.QThread):
def __init__(self, parent=None):
QtCore.QThread.__init__(self)
def run(self):
x = self.xSpinBox.value()
y = self.ySpinBox.value()
create_logo((1, y, x), self.mplWidget.axes)
self.mplWidget.draw()
def create_logo(dim, axis):
'''Calculate and display the Pyramid-Logo.
Arguments:
None
Returns:
None
'''
# Input parameters:
res = 10.0 # in nm
beta = pi/2 # in rad
density = 10
# 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(res, mc.create_mag_dist(mag_shape, beta))
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', axis)
if __name__ == '__main__':
app = QtGui.QApplication(sys.argv)
gui = CreateLogoWidget()
sys.exit(app.exec_())
\ No newline at end of file
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