From dfa1958c308cbe21f8c3dd941e8b9b39a7c81995 Mon Sep 17 00:00:00 2001 From: Kenichi Maeda <99521821+kenichi-maeda@users.noreply.github.com> Date: Mon, 17 Jun 2024 23:51:25 +0200 Subject: [PATCH] Added a base class (#36) * Added a base class --- tests/test_abbottstjudeactivetip6142_6145.py | 80 ++---- tests/test_abbottstjudeactivetip6146_6149.py | 80 ++---- tests/test_abbottstjudedirected6172.py | 91 ++----- tests/test_abbottstjudedirected6173.py | 90 ++----- tests/test_bostonscientificcartesiahx.py | 106 ++------ tests/test_bostonscientificcartesiax.py | 106 ++------ tests/test_bostonscientificvercise.py | 83 ++----- tests/test_bostonscientificvercisedirected.py | 97 ++------ tests/test_diximicrotechniquesSEEG10.py | 98 ++------ tests/test_diximicrotechniquesSEEG12.py | 102 ++------ tests/test_diximicrotechniquesSEEG15.py | 108 ++------ tests/test_diximicrotechniquesSEEG18.py | 114 ++------- tests/test_diximicrotechniquesSEEG5.py | 88 ++----- tests/test_diximicrotechniquesSEEG8.py | 94 ++----- tests/test_electrodes.py | 232 ++++++++++++++++++ tests/test_medtronic3387.py | 81 ++---- tests/test_medtronic3389.py | 81 ++---- tests/test_medtronic3391.py | 80 ++---- tests/test_medtronicsensightB33005.py | 91 ++----- tests/test_medtronicsensightB33015.py | 91 ++----- tests/test_microelectrode.py | 78 ++---- tests/test_microprobescustomrodent.py | 75 ++---- tests/test_microprobessnex100.py | 105 ++------ tests/test_neuropaceDL344_10.py | 80 ++---- tests/test_neuropaceDL344_3_5.py | 80 ++---- tests/test_pinsmedicall301.py | 80 ++---- tests/test_pinsmedicall302.py | 80 ++---- tests/test_pinsmedicall303.py | 80 ++---- 28 files changed, 664 insertions(+), 1987 deletions(-) create mode 100644 tests/test_electrodes.py diff --git a/tests/test_abbottstjudeactivetip6142_6145.py b/tests/test_abbottstjudeactivetip6142_6145.py index 83d5bfb0..a65cda45 100644 --- a/tests/test_abbottstjudeactivetip6142_6145.py +++ b/tests/test_abbottstjudeactivetip6142_6145.py @@ -1,79 +1,31 @@ -import netgen -import ngsolve -import numpy as np import pytest from ossdbs.electrodes import AbbottStJudeActiveTip6142_6145 +from .test_electrodes import TestElectrode -class TestAbbottStJudeActiveTip6142_6145: + +class TestAbbottStJudeActiveTip6142_6145(TestElectrode): @pytest.fixture - def AbbottStJudeActiveTip6142_6145_electrode(self): + def electrode(self): return AbbottStJudeActiveTip6142_6145() - def test_rename_boundaries(self, AbbottStJudeActiveTip6142_6145_electrode): + @pytest.fixture + def electrode_name(self): + return "AbbottStJudeActiveTip6142_6145" + + def test_rename_boundaries(self, electrode, electrode_name): """Test whether set_contact_names() works.""" - electrode = AbbottStJudeActiveTip6142_6145_electrode - electrode.set_contact_names( - { - "Body": "RenamedBody", - "Contact_1": "RenamedContact_1", - "NonExistingPart": "NonExistingPart", - } - ) - geometry = electrode.geometry - netgen_geometry = netgen.occ.OCCGeometry(geometry) - with ngsolve.TaskManager(): - mesh = ngsolve.Mesh(netgen_geometry.GenerateMesh()) - desired = { - "RenamedBody", - "RenamedContact_1", - "Contact_2", - "Contact_3", - "Contact_4", - } - assert desired == set(mesh.GetBoundaries()) + self.check_rename_boundaries(electrode, electrode_name) - def test_contacts(self, AbbottStJudeActiveTip6142_6145_electrode): + def test_contacts(self, electrode, electrode_name): """Test the number and names of contacts.""" - electrode = AbbottStJudeActiveTip6142_6145_electrode - geometry = electrode.geometry - netgen_geometry = netgen.occ.OCCGeometry(geometry) - with ngsolve.TaskManager(): - mesh = ngsolve.Mesh(netgen_geometry.GenerateMesh()) - desired = {"Body", "Contact_1", "Contact_2", "Contact_3", "Contact_4"} - assert desired == set(mesh.GetBoundaries()) + self.check_contacts(electrode, electrode_name) - def test_electrode_volume(self, AbbottStJudeActiveTip6142_6145_electrode): + def test_electrode_volume(self, electrode, electrode_name): """Test volume of the entire electrode.""" - electrode = AbbottStJudeActiveTip6142_6145_electrode - - total_length = electrode._parameters.total_length - tip_length = electrode._parameters.tip_length - radius = electrode._parameters.lead_diameter * 0.5 - height = total_length - tip_length - - desired = (np.pi * radius**2 * height) + (4 / 3 * np.pi * radius**3 * 0.5) - actual = electrode.geometry.mass - tolerance = 1e-5 + self.check_electrode_volume(electrode, electrode_name) - np.testing.assert_allclose(actual, desired, atol=tolerance) - - def test_contacts_volume(self, AbbottStJudeActiveTip6142_6145_electrode): + def test_contacts_volume(self, electrode, electrode_name): """Test volume of all the contacts.""" - electrode = AbbottStJudeActiveTip6142_6145_electrode - - contact_length = electrode._parameters.contact_length - radius = electrode._parameters.lead_diameter * 0.5 - n_contacts = electrode._n_contacts - - C1_height = electrode._parameters.tip_length - radius - C1_volume = (4 / 3 * radius**3 * np.pi * 0.5) + ( - C1_height * radius**2 * np.pi - ) - - desired = (contact_length * radius**2 * np.pi) * (n_contacts - 1) + C1_volume - actual = electrode._contacts().mass - tolerance = 1e-5 - - np.testing.assert_allclose(actual, desired, atol=tolerance) + self.check_contacts_volume(electrode, electrode_name) diff --git a/tests/test_abbottstjudeactivetip6146_6149.py b/tests/test_abbottstjudeactivetip6146_6149.py index b8793409..741f9d7e 100644 --- a/tests/test_abbottstjudeactivetip6146_6149.py +++ b/tests/test_abbottstjudeactivetip6146_6149.py @@ -1,79 +1,31 @@ -import netgen -import ngsolve -import numpy as np import pytest from ossdbs.electrodes import AbbottStJudeActiveTip6146_6149 +from .test_electrodes import TestElectrode -class TestAbbottStJudeActiveTip6146_6149: + +class TestAbbottStJudeActiveTip6146_6149(TestElectrode): @pytest.fixture - def AbbottStJudeActiveTip6146_6149_electrode(self): + def electrode(self): return AbbottStJudeActiveTip6146_6149() - def test_rename_boundaries(self, AbbottStJudeActiveTip6146_6149_electrode): + @pytest.fixture + def electrode_name(self): + return "AbbottStJudeActiveTip6146_6149" + + def test_rename_boundaries(self, electrode, electrode_name): """Test whether set_contact_names() works.""" - electrode = AbbottStJudeActiveTip6146_6149_electrode - electrode.set_contact_names( - { - "Body": "RenamedBody", - "Contact_1": "RenamedContact_1", - "NonExistingPart": "NonExistingPart", - } - ) - geometry = electrode.geometry - netgen_geometry = netgen.occ.OCCGeometry(geometry) - with ngsolve.TaskManager(): - mesh = ngsolve.Mesh(netgen_geometry.GenerateMesh()) - desired = { - "RenamedBody", - "RenamedContact_1", - "Contact_2", - "Contact_3", - "Contact_4", - } - assert desired == set(mesh.GetBoundaries()) + self.check_rename_boundaries(electrode, electrode_name) - def test_contacts(self, AbbottStJudeActiveTip6146_6149_electrode): + def test_contacts(self, electrode, electrode_name): """Test the number and names of contacts.""" - electrode = AbbottStJudeActiveTip6146_6149_electrode - geometry = electrode.geometry - netgen_geometry = netgen.occ.OCCGeometry(geometry) - with ngsolve.TaskManager(): - mesh = ngsolve.Mesh(netgen_geometry.GenerateMesh()) - desired = {"Body", "Contact_1", "Contact_2", "Contact_3", "Contact_4"} - assert desired == set(mesh.GetBoundaries()) + self.check_contacts(electrode, electrode_name) - def test_electrode_volume(self, AbbottStJudeActiveTip6146_6149_electrode): + def test_electrode_volume(self, electrode, electrode_name): """Test volume of the entire electrode.""" - electrode = AbbottStJudeActiveTip6146_6149_electrode - - total_length = electrode._parameters.total_length - tip_length = electrode._parameters.tip_length - radius = electrode._parameters.lead_diameter * 0.5 - height = total_length - tip_length - - desired = (np.pi * radius**2 * height) + (4 / 3 * np.pi * radius**3 * 0.5) - actual = electrode.geometry.mass - tolerance = 1e-5 + self.check_electrode_volume(electrode, electrode_name) - np.testing.assert_allclose(actual, desired, atol=tolerance) - - def test_contacts_volume(self, AbbottStJudeActiveTip6146_6149_electrode): + def test_contacts_volume(self, electrode, electrode_name): """Test volume of all the contacts.""" - electrode = AbbottStJudeActiveTip6146_6149_electrode - - contact_length = electrode._parameters.contact_length - radius = electrode._parameters.lead_diameter * 0.5 - n_contacts = electrode._n_contacts - - C1_height = electrode._parameters.tip_length - radius - C1_volume = (4 / 3 * radius**3 * np.pi * 0.5) + ( - C1_height * radius**2 * np.pi - ) - - desired = (contact_length * radius**2 * np.pi) * (n_contacts - 1) + C1_volume - actual = electrode._contacts().mass - tolerance = 1e-5 - - np.testing.assert_allclose(actual, desired, atol=tolerance) + self.check_contacts_volume(electrode, electrode_name) diff --git a/tests/test_abbottstjudedirected6172.py b/tests/test_abbottstjudedirected6172.py index d64bafed..640e6baf 100644 --- a/tests/test_abbottstjudedirected6172.py +++ b/tests/test_abbottstjudedirected6172.py @@ -1,90 +1,31 @@ -import netgen -import ngsolve -import numpy as np import pytest from ossdbs.electrodes import AbbottStJudeDirected6172 +from .test_electrodes import TestElectrode -class TestAbbottStJudeDirected6172: + +class TestAbbottStJudeDirected6172(TestElectrode): @pytest.fixture - def AbbottStJudeDirected6172_electrode(self): + def electrode(self): return AbbottStJudeDirected6172() - def test_rename_boundaries(self, AbbottStJudeDirected6172_electrode): + @pytest.fixture + def electrode_name(self): + return "AbbottStJudeDirected6172" + + def test_rename_boundaries(self, electrode, electrode_name): """Test whether set_contact_names() works.""" - electrode = AbbottStJudeDirected6172_electrode - electrode.set_contact_names( - { - "Body": "RenamedBody", - "Contact_1": "RenamedContact_1", - "NonExistingPart": "NonExistingPart", - } - ) - geometry = electrode.geometry - netgen_geometry = netgen.occ.OCCGeometry(geometry) - with ngsolve.TaskManager(): - mesh = ngsolve.Mesh(netgen_geometry.GenerateMesh()) - desired = { - "RenamedBody", - "RenamedContact_1", - "Contact_2", - "Contact_3", - "Contact_4", - "Contact_5", - "Contact_6", - "Contact_7", - "Contact_8", - } - assert desired == set(mesh.GetBoundaries()) + self.check_rename_boundaries(electrode, electrode_name) - def test_contacts(self, AbbottStJudeDirected6172_electrode): + def test_contacts(self, electrode, electrode_name): """Test the number and names of contacts.""" - electrode = AbbottStJudeDirected6172_electrode - geometry = electrode.geometry - netgen_geometry = netgen.occ.OCCGeometry(geometry) - with ngsolve.TaskManager(): - mesh = ngsolve.Mesh(netgen_geometry.GenerateMesh()) - desired = { - "Body", - "Contact_1", - "Contact_2", - "Contact_3", - "Contact_4", - "Contact_5", - "Contact_6", - "Contact_7", - "Contact_8", - } - assert desired == set(mesh.GetBoundaries()) + self.check_contacts(electrode, electrode_name) - def test_electrode_volume(self, AbbottStJudeDirected6172_electrode): + def test_electrode_volume(self, electrode, electrode_name): """Test volume of the entire electrode.""" - electrode = AbbottStJudeDirected6172_electrode - - total_length = electrode._parameters.total_length - tip_length = electrode._parameters.tip_length - radius = electrode._parameters.lead_diameter * 0.5 - height = total_length - tip_length - - desired = (np.pi * radius**2 * height) + (4 / 3 * np.pi * radius**3 * 0.5) - actual = electrode.geometry.mass - tolerance = 1e-5 + self.check_electrode_volume(electrode, electrode_name) - np.testing.assert_allclose(actual, desired, atol=tolerance) - - def test_contacts_volume(self, AbbottStJudeDirected6172_electrode): + def test_contacts_volume(self, electrode, electrode_name): """Test volume of all the contacts.""" - electrode = AbbottStJudeDirected6172_electrode - - contact_length = electrode._parameters.contact_length - radius = electrode._parameters.lead_diameter * 0.5 - - desired = (np.pi * radius**2 * contact_length * 2) + ( - np.pi * radius**2 * contact_length * 90 / 360 - ) * 6 - - actual = electrode._contacts().mass - tolerance = 1e-5 - - np.testing.assert_allclose(actual, desired, atol=tolerance) + self.check_contacts_volume(electrode, electrode_name) diff --git a/tests/test_abbottstjudedirected6173.py b/tests/test_abbottstjudedirected6173.py index d8adbc45..fb22fb18 100644 --- a/tests/test_abbottstjudedirected6173.py +++ b/tests/test_abbottstjudedirected6173.py @@ -1,89 +1,31 @@ -import netgen -import ngsolve -import numpy as np import pytest from ossdbs.electrodes import AbbottStJudeDirected6173 +from .test_electrodes import TestElectrode -class TestAbbottStJudeDirected6173: + +class TestAbbottStJudeDirected6173(TestElectrode): @pytest.fixture - def AbbottStJudeDirected6173_electrode(self): + def electrode(self): return AbbottStJudeDirected6173() - def test_rename_boundaries(self, AbbottStJudeDirected6173_electrode): + @pytest.fixture + def electrode_name(self): + return "AbbottStJudeDirected6173" + + def test_rename_boundaries(self, electrode, electrode_name): """Test whether set_contact_names() works.""" - electrode = AbbottStJudeDirected6173_electrode - electrode.set_contact_names( - { - "Body": "RenamedBody", - "Contact_1": "RenamedContact_1", - "NonExistingPart": "NonExistingPart", - } - ) - geometry = electrode.geometry - netgen_geometry = netgen.occ.OCCGeometry(geometry) - with ngsolve.TaskManager(): - mesh = ngsolve.Mesh(netgen_geometry.GenerateMesh()) - desired = { - "RenamedBody", - "RenamedContact_1", - "Contact_2", - "Contact_3", - "Contact_4", - "Contact_5", - "Contact_6", - "Contact_7", - "Contact_8", - } - assert desired == set(mesh.GetBoundaries()) + self.check_rename_boundaries(electrode, electrode_name) - def test_contacts(self, AbbottStJudeDirected6173_electrode): + def test_contacts(self, electrode, electrode_name): """Test the number and names of contacts.""" - electrode = AbbottStJudeDirected6173_electrode - geometry = electrode.geometry - netgen_geometry = netgen.occ.OCCGeometry(geometry) - with ngsolve.TaskManager(): - mesh = ngsolve.Mesh(netgen_geometry.GenerateMesh()) - desired = { - "Body", - "Contact_1", - "Contact_2", - "Contact_3", - "Contact_4", - "Contact_5", - "Contact_6", - "Contact_7", - "Contact_8", - } - assert desired == set(mesh.GetBoundaries()) + self.check_contacts(electrode, electrode_name) - def test_electrode_volume(self, AbbottStJudeDirected6173_electrode): + def test_electrode_volume(self, electrode, electrode_name): """Test volume of the entire electrode.""" - electrode = AbbottStJudeDirected6173_electrode - - total_length = electrode._parameters.total_length - tip_length = electrode._parameters.tip_length - radius = electrode._parameters.lead_diameter * 0.5 - height = total_length - tip_length - - desired = (np.pi * radius**2 * height) + (4 / 3 * np.pi * radius**3 * 0.5) - actual = electrode.geometry.mass - tolerance = 1e-5 + self.check_electrode_volume(electrode, electrode_name) - np.testing.assert_allclose(actual, desired, atol=tolerance) - - def test_contacts_volume(self, AbbottStJudeDirected6173_electrode): + def test_contacts_volume(self, electrode, electrode_name): """Test volume of all the contacts.""" - electrode = AbbottStJudeDirected6173_electrode - - contact_length = electrode._parameters.contact_length - radius = electrode._parameters.lead_diameter * 0.5 - - desired = (np.pi * radius**2 * contact_length * 2) + ( - np.pi * radius**2 * contact_length * 90 / 360 - ) * 6 - actual = electrode._contacts().mass - tolerance = 1e-5 - - np.testing.assert_allclose(actual, desired, atol=tolerance) + self.check_contacts_volume(electrode, electrode_name) diff --git a/tests/test_bostonscientificcartesiahx.py b/tests/test_bostonscientificcartesiahx.py index 3c52a9b3..b733c975 100644 --- a/tests/test_bostonscientificcartesiahx.py +++ b/tests/test_bostonscientificcartesiahx.py @@ -1,105 +1,31 @@ -import netgen -import ngsolve -import numpy as np import pytest from ossdbs.electrodes import BostonScientificCartesiaHX +from .test_electrodes import TestElectrode -class TestBostonScientificCartesiaHX: + +class TestBostonScientificCartesiaHX(TestElectrode): @pytest.fixture - def BostonScientificCartesiaHX_electrode(self): + def electrode(self): return BostonScientificCartesiaHX() - def test_rename_boundaries(self, BostonScientificCartesiaHX_electrode): + @pytest.fixture + def electrode_name(self): + return "BostonScientificCartesiaHX" + + def test_rename_boundaries(self, electrode, electrode_name): """Test whether set_contact_names() works.""" - electrode = BostonScientificCartesiaHX_electrode - electrode.set_contact_names( - { - "Body": "RenamedBody", - "Contact_1": "RenamedContact_1", - "NonExistingPart": "NonExistingPart", - } - ) - geometry = electrode.geometry - netgen_geometry = netgen.occ.OCCGeometry(geometry) - with ngsolve.TaskManager(): - mesh = ngsolve.Mesh(netgen_geometry.GenerateMesh()) - desired = { - "RenamedBody", - "RenamedContact_1", - "Contact_2", - "Contact_3", - "Contact_4", - "Contact_5", - "Contact_6", - "Contact_7", - "Contact_8", - "Contact_9", - "Contact_10", - "Contact_11", - "Contact_12", - "Contact_13", - "Contact_14", - "Contact_15", - "Contact_16", - } - assert desired == set(mesh.GetBoundaries()) + self.check_rename_boundaries(electrode, electrode_name) - def test_contacts(self, BostonScientificCartesiaHX_electrode): + def test_contacts(self, electrode, electrode_name): """Test the number and names of contacts.""" - electrode = BostonScientificCartesiaHX_electrode - geometry = electrode.geometry - netgen_geometry = netgen.occ.OCCGeometry(geometry) - with ngsolve.TaskManager(): - mesh = ngsolve.Mesh(netgen_geometry.GenerateMesh()) - desired = { - "Body", - "Contact_1", - "Contact_2", - "Contact_3", - "Contact_4", - "Contact_5", - "Contact_6", - "Contact_7", - "Contact_8", - "Contact_9", - "Contact_10", - "Contact_11", - "Contact_12", - "Contact_13", - "Contact_14", - "Contact_15", - "Contact_16", - } - assert desired == set(mesh.GetBoundaries()) + self.check_contacts(electrode, electrode_name) - def test_electrode_volume(self, BostonScientificCartesiaHX_electrode): + def test_electrode_volume(self, electrode, electrode_name): """Test volume of the entire electrode.""" - electrode = BostonScientificCartesiaHX_electrode - - total_length = electrode._parameters.total_length - tip_length = electrode._parameters.tip_length - radius = electrode._parameters.lead_diameter * 0.5 - height = total_length - tip_length - - desired = (np.pi * radius**2 * height) + (4 / 3 * np.pi * radius**3 * 0.5) - actual = electrode.geometry.mass - tolerance = 1e-5 + self.check_electrode_volume(electrode, electrode_name) - np.testing.assert_allclose(actual, desired, atol=tolerance) - - def test_contacts_volume(self, BostonScientificCartesiaHX_electrode): + def test_contacts_volume(self, electrode, electrode_name): """Test volume of all the contacts.""" - electrode = BostonScientificCartesiaHX_electrode - - contact_length = electrode._parameters.contact_length - radius = electrode._parameters.lead_diameter * 0.5 - - desired = (np.pi * radius**2 * contact_length) * 4 + ( - np.pi * radius**2 * contact_length * 90 / 360 - ) * 12 - actual = electrode._contacts().mass - tolerance = 1e-5 - - np.testing.assert_allclose(actual, desired, atol=tolerance) + self.check_contacts_volume(electrode, electrode_name) diff --git a/tests/test_bostonscientificcartesiax.py b/tests/test_bostonscientificcartesiax.py index 9326ed51..ddd08cf2 100644 --- a/tests/test_bostonscientificcartesiax.py +++ b/tests/test_bostonscientificcartesiax.py @@ -1,105 +1,31 @@ -import netgen -import ngsolve -import numpy as np import pytest from ossdbs.electrodes import BostonScientificCartesiaX +from .test_electrodes import TestElectrode -class TestBostonScientificCartesiaX: + +class TestBostonScientificCartesiaX(TestElectrode): @pytest.fixture - def BostonScientificCartesiaX_electrode(self): + def electrode(self): return BostonScientificCartesiaX() - def test_rename_boundaries(self, BostonScientificCartesiaX_electrode): + @pytest.fixture + def electrode_name(self): + return "BostonScientificCartesiaX" + + def test_rename_boundaries(self, electrode, electrode_name): """Test whether set_contact_names() works.""" - electrode = BostonScientificCartesiaX_electrode - electrode.set_contact_names( - { - "Body": "RenamedBody", - "Contact_1": "RenamedContact_1", - "NonExistingPart": "NonExistingPart", - } - ) - geometry = electrode.geometry - netgen_geometry = netgen.occ.OCCGeometry(geometry) - with ngsolve.TaskManager(): - mesh = ngsolve.Mesh(netgen_geometry.GenerateMesh()) - desired = { - "RenamedBody", - "RenamedContact_1", - "Contact_2", - "Contact_3", - "Contact_4", - "Contact_5", - "Contact_6", - "Contact_7", - "Contact_8", - "Contact_9", - "Contact_10", - "Contact_11", - "Contact_12", - "Contact_13", - "Contact_14", - "Contact_15", - "Contact_16", - } - assert desired == set(mesh.GetBoundaries()) + self.check_rename_boundaries(electrode, electrode_name) - def test_contacts(self, BostonScientificCartesiaX_electrode): + def test_contacts(self, electrode, electrode_name): """Test the number and names of contacts.""" - electrode = BostonScientificCartesiaX_electrode - geometry = electrode.geometry - netgen_geometry = netgen.occ.OCCGeometry(geometry) - with ngsolve.TaskManager(): - mesh = ngsolve.Mesh(netgen_geometry.GenerateMesh()) - desired = { - "Body", - "Contact_1", - "Contact_2", - "Contact_3", - "Contact_4", - "Contact_5", - "Contact_6", - "Contact_7", - "Contact_8", - "Contact_9", - "Contact_10", - "Contact_11", - "Contact_12", - "Contact_13", - "Contact_14", - "Contact_15", - "Contact_16", - } - assert desired == set(mesh.GetBoundaries()) + self.check_contacts(electrode, electrode_name) - def test_electrode_volume(self, BostonScientificCartesiaX_electrode): + def test_electrode_volume(self, electrode, electrode_name): """Test volume of the entire electrode.""" - electrode = BostonScientificCartesiaX_electrode - - total_length = electrode._parameters.total_length - tip_length = electrode._parameters.tip_length - radius = electrode._parameters.lead_diameter * 0.5 - height = total_length - tip_length - - desired = (np.pi * radius**2 * height) + (4 / 3 * np.pi * radius**3 * 0.5) - actual = electrode.geometry.mass - tolerance = 1e-5 + self.check_electrode_volume(electrode, electrode_name) - np.testing.assert_allclose(actual, desired, atol=tolerance) - - def test_contacts_volume(self, BostonScientificCartesiaX_electrode): + def test_contacts_volume(self, electrode, electrode_name): """Test volume of all the contacts.""" - electrode = BostonScientificCartesiaX_electrode - - contact_length = electrode._parameters.contact_length - radius = electrode._parameters.lead_diameter * 0.5 - - desired = (np.pi * radius**2 * contact_length) + ( - np.pi * radius**2 * contact_length * 90 / 360 - ) * 15 - actual = electrode._contacts().mass - tolerance = 1e-5 - - np.testing.assert_allclose(actual, desired, atol=tolerance) + self.check_contacts_volume(electrode, electrode_name) diff --git a/tests/test_bostonscientificvercise.py b/tests/test_bostonscientificvercise.py index 287124a6..288c5c23 100644 --- a/tests/test_bostonscientificvercise.py +++ b/tests/test_bostonscientificvercise.py @@ -1,82 +1,31 @@ -import numpy as np import pytest from ossdbs.electrodes import BostonScientificVercise +from .test_electrodes import TestElectrode -class TestBostonScientificVercise: + +class TestBostonScientificVercise(TestElectrode): @pytest.fixture - def BostonScientificVercise_electrode(self): + def electrode(self): return BostonScientificVercise() - def test_rename_boundaries(self, BostonScientificVercise_electrode): + @pytest.fixture + def electrode_name(self): + return "BostonScientificVercise" + + def test_rename_boundaries(self, electrode, electrode_name): """Test whether set_contact_names() works.""" - electrode = BostonScientificVercise_electrode - electrode.set_contact_names( - { - "Body": "RenamedBody", - "Contact_1": "RenamedContact_1", - "NonExistingPart": "NonExistingPart", - } - ) - geometry = electrode.geometry - faces = [face.name for face in geometry.faces] - desired = { - "RenamedBody", - "RenamedContact_1", - "Contact_2", - "Contact_3", - "Contact_4", - "Contact_5", - "Contact_6", - "Contact_7", - "Contact_8", - } - assert desired == set(faces) + self.check_rename_boundaries(electrode, electrode_name) - def test_contacts(self, BostonScientificVercise_electrode): + def test_contacts(self, electrode, electrode_name): """Test the number and names of contacts.""" - electrode = BostonScientificVercise_electrode - geometry = electrode.geometry - faces = [face.name for face in geometry.faces] - desired = { - "Body", - "Contact_1", - "Contact_2", - "Contact_3", - "Contact_4", - "Contact_5", - "Contact_6", - "Contact_7", - "Contact_8", - } - assert desired == set(faces) + self.check_contacts(electrode, electrode_name) - def test_electrode_volume(self, BostonScientificVercise_electrode): + def test_electrode_volume(self, electrode, electrode_name): """Test volume of the entire electrode.""" - electrode = BostonScientificVercise_electrode - - total_length = electrode._parameters.total_length - tip_length = electrode._parameters.tip_length - radius = electrode._parameters.lead_diameter * 0.5 - height = total_length - tip_length - - desired = (np.pi * radius**2 * height) + (4 / 3 * np.pi * radius**3 * 0.5) - actual = electrode.geometry.mass - tolerance = 1e-5 + self.check_electrode_volume(electrode, electrode_name) - np.testing.assert_allclose(actual, desired, atol=tolerance) - - def test_contacts_volume(self, BostonScientificVercise_electrode): + def test_contacts_volume(self, electrode, electrode_name): """Test volume of all the contacts.""" - electrode = BostonScientificVercise_electrode - - contact_length = electrode._parameters.contact_length - radius = electrode._parameters.lead_diameter * 0.5 - n_contacts = electrode._n_contacts - - desired = (contact_length * radius**2 * np.pi) * n_contacts - actual = electrode._contacts().mass - tolerance = 1e-5 - - np.testing.assert_allclose(actual, desired, atol=tolerance) + self.check_contacts_volume(electrode, electrode_name) diff --git a/tests/test_bostonscientificvercisedirected.py b/tests/test_bostonscientificvercisedirected.py index dfd33730..8a9fec52 100644 --- a/tests/test_bostonscientificvercisedirected.py +++ b/tests/test_bostonscientificvercisedirected.py @@ -1,96 +1,31 @@ -import netgen -import ngsolve -import numpy as np import pytest from ossdbs.electrodes import BostonScientificVerciseDirected +from .test_electrodes import TestElectrode -class TestBostonScientificVerciseDirected: + +class TestBostonScientificVerciseDirected(TestElectrode): @pytest.fixture - def BostonScientificVerciseDirected_electrode(self): + def electrode(self): return BostonScientificVerciseDirected() - def test_rename_boundaries(self, BostonScientificVerciseDirected_electrode): + @pytest.fixture + def electrode_name(self): + return "BostonScientificVerciseDirected" + + def test_rename_boundaries(self, electrode, electrode_name): """Test whether set_contact_names() works.""" - electrode = BostonScientificVerciseDirected_electrode - electrode.set_contact_names( - { - "Body": "RenamedBody", - "Contact_1": "RenamedContact_1", - "NonExistingPart": "NonExistingPart", - } - ) - geometry = electrode.geometry - netgen_geometry = netgen.occ.OCCGeometry(geometry) - with ngsolve.TaskManager(): - mesh = ngsolve.Mesh(netgen_geometry.GenerateMesh()) - desired = { - "RenamedBody", - "RenamedContact_1", - "Contact_2", - "Contact_3", - "Contact_4", - "Contact_5", - "Contact_6", - "Contact_7", - "Contact_8", - } - assert desired == set(mesh.GetBoundaries()) + self.check_rename_boundaries(electrode, electrode_name) - def test_contacts(self, BostonScientificVerciseDirected_electrode): + def test_contacts(self, electrode, electrode_name): """Test the number and names of contacts.""" - electrode = BostonScientificVerciseDirected_electrode - geometry = electrode.geometry - netgen_geometry = netgen.occ.OCCGeometry(geometry) - with ngsolve.TaskManager(): - mesh = ngsolve.Mesh(netgen_geometry.GenerateMesh()) - desired = { - "Body", - "Contact_1", - "Contact_2", - "Contact_3", - "Contact_4", - "Contact_5", - "Contact_6", - "Contact_7", - "Contact_8", - } - assert desired == set(mesh.GetBoundaries()) + self.check_contacts(electrode, electrode_name) - def test_electrode_volume(self, BostonScientificVerciseDirected_electrode): + def test_electrode_volume(self, electrode, electrode_name): """Test volume of the entire electrode.""" - electrode = BostonScientificVerciseDirected_electrode - - total_length = electrode._parameters.total_length - tip_length = electrode._parameters.tip_length - radius = electrode._parameters.lead_diameter * 0.5 - height = total_length - tip_length - - desired = (np.pi * radius**2 * height) + (4 / 3 * np.pi * radius**3 * 0.5) - actual = electrode.geometry.mass - tolerance = 1e-5 + self.check_electrode_volume(electrode, electrode_name) - np.testing.assert_allclose(actual, desired, atol=tolerance) - - def test_contacts_volume(self, BostonScientificVerciseDirected_electrode): + def test_contacts_volume(self, electrode, electrode_name): """Test volume of all the contacts.""" - electrode = BostonScientificVerciseDirected_electrode - - contact_length = electrode._parameters.contact_length - radius = electrode._parameters.lead_diameter * 0.5 - - C1_height = electrode._parameters.tip_length - radius - C1_volume = (4 / 3 * radius**3 * np.pi * 0.5) + ( - C1_height * radius**2 * np.pi - ) - - desired = ( - C1_volume - + (np.pi * radius**2 * contact_length) - + (np.pi * radius**2 * contact_length * 90 / 360) * 6 - ) - actual = electrode._contacts().mass - tolerance = 1e-5 - - np.testing.assert_allclose(actual, desired, atol=tolerance) + self.check_contacts_volume(electrode, electrode_name) diff --git a/tests/test_diximicrotechniquesSEEG10.py b/tests/test_diximicrotechniquesSEEG10.py index 13974b42..ad1c1997 100644 --- a/tests/test_diximicrotechniquesSEEG10.py +++ b/tests/test_diximicrotechniquesSEEG10.py @@ -1,97 +1,31 @@ -import netgen -import ngsolve -import numpy as np import pytest from ossdbs.electrodes import DixiSEEG10 +from .test_electrodes import TestElectrode -class TestDixiMicrotechniquesSEEG10: + +class TestDixiSEEG10(TestElectrode): @pytest.fixture - def DixiSEEG10_electrode(self): + def electrode(self): return DixiSEEG10() - def test_rename_boundaries(self, DixiSEEG10_electrode): + @pytest.fixture + def electrode_name(self): + return "DixiSEEG10" + + def test_rename_boundaries(self, electrode, electrode_name): """Test whether set_contact_names() works.""" - electrode = DixiSEEG10_electrode - electrode.set_contact_names( - { - "Body": "RenamedBody", - "Contact_1": "RenamedContact_1", - "NonExistingPart": "NonExistingPart", - } - ) - geometry = electrode.geometry - netgen_geometry = netgen.occ.OCCGeometry(geometry) - with ngsolve.TaskManager(): - mesh = ngsolve.Mesh(netgen_geometry.GenerateMesh()) - desired = { - "RenamedBody", - "RenamedContact_1", - "Contact_2", - "Contact_3", - "Contact_4", - "Contact_5", - "Contact_6", - "Contact_7", - "Contact_8", - "Contact_9", - "Contact_10", - } - assert desired == set(mesh.GetBoundaries()) + self.check_rename_boundaries(electrode, electrode_name) - def test_contacts(self, DixiSEEG10_electrode): + def test_contacts(self, electrode, electrode_name): """Test the number and names of contacts.""" - electrode = DixiSEEG10_electrode - geometry = electrode.geometry - netgen_geometry = netgen.occ.OCCGeometry(geometry) - with ngsolve.TaskManager(): - mesh = ngsolve.Mesh(netgen_geometry.GenerateMesh()) - desired = { - "Body", - "Contact_1", - "Contact_2", - "Contact_3", - "Contact_4", - "Contact_5", - "Contact_6", - "Contact_7", - "Contact_8", - "Contact_9", - "Contact_10", - } - assert desired == set(mesh.GetBoundaries()) + self.check_contacts(electrode, electrode_name) - def test_electrode_volume(self, DixiSEEG10_electrode): + def test_electrode_volume(self, electrode, electrode_name): """Test volume of the entire electrode.""" - electrode = DixiSEEG10_electrode - - total_length = electrode._parameters.total_length - tip_length = electrode._parameters.tip_length - radius = electrode._parameters.lead_diameter * 0.5 - height = total_length - tip_length - - desired = (np.pi * radius**2 * height) + (4 / 3 * np.pi * radius**3 * 0.5) - actual = electrode.geometry.mass - tolerance = 1e-5 + self.check_electrode_volume(electrode, electrode_name) - np.testing.assert_allclose(actual, desired, atol=tolerance) - - def test_contacts_volume(self, DixiSEEG10_electrode): + def test_contacts_volume(self, electrode, electrode_name): """Test volume of all the contacts.""" - electrode = DixiSEEG10_electrode - - contact_length = electrode._parameters.contact_length - radius = electrode._parameters.lead_diameter * 0.5 - n_contacts = electrode._n_contacts - - C1_height = contact_length - radius - C1_volume = (4 / 3 * radius**3 * np.pi * 0.5) + ( - C1_height * radius**2 * np.pi - ) - - desired = (contact_length * radius**2 * np.pi) * (n_contacts - 1) + C1_volume - actual = electrode._contacts().mass - tolerance = 1e-5 - - np.testing.assert_allclose(actual, desired, atol=tolerance) + self.check_contacts_volume(electrode, electrode_name) diff --git a/tests/test_diximicrotechniquesSEEG12.py b/tests/test_diximicrotechniquesSEEG12.py index c1084224..0c300503 100644 --- a/tests/test_diximicrotechniquesSEEG12.py +++ b/tests/test_diximicrotechniquesSEEG12.py @@ -1,101 +1,31 @@ -import netgen -import ngsolve -import numpy as np import pytest from ossdbs.electrodes import DixiSEEG12 +from .test_electrodes import TestElectrode -class TestDixiMicrotechniquesSEEG12: + +class TestDixiSEEG12(TestElectrode): @pytest.fixture - def DixiSEEG12_electrode(self): + def electrode(self): return DixiSEEG12() - def test_rename_boundaries(self, DixiSEEG12_electrode): + @pytest.fixture + def electrode_name(self): + return "DixiSEEG12" + + def test_rename_boundaries(self, electrode, electrode_name): """Test whether set_contact_names() works.""" - electrode = DixiSEEG12_electrode - electrode.set_contact_names( - { - "Body": "RenamedBody", - "Contact_1": "RenamedContact_1", - "NonExistingPart": "NonExistingPart", - } - ) - geometry = electrode.geometry - netgen_geometry = netgen.occ.OCCGeometry(geometry) - with ngsolve.TaskManager(): - mesh = ngsolve.Mesh(netgen_geometry.GenerateMesh()) - desired = { - "RenamedBody", - "RenamedContact_1", - "Contact_2", - "Contact_3", - "Contact_4", - "Contact_5", - "Contact_6", - "Contact_7", - "Contact_8", - "Contact_9", - "Contact_10", - "Contact_11", - "Contact_12", - } - assert desired == set(mesh.GetBoundaries()) + self.check_rename_boundaries(electrode, electrode_name) - def test_contacts(self, DixiSEEG12_electrode): + def test_contacts(self, electrode, electrode_name): """Test the number and names of contacts.""" - electrode = DixiSEEG12_electrode - geometry = electrode.geometry - netgen_geometry = netgen.occ.OCCGeometry(geometry) - with ngsolve.TaskManager(): - mesh = ngsolve.Mesh(netgen_geometry.GenerateMesh()) - desired = { - "Body", - "Contact_1", - "Contact_2", - "Contact_3", - "Contact_4", - "Contact_5", - "Contact_6", - "Contact_7", - "Contact_8", - "Contact_9", - "Contact_10", - "Contact_11", - "Contact_12", - } - assert desired == set(mesh.GetBoundaries()) + self.check_contacts(electrode, electrode_name) - def test_electrode_volume(self, DixiSEEG12_electrode): + def test_electrode_volume(self, electrode, electrode_name): """Test volume of the entire electrode.""" - electrode = DixiSEEG12_electrode - - total_length = electrode._parameters.total_length - tip_length = electrode._parameters.tip_length - radius = electrode._parameters.lead_diameter * 0.5 - height = total_length - tip_length - - desired = (np.pi * radius**2 * height) + (4 / 3 * np.pi * radius**3 * 0.5) - actual = electrode.geometry.mass - tolerance = 1e-5 + self.check_electrode_volume(electrode, electrode_name) - np.testing.assert_allclose(actual, desired, atol=tolerance) - - def test_contacts_volume(self, DixiSEEG12_electrode): + def test_contacts_volume(self, electrode, electrode_name): """Test volume of all the contacts.""" - electrode = DixiSEEG12_electrode - - contact_length = electrode._parameters.contact_length - radius = electrode._parameters.lead_diameter * 0.5 - n_contacts = electrode._n_contacts - - C1_height = contact_length - radius - C1_volume = (4 / 3 * radius**3 * np.pi * 0.5) + ( - C1_height * radius**2 * np.pi - ) - - desired = (contact_length * radius**2 * np.pi) * (n_contacts - 1) + C1_volume - actual = electrode._contacts().mass - tolerance = 1e-5 - - np.testing.assert_allclose(actual, desired, atol=tolerance) + self.check_contacts_volume(electrode, electrode_name) diff --git a/tests/test_diximicrotechniquesSEEG15.py b/tests/test_diximicrotechniquesSEEG15.py index 226a068c..df63fce9 100644 --- a/tests/test_diximicrotechniquesSEEG15.py +++ b/tests/test_diximicrotechniquesSEEG15.py @@ -1,107 +1,31 @@ -import netgen -import ngsolve -import numpy as np import pytest from ossdbs.electrodes import DixiSEEG15 +from .test_electrodes import TestElectrode -class TestDixiMicrotechniquesSEEG15: + +class TestDixiSEEG15(TestElectrode): @pytest.fixture - def DixiSEEG15_electrode(self): + def electrode(self): return DixiSEEG15() - def test_rename_boundaries(self, DixiSEEG15_electrode): + @pytest.fixture + def electrode_name(self): + return "DixiSEEG15" + + def test_rename_boundaries(self, electrode, electrode_name): """Test whether set_contact_names() works.""" - electrode = DixiSEEG15_electrode - electrode.set_contact_names( - { - "Body": "RenamedBody", - "Contact_1": "RenamedContact_1", - "NonExistingPart": "NonExistingPart", - } - ) - geometry = electrode.geometry - netgen_geometry = netgen.occ.OCCGeometry(geometry) - with ngsolve.TaskManager(): - mesh = ngsolve.Mesh(netgen_geometry.GenerateMesh()) - desired = { - "RenamedBody", - "RenamedContact_1", - "Contact_2", - "Contact_3", - "Contact_4", - "Contact_5", - "Contact_6", - "Contact_7", - "Contact_8", - "Contact_9", - "Contact_10", - "Contact_11", - "Contact_12", - "Contact_13", - "Contact_14", - "Contact_15", - } - assert desired == set(mesh.GetBoundaries()) + self.check_rename_boundaries(electrode, electrode_name) - def test_contacts(self, DixiSEEG15_electrode): + def test_contacts(self, electrode, electrode_name): """Test the number and names of contacts.""" - electrode = DixiSEEG15_electrode - geometry = electrode.geometry - netgen_geometry = netgen.occ.OCCGeometry(geometry) - with ngsolve.TaskManager(): - mesh = ngsolve.Mesh(netgen_geometry.GenerateMesh()) - desired = { - "Body", - "Contact_1", - "Contact_2", - "Contact_3", - "Contact_4", - "Contact_5", - "Contact_6", - "Contact_7", - "Contact_8", - "Contact_9", - "Contact_10", - "Contact_11", - "Contact_12", - "Contact_13", - "Contact_14", - "Contact_15", - } - assert desired == set(mesh.GetBoundaries()) + self.check_contacts(electrode, electrode_name) - def test_electrode_volume(self, DixiSEEG15_electrode): + def test_electrode_volume(self, electrode, electrode_name): """Test volume of the entire electrode.""" - electrode = DixiSEEG15_electrode - - total_length = electrode._parameters.total_length - tip_length = electrode._parameters.tip_length - radius = electrode._parameters.lead_diameter * 0.5 - height = total_length - tip_length - - desired = (np.pi * radius**2 * height) + (4 / 3 * np.pi * radius**3 * 0.5) - actual = electrode.geometry.mass - tolerance = 1e-5 + self.check_electrode_volume(electrode, electrode_name) - np.testing.assert_allclose(actual, desired, atol=tolerance) - - def test_contacts_volume(self, DixiSEEG15_electrode): + def test_contacts_volume(self, electrode, electrode_name): """Test volume of all the contacts.""" - electrode = DixiSEEG15_electrode - - contact_length = electrode._parameters.contact_length - radius = electrode._parameters.lead_diameter * 0.5 - n_contacts = electrode._n_contacts - - C1_height = contact_length - radius - C1_volume = (4 / 3 * radius**3 * np.pi * 0.5) + ( - C1_height * radius**2 * np.pi - ) - - desired = (contact_length * radius**2 * np.pi) * (n_contacts - 1) + C1_volume - actual = electrode._contacts().mass - tolerance = 1e-5 - - np.testing.assert_allclose(actual, desired, atol=tolerance) + self.check_contacts_volume(electrode, electrode_name) diff --git a/tests/test_diximicrotechniquesSEEG18.py b/tests/test_diximicrotechniquesSEEG18.py index 1d5849bf..738c9d26 100644 --- a/tests/test_diximicrotechniquesSEEG18.py +++ b/tests/test_diximicrotechniquesSEEG18.py @@ -1,113 +1,31 @@ -import netgen -import ngsolve -import numpy as np import pytest from ossdbs.electrodes import DixiSEEG18 +from .test_electrodes import TestElectrode -class TestDixiMicrotechniquesSEEG18: + +class TestDixiSEEG18(TestElectrode): @pytest.fixture - def DixiSEEG18_electrode(self): + def electrode(self): return DixiSEEG18() - def test_rename_boundaries(self, DixiSEEG18_electrode): + @pytest.fixture + def electrode_name(self): + return "DixiSEEG18" + + def test_rename_boundaries(self, electrode, electrode_name): """Test whether set_contact_names() works.""" - electrode = DixiSEEG18_electrode - electrode.set_contact_names( - { - "Body": "RenamedBody", - "Contact_1": "RenamedContact_1", - "NonExistingPart": "NonExistingPart", - } - ) - geometry = electrode.geometry - netgen_geometry = netgen.occ.OCCGeometry(geometry) - with ngsolve.TaskManager(): - mesh = ngsolve.Mesh(netgen_geometry.GenerateMesh()) - desired = { - "RenamedBody", - "RenamedContact_1", - "Contact_2", - "Contact_3", - "Contact_4", - "Contact_5", - "Contact_6", - "Contact_7", - "Contact_8", - "Contact_9", - "Contact_10", - "Contact_11", - "Contact_12", - "Contact_13", - "Contact_14", - "Contact_15", - "Contact_16", - "Contact_17", - "Contact_18", - } - assert desired == set(mesh.GetBoundaries()) + self.check_rename_boundaries(electrode, electrode_name) - def test_contacts(self, DixiSEEG18_electrode): + def test_contacts(self, electrode, electrode_name): """Test the number and names of contacts.""" - electrode = DixiSEEG18_electrode - geometry = electrode.geometry - netgen_geometry = netgen.occ.OCCGeometry(geometry) - with ngsolve.TaskManager(): - mesh = ngsolve.Mesh(netgen_geometry.GenerateMesh()) - desired = { - "Body", - "Contact_1", - "Contact_2", - "Contact_3", - "Contact_4", - "Contact_5", - "Contact_6", - "Contact_7", - "Contact_8", - "Contact_9", - "Contact_10", - "Contact_11", - "Contact_12", - "Contact_13", - "Contact_14", - "Contact_15", - "Contact_16", - "Contact_17", - "Contact_18", - } - assert desired == set(mesh.GetBoundaries()) + self.check_contacts(electrode, electrode_name) - def test_electrode_volume(self, DixiSEEG18_electrode): + def test_electrode_volume(self, electrode, electrode_name): """Test volume of the entire electrode.""" - electrode = DixiSEEG18_electrode - - total_length = electrode._parameters.total_length - tip_length = electrode._parameters.tip_length - radius = electrode._parameters.lead_diameter * 0.5 - height = total_length - tip_length - - desired = (np.pi * radius**2 * height) + (4 / 3 * np.pi * radius**3 * 0.5) - actual = electrode.geometry.mass - tolerance = 1e-5 + self.check_electrode_volume(electrode, electrode_name) - np.testing.assert_allclose(actual, desired, atol=tolerance) - - def test_contacts_volume(self, DixiSEEG18_electrode): + def test_contacts_volume(self, electrode, electrode_name): """Test volume of all the contacts.""" - electrode = DixiSEEG18_electrode - - contact_length = electrode._parameters.contact_length - radius = electrode._parameters.lead_diameter * 0.5 - n_contacts = electrode._n_contacts - - C1_height = contact_length - radius - C1_volume = (4 / 3 * radius**3 * np.pi * 0.5) + ( - C1_height * radius**2 * np.pi - ) - - desired = (contact_length * radius**2 * np.pi) * (n_contacts - 1) + C1_volume - actual = electrode._contacts().mass - tolerance = 1e-5 - - np.testing.assert_allclose(actual, desired, atol=tolerance) + self.check_contacts_volume(electrode, electrode_name) diff --git a/tests/test_diximicrotechniquesSEEG5.py b/tests/test_diximicrotechniquesSEEG5.py index 88b6a964..78663352 100644 --- a/tests/test_diximicrotechniquesSEEG5.py +++ b/tests/test_diximicrotechniquesSEEG5.py @@ -1,87 +1,31 @@ -import netgen -import ngsolve -import numpy as np import pytest from ossdbs.electrodes import DixiSEEG5 +from .test_electrodes import TestElectrode -class TestDixiMicrotechniquesSEEG5: + +class TestDixiSEEG5(TestElectrode): @pytest.fixture - def DixiSEEG5_electrode(self): + def electrode(self): return DixiSEEG5() - def test_rename_boundaries(self, DixiSEEG5_electrode): + @pytest.fixture + def electrode_name(self): + return "DixiSEEG5" + + def test_rename_boundaries(self, electrode, electrode_name): """Test whether set_contact_names() works.""" - electrode = DixiSEEG5_electrode - electrode.set_contact_names( - { - "Body": "RenamedBody", - "Contact_1": "RenamedContact_1", - "NonExistingPart": "NonExistingPart", - } - ) - geometry = electrode.geometry - netgen_geometry = netgen.occ.OCCGeometry(geometry) - with ngsolve.TaskManager(): - mesh = ngsolve.Mesh(netgen_geometry.GenerateMesh()) - desired = { - "RenamedBody", - "RenamedContact_1", - "Contact_2", - "Contact_3", - "Contact_4", - "Contact_5", - } - assert desired == set(mesh.GetBoundaries()) + self.check_rename_boundaries(electrode, electrode_name) - def test_contacts(self, DixiSEEG5_electrode): + def test_contacts(self, electrode, electrode_name): """Test the number and names of contacts.""" - electrode = DixiSEEG5_electrode - geometry = electrode.geometry - netgen_geometry = netgen.occ.OCCGeometry(geometry) - with ngsolve.TaskManager(): - mesh = ngsolve.Mesh(netgen_geometry.GenerateMesh()) - desired = { - "Body", - "Contact_1", - "Contact_2", - "Contact_3", - "Contact_4", - "Contact_5", - } - assert desired == set(mesh.GetBoundaries()) + self.check_contacts(electrode, electrode_name) - def test_electrode_volume(self, DixiSEEG5_electrode): + def test_electrode_volume(self, electrode, electrode_name): """Test volume of the entire electrode.""" - electrode = DixiSEEG5_electrode - - total_length = electrode._parameters.total_length - tip_length = electrode._parameters.tip_length - radius = electrode._parameters.lead_diameter * 0.5 - height = total_length - tip_length - - desired = (np.pi * radius**2 * height) + (4 / 3 * np.pi * radius**3 * 0.5) - actual = electrode.geometry.mass - tolerance = 1e-5 + self.check_electrode_volume(electrode, electrode_name) - np.testing.assert_allclose(actual, desired, atol=tolerance) - - def test_contacts_volume(self, DixiSEEG5_electrode): + def test_contacts_volume(self, electrode, electrode_name): """Test volume of all the contacts.""" - electrode = DixiSEEG5_electrode - - contact_length = electrode._parameters.contact_length - radius = electrode._parameters.lead_diameter * 0.5 - n_contacts = electrode._n_contacts - - C1_height = contact_length - radius - C1_volume = (4 / 3 * radius**3 * np.pi * 0.5) + ( - C1_height * radius**2 * np.pi - ) - - desired = (contact_length * radius**2 * np.pi) * (n_contacts - 1) + C1_volume - actual = electrode._contacts().mass - tolerance = 1e-5 - - np.testing.assert_allclose(actual, desired, atol=tolerance) + self.check_contacts_volume(electrode, electrode_name) diff --git a/tests/test_diximicrotechniquesSEEG8.py b/tests/test_diximicrotechniquesSEEG8.py index 70641dc4..b1fd0dc8 100644 --- a/tests/test_diximicrotechniquesSEEG8.py +++ b/tests/test_diximicrotechniquesSEEG8.py @@ -1,93 +1,31 @@ -import netgen -import ngsolve -import numpy as np import pytest from ossdbs.electrodes import DixiSEEG8 +from .test_electrodes import TestElectrode -class TestDixiMicrotechniquesSEEG8: + +class TestDixiSEEG8(TestElectrode): @pytest.fixture - def DixiSEEG8_electrode(self): + def electrode(self): return DixiSEEG8() - def test_rename_boundaries(self, DixiSEEG8_electrode): + @pytest.fixture + def electrode_name(self): + return "DixiSEEG8" + + def test_rename_boundaries(self, electrode, electrode_name): """Test whether set_contact_names() works.""" - electrode = DixiSEEG8_electrode - electrode.set_contact_names( - { - "Body": "RenamedBody", - "Contact_1": "RenamedContact_1", - "NonExistingPart": "NonExistingPart", - } - ) - geometry = electrode.geometry - netgen_geometry = netgen.occ.OCCGeometry(geometry) - with ngsolve.TaskManager(): - mesh = ngsolve.Mesh(netgen_geometry.GenerateMesh()) - desired = { - "RenamedBody", - "RenamedContact_1", - "Contact_2", - "Contact_3", - "Contact_4", - "Contact_5", - "Contact_6", - "Contact_7", - "Contact_8", - } - assert desired == set(mesh.GetBoundaries()) + self.check_rename_boundaries(electrode, electrode_name) - def test_contacts(self, DixiSEEG8_electrode): + def test_contacts(self, electrode, electrode_name): """Test the number and names of contacts.""" - electrode = DixiSEEG8_electrode - geometry = electrode.geometry - netgen_geometry = netgen.occ.OCCGeometry(geometry) - with ngsolve.TaskManager(): - mesh = ngsolve.Mesh(netgen_geometry.GenerateMesh()) - desired = { - "Body", - "Contact_1", - "Contact_2", - "Contact_3", - "Contact_4", - "Contact_5", - "Contact_6", - "Contact_7", - "Contact_8", - } - assert desired == set(mesh.GetBoundaries()) + self.check_contacts(electrode, electrode_name) - def test_electrode_volume(self, DixiSEEG8_electrode): + def test_electrode_volume(self, electrode, electrode_name): """Test volume of the entire electrode.""" - electrode = DixiSEEG8_electrode - - total_length = electrode._parameters.total_length - tip_length = electrode._parameters.tip_length - radius = electrode._parameters.lead_diameter * 0.5 - height = total_length - tip_length - - desired = (np.pi * radius**2 * height) + (4 / 3 * np.pi * radius**3 * 0.5) - actual = electrode.geometry.mass - tolerance = 1e-5 + self.check_electrode_volume(electrode, electrode_name) - np.testing.assert_allclose(actual, desired, atol=tolerance) - - def test_contacts_volume(self, DixiSEEG8_electrode): + def test_contacts_volume(self, electrode, electrode_name): """Test volume of all the contacts.""" - electrode = DixiSEEG8_electrode - - contact_length = electrode._parameters.contact_length - radius = electrode._parameters.lead_diameter * 0.5 - n_contacts = electrode._n_contacts - - C1_height = contact_length - radius - C1_volume = (4 / 3 * radius**3 * np.pi * 0.5) + ( - C1_height * radius**2 * np.pi - ) - - desired = (contact_length * radius**2 * np.pi) * (n_contacts - 1) + C1_volume - actual = electrode._contacts().mass - tolerance = 1e-5 - - np.testing.assert_allclose(actual, desired, atol=tolerance) + self.check_contacts_volume(electrode, electrode_name) diff --git a/tests/test_electrodes.py b/tests/test_electrodes.py new file mode 100644 index 00000000..ae129d4c --- /dev/null +++ b/tests/test_electrodes.py @@ -0,0 +1,232 @@ +from typing import ClassVar, List + +import numpy as np + + +class TestElectrode: + """Class for testing electrodes.""" + + AbbottStJudeDirected: ClassVar[List[str]] = [ + "AbbottStJudeDirected6172", + "AbbottStJudeDirected6173", + ] + Medtronic: ClassVar[List[str]] = ["Medtronic3387", "Medtronic3389", "Medtronic3391"] + MedtronicSenSight: ClassVar[List[str]] = [ + "MedtronicSenSightB33005", + "MedtronicSenSightB33015", + ] + NeuroPace: ClassVar[List[str]] = ["NeuroPaceDL344_3_5", "NeuroPaceDL344_10"] + PINSMedical: ClassVar[List[str]] = [ + "PINSMedicalL301", + "PINSMedicalL302", + "PINSMedicalL303", + ] + Dixi: ClassVar[List[str]] = [ + "DixiSEEG5", + "DixiSEEG8", + "DixiSEEG10", + "DixiSEEG12", + "DixiSEEG15", + "DixiSEEG18", + ] + + def check_rename_boundaries(self, electrode, electrode_name): + """Check whether set_contact_names() works.""" + changes = { + "Body": "RenamedBody", + "Contact_1": "RenamedContact_1", + "NonExistingPart": "NonExistingPart", + } + + electrode.set_contact_names(changes) + n_contacts = electrode.n_contacts + geometry = electrode.geometry + faces = [face.name for face in geometry.faces] + + desired = {"RenamedBody", "RenamedContact_1"} + + if electrode_name == "MicroElectrode": + desired.add("fillet") + else: + desired.update({f"Contact_{i+2}" for i in range(n_contacts - 1)}) + + assert desired == set(faces) + + def check_contacts(self, electrode, electrode_name): + """Check the number and names of contacts.""" + n_contacts = electrode.n_contacts + geometry = electrode.geometry + faces = [face.name for face in geometry.faces] + + desired = {"Body"} + desired.update({f"Contact_{i+1}" for i in range(n_contacts)}) + + if electrode_name == "MicroElectrode": + desired.add("fillet") + + assert desired == set(faces) + + def check_electrode_volume(self, electrode, electrode_name): + """Check volume of the entire electrode.""" + desired = self._calculate_electrode_volume(electrode, electrode_name) + actual = electrode.geometry.mass + tolerance = 1e-5 + + np.testing.assert_allclose(actual, desired, atol=tolerance) + + def check_contacts_volume(self, electrode, electrode_name): + """Check volume of all the contacts.""" + desired = self._calculate_contacts_volume(electrode, electrode_name) + actual = electrode._contacts().mass + tolerance = 1e-5 + + np.testing.assert_allclose(actual, desired, atol=tolerance) + + def _calculate_electrode_volume(self, electrode, electrode_name): + if electrode_name == "MicroProbesRodentElectrode": + total_length = electrode._parameters.total_length + lead_radius = electrode._parameters.lead_radius + contact_radius = electrode._parameters.contact_radius + height = total_length - contact_radius + + return (height * lead_radius**2 * np.pi) + ( + 4 / 3 * np.pi * contact_radius**3 * 0.5 + ) + + elif electrode_name == "MicroProbesSNEX100": + radius_1 = electrode._parameters.core_tubing_diameter * 0.5 + height_1 = electrode._parameters.core_tubing_length + + distance_2 = ( + electrode._parameters.core_electrode_length + + electrode._parameters.core_tubing_length + + electrode._parameters.outer_electrode_length + ) + + radius_2 = electrode._parameters.outer_tubing_diameter * 0.5 + height_2 = electrode._parameters.total_length - distance_2 + + body1 = np.pi * radius_1**2 * height_1 + body2 = np.pi * radius_2**2 * height_2 + + outer_electrode_radius = ( + electrode._parameters.outer_electrode_diameter * 0.5 + ) + outer_electrode_length = electrode._parameters.outer_electrode_length + + core_electrode_radius = electrode._parameters.core_electrode_diameter * 0.5 + core_electrode_length = electrode._parameters.core_electrode_length + + contact_1 = np.pi * outer_electrode_radius**2 * outer_electrode_length + contact_2 = (4 / 3 * np.pi * core_electrode_radius**3 * 0.5) + ( + np.pi + * core_electrode_radius**2 + * (core_electrode_length - core_electrode_radius) + ) + + return body1 + body2 + contact_1 + contact_2 + + else: + contact_length = electrode._parameters.contact_length + lead_radius = electrode._parameters.lead_diameter * 0.5 + tip_length = electrode._parameters.tip_length + total_length = electrode._parameters.total_length + height = total_length - tip_length + + if electrode_name == "MicroElectrode": + tip_radius = electrode._parameters.tip_diameter * 0.5 + filet_val = 0.001142187023875807 + + return ( + (contact_length * tip_radius**2 * np.pi) + + (height * lead_radius**2 * np.pi) + - filet_val + ) + + else: + return (np.pi * lead_radius**2 * height) + ( + 4 / 3 * np.pi * lead_radius**3 * 0.5 + ) + + def _calculate_contacts_volume(self, electrode, electrode_name): + if electrode_name == "MicroProbesRodentElectrode": + contact_radius = electrode._parameters.contact_radius + return 4 / 3 * np.pi * contact_radius**3 * 0.5 + elif electrode_name == "MicroProbesSNEX100": + outer_electrode_radius = ( + electrode._parameters.outer_electrode_diameter * 0.5 + ) + outer_electrode_length = electrode._parameters.outer_electrode_length + + core_electrode_radius = electrode._parameters.core_electrode_diameter * 0.5 + core_electrode_length = electrode._parameters.core_electrode_length + + contact_1 = np.pi * outer_electrode_radius**2 * outer_electrode_length + contact_2 = (4 / 3 * np.pi * core_electrode_radius**3 * 0.5) + ( + np.pi + * core_electrode_radius**2 + * (core_electrode_length - core_electrode_radius) + ) + + return contact_1 + contact_2 + else: + contact_length = electrode._parameters.contact_length + lead_radius = electrode._parameters.lead_diameter * 0.5 + tip_length = electrode._parameters.tip_length + n_contacts = electrode._n_contacts + + if electrode_name == "BostonScientificCartesiaHX": + return (np.pi * lead_radius**2 * contact_length) * 4 + ( + np.pi * lead_radius**2 * contact_length * 90 / 360 + ) * 12 + elif electrode_name == "BostonScientificCartesiaX": + return (np.pi * lead_radius**2 * contact_length) + ( + np.pi * lead_radius**2 * contact_length * 90 / 360 + ) * 15 + elif electrode_name == "BostonScientificVerciseDirected": + C1_height = tip_length - lead_radius + C1_volume = (4 / 3 * lead_radius**3 * np.pi * 0.5) + ( + C1_height * lead_radius**2 * np.pi + ) + return ( + C1_volume + + (np.pi * lead_radius**2 * contact_length) + + (np.pi * lead_radius**2 * contact_length * 90 / 360) * 6 + ) + + elif ( + electrode_name == "BostonScientificVercise" + or electrode_name in self.Medtronic + or electrode_name in self.NeuroPace + or electrode_name in self.PINSMedical + ): + C1_height = tip_length - lead_radius + C1_volume = (4 / 3 * lead_radius**3 * np.pi * 0.5) + ( + C1_height * lead_radius**2 * np.pi + ) + + return (contact_length * lead_radius**2 * np.pi) * n_contacts + elif ( + electrode_name in self.AbbottStJudeDirected + or electrode_name in self.MedtronicSenSight + ): + return (np.pi * lead_radius**2 * contact_length * 2) + ( + np.pi * lead_radius**2 * contact_length * 90 / 360 + ) * 6 + elif electrode_name == "MicroElectrode": + tip_radius = electrode._parameters.tip_diameter * 0.5 + filet_val = 0.00114218702387580 + return (contact_length * tip_radius**2 * np.pi) - filet_val + + else: + if electrode_name in self.Dixi: + C1_height = contact_length - lead_radius + else: + C1_height = tip_length - lead_radius + C1_volume = (4 / 3 * lead_radius**3 * np.pi * 0.5) + ( + C1_height * lead_radius**2 * np.pi + ) + + return (contact_length * lead_radius**2 * np.pi) * ( + n_contacts - 1 + ) + C1_volume diff --git a/tests/test_medtronic3387.py b/tests/test_medtronic3387.py index f407b9a9..a9f6ace0 100644 --- a/tests/test_medtronic3387.py +++ b/tests/test_medtronic3387.py @@ -1,80 +1,31 @@ -import netgen -import ngsolve -import numpy as np import pytest from ossdbs.electrodes import Medtronic3387 +from .test_electrodes import TestElectrode -class TestMedtronic3387: + +class TestMedtronic3387(TestElectrode): @pytest.fixture - def Medtronic3387_electrode(self): + def electrode(self): return Medtronic3387() - def test_rename_boundaries(self, Medtronic3387_electrode): + @pytest.fixture + def electrode_name(self): + return "Medtronic3387" + + def test_rename_boundaries(self, electrode, electrode_name): """Test whether set_contact_names() works.""" - electrode = Medtronic3387_electrode - electrode.set_contact_names( - { - "Body": "RenamedBody", - "Contact_1": "RenamedContact_1", - "NonExistingPart": "NonExistingPart", - } - ) - geometry = electrode.geometry - netgen_geometry = netgen.occ.OCCGeometry(geometry) - with ngsolve.TaskManager(): - mesh = ngsolve.Mesh(netgen_geometry.GenerateMesh()) - desired = { - "RenamedBody", - "RenamedContact_1", - "Contact_2", - "Contact_3", - "Contact_4", - } - assert desired == set(mesh.GetBoundaries()) + self.check_rename_boundaries(electrode, electrode_name) - def test_contacts(self, Medtronic3387_electrode): + def test_contacts(self, electrode, electrode_name): """Test the number and names of contacts.""" - electrode = Medtronic3387_electrode - geometry = electrode.geometry - netgen_geometry = netgen.occ.OCCGeometry(geometry) - with ngsolve.TaskManager(): - mesh = ngsolve.Mesh(netgen_geometry.GenerateMesh()) - desired = { - "Body", - "Contact_1", - "Contact_2", - "Contact_3", - "Contact_4", - } - assert desired == set(mesh.GetBoundaries()) + self.check_contacts(electrode, electrode_name) - def test_electrode_volume(self, Medtronic3387_electrode): + def test_electrode_volume(self, electrode, electrode_name): """Test volume of the entire electrode.""" - electrode = Medtronic3387_electrode - - total_length = electrode._parameters.total_length - tip_length = electrode._parameters.tip_length - radius = electrode._parameters.lead_diameter * 0.5 - height = total_length - tip_length - - desired = (np.pi * radius**2 * height) + (4 / 3 * np.pi * radius**3 * 0.5) - actual = electrode.geometry.mass - tolerance = 1e-5 + self.check_electrode_volume(electrode, electrode_name) - np.testing.assert_allclose(actual, desired, atol=tolerance) - - def test_contacts_volume(self, Medtronic3387_electrode): + def test_contacts_volume(self, electrode, electrode_name): """Test volume of all the contacts.""" - electrode = Medtronic3387_electrode - - contact_length = electrode._parameters.contact_length - radius = electrode._parameters.lead_diameter * 0.5 - n_contacts = electrode._n_contacts - - desired = (contact_length * radius**2 * np.pi) * n_contacts - actual = electrode._contacts().mass - tolerance = 1e-5 - - np.testing.assert_allclose(actual, desired, atol=tolerance) + self.check_contacts_volume(electrode, electrode_name) diff --git a/tests/test_medtronic3389.py b/tests/test_medtronic3389.py index 558c0355..de71ff93 100644 --- a/tests/test_medtronic3389.py +++ b/tests/test_medtronic3389.py @@ -1,80 +1,31 @@ -import netgen -import ngsolve -import numpy as np import pytest from ossdbs.electrodes import Medtronic3389 +from .test_electrodes import TestElectrode -class TestMedtronic3389: + +class TestMedtronic3389(TestElectrode): @pytest.fixture - def Medtronic3389_electrode(self): + def electrode(self): return Medtronic3389() - def test_rename_boundaries(self, Medtronic3389_electrode): + @pytest.fixture + def electrode_name(self): + return "Medtronic3389" + + def test_rename_boundaries(self, electrode, electrode_name): """Test whether set_contact_names() works.""" - electrode = Medtronic3389_electrode - electrode.set_contact_names( - { - "Body": "RenamedBody", - "Contact_1": "RenamedContact_1", - "NonExistingPart": "NonExistingPart", - } - ) - geometry = electrode.geometry - netgen_geometry = netgen.occ.OCCGeometry(geometry) - with ngsolve.TaskManager(): - mesh = ngsolve.Mesh(netgen_geometry.GenerateMesh()) - desired = { - "RenamedBody", - "RenamedContact_1", - "Contact_2", - "Contact_3", - "Contact_4", - } - assert desired == set(mesh.GetBoundaries()) + self.check_rename_boundaries(electrode, electrode_name) - def test_contacts(self, Medtronic3389_electrode): + def test_contacts(self, electrode, electrode_name): """Test the number and names of contacts.""" - electrode = Medtronic3389_electrode - geometry = electrode.geometry - netgen_geometry = netgen.occ.OCCGeometry(geometry) - with ngsolve.TaskManager(): - mesh = ngsolve.Mesh(netgen_geometry.GenerateMesh()) - desired = { - "Body", - "Contact_1", - "Contact_2", - "Contact_3", - "Contact_4", - } - assert desired == set(mesh.GetBoundaries()) + self.check_contacts(electrode, electrode_name) - def test_electrode_volume(self, Medtronic3389_electrode): + def test_electrode_volume(self, electrode, electrode_name): """Test volume of the entire electrode.""" - electrode = Medtronic3389_electrode - - total_length = electrode._parameters.total_length - tip_length = electrode._parameters.tip_length - radius = electrode._parameters.lead_diameter * 0.5 - height = total_length - tip_length - - desired = (np.pi * radius**2 * height) + (4 / 3 * np.pi * radius**3 * 0.5) - actual = electrode.geometry.mass - tolerance = 1e-5 + self.check_electrode_volume(electrode, electrode_name) - np.testing.assert_allclose(actual, desired, atol=tolerance) - - def test_contacts_volume(self, Medtronic3389_electrode): + def test_contacts_volume(self, electrode, electrode_name): """Test volume of all the contacts.""" - electrode = Medtronic3389_electrode - - contact_length = electrode._parameters.contact_length - radius = electrode._parameters.lead_diameter * 0.5 - n_contacts = electrode._n_contacts - - desired = (contact_length * radius**2 * np.pi) * n_contacts - actual = electrode._contacts().mass - tolerance = 1e-5 - - np.testing.assert_allclose(actual, desired, atol=tolerance) + self.check_contacts_volume(electrode, electrode_name) diff --git a/tests/test_medtronic3391.py b/tests/test_medtronic3391.py index 332cc5a0..91a1801b 100644 --- a/tests/test_medtronic3391.py +++ b/tests/test_medtronic3391.py @@ -1,79 +1,31 @@ -import netgen -import ngsolve -import numpy as np import pytest from ossdbs.electrodes import Medtronic3391 +from .test_electrodes import TestElectrode -class TestMedtronic3391: + +class TestMedtronic3391(TestElectrode): @pytest.fixture - def Medtronic3391_electrode(self): + def electrode(self): return Medtronic3391() - def test_rename_boundaries(self, Medtronic3391_electrode): + @pytest.fixture + def electrode_name(self): + return "Medtronic3391" + + def test_rename_boundaries(self, electrode, electrode_name): """Test whether set_contact_names() works.""" - electrode = Medtronic3391_electrode - electrode.set_contact_names( - { - "Body": "RenamedBody", - "Contact_1": "RenamedContact_1", - "NonExistingPart": "NonExistingPart", - } - ) - geometry = electrode.geometry - netgen_geometry = netgen.occ.OCCGeometry(geometry) - with ngsolve.TaskManager(): - mesh = ngsolve.Mesh(netgen_geometry.GenerateMesh()) - desired = { - "RenamedBody", - "RenamedContact_1", - "Contact_2", - "Contact_3", - "Contact_4", - } - assert desired == set(mesh.GetBoundaries()) + self.check_rename_boundaries(electrode, electrode_name) - def test_contacts(self, Medtronic3391_electrode): + def test_contacts(self, electrode, electrode_name): """Test the number and names of contacts.""" - electrode = Medtronic3391_electrode - geometry = electrode.geometry - netgen_geometry = netgen.occ.OCCGeometry(geometry) - with ngsolve.TaskManager(): - mesh = ngsolve.Mesh(netgen_geometry.GenerateMesh()) - desired = { - "Body", - "Contact_1", - "Contact_2", - "Contact_3", - "Contact_4", - } - assert desired == set(mesh.GetBoundaries()) + self.check_contacts(electrode, electrode_name) - def test_electrode_volume(self, Medtronic3391_electrode): + def test_electrode_volume(self, electrode, electrode_name): """Test volume of the entire electrode.""" - electrode = Medtronic3391_electrode - - total_length = electrode._parameters.total_length - tip_length = electrode._parameters.tip_length - radius = electrode._parameters.lead_diameter * 0.5 - height = total_length - tip_length + self.check_electrode_volume(electrode, electrode_name) - desired = (np.pi * radius**2 * height) + (4 / 3 * np.pi * radius**3 * 0.5) - actual = electrode.geometry.mass - tolerance = 1e-5 - - np.testing.assert_allclose(actual, desired, atol=tolerance) - - def test_contacts_volume(self, Medtronic3391_electrode): + def test_contacts_volume(self, electrode, electrode_name): """Test volume of all the contacts.""" - electrode = Medtronic3391_electrode - contact_length = electrode._parameters.contact_length - radius = electrode._parameters.lead_diameter * 0.5 - n_contacts = electrode._n_contacts - - desired = (contact_length * radius**2 * np.pi) * n_contacts - actual = electrode._contacts().mass - tolerance = 1e-5 - - np.testing.assert_allclose(actual, desired, atol=tolerance) + self.check_contacts_volume(electrode, electrode_name) diff --git a/tests/test_medtronicsensightB33005.py b/tests/test_medtronicsensightB33005.py index 1b050665..3ac772c1 100644 --- a/tests/test_medtronicsensightB33005.py +++ b/tests/test_medtronicsensightB33005.py @@ -1,90 +1,31 @@ -import netgen -import ngsolve -import numpy as np import pytest from ossdbs.electrodes import MedtronicSenSightB33005 +from .test_electrodes import TestElectrode -class TestMedtronicSenSightB33005: + +class TestMedtronicSenSightB33005(TestElectrode): @pytest.fixture - def MedtronicSenSightB33005_electrode(self): + def electrode(self): return MedtronicSenSightB33005() - def test_rename_boundaries(self, MedtronicSenSightB33005_electrode): + @pytest.fixture + def electrode_name(self): + return "MedtronicSenSightB33005" + + def test_rename_boundaries(self, electrode, electrode_name): """Test whether set_contact_names() works.""" - electrode = MedtronicSenSightB33005_electrode - electrode.set_contact_names( - { - "Body": "RenamedBody", - "Contact_1": "RenamedContact_1", - "NonExistingPart": "NonExistingPart", - } - ) - geometry = electrode.geometry - netgen_geometry = netgen.occ.OCCGeometry(geometry) - with ngsolve.TaskManager(): - mesh = ngsolve.Mesh(netgen_geometry.GenerateMesh()) - desired = { - "RenamedBody", - "RenamedContact_1", - "Contact_2", - "Contact_3", - "Contact_4", - "Contact_5", - "Contact_6", - "Contact_7", - "Contact_8", - } - assert desired == set(mesh.GetBoundaries()) + self.check_rename_boundaries(electrode, electrode_name) - def test_contacts(self, MedtronicSenSightB33005_electrode): + def test_contacts(self, electrode, electrode_name): """Test the number and names of contacts.""" - electrode = MedtronicSenSightB33005_electrode - geometry = electrode.geometry - netgen_geometry = netgen.occ.OCCGeometry(geometry) - with ngsolve.TaskManager(): - mesh = ngsolve.Mesh(netgen_geometry.GenerateMesh()) - desired = { - "Body", - "Contact_1", - "Contact_2", - "Contact_3", - "Contact_4", - "Contact_5", - "Contact_6", - "Contact_7", - "Contact_8", - } - assert desired == set(mesh.GetBoundaries()) + self.check_contacts(electrode, electrode_name) - def test_electrode_volume(self, MedtronicSenSightB33005_electrode): + def test_electrode_volume(self, electrode, electrode_name): """Test volume of the entire electrode.""" - electrode = MedtronicSenSightB33005_electrode - - total_length = electrode._parameters.total_length - tip_length = electrode._parameters.tip_length - radius = electrode._parameters.lead_diameter * 0.5 - height = total_length - tip_length - - desired = (np.pi * radius**2 * height) + (4 / 3 * np.pi * radius**3 * 0.5) - actual = electrode.geometry.mass - tolerance = 1e-5 + self.check_electrode_volume(electrode, electrode_name) - np.testing.assert_allclose(actual, desired, atol=tolerance) - - def test_contacts_volume(self, MedtronicSenSightB33005_electrode): + def test_contacts_volume(self, electrode, electrode_name): """Test volume of all the contacts.""" - electrode = MedtronicSenSightB33005_electrode - - contact_length = electrode._parameters.contact_length - radius = electrode._parameters.lead_diameter * 0.5 - - desired = (np.pi * radius**2 * contact_length * 2) + ( - np.pi * radius**2 * contact_length * 90 / 360 - ) * 6 - - actual = electrode._contacts().mass - tolerance = 1e-5 - - np.testing.assert_allclose(actual, desired, atol=tolerance) + self.check_contacts_volume(electrode, electrode_name) diff --git a/tests/test_medtronicsensightB33015.py b/tests/test_medtronicsensightB33015.py index 9cb62442..23595d4c 100644 --- a/tests/test_medtronicsensightB33015.py +++ b/tests/test_medtronicsensightB33015.py @@ -1,90 +1,31 @@ -import netgen -import ngsolve -import numpy as np import pytest from ossdbs.electrodes import MedtronicSenSightB33015 +from .test_electrodes import TestElectrode -class TestMedtronicSenSightB33015: + +class TestMedtronicSenSightB33015(TestElectrode): @pytest.fixture - def MedtronicSenSightB33015_electrode(self): + def electrode(self): return MedtronicSenSightB33015() - def test_rename_boundaries(self, MedtronicSenSightB33015_electrode): + @pytest.fixture + def electrode_name(self): + return "MedtronicSenSightB33015" + + def test_rename_boundaries(self, electrode, electrode_name): """Test whether set_contact_names() works.""" - electrode = MedtronicSenSightB33015_electrode - electrode.set_contact_names( - { - "Body": "RenamedBody", - "Contact_1": "RenamedContact_1", - "NonExistingPart": "NonExistingPart", - } - ) - geometry = electrode.geometry - netgen_geometry = netgen.occ.OCCGeometry(geometry) - with ngsolve.TaskManager(): - mesh = ngsolve.Mesh(netgen_geometry.GenerateMesh()) - desired = { - "RenamedBody", - "RenamedContact_1", - "Contact_2", - "Contact_3", - "Contact_4", - "Contact_5", - "Contact_6", - "Contact_7", - "Contact_8", - } - assert desired == set(mesh.GetBoundaries()) + self.check_rename_boundaries(electrode, electrode_name) - def test_contacts(self, MedtronicSenSightB33015_electrode): + def test_contacts(self, electrode, electrode_name): """Test the number and names of contacts.""" - electrode = MedtronicSenSightB33015_electrode - geometry = electrode.geometry - netgen_geometry = netgen.occ.OCCGeometry(geometry) - with ngsolve.TaskManager(): - mesh = ngsolve.Mesh(netgen_geometry.GenerateMesh()) - desired = { - "Body", - "Contact_1", - "Contact_2", - "Contact_3", - "Contact_4", - "Contact_5", - "Contact_6", - "Contact_7", - "Contact_8", - } - assert desired == set(mesh.GetBoundaries()) + self.check_contacts(electrode, electrode_name) - def test_electrode_volume(self, MedtronicSenSightB33015_electrode): + def test_electrode_volume(self, electrode, electrode_name): """Test volume of the entire electrode.""" - electrode = MedtronicSenSightB33015_electrode - - total_length = electrode._parameters.total_length - tip_length = electrode._parameters.tip_length - radius = electrode._parameters.lead_diameter * 0.5 - height = total_length - tip_length - - desired = (np.pi * radius**2 * height) + (4 / 3 * np.pi * radius**3 * 0.5) - actual = electrode.geometry.mass - tolerance = 1e-5 + self.check_electrode_volume(electrode, electrode_name) - np.testing.assert_allclose(actual, desired, atol=tolerance) - - def test_contacts_volume(self, MedtronicSenSightB33015_electrode): + def test_contacts_volume(self, electrode, electrode_name): """Test volume of all the contacts.""" - electrode = MedtronicSenSightB33015_electrode - - contact_length = electrode._parameters.contact_length - radius = electrode._parameters.lead_diameter * 0.5 - - desired = (np.pi * radius**2 * contact_length * 2) + ( - np.pi * radius**2 * contact_length * 90 / 360 - ) * 6 - - actual = electrode._contacts().mass - tolerance = 1e-5 - - np.testing.assert_allclose(actual, desired, atol=tolerance) + self.check_contacts_volume(electrode, electrode_name) diff --git a/tests/test_microelectrode.py b/tests/test_microelectrode.py index e7e6335e..be40c3fa 100644 --- a/tests/test_microelectrode.py +++ b/tests/test_microelectrode.py @@ -1,77 +1,31 @@ -import netgen -import ngsolve -import numpy as np import pytest from ossdbs.electrodes import MicroElectrode +from .test_electrodes import TestElectrode -class TestMicroElectrode: + +class TestMicroElectrode(TestElectrode): @pytest.fixture - def MicroElectrode_electrode(self): + def electrode(self): return MicroElectrode() - def test_rename_boundaries(self, MicroElectrode_electrode): + @pytest.fixture + def electrode_name(self): + return "MicroElectrode" + + def test_rename_boundaries(self, electrode, electrode_name): """Test whether set_contact_names() works.""" - electrode = MicroElectrode_electrode - electrode.set_contact_names( - { - "Body": "RenamedBody", - "Contact_1": "RenamedContact_1", - "NonExistingPart": "NonExistingPart", - } - ) - geometry = electrode.geometry - netgen_geometry = netgen.occ.OCCGeometry(geometry) - with ngsolve.TaskManager(): - mesh = ngsolve.Mesh(netgen_geometry.GenerateMesh()) - desired = {"RenamedBody", "RenamedContact_1", "fillet"} - assert desired == set(mesh.GetBoundaries()) + self.check_rename_boundaries(electrode, electrode_name) - def test_contacts(self, MicroElectrode_electrode): + def test_contacts(self, electrode, electrode_name): """Test the number and names of contacts.""" - electrode = MicroElectrode_electrode - geometry = electrode.geometry - netgen_geometry = netgen.occ.OCCGeometry(geometry) - with ngsolve.TaskManager(): - mesh = ngsolve.Mesh(netgen_geometry.GenerateMesh()) - desired = {"Body", "Contact_1", "fillet"} - assert desired == set(mesh.GetBoundaries()) + self.check_contacts(electrode, electrode_name) - def test_electrode_volume(self, MicroElectrode_electrode): + def test_electrode_volume(self, electrode, electrode_name): """Test volume of the entire electrode.""" - electrode = MicroElectrode_electrode - - total_length = electrode._parameters.total_length - contact_length = electrode._parameters.contact_length - - tip_length = electrode._parameters.tip_length - tip_radius = electrode._parameters.tip_diameter * 0.5 - - lead_radius = electrode._parameters.lead_diameter * 0.5 - height = total_length - tip_length - filet_val = 0.001142187023875807 + self.check_electrode_volume(electrode, electrode_name) - desired = ( - (contact_length * tip_radius**2 * np.pi) - + (height * lead_radius**2 * np.pi) - - filet_val - ) - actual = electrode.geometry.mass - tolerance = 1e-5 - - np.testing.assert_allclose(actual, desired, atol=tolerance) - - def test_contacts_volume(self, MicroElectrode_electrode): + def test_contacts_volume(self, electrode, electrode_name): """Test volume of all the contacts.""" - electrode = MicroElectrode_electrode - - contact_length = electrode._parameters.contact_length - tip_radius = electrode._parameters.tip_diameter * 0.5 - filet_val = 0.001142187023875807 - - desired = (contact_length * tip_radius**2 * np.pi) - filet_val - actual = electrode._contacts().mass - tolerance = 1e-5 - - np.testing.assert_allclose(actual, desired, atol=tolerance) + self.check_contacts_volume(electrode, electrode_name) diff --git a/tests/test_microprobescustomrodent.py b/tests/test_microprobescustomrodent.py index e4247e50..1e8e11a3 100644 --- a/tests/test_microprobescustomrodent.py +++ b/tests/test_microprobescustomrodent.py @@ -1,74 +1,31 @@ -import netgen -import ngsolve -import numpy as np import pytest from ossdbs.electrodes import MicroProbesRodentElectrode +from .test_electrodes import TestElectrode -class TestMicroProbesCustomRodent: + +class TestMicroProbesRodentElectrode(TestElectrode): @pytest.fixture - def MicroProbesRodentElectrode_electrode(self): + def electrode(self): return MicroProbesRodentElectrode() - def test_rename_boundaries(self, MicroProbesRodentElectrode_electrode): + @pytest.fixture + def electrode_name(self): + return "MicroProbesRodentElectrode" + + def test_rename_boundaries(self, electrode, electrode_name): """Test whether set_contact_names() works.""" - electrode = MicroProbesRodentElectrode_electrode - electrode.set_contact_names( - { - "Body": "RenamedBody", - "Contact_1": "RenamedContact_1", - "NonExistingPart": "NonExistingPart", - } - ) - geometry = electrode.geometry - netgen_geometry = netgen.occ.OCCGeometry(geometry) - with ngsolve.TaskManager(): - mesh = ngsolve.Mesh(netgen_geometry.GenerateMesh()) - desired = { - "RenamedBody", - "RenamedContact_1", - } - assert desired == set(mesh.GetBoundaries()) + self.check_rename_boundaries(electrode, electrode_name) - def test_contacts(self, MicroProbesRodentElectrode_electrode): + def test_contacts(self, electrode, electrode_name): """Test the number and names of contacts.""" - electrode = MicroProbesRodentElectrode_electrode - geometry = electrode.geometry - netgen_geometry = netgen.occ.OCCGeometry(geometry) - with ngsolve.TaskManager(): - mesh = ngsolve.Mesh(netgen_geometry.GenerateMesh()) - desired = { - "Body", - "Contact_1", - } - assert desired == set(mesh.GetBoundaries()) + self.check_contacts(electrode, electrode_name) - def test_electrode_volume(self, MicroProbesRodentElectrode_electrode): + def test_electrode_volume(self, electrode, electrode_name): """Test volume of the entire electrode.""" - electrode = MicroProbesRodentElectrode_electrode - - total_length = electrode._parameters.total_length - lead_radius = electrode._parameters.lead_radius - contact_radius = electrode._parameters.contact_radius - height = total_length - contact_radius - - desired = (height * lead_radius**2 * np.pi) + ( - 4 / 3 * np.pi * contact_radius**3 * 0.5 - ) - actual = electrode.geometry.mass - tolerance = 1e-5 + self.check_electrode_volume(electrode, electrode_name) - np.testing.assert_allclose(actual, desired, atol=tolerance) - - def test_contacts_volume(self, MicroProbesRodentElectrode_electrode): + def test_contacts_volume(self, electrode, electrode_name): """Test volume of all the contacts.""" - electrode = MicroProbesRodentElectrode_electrode - - contact_radius = electrode._parameters.contact_radius - - desired = 4 / 3 * np.pi * contact_radius**3 * 0.5 - actual = electrode._contacts().mass - tolerance = 1e-5 - - np.testing.assert_allclose(actual, desired, atol=tolerance) + self.check_contacts_volume(electrode, electrode_name) diff --git a/tests/test_microprobessnex100.py b/tests/test_microprobessnex100.py index 744a70af..74074d7c 100644 --- a/tests/test_microprobessnex100.py +++ b/tests/test_microprobessnex100.py @@ -1,104 +1,31 @@ -import netgen -import ngsolve -import numpy as np import pytest from ossdbs.electrodes import MicroProbesSNEX100 +from .test_electrodes import TestElectrode -class TestMicroProbesSNEX_100: + +class TestMicroProbesSNEX100(TestElectrode): @pytest.fixture - def MicroProbesSNEX100_electrode(self): + def electrode(self): return MicroProbesSNEX100() - def test_rename_boundaries(self, MicroProbesSNEX100_electrode): + @pytest.fixture + def electrode_name(self): + return "MicroProbesSNEX100" + + def test_rename_boundaries(self, electrode, electrode_name): """Test whether set_contact_names() works.""" - electrode = MicroProbesSNEX100_electrode - electrode.set_contact_names( - { - "Body": "RenamedBody", - "Contact_1": "RenamedContact_1", - "NonExistingPart": "NonExistingPart", - } - ) - geometry = electrode.geometry - netgen_geometry = netgen.occ.OCCGeometry(geometry) - with ngsolve.TaskManager(): - mesh = ngsolve.Mesh(netgen_geometry.GenerateMesh()) - desired = {"RenamedBody", "RenamedContact_1", "Contact_2"} - assert desired == set(mesh.GetBoundaries()) + self.check_rename_boundaries(electrode, electrode_name) - def test_contacts(self, MicroProbesSNEX100_electrode): + def test_contacts(self, electrode, electrode_name): """Test the number and names of contacts.""" - electrode = MicroProbesSNEX100_electrode - geometry = electrode.geometry - netgen_geometry = netgen.occ.OCCGeometry(geometry) - with ngsolve.TaskManager(): - mesh = ngsolve.Mesh(netgen_geometry.GenerateMesh()) - desired = { - "Body", - "Contact_1", - "Contact_2", - } - assert desired == set(mesh.GetBoundaries()) + self.check_contacts(electrode, electrode_name) - def test_electrode_volume(self, MicroProbesSNEX100_electrode): + def test_electrode_volume(self, electrode, electrode_name): """Test volume of the entire electrode.""" - electrode = MicroProbesSNEX100_electrode - - radius_1 = electrode._parameters.core_tubing_diameter * 0.5 - height_1 = electrode._parameters.core_tubing_length - - distance_2 = ( - electrode._parameters.core_electrode_length - + electrode._parameters.core_tubing_length - + electrode._parameters.outer_electrode_length - ) - - radius_2 = electrode._parameters.outer_tubing_diameter * 0.5 - height_2 = electrode._parameters.total_length - distance_2 - - body1 = np.pi * radius_1**2 * height_1 - body2 = np.pi * radius_2**2 * height_2 - - outer_electrode_radius = electrode._parameters.outer_electrode_diameter * 0.5 - outer_electrode_length = electrode._parameters.outer_electrode_length - - core_electrode_radius = electrode._parameters.core_electrode_diameter * 0.5 - core_electrode_length = electrode._parameters.core_electrode_length + self.check_electrode_volume(electrode, electrode_name) - contact_1 = np.pi * outer_electrode_radius**2 * outer_electrode_length - contact_2 = (4 / 3 * np.pi * core_electrode_radius**3 * 0.5) + ( - np.pi - * core_electrode_radius**2 - * (core_electrode_length - core_electrode_radius) - ) - - desired = body1 + body2 + contact_1 + contact_2 - actual = electrode.geometry.mass - tolerance = 1e-5 - - np.testing.assert_allclose(actual, desired, atol=tolerance) - - def test_contacts_volume(self, MicroProbesSNEX100_electrode): + def test_contacts_volume(self, electrode, electrode_name): """Test volume of all the contacts.""" - electrode = MicroProbesSNEX100_electrode - - outer_electrode_radius = electrode._parameters.outer_electrode_diameter * 0.5 - outer_electrode_length = electrode._parameters.outer_electrode_length - - core_electrode_radius = electrode._parameters.core_electrode_diameter * 0.5 - core_electrode_length = electrode._parameters.core_electrode_length - - contact_1 = np.pi * outer_electrode_radius**2 * outer_electrode_length - contact_2 = (4 / 3 * np.pi * core_electrode_radius**3 * 0.5) + ( - np.pi - * core_electrode_radius**2 - * (core_electrode_length - core_electrode_radius) - ) - - desired = contact_1 + contact_2 - actual = electrode._contacts().mass - tolerance = 1e-5 - - np.testing.assert_allclose(actual, desired, atol=tolerance) + self.check_contacts_volume(electrode, electrode_name) diff --git a/tests/test_neuropaceDL344_10.py b/tests/test_neuropaceDL344_10.py index 0c9d2657..f5596aca 100644 --- a/tests/test_neuropaceDL344_10.py +++ b/tests/test_neuropaceDL344_10.py @@ -1,79 +1,31 @@ -import netgen -import ngsolve -import numpy as np import pytest from ossdbs.electrodes import NeuroPaceDL344_10 +from .test_electrodes import TestElectrode -class TestNeuroPaceDL344_10: + +class TestNeuroPaceDL344_10(TestElectrode): @pytest.fixture - def NeuroPaceDL344_10_electrode(self): + def electrode(self): return NeuroPaceDL344_10() - def test_rename_boundaries(self, NeuroPaceDL344_10_electrode): + @pytest.fixture + def electrode_name(self): + return "NeuroPaceDL344_10" + + def test_rename_boundaries(self, electrode, electrode_name): """Test whether set_contact_names() works.""" - electrode = NeuroPaceDL344_10_electrode - electrode.set_contact_names( - { - "Body": "RenamedBody", - "Contact_1": "RenamedContact_1", - "NonExistingPart": "NonExistingPart", - } - ) - geometry = electrode.geometry - netgen_geometry = netgen.occ.OCCGeometry(geometry) - with ngsolve.TaskManager(): - mesh = ngsolve.Mesh(netgen_geometry.GenerateMesh()) - desired = { - "RenamedBody", - "RenamedContact_1", - "Contact_2", - "Contact_3", - "Contact_4", - } - assert desired == set(mesh.GetBoundaries()) + self.check_rename_boundaries(electrode, electrode_name) - def test_contacts(self, NeuroPaceDL344_10_electrode): + def test_contacts(self, electrode, electrode_name): """Test the number and names of contacts.""" - electrode = NeuroPaceDL344_10_electrode - geometry = electrode.geometry - netgen_geometry = netgen.occ.OCCGeometry(geometry) - with ngsolve.TaskManager(): - mesh = ngsolve.Mesh(netgen_geometry.GenerateMesh()) - desired = { - "Body", - "Contact_1", - "Contact_2", - "Contact_3", - "Contact_4", - } - assert desired == set(mesh.GetBoundaries()) + self.check_contacts(electrode, electrode_name) - def test_electrode_volume(self, NeuroPaceDL344_10_electrode): + def test_electrode_volume(self, electrode, electrode_name): """Test volume of the entire electrode.""" - electrode = NeuroPaceDL344_10_electrode - - total_length = electrode._parameters.total_length - tip_length = electrode._parameters.tip_length - radius = electrode._parameters.lead_diameter * 0.5 - height = total_length - tip_length + self.check_electrode_volume(electrode, electrode_name) - desired = (np.pi * radius**2 * height) + (4 / 3 * np.pi * radius**3 * 0.5) - actual = electrode.geometry.mass - tolerance = 1e-5 - - np.testing.assert_allclose(actual, desired, atol=tolerance) - - def test_contacts_volume(self, NeuroPaceDL344_10_electrode): + def test_contacts_volume(self, electrode, electrode_name): """Test volume of all the contacts.""" - electrode = NeuroPaceDL344_10_electrode - contact_length = electrode._parameters.contact_length - radius = electrode._parameters.lead_diameter * 0.5 - n_contacts = electrode._n_contacts - - desired = (contact_length * radius**2 * np.pi) * n_contacts - actual = electrode._contacts().mass - tolerance = 1e-5 - - np.testing.assert_allclose(actual, desired, atol=tolerance) + self.check_contacts_volume(electrode, electrode_name) diff --git a/tests/test_neuropaceDL344_3_5.py b/tests/test_neuropaceDL344_3_5.py index 44709c96..3f767fe0 100644 --- a/tests/test_neuropaceDL344_3_5.py +++ b/tests/test_neuropaceDL344_3_5.py @@ -1,79 +1,31 @@ -import netgen -import ngsolve -import numpy as np import pytest from ossdbs.electrodes import NeuroPaceDL344_3_5 +from .test_electrodes import TestElectrode -class TestNeuroPaceDL344_3_5: + +class TestNeuroPaceDL344_3_5(TestElectrode): @pytest.fixture - def NeuroPaceDL344_3_5_electrode(self): + def electrode(self): return NeuroPaceDL344_3_5() - def test_rename_boundaries(self, NeuroPaceDL344_3_5_electrode): + @pytest.fixture + def electrode_name(self): + return "NeuroPaceDL344_3_5" + + def test_rename_boundaries(self, electrode, electrode_name): """Test whether set_contact_names() works.""" - electrode = NeuroPaceDL344_3_5_electrode - electrode.set_contact_names( - { - "Body": "RenamedBody", - "Contact_1": "RenamedContact_1", - "NonExistingPart": "NonExistingPart", - } - ) - geometry = electrode.geometry - netgen_geometry = netgen.occ.OCCGeometry(geometry) - with ngsolve.TaskManager(): - mesh = ngsolve.Mesh(netgen_geometry.GenerateMesh()) - desired = { - "RenamedBody", - "RenamedContact_1", - "Contact_2", - "Contact_3", - "Contact_4", - } - assert desired == set(mesh.GetBoundaries()) + self.check_rename_boundaries(electrode, electrode_name) - def test_contacts(self, NeuroPaceDL344_3_5_electrode): + def test_contacts(self, electrode, electrode_name): """Test the number and names of contacts.""" - electrode = NeuroPaceDL344_3_5_electrode - geometry = electrode.geometry - netgen_geometry = netgen.occ.OCCGeometry(geometry) - with ngsolve.TaskManager(): - mesh = ngsolve.Mesh(netgen_geometry.GenerateMesh()) - desired = { - "Body", - "Contact_1", - "Contact_2", - "Contact_3", - "Contact_4", - } - assert desired == set(mesh.GetBoundaries()) + self.check_contacts(electrode, electrode_name) - def test_electrode_volume(self, NeuroPaceDL344_3_5_electrode): + def test_electrode_volume(self, electrode, electrode_name): """Test volume of the entire electrode.""" - electrode = NeuroPaceDL344_3_5_electrode - - total_length = electrode._parameters.total_length - tip_length = electrode._parameters.tip_length - radius = electrode._parameters.lead_diameter * 0.5 - height = total_length - tip_length + self.check_electrode_volume(electrode, electrode_name) - desired = (np.pi * radius**2 * height) + (4 / 3 * np.pi * radius**3 * 0.5) - actual = electrode.geometry.mass - tolerance = 1e-5 - - np.testing.assert_allclose(actual, desired, atol=tolerance) - - def test_contacts_volume(self, NeuroPaceDL344_3_5_electrode): + def test_contacts_volume(self, electrode, electrode_name): """Test volume of all the contacts.""" - electrode = NeuroPaceDL344_3_5_electrode - contact_length = electrode._parameters.contact_length - radius = electrode._parameters.lead_diameter * 0.5 - n_contacts = electrode._n_contacts - - desired = (contact_length * radius**2 * np.pi) * n_contacts - actual = electrode._contacts().mass - tolerance = 1e-5 - - np.testing.assert_allclose(actual, desired, atol=tolerance) + self.check_contacts_volume(electrode, electrode_name) diff --git a/tests/test_pinsmedicall301.py b/tests/test_pinsmedicall301.py index 862f27dc..52e4430d 100644 --- a/tests/test_pinsmedicall301.py +++ b/tests/test_pinsmedicall301.py @@ -1,79 +1,31 @@ -import netgen -import ngsolve -import numpy as np import pytest from ossdbs.electrodes import PINSMedicalL301 +from .test_electrodes import TestElectrode -class TestPINSMedicalL301: + +class TestPINSMedicalL301(TestElectrode): @pytest.fixture - def PINSMedicalL301_electrode(self): + def electrode(self): return PINSMedicalL301() - def test_rename_boundaries(self, PINSMedicalL301_electrode): + @pytest.fixture + def electrode_name(self): + return "PINSMedicalL301" + + def test_rename_boundaries(self, electrode, electrode_name): """Test whether set_contact_names() works.""" - electrode = PINSMedicalL301_electrode - electrode.set_contact_names( - { - "Body": "RenamedBody", - "Contact_1": "RenamedContact_1", - "NonExistingPart": "NonExistingPart", - } - ) - geometry = electrode.geometry - netgen_geometry = netgen.occ.OCCGeometry(geometry) - with ngsolve.TaskManager(): - mesh = ngsolve.Mesh(netgen_geometry.GenerateMesh()) - desired = { - "RenamedBody", - "RenamedContact_1", - "Contact_2", - "Contact_3", - "Contact_4", - } - assert desired == set(mesh.GetBoundaries()) + self.check_rename_boundaries(electrode, electrode_name) - def test_contacts(self, PINSMedicalL301_electrode): + def test_contacts(self, electrode, electrode_name): """Test the number and names of contacts.""" - electrode = PINSMedicalL301_electrode - geometry = electrode.geometry - netgen_geometry = netgen.occ.OCCGeometry(geometry) - with ngsolve.TaskManager(): - mesh = ngsolve.Mesh(netgen_geometry.GenerateMesh()) - desired = { - "Body", - "Contact_1", - "Contact_2", - "Contact_3", - "Contact_4", - } - assert desired == set(mesh.GetBoundaries()) + self.check_contacts(electrode, electrode_name) - def test_electrode_volume(self, PINSMedicalL301_electrode): + def test_electrode_volume(self, electrode, electrode_name): """Test volume of the entire electrode.""" - electrode = PINSMedicalL301_electrode - - total_length = electrode._parameters.total_length - tip_length = electrode._parameters.tip_length - radius = electrode._parameters.lead_diameter * 0.5 - height = total_length - tip_length + self.check_electrode_volume(electrode, electrode_name) - desired = (np.pi * radius**2 * height) + (4 / 3 * np.pi * radius**3 * 0.5) - actual = electrode.geometry.mass - tolerance = 1e-5 - - np.testing.assert_allclose(actual, desired, atol=tolerance) - - def test_contacts_volume(self, PINSMedicalL301_electrode): + def test_contacts_volume(self, electrode, electrode_name): """Test volume of all the contacts.""" - electrode = PINSMedicalL301_electrode - contact_length = electrode._parameters.contact_length - radius = electrode._parameters.lead_diameter * 0.5 - n_contacts = electrode._n_contacts - - desired = (contact_length * radius**2 * np.pi) * n_contacts - actual = electrode._contacts().mass - tolerance = 1e-5 - - np.testing.assert_allclose(actual, desired, atol=tolerance) + self.check_contacts_volume(electrode, electrode_name) diff --git a/tests/test_pinsmedicall302.py b/tests/test_pinsmedicall302.py index 099bfe84..a2a2c55f 100644 --- a/tests/test_pinsmedicall302.py +++ b/tests/test_pinsmedicall302.py @@ -1,79 +1,31 @@ -import netgen -import ngsolve -import numpy as np import pytest from ossdbs.electrodes import PINSMedicalL302 +from .test_electrodes import TestElectrode -class TestPINSMedicalL302: + +class TestPINSMedicalL302(TestElectrode): @pytest.fixture - def PINSMedicalL302_electrode(self): + def electrode(self): return PINSMedicalL302() - def test_rename_boundaries(self, PINSMedicalL302_electrode): + @pytest.fixture + def electrode_name(self): + return "PINSMedicalL302" + + def test_rename_boundaries(self, electrode, electrode_name): """Test whether set_contact_names() works.""" - electrode = PINSMedicalL302_electrode - electrode.set_contact_names( - { - "Body": "RenamedBody", - "Contact_1": "RenamedContact_1", - "NonExistingPart": "NonExistingPart", - } - ) - geometry = electrode.geometry - netgen_geometry = netgen.occ.OCCGeometry(geometry) - with ngsolve.TaskManager(): - mesh = ngsolve.Mesh(netgen_geometry.GenerateMesh()) - desired = { - "RenamedBody", - "RenamedContact_1", - "Contact_2", - "Contact_3", - "Contact_4", - } - assert desired == set(mesh.GetBoundaries()) + self.check_rename_boundaries(electrode, electrode_name) - def test_contacts(self, PINSMedicalL302_electrode): + def test_contacts(self, electrode, electrode_name): """Test the number and names of contacts.""" - electrode = PINSMedicalL302_electrode - geometry = electrode.geometry - netgen_geometry = netgen.occ.OCCGeometry(geometry) - with ngsolve.TaskManager(): - mesh = ngsolve.Mesh(netgen_geometry.GenerateMesh()) - desired = { - "Body", - "Contact_1", - "Contact_2", - "Contact_3", - "Contact_4", - } - assert desired == set(mesh.GetBoundaries()) + self.check_contacts(electrode, electrode_name) - def test_electrode_volume(self, PINSMedicalL302_electrode): + def test_electrode_volume(self, electrode, electrode_name): """Test volume of the entire electrode.""" - electrode = PINSMedicalL302_electrode - - total_length = electrode._parameters.total_length - tip_length = electrode._parameters.tip_length - radius = electrode._parameters.lead_diameter * 0.5 - height = total_length - tip_length + self.check_electrode_volume(electrode, electrode_name) - desired = (np.pi * radius**2 * height) + (4 / 3 * np.pi * radius**3 * 0.5) - actual = electrode.geometry.mass - tolerance = 1e-5 - - np.testing.assert_allclose(actual, desired, atol=tolerance) - - def test_contacts_volume(self, PINSMedicalL302_electrode): + def test_contacts_volume(self, electrode, electrode_name): """Test volume of all the contacts.""" - electrode = PINSMedicalL302_electrode - contact_length = electrode._parameters.contact_length - radius = electrode._parameters.lead_diameter * 0.5 - n_contacts = electrode._n_contacts - - desired = (contact_length * radius**2 * np.pi) * n_contacts - actual = electrode._contacts().mass - tolerance = 1e-5 - - np.testing.assert_allclose(actual, desired, atol=tolerance) + self.check_contacts_volume(electrode, electrode_name) diff --git a/tests/test_pinsmedicall303.py b/tests/test_pinsmedicall303.py index 579e71ee..6825f0ac 100644 --- a/tests/test_pinsmedicall303.py +++ b/tests/test_pinsmedicall303.py @@ -1,79 +1,31 @@ -import netgen -import ngsolve -import numpy as np import pytest from ossdbs.electrodes import PINSMedicalL303 +from .test_electrodes import TestElectrode -class TestPINSMedicalL303: + +class TestPINSMedicalL303(TestElectrode): @pytest.fixture - def PINSMedicalL303_electrode(self): + def electrode(self): return PINSMedicalL303() - def test_rename_boundaries(self, PINSMedicalL303_electrode): + @pytest.fixture + def electrode_name(self): + return "PINSMedicalL303" + + def test_rename_boundaries(self, electrode, electrode_name): """Test whether set_contact_names() works.""" - electrode = PINSMedicalL303_electrode - electrode.set_contact_names( - { - "Body": "RenamedBody", - "Contact_1": "RenamedContact_1", - "NonExistingPart": "NonExistingPart", - } - ) - geometry = electrode.geometry - netgen_geometry = netgen.occ.OCCGeometry(geometry) - with ngsolve.TaskManager(): - mesh = ngsolve.Mesh(netgen_geometry.GenerateMesh()) - desired = { - "RenamedBody", - "RenamedContact_1", - "Contact_2", - "Contact_3", - "Contact_4", - } - assert desired == set(mesh.GetBoundaries()) + self.check_rename_boundaries(electrode, electrode_name) - def test_contacts(self, PINSMedicalL303_electrode): + def test_contacts(self, electrode, electrode_name): """Test the number and names of contacts.""" - electrode = PINSMedicalL303_electrode - geometry = electrode.geometry - netgen_geometry = netgen.occ.OCCGeometry(geometry) - with ngsolve.TaskManager(): - mesh = ngsolve.Mesh(netgen_geometry.GenerateMesh()) - desired = { - "Body", - "Contact_1", - "Contact_2", - "Contact_3", - "Contact_4", - } - assert desired == set(mesh.GetBoundaries()) + self.check_contacts(electrode, electrode_name) - def test_electrode_volume(self, PINSMedicalL303_electrode): + def test_electrode_volume(self, electrode, electrode_name): """Test volume of the entire electrode.""" - electrode = PINSMedicalL303_electrode - - total_length = electrode._parameters.total_length - tip_length = electrode._parameters.tip_length - radius = electrode._parameters.lead_diameter * 0.5 - height = total_length - tip_length + self.check_electrode_volume(electrode, electrode_name) - desired = (np.pi * radius**2 * height) + (4 / 3 * np.pi * radius**3 * 0.5) - actual = electrode.geometry.mass - tolerance = 1e-5 - - np.testing.assert_allclose(actual, desired, atol=tolerance) - - def test_contacts_volume(self, PINSMedicalL303_electrode): + def test_contacts_volume(self, electrode, electrode_name): """Test volume of all the contacts.""" - electrode = PINSMedicalL303_electrode - contact_length = electrode._parameters.contact_length - radius = electrode._parameters.lead_diameter * 0.5 - n_contacts = electrode._n_contacts - - desired = (contact_length * radius**2 * np.pi) * n_contacts - actual = electrode._contacts().mass - tolerance = 1e-5 - - np.testing.assert_allclose(actual, desired, atol=tolerance) + self.check_contacts_volume(electrode, electrode_name)