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 320 deletions
File deleted
File deleted
File deleted
File deleted
File deleted
File deleted
File deleted
File deleted
# -*- coding: utf-8 -*-
"""Testcase for the magdata module."""
import os
import unittest
import numpy as np
from pyramid.magdata import MagData
class TestCaseMagData(unittest.TestCase):
def setUp(self):
self.path = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'test_magdata')
magnitude = (np.zeros((4, 4, 4)), np.zeros((4, 4, 4)), np.zeros((4, 4, 4)))
magnitude[0][1:-1, 1:-1, 1:-1] = 1
magnitude[1][1:-1, 1:-1, 1:-1] = 1
magnitude[2][1:-1, 1:-1, 1:-1] = 1
self.mag_data = MagData(10.0, magnitude)
def tearDown(self):
self.path = None
self.mag_data = None
def test_add_magnitude(self):
reference = (np.ones((4, 4, 4)), np.ones((4, 4, 4)), np.ones((4, 4, 4)))
self.mag_data.add_magnitude(reference)
reference[0][1:-1, 1:-1, 1:-1] = 2
reference[1][1:-1, 1:-1, 1:-1] = 2
reference[2][1:-1, 1:-1, 1:-1] = 2
np.testing.assert_equal(self.mag_data.magnitude, reference,
'Unexpected behavior in add_magnitude()!')
def test_get_mask(self):
mask = self.mag_data.get_mask()
reference = np.zeros((4, 4, 4))
reference[1:-1, 1:-1, 1:-1] = True
np.testing.assert_equal(mask, reference, 'Unexpected behavior in get_mask()!')
def test_get_vector(self):
mask = self.mag_data.get_mask()
vector = self.mag_data.get_vector(mask)
reference = np.ones(np.count_nonzero(self.mag_data.magnitude[0])*3)
np.testing.assert_equal(vector, reference, 'Unexpected behavior in get_mask()!')
def test_set_vector(self):
mask = self.mag_data.get_mask()
vector = 2 * np.ones(np.count_nonzero(self.mag_data.magnitude[0])*3)
self.mag_data.set_vector(mask, vector)
reference = (np.zeros((4, 4, 4)), np.zeros((4, 4, 4)), np.zeros((4, 4, 4)))
reference[0][1:-1, 1:-1, 1:-1] = 2
reference[1][1:-1, 1:-1, 1:-1] = 2
reference[2][1:-1, 1:-1, 1:-1] = 2
np.testing.assert_equal(self.mag_data.magnitude, reference,
'Unexpected behavior in set_mask()!')
def test_scale_down(self):
self.mag_data.scale_down()
reference = (1/8. * np.ones((2, 2, 2)),
1/8. * np.ones((2, 2, 2)),
1/8. * np.ones((2, 2, 2)))
np.testing.assert_equal(self.mag_data.magnitude, reference,
'Unexpected behavior in scale_down()!')
np.testing.assert_equal(self.mag_data.res, 20, 'Unexpected behavior in scale_down()!')
def test_load_from_llg(self):
self.mag_data = MagData.load_from_llg(os.path.join(self.path, 'ref_mag_data.txt'))
reference = (np.zeros((4, 4, 4)), np.zeros((4, 4, 4)), np.zeros((4, 4, 4)))
reference[0][1:-1, 1:-1, 1:-1] = 1
reference[1][1:-1, 1:-1, 1:-1] = 1
reference[2][1:-1, 1:-1, 1:-1] = 1
np.testing.assert_equal(self.mag_data.magnitude, reference,
'Unexpected behavior in load_from_llg()!')
np.testing.assert_equal(self.mag_data.res, 10, 'Unexpected behavior in load_from_llg()!')
def test_load_from_netcdf4(self):
self.mag_data = MagData.load_from_netcdf4(os.path.join(self.path, 'ref_mag_data.nc'))
reference = (np.zeros((4, 4, 4)), np.zeros((4, 4, 4)), np.zeros((4, 4, 4)))
reference[0][1:-1, 1:-1, 1:-1] = 1
reference[1][1:-1, 1:-1, 1:-1] = 1
reference[2][1:-1, 1:-1, 1:-1] = 1
np.testing.assert_equal(self.mag_data.magnitude, reference,
'Unexpected behavior in load_from_netcdf4()!')
np.testing.assert_equal(self.mag_data.res, 10,
'Unexpected behavior in load_from_netcdf4()!')
if __name__ == '__main__':
suite = unittest.TestLoader().loadTestsFromTestCase(TestCaseMagData)
unittest.TextTestRunner(verbosity=2).run(suite)
File deleted
LLGFileCreator: test_magdata/ref_mag_data
4 4 4
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
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
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
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
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
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 1.000000e+00 1.000000e+00 1.000000e+00
2.500000e-06 1.500000e-06 1.500000e-06 1.000000e+00 1.000000e+00 1.000000e+00
3.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 1.000000e+00 1.000000e+00 1.000000e+00
2.500000e-06 2.500000e-06 1.500000e-06 1.000000e+00 1.000000e+00 1.000000e+00
3.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 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
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 1.000000e+00 1.000000e+00 1.000000e+00
2.500000e-06 1.500000e-06 2.500000e-06 1.000000e+00 1.000000e+00 1.000000e+00
3.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 1.000000e+00 1.000000e+00 1.000000e+00
2.500000e-06 2.500000e-06 2.500000e-06 1.000000e+00 1.000000e+00 1.000000e+00
3.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 0.000000e+00 0.000000e+00 0.000000e+00
3.500000e-06 3.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
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
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 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 0.000000e+00 0.000000e+00 0.000000e+00
\ No newline at end of file
# -*- coding: utf-8 -*-
"""Testcase for the phasemap module."""
import os
import unittest
import numpy as np
from pyramid.phasemap import PhaseMap
class TestCasePhaseMap(unittest.TestCase):
def setUp(self):
self.path = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'test_phasemap')
phase = np.zeros((4, 4))
phase[1:-1, 1:-1] = 1
self.phase_map = PhaseMap(10.0, phase)
def tearDown(self):
self.path = None
self.phase_map = None
def test_set_unit(self):
with self.assertRaises(AssertionError):
self.phase_map.set_unit('nonsense')
self.phase_map.set_unit('mrad')
self.assertEqual(self.phase_map.unit, 'mrad', 'Unexpected behavior in set_unit()')
def test_load_from_txt(self):
self.mag_data = PhaseMap.load_from_txt(os.path.join(self.path, 'ref_phase_map.txt'))
reference = np.zeros((4, 4))
reference[1:-1, 1:-1] = 1
np.testing.assert_equal(self.phase_map.phase, reference,
'Unexpected behavior in load_from_txt()!')
np.testing.assert_equal(self.phase_map.res, 10, 'Unexpected behavior in load_from_llg()!')
def test_load_from_netcdf4(self):
self.mag_data = PhaseMap.load_from_netcdf4(os.path.join(self.path, 'ref_phase_map.nc'))
reference = np.zeros((4, 4))
reference[1:-1, 1:-1] = 1
np.testing.assert_equal(self.phase_map.phase, reference,
'Unexpected behavior in load_from_netcdf4()!')
np.testing.assert_equal(self.phase_map.res, 10,
'Unexpected behavior in load_from_netcdf4()!')
if __name__ == '__main__':
suite = unittest.TestLoader().loadTestsFromTestCase(TestCasePhaseMap)
unittest.TextTestRunner(verbosity=2).run(suite)
File deleted
test_phasemap/ref_phase_map
resolution = 10.0 nm
0.000000e+00 0.000000e+00 0.000000e+00 0.000000e+00
0.000000e+00 1.000000e+00 1.000000e+00 0.000000e+00
0.000000e+00 1.000000e+00 1.000000e+00 0.000000e+00
0.000000e+00 0.000000e+00 0.000000e+00 0.000000e+00
# -*- coding: utf-8 -*-
"""Testcase for the phasemapper module."""
import os
import unittest
import numpy as np
import pyramid.phasemapper as pm
class TestCasePhaseMapper(unittest.TestCase):
def setUp(self):
self.path = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'test_phasemapper')
self.projection = (np.zeros((4, 4)), np.zeros((4, 4)), np.zeros((4, 4)))
self.projection[0][1:-1, 1:-1] = 1
self.projection[1][1:-1, 1:-1] = 1
self.projection[2][1:-1, 1:-1] = 1
self.res = 10.0
def tearDown(self):
self.path = None
self.projection = None
def test_phase_mag_fourier(self):
phase = pm.phase_mag_fourier(self.res, self.projection, padding=10)
reference = np.load(os.path.join(self.path, 'ref_phase_mag_fft.npy'))
np.testing.assert_almost_equal(phase, reference, 7,
'Unexpected behavior in phase_mag_fourier()')
def test_phase_mag_real(self):
phase_slab = pm.phase_mag_real(self.res, self.projection, method='slab')
phase_disc = pm.phase_mag_real(self.res, self.projection, method='disc')
ref_slab = np.load(os.path.join(self.path, 'ref_phase_mag_slab.npy'))
ref_disc = np.load(os.path.join(self.path, 'ref_phase_mag_disc.npy'))
np.testing.assert_almost_equal(phase_slab, ref_slab, 7,
'Unexpected behavior in phase_mag_real() (slab)')
np.testing.assert_almost_equal(phase_disc, ref_disc, 7,
'Unexpected behavior in phase_mag_real() (disc)')
def test_phase_mag_real_conv(self):
phase_slab = pm.phase_mag_real_conv(self.res, self.projection, method='slab')
phase_disc = pm.phase_mag_real_conv(self.res, self.projection, method='disc')
ref_slab = np.load(os.path.join(self.path, 'ref_phase_mag_slab.npy'))
ref_disc = np.load(os.path.join(self.path, 'ref_phase_mag_disc.npy'))
np.testing.assert_almost_equal(phase_slab, ref_slab, 7,
'Unexpected behavior in phase_mag_real_conv() (slab)')
np.testing.assert_almost_equal(phase_disc, ref_disc, 7,
'Unexpected behavior in phase_mag_real_conv() (disc)')
def test_phase_elec(self):
phase = pm.phase_elec(self.res, self.projection, v_0=1, v_acc=30000)
reference = np.load(os.path.join(self.path, 'ref_phase_elec.npy'))
np.testing.assert_almost_equal(phase, reference, 7,
'Unexpected behavior in phase_elec()')
if __name__ == '__main__':
suite = unittest.TestLoader().loadTestsFromTestCase(TestCasePhaseMapper)
unittest.TextTestRunner(verbosity=2).run(suite)
File deleted
File deleted
File deleted
File deleted
# -*- coding: utf-8 -*-
"""Testcase for the projector module."""
import os
import unittest
import numpy as np
import pyramid.projector as pj
from pyramid.magdata import MagData
class TestCaseProjector(unittest.TestCase):
def setUp(self):
self.path = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'test_projector')
self.mag_data = MagData.load_from_llg(os.path.join(self.path, 'ref_mag_data.txt'))
def tearDown(self):
self.path = None
self.mag_data = None
def test_simple_axis_projection(self):
z_proj_ref = (np.loadtxt(os.path.join(self.path, 'ref_proj_z.txt')))
y_proj_ref = (np.loadtxt(os.path.join(self.path, 'ref_proj_y.txt')))
x_proj_ref = (np.loadtxt(os.path.join(self.path, '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, '1')
np.testing.assert_equal(z_proj[1], z_proj_ref, '2')
np.testing.assert_equal(z_proj[2], z_proj_ref, '3')
np.testing.assert_equal(y_proj[0], y_proj_ref, '4')
np.testing.assert_equal(y_proj[1], y_proj_ref, '5')
np.testing.assert_equal(y_proj[2], y_proj_ref, '6')
np.testing.assert_equal(x_proj[0], x_proj_ref, '7')
np.testing.assert_equal(x_proj[1], x_proj_ref, '8')
np.testing.assert_equal(x_proj[2], x_proj_ref, '9')
def test_single_axis_projection(self):
raise AssertionError
if __name__ == '__main__':
suite = unittest.TestLoader().loadTestsFromTestCase(TestCaseProjector)
unittest.TextTestRunner(verbosity=2).run(suite)