From 82e3014d0e8897a8caa83470c45095a47d3da750 Mon Sep 17 00:00:00 2001 From: MatejTomes Date: Thu, 5 Jun 2025 16:16:03 +0200 Subject: [PATCH 01/10] Add read access to line and lineshape attributes This should add the possibility to fully investigate what emission models an observation was performed with. --- cherab/core/model/plasma/impact_excitation.pyx | 10 ++++++++++ cherab/core/model/plasma/recombination.pyx | 10 ++++++++++ cherab/core/model/plasma/thermal_cx.pyx | 10 ++++++++++ cherab/core/model/plasma/total_radiated_power.pyx | 11 +++++++++++ 4 files changed, 41 insertions(+) diff --git a/cherab/core/model/plasma/impact_excitation.pyx b/cherab/core/model/plasma/impact_excitation.pyx index b26336f1..e10b6280 100644 --- a/cherab/core/model/plasma/impact_excitation.pyx +++ b/cherab/core/model/plasma/impact_excitation.pyx @@ -47,6 +47,8 @@ cdef class ExcitationLine(PlasmaModel): :ivar Plasma plasma: The plasma to which this emission model is attached. :ivar AtomicData atomic_data: The atomic data provider for this model. + :ivar Line line: The emission line object. + :ivar LineShapeModel lineshape: The line shape model. """ def __init__(self, Line line, Plasma plasma=None, AtomicData atomic_data=None, object lineshape=None, @@ -75,6 +77,14 @@ cdef class ExcitationLine(PlasmaModel): def __repr__(self): return ''.format(self._line.element.name, self._line.charge, self._line.transition) + @property + def line(self): + return self._line + + @property + def lineshape(self): + return self._lineshape + cpdef Spectrum emission(self, Point3D point, Vector3D direction, Spectrum spectrum): cdef double ne, ni, te, radiance diff --git a/cherab/core/model/plasma/recombination.pyx b/cherab/core/model/plasma/recombination.pyx index a33009d0..db00ad35 100644 --- a/cherab/core/model/plasma/recombination.pyx +++ b/cherab/core/model/plasma/recombination.pyx @@ -47,6 +47,8 @@ cdef class RecombinationLine(PlasmaModel): :ivar Plasma plasma: The plasma to which this emission model is attached. :ivar AtomicData atomic_data: The atomic data provider for this model. + :ivar Line line: The emission line object. + :ivar LineShapeModel lineshape: The line shape model. """ def __init__(self, Line line, Plasma plasma=None, AtomicData atomic_data=None, object lineshape=None, @@ -75,6 +77,14 @@ cdef class RecombinationLine(PlasmaModel): def __repr__(self): return ''.format(self._line.element.name, self._line.charge, self._line.transition) + @property + def line(self): + return self._line + + @property + def lineshape(self): + return self._lineshape + cpdef Spectrum emission(self, Point3D point, Vector3D direction, Spectrum spectrum): cdef double ne, ni, te, radiance diff --git a/cherab/core/model/plasma/thermal_cx.pyx b/cherab/core/model/plasma/thermal_cx.pyx index 88af9ae8..aa1e9ffa 100644 --- a/cherab/core/model/plasma/thermal_cx.pyx +++ b/cherab/core/model/plasma/thermal_cx.pyx @@ -49,6 +49,8 @@ cdef class ThermalCXLine(PlasmaModel): :ivar Plasma plasma: The plasma to which this emission model is attached. :ivar AtomicData atomic_data: The atomic data provider for this model. + :ivar Line line: The emission line object. + :ivar LineShapeModel lineshape: The line shape model. """ def __init__(self, Line line, Plasma plasma=None, AtomicData atomic_data=None, object lineshape=None, @@ -77,6 +79,14 @@ cdef class ThermalCXLine(PlasmaModel): def __repr__(self): return ''.format(self._line.element.name, self._line.charge, self._line.transition) + @property + def line(self): + return self._line + + @property + def lineshape(self): + return self._lineshape + cpdef Spectrum emission(self, Point3D point, Vector3D direction, Spectrum spectrum): cdef: diff --git a/cherab/core/model/plasma/total_radiated_power.pyx b/cherab/core/model/plasma/total_radiated_power.pyx index 84b42424..742cb3db 100644 --- a/cherab/core/model/plasma/total_radiated_power.pyx +++ b/cherab/core/model/plasma/total_radiated_power.pyx @@ -53,6 +53,9 @@ cdef class TotalRadiatedPower(PlasmaModel): :param int charge: The charge state of the element/isotope. :param Plasma plasma: The plasma to which this emission model is attached. Default is None. :param AtomicData atomic_data: The atomic data provider for this model. Default is None. + + :ivar Element element: The atomic element/isotope. + :ivar int charge: The charge state of the element/isotope. """ def __init__(self, Element element, int charge, Plasma plasma=None, AtomicData atomic_data=None): @@ -68,6 +71,14 @@ cdef class TotalRadiatedPower(PlasmaModel): # ensure that cache is initialised self._change() + + @property + def element(self): + return self._element + + @property + def charge(self): + return self._charge cpdef Spectrum emission(self, Point3D point, Vector3D direction, Spectrum spectrum): From 717378752adf59fc1c5f20e529cf4392fa9e1c11 Mon Sep 17 00:00:00 2001 From: MatejTomes Date: Thu, 5 Jun 2025 16:21:44 +0200 Subject: [PATCH 02/10] Add documentation to readonly attributes --- cherab/core/atomic/line.pyx | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/cherab/core/atomic/line.pyx b/cherab/core/atomic/line.pyx index 262c7a2f..1cb34584 100644 --- a/cherab/core/atomic/line.pyx +++ b/cherab/core/atomic/line.pyx @@ -33,6 +33,14 @@ cdef class Line: specify the n-levels with integers (e.g. (3,2)). For all other ions the full spectroscopic configuration string should be specified for both states. It is up to the atomic data provider package to define the exact notation. + + :ivar Element element: The atomic element/isotope to which this emission line belongs. + :ivar int charge: The charge state of the element/isotope that emits this line. + :ivar tuple transition: A two element tuple that defines the upper and lower electron + configuration states of the transition. For hydrogen-like ions it may be enough to + specify the n-levels with integers (e.g. (3,2)). For all other ions the full spectroscopic + configuration string should be specified for both states. It is up to the atomic data + provider package to define the exact notation. .. code-block:: pycon From 58e48ddf7a80ec7eafb88f2fef1af11fc766f847 Mon Sep 17 00:00:00 2001 From: MatejTomes Date: Thu, 5 Jun 2025 16:23:02 +0200 Subject: [PATCH 03/10] Modify changelog --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4f22a5d4..35a926c1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,9 @@ Project Changelog Release 1.6.0 (TBD) ------------------- +API changes: +* Add emission model attribute access to line and lineshape . (#294) + New: * Add Function6D framework. (#478) * Add e_field attribute to Plasma object for electric field vector. (#465) From 63b9a8c5132d8a29121aae30b4a5af53fbd9bc71 Mon Sep 17 00:00:00 2001 From: MatejTomes Date: Wed, 29 Oct 2025 21:04:21 +0100 Subject: [PATCH 04/10] Chage docstrings - reference existing parameters Kindo of following DRY in docstrings... --- cherab/core/atomic/line.pyx | 10 +++------- cherab/core/model/plasma/impact_excitation.pyx | 4 ++-- cherab/core/model/plasma/recombination.pyx | 4 ++-- cherab/core/model/plasma/thermal_cx.pyx | 4 ++-- cherab/core/model/plasma/total_radiated_power.pyx | 4 ++-- 5 files changed, 11 insertions(+), 15 deletions(-) diff --git a/cherab/core/atomic/line.pyx b/cherab/core/atomic/line.pyx index 1cb34584..cbd07bba 100644 --- a/cherab/core/atomic/line.pyx +++ b/cherab/core/atomic/line.pyx @@ -34,13 +34,9 @@ cdef class Line: configuration string should be specified for both states. It is up to the atomic data provider package to define the exact notation. - :ivar Element element: The atomic element/isotope to which this emission line belongs. - :ivar int charge: The charge state of the element/isotope that emits this line. - :ivar tuple transition: A two element tuple that defines the upper and lower electron - configuration states of the transition. For hydrogen-like ions it may be enough to - specify the n-levels with integers (e.g. (3,2)). For all other ions the full spectroscopic - configuration string should be specified for both states. It is up to the atomic data - provider package to define the exact notation. + :ivar Element element: See parameter 'element'. + :ivar int charge: See parameter 'charge'. + :ivar tuple transition: See parameter 'transition'. .. code-block:: pycon diff --git a/cherab/core/model/plasma/impact_excitation.pyx b/cherab/core/model/plasma/impact_excitation.pyx index e10b6280..1e40754a 100644 --- a/cherab/core/model/plasma/impact_excitation.pyx +++ b/cherab/core/model/plasma/impact_excitation.pyx @@ -45,8 +45,8 @@ cdef class ExcitationLine(PlasmaModel): :param object lineshape_args: A list of line shape model arguments. Default is None. :param object lineshape_kwargs: A dictionary of line shape model keyword arguments. Default is None. - :ivar Plasma plasma: The plasma to which this emission model is attached. - :ivar AtomicData atomic_data: The atomic data provider for this model. + :ivar Plasma plasma: See parameter 'plasma'. + :ivar AtomicData atomic_data: See parameter 'atomic_data'. :ivar Line line: The emission line object. :ivar LineShapeModel lineshape: The line shape model. """ diff --git a/cherab/core/model/plasma/recombination.pyx b/cherab/core/model/plasma/recombination.pyx index db00ad35..f92c157c 100644 --- a/cherab/core/model/plasma/recombination.pyx +++ b/cherab/core/model/plasma/recombination.pyx @@ -45,8 +45,8 @@ cdef class RecombinationLine(PlasmaModel): :param object lineshape_args: A list of line shape model arguments. Default is None. :param object lineshape_kwargs: A dictionary of line shape model keyword arguments. Default is None. - :ivar Plasma plasma: The plasma to which this emission model is attached. - :ivar AtomicData atomic_data: The atomic data provider for this model. + :ivar Plasma plasma: See parameter 'plasma'. + :ivar AtomicData atomic_data: See parameter 'atomic_data'. :ivar Line line: The emission line object. :ivar LineShapeModel lineshape: The line shape model. """ diff --git a/cherab/core/model/plasma/thermal_cx.pyx b/cherab/core/model/plasma/thermal_cx.pyx index aa1e9ffa..ef9819a8 100644 --- a/cherab/core/model/plasma/thermal_cx.pyx +++ b/cherab/core/model/plasma/thermal_cx.pyx @@ -47,8 +47,8 @@ cdef class ThermalCXLine(PlasmaModel): :param object lineshape_args: A list of line shape model arguments. Default is None. :param object lineshape_kwargs: A dictionary of line shape model keyword arguments. Default is None. - :ivar Plasma plasma: The plasma to which this emission model is attached. - :ivar AtomicData atomic_data: The atomic data provider for this model. + :ivar Plasma plasma: See parameter 'plasma'. + :ivar AtomicData atomic_data: See parameter 'atomic_data'. :ivar Line line: The emission line object. :ivar LineShapeModel lineshape: The line shape model. """ diff --git a/cherab/core/model/plasma/total_radiated_power.pyx b/cherab/core/model/plasma/total_radiated_power.pyx index 742cb3db..545a3727 100644 --- a/cherab/core/model/plasma/total_radiated_power.pyx +++ b/cherab/core/model/plasma/total_radiated_power.pyx @@ -54,8 +54,8 @@ cdef class TotalRadiatedPower(PlasmaModel): :param Plasma plasma: The plasma to which this emission model is attached. Default is None. :param AtomicData atomic_data: The atomic data provider for this model. Default is None. - :ivar Element element: The atomic element/isotope. - :ivar int charge: The charge state of the element/isotope. + :ivar Element element: See parameter 'element'. + :ivar int charge: See parameter 'charge'. """ def __init__(self, Element element, int charge, Plasma plasma=None, AtomicData atomic_data=None): From 45cce623d4edc3970517a0584d6d6c6f91d9079f Mon Sep 17 00:00:00 2001 From: MatejTomes Date: Wed, 29 Oct 2025 21:09:45 +0100 Subject: [PATCH 05/10] Add Line class tests --- cherab/core/atomic/tests/test_line.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 cherab/core/atomic/tests/test_line.py diff --git a/cherab/core/atomic/tests/test_line.py b/cherab/core/atomic/tests/test_line.py new file mode 100644 index 00000000..f268b82b --- /dev/null +++ b/cherab/core/atomic/tests/test_line.py @@ -0,0 +1,27 @@ +import unittest + +from cherab.core.atomic import Line, deuterium + + +class TestLine(unittest.TestCase): + + def test_initialisation(self): + line = Line(deuterium, 0, (3, 2)) + self.assertEqual(line.element, deuterium) + self.assertEqual(line.charge, 0) + self.assertEqual(line.transition, (3, 2)) + + # test invalid charge + with self.assertRaises(ValueError): + Line(deuterium, 2, (3, 2)) + with self.assertRaises(ValueError): + Line(deuterium, -1, (3, 2)) + + def test_properties(self): + element = deuterium + charge = 0 + transition = (3, 2) + line = Line(element, charge, transition) + self.assertEqual(line.element, element) + self.assertEqual(line.charge, charge) + self.assertEqual(line.transition, transition) \ No newline at end of file From 8edb74767ed6fc7797ffaff73d02c57e5367a9ce Mon Sep 17 00:00:00 2001 From: MatejTomes Date: Wed, 29 Oct 2025 21:58:47 +0100 Subject: [PATCH 06/10] Add plasma model tests --- cherab/core/model/plasma/tests/test_models.py | 58 +++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 cherab/core/model/plasma/tests/test_models.py diff --git a/cherab/core/model/plasma/tests/test_models.py b/cherab/core/model/plasma/tests/test_models.py new file mode 100644 index 00000000..56203db0 --- /dev/null +++ b/cherab/core/model/plasma/tests/test_models.py @@ -0,0 +1,58 @@ +import unittest + +from raysect.optical import Point3D, Vector3D, Spectrum + +from cherab.core.model.plasma import ExcitationLine, RecombinationLine, TotalRadiatedPower +from cherab.core.atomic import Line, hydrogen +from cherab.core.model import GaussianLine +from cherab.tools.plasmas.slab import build_slab_plasma +from cherab.openadas import OpenADAS + +class TestPlasmaModels(unittest.TestCase): + + # make a slab plasma + + plasma = build_slab_plasma(peak_density=5e19) + plasma.atomic_data = OpenADAS(permit_extrapolation=True) + balmer_alpha = Line(hydrogen, 0, (3, 2)) + + def test_excitation(self): + + exc = ExcitationLine(self.balmer_alpha) + self.plasma.models = [exc] + + # sample emission to trigger the caching mechanism + exc.emission(Point3D(0, 0, 0), Vector3D(0, 0, 1), Spectrum(300, 1000, 1000)) + + #check exc has the correct line + self.assertEqual(exc.line, self.balmer_alpha) + + #check exc has the correct lineshape + self.assertIsInstance(exc.lineshape, GaussianLine) + + def test_recombination(self): + rec = RecombinationLine(self.balmer_alpha) + self.plasma.models = [rec] + + # sample emission to trigger the caching mechanism + rec.emission(Point3D(0, 0, 0), Vector3D(0, 0, 1), Spectrum(300, 1000, 1000)) + + #check rec has the correct line + self.assertEqual(rec.line, self.balmer_alpha) + + #check rec has the correct lineshape + self.assertIsInstance(rec.lineshape, GaussianLine) + + def test_total_radiated_power(self): + trp = TotalRadiatedPower(hydrogen, 0) + self.plasma.models = [trp] + + # check initialisation + with self.assertRaises(ValueError): + TotalRadiatedPower(hydrogen, 2) + with self.assertRaises(ValueError): + TotalRadiatedPower(hydrogen, -1) + + #check trp has the correct element and charge + self.assertEqual(trp.element, hydrogen) + self.assertEqual(trp.charge, 0) From 9d9a1608fca4534bd938c70d4e79cfeeb006d00d Mon Sep 17 00:00:00 2001 From: MatejTomes Date: Wed, 29 Oct 2025 21:59:33 +0100 Subject: [PATCH 07/10] Add forgotten __init__.py files --- cherab/core/atomic/tests/__init__.py | 0 cherab/core/model/plasma/tests/__init__.py | 0 2 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 cherab/core/atomic/tests/__init__.py create mode 100644 cherab/core/model/plasma/tests/__init__.py diff --git a/cherab/core/atomic/tests/__init__.py b/cherab/core/atomic/tests/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/cherab/core/model/plasma/tests/__init__.py b/cherab/core/model/plasma/tests/__init__.py new file mode 100644 index 00000000..e69de29b From a277d02c53933e6f80f07ea7dcec0ec5640f5776 Mon Sep 17 00:00:00 2001 From: MatejTomes Date: Wed, 29 Oct 2025 22:10:02 +0100 Subject: [PATCH 08/10] Add typing to the properties --- cherab/core/model/plasma/impact_excitation.pyx | 4 ++-- cherab/core/model/plasma/recombination.pyx | 4 ++-- cherab/core/model/plasma/thermal_cx.pyx | 4 ++-- cherab/core/model/plasma/total_radiated_power.pyx | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/cherab/core/model/plasma/impact_excitation.pyx b/cherab/core/model/plasma/impact_excitation.pyx index 1e40754a..5c12d94f 100644 --- a/cherab/core/model/plasma/impact_excitation.pyx +++ b/cherab/core/model/plasma/impact_excitation.pyx @@ -78,11 +78,11 @@ cdef class ExcitationLine(PlasmaModel): return ''.format(self._line.element.name, self._line.charge, self._line.transition) @property - def line(self): + def line(self) -> Line: return self._line @property - def lineshape(self): + def lineshape(self) -> LineShapeModel: return self._lineshape cpdef Spectrum emission(self, Point3D point, Vector3D direction, Spectrum spectrum): diff --git a/cherab/core/model/plasma/recombination.pyx b/cherab/core/model/plasma/recombination.pyx index f92c157c..7f85dad8 100644 --- a/cherab/core/model/plasma/recombination.pyx +++ b/cherab/core/model/plasma/recombination.pyx @@ -78,11 +78,11 @@ cdef class RecombinationLine(PlasmaModel): return ''.format(self._line.element.name, self._line.charge, self._line.transition) @property - def line(self): + def line(self) -> Line: return self._line @property - def lineshape(self): + def lineshape(self) -> LineShapeModel: return self._lineshape cpdef Spectrum emission(self, Point3D point, Vector3D direction, Spectrum spectrum): diff --git a/cherab/core/model/plasma/thermal_cx.pyx b/cherab/core/model/plasma/thermal_cx.pyx index ef9819a8..e0943a14 100644 --- a/cherab/core/model/plasma/thermal_cx.pyx +++ b/cherab/core/model/plasma/thermal_cx.pyx @@ -80,11 +80,11 @@ cdef class ThermalCXLine(PlasmaModel): return ''.format(self._line.element.name, self._line.charge, self._line.transition) @property - def line(self): + def line(self) -> Line: return self._line @property - def lineshape(self): + def lineshape(self) -> LineShapeModel: return self._lineshape cpdef Spectrum emission(self, Point3D point, Vector3D direction, Spectrum spectrum): diff --git a/cherab/core/model/plasma/total_radiated_power.pyx b/cherab/core/model/plasma/total_radiated_power.pyx index 545a3727..f0c94281 100644 --- a/cherab/core/model/plasma/total_radiated_power.pyx +++ b/cherab/core/model/plasma/total_radiated_power.pyx @@ -73,11 +73,11 @@ cdef class TotalRadiatedPower(PlasmaModel): self._change() @property - def element(self): + def element(self) -> Element: return self._element @property - def charge(self): + def charge(self) -> int: return self._charge cpdef Spectrum emission(self, Point3D point, Vector3D direction, Spectrum spectrum): From b24018f31dcc4fcadcb37e5ed02316742415e1d6 Mon Sep 17 00:00:00 2001 From: MatejTomes Date: Mon, 3 Nov 2025 00:21:02 +0100 Subject: [PATCH 09/10] Add hooks to avoid file reading --- cherab/core/model/plasma/tests/test_models.py | 67 ++++++++++++++++--- 1 file changed, 57 insertions(+), 10 deletions(-) diff --git a/cherab/core/model/plasma/tests/test_models.py b/cherab/core/model/plasma/tests/test_models.py index 56203db0..06dbd2d0 100644 --- a/cherab/core/model/plasma/tests/test_models.py +++ b/cherab/core/model/plasma/tests/test_models.py @@ -1,35 +1,78 @@ import unittest +from unittest.mock import patch + +import numpy as np from raysect.optical import Point3D, Vector3D, Spectrum -from cherab.core.model.plasma import ExcitationLine, RecombinationLine, TotalRadiatedPower +from cherab.core.model.plasma import ( + ExcitationLine, + RecombinationLine, + TotalRadiatedPower, +) from cherab.core.atomic import Line, hydrogen from cherab.core.model import GaussianLine from cherab.tools.plasmas.slab import build_slab_plasma from cherab.openadas import OpenADAS -class TestPlasmaModels(unittest.TestCase): +class TestPlasmaModels(unittest.TestCase): # make a slab plasma - + plasma = build_slab_plasma(peak_density=5e19) plasma.atomic_data = OpenADAS(permit_extrapolation=True) balmer_alpha = Line(hydrogen, 0, (3, 2)) - def test_excitation(self): + def setUp(self): + # setup mock to avoid reading the data from the repository + self.patcher_pec = patch( + "cherab.openadas.openadas.repository.get_pec_excitation_rate", + return_value={ + "ne": np.linspace(1e18, 1e20, 10), + "te": np.linspace(1, 1e3, 12), + "rate": np.ones((10, 12)), + }, + ) + self.mock_get_pec = self.patcher_pec.start() + + self.patcher_rec = patch( + "cherab.openadas.openadas.repository.get_pec_recombination_rate", + return_value={ + "ne": np.linspace(1e18, 1e20, 10), + "te": np.linspace(1, 1e3, 12), + "rate": np.ones((10, 12)), + }, + ) + self.mock_get_rec = self.patcher_rec.start() + self.patcher_wl = patch( + "cherab.openadas.openadas.repository.get_wavelength", return_value=656.28 + ) + self.mock_get_wavelength = self.patcher_wl.start() + + def tearDown(self): + # stop the mocks after a test is run + self.patcher_pec.stop() + self.patcher_rec.stop() + self.patcher_wl.stop() + + def test_excitation(self): exc = ExcitationLine(self.balmer_alpha) self.plasma.models = [exc] # sample emission to trigger the caching mechanism exc.emission(Point3D(0, 0, 0), Vector3D(0, 0, 1), Spectrum(300, 1000, 1000)) - #check exc has the correct line + # check exc has the correct line self.assertEqual(exc.line, self.balmer_alpha) - #check exc has the correct lineshape + # check exc has the correct lineshape self.assertIsInstance(exc.lineshape, GaussianLine) - + + # check the mock was called + self.mock_get_pec.assert_called_once() + self.assertEqual(self.mock_get_wavelength.call_count, 2) + def test_recombination(self): rec = RecombinationLine(self.balmer_alpha) self.plasma.models = [rec] @@ -37,12 +80,16 @@ def test_recombination(self): # sample emission to trigger the caching mechanism rec.emission(Point3D(0, 0, 0), Vector3D(0, 0, 1), Spectrum(300, 1000, 1000)) - #check rec has the correct line + # check rec has the correct line self.assertEqual(rec.line, self.balmer_alpha) - #check rec has the correct lineshape + # check rec has the correct lineshape self.assertIsInstance(rec.lineshape, GaussianLine) + # check the mock was called + self.mock_get_rec.assert_called_once() + self.assertEqual(self.mock_get_wavelength.call_count, 2) + def test_total_radiated_power(self): trp = TotalRadiatedPower(hydrogen, 0) self.plasma.models = [trp] @@ -53,6 +100,6 @@ def test_total_radiated_power(self): with self.assertRaises(ValueError): TotalRadiatedPower(hydrogen, -1) - #check trp has the correct element and charge + # check trp has the correct element and charge self.assertEqual(trp.element, hydrogen) self.assertEqual(trp.charge, 0) From c3b936089bbc0c9cb9f8b032d5cfc92f3757f7ea Mon Sep 17 00:00:00 2001 From: MatejTomes Date: Mon, 3 Nov 2025 00:33:05 +0100 Subject: [PATCH 10/10] Improve naming --- cherab/core/model/plasma/tests/test_models.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/cherab/core/model/plasma/tests/test_models.py b/cherab/core/model/plasma/tests/test_models.py index 06dbd2d0..b0a15417 100644 --- a/cherab/core/model/plasma/tests/test_models.py +++ b/cherab/core/model/plasma/tests/test_models.py @@ -25,7 +25,7 @@ class TestPlasmaModels(unittest.TestCase): def setUp(self): # setup mock to avoid reading the data from the repository - self.patcher_pec = patch( + self.patcher_excitation = patch( "cherab.openadas.openadas.repository.get_pec_excitation_rate", return_value={ "ne": np.linspace(1e18, 1e20, 10), @@ -33,9 +33,9 @@ def setUp(self): "rate": np.ones((10, 12)), }, ) - self.mock_get_pec = self.patcher_pec.start() + self.mock_get_excitation = self.patcher_excitation.start() - self.patcher_rec = patch( + self.patcher_recombination = patch( "cherab.openadas.openadas.repository.get_pec_recombination_rate", return_value={ "ne": np.linspace(1e18, 1e20, 10), @@ -43,7 +43,7 @@ def setUp(self): "rate": np.ones((10, 12)), }, ) - self.mock_get_rec = self.patcher_rec.start() + self.mock_get_recombination = self.patcher_recombination.start() self.patcher_wl = patch( "cherab.openadas.openadas.repository.get_wavelength", return_value=656.28 @@ -52,8 +52,8 @@ def setUp(self): def tearDown(self): # stop the mocks after a test is run - self.patcher_pec.stop() - self.patcher_rec.stop() + self.patcher_excitation.stop() + self.patcher_recombination.stop() self.patcher_wl.stop() def test_excitation(self): @@ -70,7 +70,7 @@ def test_excitation(self): self.assertIsInstance(exc.lineshape, GaussianLine) # check the mock was called - self.mock_get_pec.assert_called_once() + self.mock_get_excitation.assert_called_once() self.assertEqual(self.mock_get_wavelength.call_count, 2) def test_recombination(self): @@ -87,7 +87,7 @@ def test_recombination(self): self.assertIsInstance(rec.lineshape, GaussianLine) # check the mock was called - self.mock_get_rec.assert_called_once() + self.mock_get_recombination.assert_called_once() self.assertEqual(self.mock_get_wavelength.call_count, 2) def test_total_radiated_power(self):