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

shapes are now in a dedicated module!

parent 2e90dd41
No related branches found
No related tags found
No related merge requests found
Showing
with 312 additions and 289 deletions
......@@ -50,6 +50,7 @@ numcore
from . import analytic
from . import magcreator
from . import shapes
from . import reconstruction
from . import fft
from . import fieldconverter
......@@ -77,7 +78,7 @@ _log = logging.getLogger(__name__)
_log.info("Starting Pyramid V{} HG{}".format(__version__, __hg_revision__))
del logging
__all__ = ['analytic', 'magcreator', 'reconstruction', 'fft', 'fieldconverter']
__all__ = ['analytic', 'magcreator', 'shapes', 'reconstruction', 'fft', 'fieldconverter']
__all__.extend(costfunction.__all__)
__all__.extend(dataset.__all__)
__all__.extend(diagnostics.__all__)
......
......@@ -5,9 +5,9 @@
"""Create simple magnetic distributions.
The :mod:`~.magcreator` module is responsible for the creation of simple distributions of
magnetic moments. In the :class:`~.Shapes` class, you can find several general shapes for the
magnetic moments. In the :mod:`~.shapes` module, you can find several general shapes for the
3-dimensional volume that should be magnetized (e.g. slabs, spheres, discs or single pixels).
These magnetic shapes are then used as input for the creating functions (or you could specify the
These shapes are then used as input for the creating functions (or you could specify the
volume yourself as a 3-dimensional boolean matrix or a matrix with values in the range from 0 to 1,
which modifies the magnetization amplitude). The specified volume can either be magnetized
homogeneously with the :func:`~.create_mag_dist_homog` function by specifying the magnetization
......@@ -18,268 +18,22 @@ center.
from __future__ import division
import abc
import logging
import numpy as np
from numpy import pi
__all__ = ['Shapes', 'create_mag_dist_homog', 'create_mag_dist_vortex']
__all__ = ['create_mag_dist_homog', 'create_mag_dist_vortex']
_log = logging.getLogger(__name__)
class Shapes(object, metaclass=abc.ABCMeta):
"""Abstract class containing functions for generating magnetic shapes.
The :class:`~.Shapes` class is a collection of some methods that return a 3-dimensional
matrix that represents the magnetized volume and consists of values between 0 and 1.
This matrix is used in the functions of the :mod:`~.magcreator` module to create
:class:`~pyramid.magdata.VectorData` objects which store the magnetic informations.
"""
_log = logging.getLogger(__name__ + '.Shapes')
@staticmethod
def slab(dim, center, width):
"""Create the shape of a slab.
Parameters
----------
dim : tuple (N=3)
The dimensions of the grid `(z, y, x)`.
center : tuple (N=3)
The center of the slab in pixel coordinates `(z, y, x)`.
width : tuple (N=3)
The width of the slab in pixel coordinates `(z, y, x)`.
Returns
-------
mag_shape : :class:`~numpy.ndarray` (N=3)
The magnetic shape as a 3D-array with values between 1 and 0.
"""
_log.debug('Calling slab')
assert np.shape(dim) == (3,), 'Parameter dim has to be a tuple of length 3!'
assert np.shape(center) == (3,), 'Parameter center has to be a tuple of length 3!'
assert np.shape(width) == (3,), 'Parameter width has to be a tuple of length 3!'
zz, yy, xx = np.indices(dim) + 0.5
xx_shape = np.where(abs(xx - center[2]) <= width[2] / 2, True, False)
yy_shape = np.where(abs(yy - center[1]) <= width[1] / 2, True, False)
zz_shape = np.where(abs(zz - center[0]) <= width[0] / 2, True, False)
return np.logical_and(np.logical_and(xx_shape, yy_shape), zz_shape)
@staticmethod
def disc(dim, center, radius, height, axis='z'):
"""Create the shape of a cylindrical disc in x-, y-, or z-direction.
Parameters
----------
dim : tuple (N=3)
The dimensions of the grid `(z, y, x)`.
center : tuple (N=3)
The center of the disc in pixel coordinates `(z, y, x)`.
radius : float
The radius of the disc in pixel coordinates.
height : float
The height of the disc in pixel coordinates.
axis : {'z', 'y', 'x'}, optional
The orientation of the disc axis. The default is 'z'.
Returns
-------
mag_shape : :class:`~numpy.ndarray` (N=3)
The magnetic shape as a 3D-array with values between 1 and 0.
"""
_log.debug('Calling disc')
assert np.shape(dim) == (3,), 'Parameter dim has to be a a tuple of length 3!'
assert np.shape(center) == (3,), 'Parameter center has to be a a tuple of length 3!'
assert radius > 0 and np.shape(radius) == (), 'Radius has to be a positive scalar value!'
assert height > 0 and np.shape(height) == (), 'Height has to be a positive scalar value!'
assert axis in {'z', 'y', 'x'}, 'Axis has to be x, y or z (as a string)!'
zz, yy, xx = np.indices(dim) + 0.5
xx -= center[2]
yy -= center[1]
zz -= center[0]
if axis == 'z':
uu, vv, ww = xx, yy, zz
elif axis == 'y':
uu, vv, ww = zz, xx, yy
elif axis == 'x':
uu, vv, ww = yy, zz, xx
else:
raise ValueError('{} is not a valid argument (use x, y or z)'.format(axis))
return np.logical_and(np.where(np.hypot(uu, vv) <= radius, True, False),
np.where(abs(ww) <= height / 2, True, False))
@staticmethod
def ellipse(dim, center, width, height, axis='z'):
"""Create the shape of an elliptical cylinder in x-, y-, or z-direction.
Parameters
----------
dim : tuple (N=3)
The dimensions of the grid `(z, y, x)`.
center : tuple (N=3)
The center of the ellipse in pixel coordinates `(z, y, x)`.
width : tuple (N=2)
Length of the two axes of the ellipse.
height : float
The height of the ellipse in pixel coordinates.
axis : {'z', 'y', 'x'}, optional
The orientation of the ellipse axis. The default is 'z'.
Returns
-------
mag_shape : :class:`~numpy.ndarray` (N=3)
The magnetic shape as a 3D-array with values between 1 and 0.
"""
_log.debug('Calling ellipse')
assert np.shape(dim) == (3,), 'Parameter dim has to be a a tuple of length 3!'
assert np.shape(center) == (3,), 'Parameter center has to be a a tuple of length 3!'
assert np.shape(width) == (2,), 'Parameter width has to be a a tuple of length 2!'
assert height > 0 and np.shape(height) == (), 'Height has to be a positive scalar value!'
assert axis in {'z', 'y', 'x'}, 'Axis has to be x, y or z (as a string)!'
zz, yy, xx = np.indices(dim) + 0.5
xx -= center[2]
yy -= center[1]
zz -= center[0]
if axis == 'z':
uu, vv, ww = xx, yy, zz
elif axis == 'y':
uu, vv, ww = xx, zz, yy
elif axis == 'x':
uu, vv, ww = yy, zz, xx
else:
raise ValueError('{} is not a valid argument (use x, y or z)'.format(axis))
distance = np.hypot(uu / (width[1] / 2), vv / (width[0] / 2))
return np.logical_and(np.where(distance <= 1, True, False),
np.where(abs(ww) <= height / 2, True, False))
@staticmethod
def sphere(dim, center, radius):
"""Create the shape of a sphere.
Parameters
----------
dim : tuple (N=3)
The dimensions of the grid `(z, y, x)`.
center : tuple (N=3)
The center of the sphere in pixel coordinates `(z, y, x)`.
radius : float
The radius of the sphere in pixel coordinates.
Returns
-------
mag_shape : :class:`~numpy.ndarray` (N=3)
The magnetic shape as a 3D-array with values between 1 and 0.
"""
_log.debug('Calling sphere')
assert np.shape(dim) == (3,), 'Parameter dim has to be a a tuple of length 3!'
assert np.shape(center) == (3,), 'Parameter center has to be a a tuple of length 3!'
assert radius > 0 and np.shape(radius) == (), 'Radius has to be a positive scalar value!'
zz, yy, xx = np.indices(dim) + 0.5
distance = np.sqrt((xx - center[2]) ** 2 + (yy - center[1]) ** 2 + (zz - center[0]) ** 2)
return np.where(distance <= radius, True, False)
@staticmethod
def ellipsoid(dim, center, width):
"""Create the shape of an ellipsoid.
Parameters
----------
dim : tuple (N=3)
The dimensions of the grid `(z, y, x)`.
center : tuple (N=3)
The center of the ellipsoid in pixel coordinates `(z, y, x)`.
width : tuple (N=3)
The width of the ellipsoid `(z, y, x)`.
Returns
-------
mag_shape : :class:`~numpy.ndarray` (N=3)
The magnetic shape as a 3D-array with values between 1 and 0.
"""
_log.debug('Calling ellipsoid')
assert np.shape(dim) == (3,), 'Parameter dim has to be a a tuple of length 3!'
assert np.shape(center) == (3,), 'Parameter center has to be a a tuple of length 3!'
assert np.shape(width) == (3,), 'Parameter width has to be a a tuple of length 3!'
zz, yy, xx = np.indices(dim) + 0.5
distance = np.sqrt(((xx - center[2]) / (width[2] / 2)) ** 2
+ ((yy - center[1]) / (width[1] / 2)) ** 2
+ ((zz - center[0]) / (width[0] / 2)) ** 2)
return np.where(distance <= 1, True, False)
@staticmethod
def filament(dim, pos, axis='y'):
"""Create the shape of a filament.
Parameters
----------
dim : tuple (N=3)
The dimensions of the grid `(z, y, x)`.
pos : tuple (N=2)
The position of the filament in pixel coordinates `(coord1, coord2)`.
`coord1` and `coord2` stand for the two axes, which are perpendicular to `axis`. For
the default case (`axis = y`), it is `(coord1, coord2) = (z, x)`.
axis : {'y', 'x', 'z'}, optional
The orientation of the filament axis. The default is 'y'.
Returns
-------
mag_shape : :class:`~numpy.ndarray` (N=3)
The magnetic shape as a 3D-array with values between 1 and 0.
"""
_log.debug('Calling filament')
assert np.shape(dim) == (3,), 'Parameter dim has to be a tuple of length 3!'
assert np.shape(pos) == (2,), 'Parameter pos has to be a tuple of length 2!'
assert axis in {'z', 'y', 'x'}, 'Axis has to be x, y or z (as a string)!'
mag_shape = np.zeros(dim)
if axis == 'z':
mag_shape[:, pos[0], pos[1]] = 1
elif axis == 'y':
mag_shape[pos[0], :, pos[1]] = 1
elif axis == 'x':
mag_shape[pos[0], pos[1], :] = 1
return mag_shape
@staticmethod
def pixel(dim, pixel):
"""Create the shape of a single pixel.
Parameters
----------
dim : tuple (N=3)
The dimensions of the grid `(z, y, x)`.
pixel : tuple (N=3)
The coordinates of the pixel `(z, y, x)`.
Returns
-------
mag_shape : :class:`~numpy.ndarray` (N=3)
The magnetic shape as a 3D-array with values between 1 and 0.
"""
_log.debug('Calling pixel')
assert np.shape(dim) == (3,), 'Parameter dim has to be a tuple of length 3!'
assert np.shape(pixel) == (3,), 'Parameter pixel has to be a tuple of length 3!'
mag_shape = np.zeros(dim)
mag_shape[pixel] = 1
return mag_shape
def create_mag_dist_homog(mag_shape, phi, theta=pi / 2, amplitude=1):
"""Create a 3-dimensional magnetic distribution of a homogeneously magnetized object.
Parameters
----------
mag_shape : :class:`~numpy.ndarray` (N=3)
The magnetic shapes (see Shapes.* for examples).
The magnetic shapes (see :mod:`.~shapes` for examples).
phi : float
The azimuthal angle, describing the direction of the magnetized object.
theta : float, optional
......@@ -310,7 +64,7 @@ def create_mag_dist_vortex(mag_shape, center=None, axis='z', amplitude=1):
Parameters
----------
mag_shape : :class:`~numpy.ndarray` (N=3)
The magnetic shapes (see :class:`.~Shapes` for examples).
The magnetic shapes (see :mod:`.~shapes`` for examples).
center : tuple (N=2 or N=3), optional
The vortex center, given in 2D `(v, u)` or 3D `(z, y, x)`, where the perpendicular axis
is is discarded. Is set to the center of the field of view if not specified. The vortex
......
# -*- coding: utf-8 -*-
# Copyright 2016 by Forschungszentrum Juelich GmbH
# Author: J. Caron
#
"""Provide simple shapes.
This module is a collection of some methods that return a 3-dimensional
matrix that represents the field volume and consists of boolean values.
This matrix is used in the functions of the :mod:`~.magcreator` module to create
:class:`~pyramid.fielddata.VectorData` objects which store the field information.
"""
import logging
import numpy as np
__all__ = ['slab', 'disc', 'ellipse', 'ellipsoid', 'sphere', 'filament', 'pixel']
_log = logging.getLogger(__name__)
def slab(dim, center, width):
"""Create the shape of a slab.
Parameters
----------
dim : tuple (N=3)
The dimensions of the grid `(z, y, x)`.
center : tuple (N=3)
The center of the slab in pixel coordinates `(z, y, x)`.
width : tuple (N=3)
The width of the slab in pixel coordinates `(z, y, x)`.
Returns
-------
shape : :class:`~numpy.ndarray` (N=3)
The shape as a 3D-array.
"""
_log.debug('Calling slab')
assert np.shape(dim) == (3,), 'Parameter dim has to be a tuple of length 3!'
assert np.shape(center) == (3,), 'Parameter center has to be a tuple of length 3!'
assert np.shape(width) == (3,), 'Parameter width has to be a tuple of length 3!'
zz, yy, xx = np.indices(dim) + 0.5
xx_shape = np.where(abs(xx - center[2]) <= width[2] / 2, True, False)
yy_shape = np.where(abs(yy - center[1]) <= width[1] / 2, True, False)
zz_shape = np.where(abs(zz - center[0]) <= width[0] / 2, True, False)
return np.logical_and(np.logical_and(xx_shape, yy_shape), zz_shape)
def disc(dim, center, radius, height, axis='z'):
"""Create the shape of a cylindrical disc in x-, y-, or z-direction.
Parameters
----------
dim : tuple (N=3)
The dimensions of the grid `(z, y, x)`.
center : tuple (N=3)
The center of the disc in pixel coordinates `(z, y, x)`.
radius : float
The radius of the disc in pixel coordinates.
height : float
The height of the disc in pixel coordinates.
axis : {'z', 'y', 'x'}, optional
The orientation of the disc axis. The default is 'z'.
Returns
-------
shape : :class:`~numpy.ndarray` (N=3)
The shape as a 3D-array.
"""
_log.debug('Calling disc')
assert np.shape(dim) == (3,), 'Parameter dim has to be a a tuple of length 3!'
assert np.shape(center) == (3,), 'Parameter center has to be a a tuple of length 3!'
assert radius > 0 and np.shape(radius) == (), 'Radius has to be a positive scalar value!'
assert height > 0 and np.shape(height) == (), 'Height has to be a positive scalar value!'
assert axis in {'z', 'y', 'x'}, 'Axis has to be x, y or z (as a string)!'
zz, yy, xx = np.indices(dim) + 0.5
xx -= center[2]
yy -= center[1]
zz -= center[0]
if axis == 'z':
uu, vv, ww = xx, yy, zz
elif axis == 'y':
uu, vv, ww = zz, xx, yy
elif axis == 'x':
uu, vv, ww = yy, zz, xx
else:
raise ValueError('{} is not a valid argument (use x, y or z)'.format(axis))
return np.logical_and(np.where(np.hypot(uu, vv) <= radius, True, False),
np.where(abs(ww) <= height / 2, True, False))
def ellipse(dim, center, width, height, axis='z'):
"""Create the shape of an elliptical cylinder in x-, y-, or z-direction.
Parameters
----------
dim : tuple (N=3)
The dimensions of the grid `(z, y, x)`.
center : tuple (N=3)
The center of the ellipse in pixel coordinates `(z, y, x)`.
width : tuple (N=2)
Length of the two axes of the ellipse.
height : float
The height of the ellipse in pixel coordinates.
axis : {'z', 'y', 'x'}, optional
The orientation of the ellipse axis. The default is 'z'.
Returns
-------
shape : :class:`~numpy.ndarray` (N=3)
The shape as a 3D-array.
"""
_log.debug('Calling ellipse')
assert np.shape(dim) == (3,), 'Parameter dim has to be a a tuple of length 3!'
assert np.shape(center) == (3,), 'Parameter center has to be a a tuple of length 3!'
assert np.shape(width) == (2,), 'Parameter width has to be a a tuple of length 2!'
assert height > 0 and np.shape(height) == (), 'Height has to be a positive scalar value!'
assert axis in {'z', 'y', 'x'}, 'Axis has to be x, y or z (as a string)!'
zz, yy, xx = np.indices(dim) + 0.5
xx -= center[2]
yy -= center[1]
zz -= center[0]
if axis == 'z':
uu, vv, ww = xx, yy, zz
elif axis == 'y':
uu, vv, ww = xx, zz, yy
elif axis == 'x':
uu, vv, ww = yy, zz, xx
else:
raise ValueError('{} is not a valid argument (use x, y or z)'.format(axis))
distance = np.hypot(uu / (width[1] / 2), vv / (width[0] / 2))
return np.logical_and(np.where(distance <= 1, True, False),
np.where(abs(ww) <= height / 2, True, False))
def ellipsoid(dim, center, width):
"""Create the shape of an ellipsoid.
Parameters
----------
dim : tuple (N=3)
The dimensions of the grid `(z, y, x)`.
center : tuple (N=3)
The center of the ellipsoid in pixel coordinates `(z, y, x)`.
width : tuple (N=3)
The width of the ellipsoid `(z, y, x)`.
Returns
-------
shape : :class:`~numpy.ndarray` (N=3)
The shape as a 3D-array.
"""
_log.debug('Calling ellipsoid')
assert np.shape(dim) == (3,), 'Parameter dim has to be a a tuple of length 3!'
assert np.shape(center) == (3,), 'Parameter center has to be a a tuple of length 3!'
assert np.shape(width) == (3,), 'Parameter width has to be a a tuple of length 3!'
zz, yy, xx = np.indices(dim) + 0.5
distance = np.sqrt(((xx - center[2]) / (width[2] / 2)) ** 2
+ ((yy - center[1]) / (width[1] / 2)) ** 2
+ ((zz - center[0]) / (width[0] / 2)) ** 2)
return np.where(distance <= 1, True, False)
def sphere(dim, center, radius):
"""Create the shape of a sphere.
Parameters
----------
dim : tuple (N=3)
The dimensions of the grid `(z, y, x)`.
center : tuple (N=3)
The center of the sphere in pixel coordinates `(z, y, x)`.
radius : float
The radius of the sphere in pixel coordinates.
Returns
-------
shape : :class:`~numpy.ndarray` (N=3)
The shape as a 3D-array.
"""
_log.debug('Calling sphere')
assert np.shape(dim) == (3,), 'Parameter dim has to be a a tuple of length 3!'
assert np.shape(center) == (3,), 'Parameter center has to be a a tuple of length 3!'
assert radius > 0 and np.shape(radius) == (), 'Radius has to be a positive scalar value!'
zz, yy, xx = np.indices(dim) + 0.5
distance = np.sqrt((xx - center[2]) ** 2 + (yy - center[1]) ** 2 + (zz - center[0]) ** 2)
return np.where(distance <= radius, True, False)
def filament(dim, pos, axis='y'):
"""Create the shape of a filament.
Parameters
----------
dim : tuple (N=3)
The dimensions of the grid `(z, y, x)`.
pos : tuple (N=2)
The position of the filament in pixel coordinates `(coord1, coord2)`.
`coord1` and `coord2` stand for the two axes, which are perpendicular to `axis`. For
the default case (`axis = y`), it is `(coord1, coord2) = (z, x)`.
axis : {'y', 'x', 'z'}, optional
The orientation of the filament axis. The default is 'y'.
Returns
-------
shape : :class:`~numpy.ndarray` (N=3)
The shape as a 3D-array.
"""
_log.debug('Calling filament')
assert np.shape(dim) == (3,), 'Parameter dim has to be a tuple of length 3!'
assert np.shape(pos) == (2,), 'Parameter pos has to be a tuple of length 2!'
assert axis in {'z', 'y', 'x'}, 'Axis has to be x, y or z (as a string)!'
shape = np.zeros(dim, dtype=bool)
if axis == 'z':
shape[:, pos[0], pos[1]] = True
elif axis == 'y':
shape[pos[0], :, pos[1]] = True
elif axis == 'x':
shape[pos[0], pos[1], :] = True
return shape
def pixel(dim, pixel):
"""Create the shape of a single pixel.
Parameters
----------
dim : tuple (N=3)
The dimensions of the grid `(z, y, x)`.
pixel : tuple (N=3)
The coordinates of the pixel `(z, y, x)`.
Returns
-------
shape : :class:`~numpy.ndarray` (N=3)
The shape as a 3D-array.
"""
_log.debug('Calling pixel')
assert np.shape(dim) == (3,), 'Parameter dim has to be a tuple of length 3!'
assert np.shape(pixel) == (3,), 'Parameter pixel has to be a tuple of length 3!'
shape = np.zeros(dim, dtype=bool)
shape[pixel] = True
return shape
......@@ -9,20 +9,21 @@ from numpy import pi
from numpy.testing import assert_allclose
import pyramid.magcreator as mc
from pyramid import shapes
class TestCaseMagCreator(unittest.TestCase):
path = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'test_magcreator')
def test_shape_slab(self):
test_slab = mc.Shapes.slab((5, 6, 7), (2.5, 3.5, 4.5), (1, 3, 5))
test_slab = shapes.slab((5, 6, 7), (2.5, 3.5, 4.5), (1, 3, 5))
assert_allclose(test_slab, np.load(os.path.join(self.path, 'ref_slab.npy')),
err_msg='Created slab does not match expectation!')
def test_shape_disc(self):
test_disc_z = mc.Shapes.disc((5, 6, 7), (2.5, 3.5, 4.5), 2, 3, 'z')
test_disc_y = mc.Shapes.disc((5, 6, 7), (2.5, 3.5, 4.5), 2, 3, 'y')
test_disc_x = mc.Shapes.disc((5, 6, 7), (2.5, 3.5, 4.5), 2, 3, 'x')
test_disc_z = shapes.disc((5, 6, 7), (2.5, 3.5, 4.5), 2, 3, 'z')
test_disc_y = shapes.disc((5, 6, 7), (2.5, 3.5, 4.5), 2, 3, 'y')
test_disc_x = shapes.disc((5, 6, 7), (2.5, 3.5, 4.5), 2, 3, 'x')
assert_allclose(test_disc_z, np.load(os.path.join(self.path, 'ref_disc_z.npy')),
err_msg='Created disc in z-direction does not match expectation!')
assert_allclose(test_disc_y, np.load(os.path.join(self.path, 'ref_disc_y.npy')),
......@@ -31,9 +32,9 @@ class TestCaseMagCreator(unittest.TestCase):
err_msg='Created disc in x-direction does not match expectation!')
def test_shape_ellipse(self):
test_ellipse_z = mc.Shapes.ellipse((7, 8, 9), (3.5, 4.5, 5.5), (3, 5), 1, 'z')
test_ellipse_y = mc.Shapes.ellipse((7, 8, 9), (3.5, 4.5, 5.5), (3, 5), 1, 'y')
test_ellipse_x = mc.Shapes.ellipse((7, 8, 9), (3.5, 4.5, 5.5), (3, 5), 1, 'x')
test_ellipse_z = shapes.ellipse((7, 8, 9), (3.5, 4.5, 5.5), (3, 5), 1, 'z')
test_ellipse_y = shapes.ellipse((7, 8, 9), (3.5, 4.5, 5.5), (3, 5), 1, 'y')
test_ellipse_x = shapes.ellipse((7, 8, 9), (3.5, 4.5, 5.5), (3, 5), 1, 'x')
assert_allclose(test_ellipse_z, np.load(os.path.join(self.path, 'ref_ellipse_z.npy')),
err_msg='Created ellipse does not match expectation (z)!')
assert_allclose(test_ellipse_y, np.load(os.path.join(self.path, 'ref_ellipse_y.npy')),
......@@ -42,19 +43,19 @@ class TestCaseMagCreator(unittest.TestCase):
err_msg='Created ellipse does not match expectation (x)!')
def test_shape_sphere(self):
test_sphere = mc.Shapes.sphere((5, 6, 7), (2.5, 3.5, 4.5), 2)
test_sphere = shapes.sphere((5, 6, 7), (2.5, 3.5, 4.5), 2)
assert_allclose(test_sphere, np.load(os.path.join(self.path, 'ref_sphere.npy')),
err_msg='Created sphere does not match expectation!')
def test_shape_ellipsoid(self):
test_ellipsoid = mc.Shapes.ellipsoid((7, 8, 9), (3.5, 4.5, 4.5), (3, 5, 7))
test_ellipsoid = shapes.ellipsoid((7, 8, 9), (3.5, 4.5, 4.5), (3, 5, 7))
assert_allclose(test_ellipsoid, np.load(os.path.join(self.path, 'ref_ellipsoid.npy')),
err_msg='Created ellipsoid does not match expectation!')
def test_shape_filament(self):
test_filament_z = mc.Shapes.filament((5, 6, 7), (2, 3), 'z')
test_filament_y = mc.Shapes.filament((5, 6, 7), (2, 3), 'y')
test_filament_x = mc.Shapes.filament((5, 6, 7), (2, 3), 'x')
test_filament_z = shapes.filament((5, 6, 7), (2, 3), 'z')
test_filament_y = shapes.filament((5, 6, 7), (2, 3), 'y')
test_filament_x = shapes.filament((5, 6, 7), (2, 3), 'x')
assert_allclose(test_filament_z, np.load(os.path.join(self.path, 'ref_fil_z.npy')),
err_msg='Created filament in z-direction does not match expectation!')
assert_allclose(test_filament_y, np.load(os.path.join(self.path, 'ref_fil_y.npy')),
......@@ -63,18 +64,18 @@ class TestCaseMagCreator(unittest.TestCase):
err_msg='Created filament in x-direction does not match expectation!')
def test_shape_pixel(self):
test_pixel = mc.Shapes.pixel((5, 6, 7), (2, 3, 4))
test_pixel = shapes.pixel((5, 6, 7), (2, 3, 4))
assert_allclose(test_pixel, np.load(os.path.join(self.path, 'ref_pixel.npy')),
err_msg='Created pixel does not match expectation!')
def test_create_mag_dist_homog(self):
mag_shape = mc.Shapes.disc((1, 10, 10), (0, 5, 5), 3, 1)
mag_shape = shapes.disc((1, 10, 10), (0, 5, 5), 3, 1)
magnitude = mc.create_mag_dist_homog(mag_shape, pi / 4)
assert_allclose(magnitude, np.load(os.path.join(self.path, 'ref_mag_disc.npy')),
err_msg='Created homog. magnetic distribution does not match expectation')
def test_create_mag_dist_vortex(self):
mag_shape = mc.Shapes.disc((1, 10, 10), (0, 5, 5), 3, 1)
mag_shape = shapes.disc((1, 10, 10), (0, 5, 5), 3, 1)
magnitude = mc.create_mag_dist_vortex(mag_shape)
assert_allclose(magnitude, np.load(os.path.join(self.path, 'ref_mag_vort.npy')),
err_msg='Created vortex magnetic distribution does not match expectation')
......
......@@ -7,6 +7,7 @@ import logging.config
import numpy as np
import pyramid as pr
import shapes
logging.config.fileConfig(pr.LOGGING_CONFIG, disable_existing_loggers=False)
......@@ -23,7 +24,7 @@ mag_data = pr.VectorData(a, np.zeros((3,) + dim))
count = int((dim[1] - 1) / spacing) + 1
for i in range(count):
pos = i * spacing
mag_shape = pr.magcreator.Shapes.filament(dim, (0, pos))
mag_shape = shapes.Shapes.filament(dim, (0, pos))
mag_data += pr.VectorData(a, pr.magcreator.create_mag_dist_homog(mag_shape, phi))
phi *= -1 # Switch the angle
mag_data.save_to_hdf5(filename, overwrite=True)
......@@ -7,6 +7,7 @@ import logging.config
import numpy as np
import pyramid as pr
import shapes
logging.config.fileConfig(pr.LOGGING_CONFIG, disable_existing_loggers=False)
......@@ -18,16 +19,16 @@ filename = 'magdata_mc_array_sphere_disc_slab.hdf5'
# 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 = pr.magcreator.Shapes.slab(dim, center, width)
mag_shape_slab = shapes.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 = pr.magcreator.Shapes.disc(dim, center, radius, height)
mag_shape_disc = shapes.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 = pr.magcreator.Shapes.sphere(dim, center, radius)
mag_shape_sphere = shapes.Shapes.sphere(dim, center, radius)
# Create and save VectorData object:
mag_data = pr.VectorData(a, pr.magcreator.create_mag_dist_homog(mag_shape_slab, np.pi / 4))
......
......@@ -7,6 +7,7 @@ import logging.config
import numpy as np
import pyramid as pr
import shapes
logging.config.fileConfig(pr.LOGGING_CONFIG, disable_existing_loggers=False)
......@@ -20,8 +21,8 @@ height = dim[0] // 2
filename = 'magdata_mc_core_shell_disc.hdf5'
# Magnetic shape:
mag_shape_core = pr.magcreator.Shapes.disc(dim, center, radius_core, height)
mag_shape_outer = pr.magcreator.Shapes.disc(dim, center, radius_shell, height)
mag_shape_core = shapes.Shapes.disc(dim, center, radius_core, height)
mag_shape_outer = shapes.Shapes.disc(dim, center, radius_shell, height)
mag_shape_shell = np.logical_xor(mag_shape_outer, mag_shape_core)
# Create and save VectorData object:
......
......@@ -7,6 +7,7 @@ import logging.config
import numpy as np
import pyramid as pr
import shapes
logging.config.fileConfig(pr.LOGGING_CONFIG, disable_existing_loggers=False)
......@@ -19,8 +20,8 @@ radius_shell = dim[1] // 4
filename = 'magdata_mc_core_shell_sphere.hdf5'
# Magnetic shape:
mag_shape_sphere = pr.magcreator.Shapes.sphere(dim, center, radius_shell)
mag_shape_disc = pr.magcreator.Shapes.disc(dim, center, radius_core, height=dim[0])
mag_shape_sphere = shapes.Shapes.sphere(dim, center, radius_shell)
mag_shape_disc = shapes.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))
......
......@@ -7,6 +7,7 @@ import logging.config
import numpy as np
import pyramid as pr
import shapes
logging.config.fileConfig(pr.LOGGING_CONFIG, disable_existing_loggers=False)
......@@ -23,8 +24,8 @@ tilt = 0
center_1 = (0, dim[1] // 2 - 0.5 + 40, dim[2] // 2 - 0.5)
center_2 = (0, dim[1] // 2 - 0.5 - 40, dim[2] // 2 - 0.5)
width = (1, 80, 80) # in px
mag_shape_1 = pr.magcreator.Shapes.slab(dim, center_1, width)
mag_shape_2 = pr.magcreator.Shapes.slab(dim, center_2, width)
mag_shape_1 = shapes.Shapes.slab(dim, center_1, width)
mag_shape_2 = shapes.Shapes.slab(dim, center_2, width)
# Create and save VectorData object:
mag = pr.magcreator.create_mag_dist_homog(mag_shape_1, phi=7 / 12. * np.pi, amplitude=amplitude)
......
......@@ -5,6 +5,7 @@
import logging.config
import pyramid as pr
import shapes
logging.config.fileConfig(pr.LOGGING_CONFIG, disable_existing_loggers=False)
......@@ -18,7 +19,7 @@ filename = 'magdata_mc_vortex_slab.hdf5'
# Magnetic shape:
center = (0, dim[1] // 2 - 0.5, dim[2] // 2 - 0.5)
width = (1, 128, 128) # in px
mag_shape = pr.magcreator.Shapes.slab(dim, center, width)
mag_shape = shapes.Shapes.slab(dim, center, width)
# Create and save VectorData object:
magnitude = pr.magcreator.create_mag_dist_vortex(mag_shape, center, axis, amplitude)
......
......@@ -7,6 +7,7 @@ import logging.config
import numpy as np
import pyramid as pr
import shapes
logging.config.fileConfig(pr.LOGGING_CONFIG, disable_existing_loggers=False)
......@@ -22,7 +23,7 @@ filename = 'magdata_mc_homog_disc.hdf5'
center = (dim[0] // 2 - 0.5, dim[1] // 2 - 0.5, dim[2] // 2 - 0.5)
radius = dim[2] // 4
height = dim[0] // 2
mag_shape = pr.magcreator.Shapes.disc(dim, center, radius, height)
mag_shape = shapes.Shapes.disc(dim, center, radius, height)
# Create and save VectorData object:
mag_data = pr.VectorData(a, pr.magcreator.create_mag_dist_homog(mag_shape, phi, theta, amplitude))
......
......@@ -7,6 +7,7 @@ import logging.config
import numpy as np
import pyramid as pr
import shapes
logging.config.fileConfig(pr.LOGGING_CONFIG, disable_existing_loggers=False)
......@@ -20,7 +21,7 @@ filename = 'magdata_mc_homog_filament.hdf5'
# Magnetic shape:
pos = (0, dim[1] // 2)
mag_shape = pr.magcreator.Shapes.filament(dim, pos)
mag_shape = shapes.Shapes.filament(dim, pos)
# Create and save VectorData object:
mag_data = pr.VectorData(a, pr.magcreator.create_mag_dist_homog(mag_shape, phi, theta, amplitude))
......
......@@ -7,6 +7,7 @@ import logging.config
import numpy as np
import pyramid as pr
import shapes
logging.config.fileConfig(pr.LOGGING_CONFIG, disable_existing_loggers=False)
......@@ -20,7 +21,7 @@ filename = 'magdata_mc_pixel.hdf5'
# Magnetic shape:
pixel = (0, dim[1] // 4, dim[2] // 4)
mag_shape = pr.magcreator.Shapes.pixel(dim, pixel)
mag_shape = shapes.Shapes.pixel(dim, pixel)
# Create and save VectorData object:
mag_data = pr.VectorData(a, pr.magcreator.create_mag_dist_homog(mag_shape, phi, theta, amplitude))
......
......@@ -7,6 +7,7 @@ import logging.config
import numpy as np
import pyramid as pr
import shapes
logging.config.fileConfig(pr.LOGGING_CONFIG, disable_existing_loggers=False)
......@@ -21,7 +22,7 @@ filename = 'magdata_mc_homog_slab.hdf5'
# Magnetic shape:
center = (dim[0] // 2 - 0.5, dim[1] // 2 - 0.5, dim[2] // 2 - 0.5)
width = (dim[0] // 8, dim[1] // 2, dim[2] // 4)
mag_shape = pr.magcreator.Shapes.slab(dim, center, width)
mag_shape = shapes.Shapes.slab(dim, center, width)
# Create and save VectorData object:
mag_data = pr.VectorData(a, pr.magcreator.create_mag_dist_homog(mag_shape, phi, theta, amplitude))
......
......@@ -7,6 +7,7 @@ import logging.config
import numpy as np
import pyramid as pr
import shapes
logging.config.fileConfig(pr.LOGGING_CONFIG, disable_existing_loggers=False)
......@@ -21,7 +22,7 @@ filename = 'magdata_mc_homog_sphere.hdf5'
# Magnetic shape:
center = (dim[0] // 2 - 0.5, dim[1] // 2 - 0.5, dim[2] // 2 - 0.5)
radius = dim[2] // 4 # in px
mag_shape = pr.magcreator.Shapes.sphere(dim, center, radius)
mag_shape = shapes.Shapes.sphere(dim, center, radius)
# Create and save VectorData object:
mag_data = pr.VectorData(a, pr.magcreator.create_mag_dist_homog(mag_shape, phi, theta, amplitude))
......
......@@ -7,6 +7,7 @@ import logging.config
import numpy as np
import pyramid as pr
import shapes
logging.config.fileConfig(pr.LOGGING_CONFIG, disable_existing_loggers=False)
......@@ -20,8 +21,8 @@ height = dim[0] // 2
filename = 'magdata_mc_horseshoe.hdf5'
# Magnetic shape:
mag_shape_core = pr.magcreator.Shapes.disc(dim, center, radius_core, height)
mag_shape_outer = pr.magcreator.Shapes.disc(dim, center, radius_shell, height)
mag_shape_core = shapes.Shapes.disc(dim, center, radius_core, height)
mag_shape_outer = shapes.Shapes.disc(dim, center, radius_shell, height)
mag_shape_horseshoe = np.logical_xor(mag_shape_outer, mag_shape_core)
mag_shape_horseshoe[:, dim[1] // 2:, :] = False
......
......@@ -8,6 +8,7 @@ import random as rnd
import numpy as np
import pyramid as pr
import shapes
logging.config.fileConfig(pr.LOGGING_CONFIG, disable_existing_loggers=False)
......@@ -32,7 +33,7 @@ mag_shape[0, ...] = np.logical_and(np.logical_and(left, right), bottom)
mag_data = pr.VectorData(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 = pr.magcreator.Shapes.pixel(dim, pixel)
mag_shape = shapes.Shapes.pixel(dim, pixel)
phi = 2 * np.pi * rnd.random()
mag_data += pr.VectorData(a, pr.magcreator.create_mag_dist_homog(mag_shape, phi))
mag_data.save_to_hdf5(filename, overwrite=True)
......@@ -8,6 +8,7 @@ import random as rnd
import numpy as np
import pyramid as pr
import shapes
logging.config.fileConfig(pr.LOGGING_CONFIG, disable_existing_loggers=False)
......@@ -36,7 +37,7 @@ for i in range(count):
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 = pr.magcreator.Shapes.slab(dim, center, width)
mag_shape = shapes.Shapes.slab(dim, center, width)
phi = 2 * np.pi * rnd.random()
mag_data += pr.VectorData(a, pr.magcreator.create_mag_dist_homog(mag_shape, phi))
mag_data.save_to_hdf5(filename, overwrite=True)
......@@ -5,6 +5,7 @@
import logging.config
import pyramid as pr
import shapes
logging.config.fileConfig(pr.LOGGING_CONFIG, disable_existing_loggers=False)
......@@ -19,7 +20,7 @@ filename = 'magdata_mc_vortex_disc_x.hdf5'
center = (dim[0] // 2, dim[1] // 2, dim[2] // 2)
radius = dim[2] // 4
height = dim[0] // 2
mag_shape = pr.magcreator.Shapes.disc(dim, center, radius, height, axis)
mag_shape = shapes.Shapes.disc(dim, center, radius, height, axis)
# Create and save VectorData object:
magnitude = pr.magcreator.create_mag_dist_vortex(mag_shape, center, axis, amplitude)
......
......@@ -5,6 +5,7 @@
import logging.config
import pyramid as pr
import shapes
logging.config.fileConfig(pr.LOGGING_CONFIG, disable_existing_loggers=False)
......@@ -18,7 +19,7 @@ filename = 'magdata_mc_vortex_sphere.hdf5'
# Magnetic shape:
center = (dim[0] // 2 - 0.5, dim[1] // 2 - 0.5, dim[2] // 2 - 0.5)
radius = dim[2] // 4 # in px
mag_shape = pr.magcreator.Shapes.sphere(dim, center, radius)
mag_shape = shapes.Shapes.sphere(dim, center, radius)
# Create and save VectorData object:
magnitude = pr.magcreator.create_mag_dist_vortex(mag_shape, center, axis, amplitude)
......
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