diff --git a/cherab/core/atomic/gaunt.pxd b/cherab/core/atomic/gaunt.pxd index 827831b6..a18ca802 100644 --- a/cherab/core/atomic/gaunt.pxd +++ b/cherab/core/atomic/gaunt.pxd @@ -21,7 +21,7 @@ from cherab.core.math cimport Function2D cdef class FreeFreeGauntFactor(): - cpdef double evaluate(self, double z, double temperature, double wavelength) except? -1e999 + cdef double evaluate(self, double z, double temperature, double wavelength) except? -1e999 cdef class InterpolatedFreeFreeGauntFactor(FreeFreeGauntFactor): diff --git a/cherab/core/atomic/gaunt.pyx b/cherab/core/atomic/gaunt.pyx index eb1dbe59..001ff214 100644 --- a/cherab/core/atomic/gaunt.pyx +++ b/cherab/core/atomic/gaunt.pyx @@ -37,9 +37,9 @@ cdef class FreeFreeGauntFactor(): The base class for temperature-averaged free-free Gaunt factors. """ - cpdef double evaluate(self, double z, double temperature, double wavelength) except? -1e999: + cdef double evaluate(self, double z, double temperature, double wavelength) except? -1e999: """ - Returns the temperature-averaged free-free Gaunt factor for the supplied parameters. + Return the temperature-averaged free-free Gaunt factor for the supplied parameters. :param double z: Species charge or effective plasma charge. :param double temperature: Electron temperature in eV. @@ -51,7 +51,7 @@ cdef class FreeFreeGauntFactor(): def __call__(self, double z, double temperature, double wavelength): """ - Returns the temperature-averaged free-free Gaunt factor for the supplied parameters. + Return the temperature-averaged free-free Gaunt factor for the supplied parameters. :param double z: Species charge or effective plasma charge. :param double temperature: Electron temperature in eV. @@ -106,9 +106,9 @@ cdef class InterpolatedFreeFreeGauntFactor(FreeFreeGauntFactor): self._gaunt_factor = Interpolator2DArray(np.log10(u), np.log10(gamma2), gaunt_factor, 'cubic', 'none', 0, 0) @cython.cdivision(True) - cpdef double evaluate(self, double z, double temperature, double wavelength) except? -1e999: + cdef double evaluate(self, double z, double temperature, double wavelength) except? -1e999: """ - Returns the temperature-averaged free-free Gaunt factor for the supplied parameters. + Return the temperature-averaged free-free Gaunt factor for the supplied parameters. :param double z: Species charge or effective plasma charge. :param double temperature: Electron temperature in eV. diff --git a/cherab/core/atomic/tests/test_zeeman.py b/cherab/core/atomic/tests/test_zeeman.py new file mode 100644 index 00000000..f2e6a62f --- /dev/null +++ b/cherab/core/atomic/tests/test_zeeman.py @@ -0,0 +1,70 @@ +import unittest + +import numpy as np +from raysect.core.math.function.float import Arg1D, Constant1D + +from cherab.core.atomic import ZeemanStructure + + +class TestZeemanStructure(unittest.TestCase): + def test_initialisation_rejects_invalid_component_shape(self): + with self.assertRaises(ValueError): + ZeemanStructure([(Constant1D(656.1),)], [], []) + + with self.assertRaises(ValueError): + ZeemanStructure([], [(Constant1D(656.1),)], []) + + with self.assertRaises(ValueError): + ZeemanStructure([], [], [(Constant1D(656.1),)]) + + def test_call_returns_expected_components_and_normalised_ratios(self): + pi_components = [ + (Constant1D(656.1), Constant1D(2.0)), + (Constant1D(656.2), Constant1D(6.0)), + ] + sigma_plus_components = [ + (656.0 + 0.01 * Arg1D(), Constant1D(3.0)), + (656.3 + 0.02 * Arg1D(), Constant1D(1.0)), + ] + sigma_minus_components = [ + (Constant1D(655.9), Constant1D(1.0)), + (Constant1D(656.4), Constant1D(1.0)), + ] + zeeman = ZeemanStructure(pi_components, sigma_plus_components, sigma_minus_components) + + b = 2.0 + + pi = zeeman(b, 'PI') + np.testing.assert_allclose(pi[0], np.array([656.1, 656.2])) + np.testing.assert_allclose(pi[1], np.array([0.25, 0.75])) + + sigma_plus = zeeman(b, 'SIGMA_PLUS') + np.testing.assert_allclose(sigma_plus[0], np.array([656.02, 656.34])) + np.testing.assert_allclose(sigma_plus[1], np.array([0.75, 0.25])) + + sigma_minus = zeeman(b, 'sigma_minus') + np.testing.assert_allclose(sigma_minus[0], np.array([655.9, 656.4])) + np.testing.assert_allclose(sigma_minus[1], np.array([0.5, 0.5])) + + def test_call_keeps_zero_ratios_when_sum_is_zero(self): + zeeman = ZeemanStructure( + pi_components=[ + (Constant1D(656.1), Constant1D(0.0)), + (Constant1D(656.2), Constant1D(0.0)), + ], + sigma_plus_components=[], + sigma_minus_components=[], + ) + + pi = zeeman(0.0, 'pi') + np.testing.assert_allclose(pi[0], np.array([656.1, 656.2])) + np.testing.assert_allclose(pi[1], np.array([0.0, 0.0])) + + def test_call_raises_for_invalid_arguments(self): + zeeman = ZeemanStructure([], [], []) + + with self.assertRaises(ValueError): + zeeman(-1.0, 'pi') + + with self.assertRaises(ValueError): + zeeman(1.0, 'sigma') diff --git a/cherab/core/atomic/zeeman.pyx b/cherab/core/atomic/zeeman.pyx index 68382d32..10c1928a 100644 --- a/cherab/core/atomic/zeeman.pyx +++ b/cherab/core/atomic/zeeman.pyx @@ -139,4 +139,4 @@ cdef class ZeemanStructure(): if polarisation.lower() == 'sigma_minus': return np.asarray(self.evaluate(b, SIGMA_MINUS_POLARISATION)) - raise ValueError('Argument "polarisation" must be "pi", "sigma_plus" or "sigma_minus", {} given.'.fotmat(polarisation)) + raise ValueError('Argument "polarisation" must be "pi", "sigma_plus" or "sigma_minus", {} given.'.format(polarisation)) diff --git a/cherab/core/math/integrators/integrators1d.pyx b/cherab/core/math/integrators/integrators1d.pyx index 7ff9be74..6b52157c 100644 --- a/cherab/core/math/integrators/integrators1d.pyx +++ b/cherab/core/math/integrators/integrators1d.pyx @@ -39,7 +39,7 @@ cdef class Integrator1D: """ A 1D function to integrate. - :rtype: int + :rtype: Function1D """ return self.function diff --git a/cherab/core/math/integrators/integrators2d.pyx b/cherab/core/math/integrators/integrators2d.pyx index 58627afe..993decc2 100644 --- a/cherab/core/math/integrators/integrators2d.pyx +++ b/cherab/core/math/integrators/integrators2d.pyx @@ -33,7 +33,7 @@ cdef class Integrator2D: """ A 2D function to integrate. - :rtype: int + :rtype: Function2D """ return self.function diff --git a/cherab/core/math/mask.pyx b/cherab/core/math/mask.pyx index 14b8a3a1..91894908 100644 --- a/cherab/core/math/mask.pyx +++ b/cherab/core/math/mask.pyx @@ -65,6 +65,3 @@ cdef class PolygonMask2D(Function2D): cdef double evaluate(self, double x, double y) except? -1e999: return self._mesh.evaluate(x, y) - - - diff --git a/cherab/core/math/samplers.pyx b/cherab/core/math/samplers.pyx index 482dc813..caa027f7 100644 --- a/cherab/core/math/samplers.pyx +++ b/cherab/core/math/samplers.pyx @@ -42,7 +42,7 @@ cpdef tuple sample1d(object function1d, tuple x_range): :param function1d: a Python function or Function1D object :param x_range: a tuple defining the sample range: (min, max, samples) :return: a tuple containing the sampled values: (x_points, function_samples) - + .. code-block:: pycon >>> from cherab.core.math import sample1d @@ -221,7 +221,7 @@ cpdef np.ndarray sample2d_points(object function2d, object points): .. code-block:: pycon - >>> from cherab.core.math import sample2d + >>> from cherab.core.math import sample2d_points >>> >>> def f1(x, y): >>> return x**2 + y @@ -316,7 +316,7 @@ cpdef tuple sample3d(object function3d, tuple x_range, tuple y_range, tuple z_ra """ Samples a 3D function over the specified range. - :param function3d: a Python function or Function2D object + :param function3d: a Python function or Function3D object :param x_range: a tuple defining the x sample range: (x_min, x_max, x_samples) :param y_range: a tuple defining the y sample range: (y_min, y_max, y_samples) :param z_range: a tuple defining the z sample range: (z_min, z_max, z_samples) @@ -335,7 +335,7 @@ cpdef tuple sample3d(object function3d, tuple x_range, tuple y_range, tuple z_ra >>> f_vals array([[[ 3., 4., 5.], [ 6., 7., 8.], - [11., 12., 13.]], + [11., 12., 13.]], [[10., 11., 12.], [13., 14., 15.], [18., 19., 20.]], @@ -415,7 +415,7 @@ cpdef np.ndarray sample3d_points(object function3d, object points): :param function3d: a Python function or Function3D object :param points: an Nx3 array of points at which to sample the function :return: a 1D array containing the sampled values at each point - + .. code-block:: pycon >>> from cherab.core.math import sample3d_points @@ -744,7 +744,7 @@ cpdef tuple samplevector3d(object function3d, tuple x_range, tuple y_range, tupl The function samples returns are an NxMxKx3 array where the last axis are the x, y, and z components of the vector respectively. - :param function3d: a Python function or Function2D object + :param function3d: a Python function or Function3D object :param x_range: a tuple defining the x sample range: (x_min, x_max, x_samples) :param y_range: a tuple defining the y sample range: (y_min, y_max, y_samples) :param z_range: a tuple defining the z sample range: (z_min, z_max, z_samples) diff --git a/cherab/core/math/transform/periodic.pyx b/cherab/core/math/transform/periodic.pyx index 13869458..617abfce 100644 --- a/cherab/core/math/transform/periodic.pyx +++ b/cherab/core/math/transform/periodic.pyx @@ -306,7 +306,7 @@ cdef class VectorPeriodicTransform3D(VectorFunction3D): .. code-block:: pycon - >>> from cherab.core.math import PeriodicTransform3D + >>> from cherab.core.math import VectorPeriodicTransform3D >>> >>> def f1(x, y, z): >>> return Vector3D(x, y, z) @@ -327,7 +327,7 @@ cdef class VectorPeriodicTransform3D(VectorFunction3D): def __init__(self, object function3d, double period_x, double period_y, double period_z): if not callable(function3d): - raise TypeError("function2d is not callable.") + raise TypeError("function3d is not callable.") self.function3d = autowrap_vectorfunction3d(function3d) diff --git a/cherab/tools/primitives/axisymmetric_mesh.pyx b/cherab/tools/primitives/axisymmetric_mesh.pyx index 81533cb0..d3c79c37 100644 --- a/cherab/tools/primitives/axisymmetric_mesh.pyx +++ b/cherab/tools/primitives/axisymmetric_mesh.pyx @@ -23,10 +23,10 @@ from .toroidal_mesh import toroidal_mesh_from_polygon cpdef Mesh axisymmetric_mesh_from_polygon(object polygon, int num_toroidal_segments=500): """ - Generates an Raysect Mesh primitive from the specified 2D polygon. + Generate a Raysect Mesh primitive from the specified 2D polygon. - :param object polygon: An object which can be converted to a numpy array with shape [N,2] - specifying the wall outline polygon in the R-Z plane. The polygon + :param object polygon: An object which can be converted to a numpy array with shape [N,2] + specifying the wall outline polygon in the R-Z plane. The polygon should not be closed, i.e. vertex i = 0 and i = N should not be the same vertex, but neighbours. :param int num_toroidal_segments: The number of repeating toroidal segments that will be used