diff --git a/tests/test_abbottstjudeactivetip6142_6145.py b/tests/test_abbottstjudeactivetip6142_6145.py index 15f571c0..3ba05091 100644 --- a/tests/test_abbottstjudeactivetip6142_6145.py +++ b/tests/test_abbottstjudeactivetip6142_6145.py @@ -1,11 +1,12 @@ -from ossdbs.electrodes import AbbottStJudeActiveTip6142_6145 -import pytest import netgen import ngsolve import numpy as np +import pytest + +from ossdbs.electrodes import AbbottStJudeActiveTip6142_6145 -class TestAbbottStJudeActiveTip6142_6145(): +class TestAbbottStJudeActiveTip6142_6145: """ FILE_PREFIX = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'test_data', @@ -52,39 +53,41 @@ def test_geometry_default(self): def AbbottStJudeActiveTip6142_6145_electrode(self): return AbbottStJudeActiveTip6142_6145() - # Test whether set_contact_names() works def test_rename_boundaries(self, AbbottStJudeActiveTip6142_6145_electrode): + """Test whether set_contact_names() works.""" electrode = AbbottStJudeActiveTip6142_6145_electrode - electrode.set_contact_names({'Body': 'RenamedBody', - 'Contact_1': 'RenamedContact_1', - 'NonExistingPart': 'NonExistingPart'}) + 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 = set(['RenamedBody', - 'RenamedContact_1', - 'Contact_2', - 'Contact_3', - 'Contact_4']) + desired = { + "RenamedBody", + "RenamedContact_1", + "Contact_2", + "Contact_3", + "Contact_4", + } assert desired == set(mesh.GetBoundaries()) - # Test the number and names of contacts def test_contacts(self, AbbottStJudeActiveTip6142_6145_electrode): + """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 = set(['Body', - 'Contact_1', - 'Contact_2', - 'Contact_3', - 'Contact_4']) + desired = {"Body", "Contact_1", "Contact_2", "Contact_3", "Contact_4"} assert desired == set(mesh.GetBoundaries()) - # Test volume of the entire electrode def test_electrode_volume(self, AbbottStJudeActiveTip6142_6145_electrode): + """Test volume of the entire electrode.""" electrode = AbbottStJudeActiveTip6142_6145_electrode total_length = electrode._parameters.total_length @@ -92,14 +95,14 @@ def test_electrode_volume(self, AbbottStJudeActiveTip6142_6145_electrode): 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) + 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) - # Test volume of all the contacts def test_contacts_volume(self, AbbottStJudeActiveTip6142_6145_electrode): + """Test volume of all the contacts.""" electrode = AbbottStJudeActiveTip6142_6145_electrode contact_length = electrode._parameters.contact_length @@ -107,9 +110,11 @@ def test_contacts_volume(self, AbbottStJudeActiveTip6142_6145_electrode): 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) + 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 + desired = (contact_length * radius**2 * np.pi) * (n_contacts - 1) + C1_volume actual = electrode._contacts().mass tolerance = 1e-5 diff --git a/tests/test_abbottstjudeactivetip6146_6149.py b/tests/test_abbottstjudeactivetip6146_6149.py index 7c5acfae..c3f0f778 100644 --- a/tests/test_abbottstjudeactivetip6146_6149.py +++ b/tests/test_abbottstjudeactivetip6146_6149.py @@ -1,11 +1,12 @@ -from ossdbs.electrodes import AbbottStJudeActiveTip6146_6149 -import pytest import netgen import ngsolve import numpy as np +import pytest + +from ossdbs.electrodes import AbbottStJudeActiveTip6146_6149 -class TestAbbottStJudeActiveTip6146_6149(): +class TestAbbottStJudeActiveTip6146_6149: """ FILE_PREFIX = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'test_data', @@ -51,39 +52,41 @@ def test_geometry_default(self): def AbbottStJudeActiveTip6146_6149_electrode(self): return AbbottStJudeActiveTip6146_6149() - # Test whether set_contact_names() works def test_rename_boundaries(self, AbbottStJudeActiveTip6146_6149_electrode): + """Test whether set_contact_names() works.""" electrode = AbbottStJudeActiveTip6146_6149_electrode - electrode.set_contact_names({'Body': 'RenamedBody', - 'Contact_1': 'RenamedContact_1', - 'NonExistingPart': 'NonExistingPart'}) + 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 = set(['RenamedBody', - 'RenamedContact_1', - 'Contact_2', - 'Contact_3', - 'Contact_4']) + desired = { + "RenamedBody", + "RenamedContact_1", + "Contact_2", + "Contact_3", + "Contact_4", + } assert desired == set(mesh.GetBoundaries()) - # Test the number and names of contacts def test_contacts(self, AbbottStJudeActiveTip6146_6149_electrode): + """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 = set(['Body', - 'Contact_1', - 'Contact_2', - 'Contact_3', - 'Contact_4']) + desired = {"Body", "Contact_1", "Contact_2", "Contact_3", "Contact_4"} assert desired == set(mesh.GetBoundaries()) - # Test volume of the entire electrode def test_electrode_volume(self, AbbottStJudeActiveTip6146_6149_electrode): + """Test volume of the entire electrode.""" electrode = AbbottStJudeActiveTip6146_6149_electrode total_length = electrode._parameters.total_length @@ -91,14 +94,14 @@ def test_electrode_volume(self, AbbottStJudeActiveTip6146_6149_electrode): 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) + 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) - # Test volume of all the contacts def test_contacts_volume(self, AbbottStJudeActiveTip6146_6149_electrode): + """Test volume of all the contacts.""" electrode = AbbottStJudeActiveTip6146_6149_electrode contact_length = electrode._parameters.contact_length @@ -106,9 +109,11 @@ def test_contacts_volume(self, AbbottStJudeActiveTip6146_6149_electrode): 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) + 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 + desired = (contact_length * radius**2 * np.pi) * (n_contacts - 1) + C1_volume actual = electrode._contacts().mass tolerance = 1e-5 diff --git a/tests/test_abbottstjudedirected6172.py b/tests/test_abbottstjudedirected6172.py index 7ec1bdfa..5a048204 100644 --- a/tests/test_abbottstjudedirected6172.py +++ b/tests/test_abbottstjudedirected6172.py @@ -1,11 +1,12 @@ -from ossdbs.electrodes import AbbottStJudeDirected6172 -import pytest import netgen import ngsolve import numpy as np +import pytest + +from ossdbs.electrodes import AbbottStJudeDirected6172 -class TestAbbottStJudeDirected6172(): +class TestAbbottStJudeDirected6172: """ FILE_PREFIX = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'test_data', @@ -51,49 +52,55 @@ def test_geometry_default(self): def AbbottStJudeDirected6172_electrode(self): return AbbottStJudeDirected6172() - # Test whether set_contact_names() works def test_rename_boundaries(self, AbbottStJudeDirected6172_electrode): + """Test whether set_contact_names() works.""" electrode = AbbottStJudeDirected6172_electrode - electrode.set_contact_names({'Body': 'RenamedBody', - 'Contact_1': 'RenamedContact_1', - 'NonExistingPart': 'NonExistingPart'}) + 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 = set(['RenamedBody', - 'RenamedContact_1', - 'Contact_2', - 'Contact_3', - 'Contact_4', - 'Contact_5', - 'Contact_6', - 'Contact_7', - 'Contact_8' - ]) + desired = { + "RenamedBody", + "RenamedContact_1", + "Contact_2", + "Contact_3", + "Contact_4", + "Contact_5", + "Contact_6", + "Contact_7", + "Contact_8", + } assert desired == set(mesh.GetBoundaries()) - # Test the number and names of contacts def test_contacts(self, AbbottStJudeDirected6172_electrode): + """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 = set(['Body', - 'Contact_1', - 'Contact_2', - 'Contact_3', - 'Contact_4', - 'Contact_5', - 'Contact_6', - 'Contact_7', - 'Contact_8' - ]) + desired = { + "Body", + "Contact_1", + "Contact_2", + "Contact_3", + "Contact_4", + "Contact_5", + "Contact_6", + "Contact_7", + "Contact_8", + } assert desired == set(mesh.GetBoundaries()) - # Test volume of the entire electrode def test_electrode_volume(self, AbbottStJudeDirected6172_electrode): + """Test volume of the entire electrode.""" electrode = AbbottStJudeDirected6172_electrode total_length = electrode._parameters.total_length @@ -101,21 +108,22 @@ def test_electrode_volume(self, AbbottStJudeDirected6172_electrode): 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) + 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) - # Test volume of all the contacts def test_contacts_volume(self, AbbottStJudeDirected6172_electrode): + """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 + desired = (np.pi * radius**2 * contact_length * 2) + ( + np.pi * radius**2 * contact_length * 90 / 360 + ) * 6 actual = electrode._contacts().mass tolerance = 1e-5 diff --git a/tests/test_abbottstjudedirected6173.py b/tests/test_abbottstjudedirected6173.py index 096dcafe..18236a65 100644 --- a/tests/test_abbottstjudedirected6173.py +++ b/tests/test_abbottstjudedirected6173.py @@ -1,11 +1,12 @@ -from ossdbs.electrodes import AbbottStJudeDirected6173 -import pytest import netgen import ngsolve import numpy as np +import pytest + +from ossdbs.electrodes import AbbottStJudeDirected6173 -class TestAbbottStJudeDirected6173(): +class TestAbbottStJudeDirected6173: """ FILE_PREFIX = os.path.join(os.path.dirname(os.path.abspath(__file__)), @@ -52,49 +53,55 @@ def test_geometry_default(self): def AbbottStJudeDirected6173_electrode(self): return AbbottStJudeDirected6173() - # Test whether set_contact_names() works def test_rename_boundaries(self, AbbottStJudeDirected6173_electrode): + """Test whether set_contact_names() works.""" electrode = AbbottStJudeDirected6173_electrode - electrode.set_contact_names({'Body': 'RenamedBody', - 'Contact_1': 'RenamedContact_1', - 'NonExistingPart': 'NonExistingPart'}) + 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 = set(['RenamedBody', - 'RenamedContact_1', - 'Contact_2', - 'Contact_3', - 'Contact_4', - 'Contact_5', - 'Contact_6', - 'Contact_7', - 'Contact_8' - ]) + desired = { + "RenamedBody", + "RenamedContact_1", + "Contact_2", + "Contact_3", + "Contact_4", + "Contact_5", + "Contact_6", + "Contact_7", + "Contact_8", + } assert desired == set(mesh.GetBoundaries()) - # Test the number and names of contacts def test_contacts(self, AbbottStJudeDirected6173_electrode): + """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 = set(['Body', - 'Contact_1', - 'Contact_2', - 'Contact_3', - 'Contact_4', - 'Contact_5', - 'Contact_6', - 'Contact_7', - 'Contact_8' - ]) + desired = { + "Body", + "Contact_1", + "Contact_2", + "Contact_3", + "Contact_4", + "Contact_5", + "Contact_6", + "Contact_7", + "Contact_8", + } assert desired == set(mesh.GetBoundaries()) - # Test volume of the entire electrode def test_electrode_volume(self, AbbottStJudeDirected6173_electrode): + """Test volume of the entire electrode.""" electrode = AbbottStJudeDirected6173_electrode total_length = electrode._parameters.total_length @@ -102,21 +109,22 @@ def test_electrode_volume(self, AbbottStJudeDirected6173_electrode): 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) + 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) - # Test volume of all the contacts def test_contacts_volume(self, AbbottStJudeDirected6173_electrode): + """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 + desired = (np.pi * radius**2 * contact_length * 2) + ( + np.pi * radius**2 * contact_length * 90 / 360 + ) * 6 actual = electrode._contacts().mass tolerance = 1e-5 diff --git a/tests/test_bostonscientificcartesiahx.py b/tests/test_bostonscientificcartesiahx.py new file mode 100644 index 00000000..3c52a9b3 --- /dev/null +++ b/tests/test_bostonscientificcartesiahx.py @@ -0,0 +1,105 @@ +import netgen +import ngsolve +import numpy as np +import pytest + +from ossdbs.electrodes import BostonScientificCartesiaHX + + +class TestBostonScientificCartesiaHX: + @pytest.fixture + def BostonScientificCartesiaHX_electrode(self): + return BostonScientificCartesiaHX() + + def test_rename_boundaries(self, BostonScientificCartesiaHX_electrode): + """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()) + + def test_contacts(self, BostonScientificCartesiaHX_electrode): + """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()) + + def test_electrode_volume(self, BostonScientificCartesiaHX_electrode): + """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 + + np.testing.assert_allclose(actual, desired, atol=tolerance) + + def test_contacts_volume(self, BostonScientificCartesiaHX_electrode): + """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) diff --git a/tests/test_bostonscientificcartesiax.py b/tests/test_bostonscientificcartesiax.py new file mode 100644 index 00000000..9326ed51 --- /dev/null +++ b/tests/test_bostonscientificcartesiax.py @@ -0,0 +1,105 @@ +import netgen +import ngsolve +import numpy as np +import pytest + +from ossdbs.electrodes import BostonScientificCartesiaX + + +class TestBostonScientificCartesiaX: + @pytest.fixture + def BostonScientificCartesiaX_electrode(self): + return BostonScientificCartesiaX() + + def test_rename_boundaries(self, BostonScientificCartesiaX_electrode): + """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()) + + def test_contacts(self, BostonScientificCartesiaX_electrode): + """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()) + + def test_electrode_volume(self, BostonScientificCartesiaX_electrode): + """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 + + np.testing.assert_allclose(actual, desired, atol=tolerance) + + def test_contacts_volume(self, BostonScientificCartesiaX_electrode): + """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) diff --git a/tests/test_bostonscientificvercise.py b/tests/test_bostonscientificvercise.py index 108dd041..77f82d1f 100644 --- a/tests/test_bostonscientificvercise.py +++ b/tests/test_bostonscientificvercise.py @@ -1,11 +1,12 @@ -from ossdbs.electrodes import BostonScientificVercise -import pytest import netgen import ngsolve import numpy as np +import pytest + +from ossdbs.electrodes import BostonScientificVercise -class TestBostonScientificVercise(): +class TestBostonScientificVercise: """ FILE_PREFIX = os.path.join(os.path.dirname(os.path.abspath(__file__)), @@ -51,48 +52,55 @@ def test_geometry_default(self): def BostonScientificVercise_electrode(self): return BostonScientificVercise() - # Test whether set_contact_names() works def test_rename_boundaries(self, BostonScientificVercise_electrode): + """Test whether set_contact_names() works.""" electrode = BostonScientificVercise_electrode - electrode.set_contact_names({'Body': 'RenamedBody', - 'Contact_1': 'RenamedContact_1', - 'NonExistingPart': 'NonExistingPart'}) + 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 = set(['RenamedBody', - 'RenamedContact_1', - 'Contact_2', - 'Contact_3', - 'Contact_4', - 'Contact_5', - 'Contact_6', - 'Contact_7', - 'Contact_8']) + desired = { + "RenamedBody", + "RenamedContact_1", + "Contact_2", + "Contact_3", + "Contact_4", + "Contact_5", + "Contact_6", + "Contact_7", + "Contact_8", + } assert desired == set(mesh.GetBoundaries()) -# Test the number and names of contacts def test_contacts(self, BostonScientificVercise_electrode): + """Test the number and names of contacts.""" electrode = BostonScientificVercise_electrode geometry = electrode.geometry netgen_geometry = netgen.occ.OCCGeometry(geometry) with ngsolve.TaskManager(): mesh = ngsolve.Mesh(netgen_geometry.GenerateMesh()) - desired = set(['Body', - 'Contact_1', - 'Contact_2', - 'Contact_3', - 'Contact_4', - 'Contact_5', - 'Contact_6', - 'Contact_7', - 'Contact_8' - ]) + desired = { + "Body", + "Contact_1", + "Contact_2", + "Contact_3", + "Contact_4", + "Contact_5", + "Contact_6", + "Contact_7", + "Contact_8", + } assert desired == set(mesh.GetBoundaries()) - # Test volume of the entire electrode def test_electrode_volume(self, BostonScientificVercise_electrode): + """Test volume of the entire electrode.""" electrode = BostonScientificVercise_electrode total_length = electrode._parameters.total_length @@ -100,21 +108,21 @@ def test_electrode_volume(self, BostonScientificVercise_electrode): 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) + 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) - # Test volume of all the contacts def test_contacts_volume(self, BostonScientificVercise_electrode): + """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 + desired = (contact_length * radius**2 * np.pi) * n_contacts actual = electrode._contacts().mass tolerance = 1e-5 diff --git a/tests/test_bostonscientificvercisedirected.py b/tests/test_bostonscientificvercisedirected.py index e2093ca9..9e1ead82 100644 --- a/tests/test_bostonscientificvercisedirected.py +++ b/tests/test_bostonscientificvercisedirected.py @@ -1,11 +1,12 @@ -from ossdbs.electrodes import BostonScientificVerciseDirected -import pytest import netgen import ngsolve import numpy as np +import pytest + +from ossdbs.electrodes import BostonScientificVerciseDirected -class TestBostonScientificVerciseDirected(): +class TestBostonScientificVerciseDirected: """ FILE_PREFIX = os.path.join(os.path.dirname(os.path.abspath(__file__)), @@ -51,47 +52,55 @@ def test_geometry_default(self): def BostonScientificVerciseDirected_electrode(self): return BostonScientificVerciseDirected() - # Test whether set_contact_names() works def test_rename_boundaries(self, BostonScientificVerciseDirected_electrode): + """Test whether set_contact_names() works.""" electrode = BostonScientificVerciseDirected_electrode - electrode.set_contact_names({'Body': 'RenamedBody', - 'Contact_1': 'RenamedContact_1', - 'NonExistingPart': 'NonExistingPart'}) + 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 = set(['RenamedBody', - 'RenamedContact_1', - 'Contact_2', - 'Contact_3', - 'Contact_4', - 'Contact_5', - 'Contact_6', - 'Contact_7', - 'Contact_8']) + desired = { + "RenamedBody", + "RenamedContact_1", + "Contact_2", + "Contact_3", + "Contact_4", + "Contact_5", + "Contact_6", + "Contact_7", + "Contact_8", + } assert desired == set(mesh.GetBoundaries()) - # Test the number and names of contacts def test_contacts(self, BostonScientificVerciseDirected_electrode): + """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 = set(['Body', - 'Contact_1', - 'Contact_2', - 'Contact_3', - 'Contact_4', - 'Contact_5', - 'Contact_6', - 'Contact_7', - 'Contact_8']) + desired = { + "Body", + "Contact_1", + "Contact_2", + "Contact_3", + "Contact_4", + "Contact_5", + "Contact_6", + "Contact_7", + "Contact_8", + } assert desired == set(mesh.GetBoundaries()) - # Test volume of the entire electrode def test_electrode_volume(self, BostonScientificVerciseDirected_electrode): + """Test volume of the entire electrode.""" electrode = BostonScientificVerciseDirected_electrode total_length = electrode._parameters.total_length @@ -99,24 +108,29 @@ def test_electrode_volume(self, BostonScientificVerciseDirected_electrode): 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) + 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) - # Test volume of all the contacts def test_contacts_volume(self, BostonScientificVerciseDirected_electrode): + """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 + 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 diff --git a/tests/test_diximicrotechniquesSEEG10.py b/tests/test_diximicrotechniquesSEEG10.py new file mode 100644 index 00000000..13974b42 --- /dev/null +++ b/tests/test_diximicrotechniquesSEEG10.py @@ -0,0 +1,97 @@ +import netgen +import ngsolve +import numpy as np +import pytest + +from ossdbs.electrodes import DixiSEEG10 + + +class TestDixiMicrotechniquesSEEG10: + @pytest.fixture + def DixiSEEG10_electrode(self): + return DixiSEEG10() + + def test_rename_boundaries(self, DixiSEEG10_electrode): + """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()) + + def test_contacts(self, DixiSEEG10_electrode): + """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()) + + def test_electrode_volume(self, DixiSEEG10_electrode): + """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 + + np.testing.assert_allclose(actual, desired, atol=tolerance) + + def test_contacts_volume(self, DixiSEEG10_electrode): + """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) diff --git a/tests/test_diximicrotechniquesSEEG12.py b/tests/test_diximicrotechniquesSEEG12.py new file mode 100644 index 00000000..c1084224 --- /dev/null +++ b/tests/test_diximicrotechniquesSEEG12.py @@ -0,0 +1,101 @@ +import netgen +import ngsolve +import numpy as np +import pytest + +from ossdbs.electrodes import DixiSEEG12 + + +class TestDixiMicrotechniquesSEEG12: + @pytest.fixture + def DixiSEEG12_electrode(self): + return DixiSEEG12() + + def test_rename_boundaries(self, DixiSEEG12_electrode): + """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()) + + def test_contacts(self, DixiSEEG12_electrode): + """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()) + + def test_electrode_volume(self, DixiSEEG12_electrode): + """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 + + np.testing.assert_allclose(actual, desired, atol=tolerance) + + def test_contacts_volume(self, DixiSEEG12_electrode): + """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) diff --git a/tests/test_diximicrotechniquesSEEG15.py b/tests/test_diximicrotechniquesSEEG15.py new file mode 100644 index 00000000..226a068c --- /dev/null +++ b/tests/test_diximicrotechniquesSEEG15.py @@ -0,0 +1,107 @@ +import netgen +import ngsolve +import numpy as np +import pytest + +from ossdbs.electrodes import DixiSEEG15 + + +class TestDixiMicrotechniquesSEEG15: + @pytest.fixture + def DixiSEEG15_electrode(self): + return DixiSEEG15() + + def test_rename_boundaries(self, DixiSEEG15_electrode): + """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()) + + def test_contacts(self, DixiSEEG15_electrode): + """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()) + + def test_electrode_volume(self, DixiSEEG15_electrode): + """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 + + np.testing.assert_allclose(actual, desired, atol=tolerance) + + def test_contacts_volume(self, DixiSEEG15_electrode): + """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) diff --git a/tests/test_diximicrotechniquesSEEG18.py b/tests/test_diximicrotechniquesSEEG18.py new file mode 100644 index 00000000..1d5849bf --- /dev/null +++ b/tests/test_diximicrotechniquesSEEG18.py @@ -0,0 +1,113 @@ +import netgen +import ngsolve +import numpy as np +import pytest + +from ossdbs.electrodes import DixiSEEG18 + + +class TestDixiMicrotechniquesSEEG18: + @pytest.fixture + def DixiSEEG18_electrode(self): + return DixiSEEG18() + + def test_rename_boundaries(self, DixiSEEG18_electrode): + """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()) + + def test_contacts(self, DixiSEEG18_electrode): + """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()) + + def test_electrode_volume(self, DixiSEEG18_electrode): + """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 + + np.testing.assert_allclose(actual, desired, atol=tolerance) + + def test_contacts_volume(self, DixiSEEG18_electrode): + """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) diff --git a/tests/test_diximicrotechniquesSEEG5.py b/tests/test_diximicrotechniquesSEEG5.py new file mode 100644 index 00000000..88b6a964 --- /dev/null +++ b/tests/test_diximicrotechniquesSEEG5.py @@ -0,0 +1,87 @@ +import netgen +import ngsolve +import numpy as np +import pytest + +from ossdbs.electrodes import DixiSEEG5 + + +class TestDixiMicrotechniquesSEEG5: + @pytest.fixture + def DixiSEEG5_electrode(self): + return DixiSEEG5() + + def test_rename_boundaries(self, DixiSEEG5_electrode): + """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()) + + def test_contacts(self, DixiSEEG5_electrode): + """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()) + + def test_electrode_volume(self, DixiSEEG5_electrode): + """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 + + np.testing.assert_allclose(actual, desired, atol=tolerance) + + def test_contacts_volume(self, DixiSEEG5_electrode): + """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) diff --git a/tests/test_diximicrotechniquesSEEG8.py b/tests/test_diximicrotechniquesSEEG8.py new file mode 100644 index 00000000..70641dc4 --- /dev/null +++ b/tests/test_diximicrotechniquesSEEG8.py @@ -0,0 +1,93 @@ +import netgen +import ngsolve +import numpy as np +import pytest + +from ossdbs.electrodes import DixiSEEG8 + + +class TestDixiMicrotechniquesSEEG8: + @pytest.fixture + def DixiSEEG8_electrode(self): + return DixiSEEG8() + + def test_rename_boundaries(self, DixiSEEG8_electrode): + """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()) + + def test_contacts(self, DixiSEEG8_electrode): + """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()) + + def test_electrode_volume(self, DixiSEEG8_electrode): + """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 + + np.testing.assert_allclose(actual, desired, atol=tolerance) + + def test_contacts_volume(self, DixiSEEG8_electrode): + """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) diff --git a/tests/test_medtronic3387.py b/tests/test_medtronic3387.py index 49fb7c3e..9b1ec7c6 100644 --- a/tests/test_medtronic3387.py +++ b/tests/test_medtronic3387.py @@ -1,11 +1,12 @@ -from ossdbs.electrodes import Medtronic3387 -import pytest import netgen import ngsolve import numpy as np +import pytest + +from ossdbs.electrodes import Medtronic3387 -class TestMedtronic3387(): +class TestMedtronic3387: """ FILE_PREFIX = os.path.join(os.path.dirname(os.path.abspath(__file__)), @@ -51,40 +52,47 @@ def test_geometry_default(self): def Medtronic3387_electrode(self): return Medtronic3387() - # Test whether set_contact_names() works def test_rename_boundaries(self, Medtronic3387_electrode): + """Test whether set_contact_names() works.""" electrode = Medtronic3387_electrode - electrode.set_contact_names({'Body': 'RenamedBody', - 'Contact_1': 'RenamedContact_1', - 'NonExistingPart': 'NonExistingPart'}) + 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 = set(['RenamedBody', - 'RenamedContact_1', - 'Contact_2', - 'Contact_3', - 'Contact_4']) + desired = { + "RenamedBody", + "RenamedContact_1", + "Contact_2", + "Contact_3", + "Contact_4", + } assert desired == set(mesh.GetBoundaries()) - # Test the number and names of contacts def test_contacts(self, Medtronic3387_electrode): + """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 = set(['Body', - 'Contact_1', - 'Contact_2', - 'Contact_3', - 'Contact_4', - ]) + desired = { + "Body", + "Contact_1", + "Contact_2", + "Contact_3", + "Contact_4", + } assert desired == set(mesh.GetBoundaries()) - # Test volume of the entire electrode def test_electrode_volume(self, Medtronic3387_electrode): + """Test volume of the entire electrode.""" electrode = Medtronic3387_electrode total_length = electrode._parameters.total_length @@ -92,21 +100,21 @@ def test_electrode_volume(self, Medtronic3387_electrode): 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) + 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) - # Test volume of all the contacts def test_contacts_volume(self, Medtronic3387_electrode): + """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 + desired = (contact_length * radius**2 * np.pi) * n_contacts actual = electrode._contacts().mass tolerance = 1e-5 diff --git a/tests/test_medtronic3389.py b/tests/test_medtronic3389.py index c7dbd8c1..68fb8cbd 100644 --- a/tests/test_medtronic3389.py +++ b/tests/test_medtronic3389.py @@ -1,11 +1,12 @@ -from ossdbs.electrodes import Medtronic3389 -import pytest import netgen import ngsolve import numpy as np +import pytest + +from ossdbs.electrodes import Medtronic3389 -class TestMedtronic3389(): +class TestMedtronic3389: """ FILE_PREFIX = os.path.join(os.path.dirname(os.path.abspath(__file__)), @@ -51,40 +52,47 @@ def test_geometry_default(self): def Medtronic3389_electrode(self): return Medtronic3389() - # Test whether set_contact_names() works def test_rename_boundaries(self, Medtronic3389_electrode): + """Test whether set_contact_names() works.""" electrode = Medtronic3389_electrode - electrode.set_contact_names({'Body': 'RenamedBody', - 'Contact_1': 'RenamedContact_1', - 'NonExistingPart': 'NonExistingPart'}) + 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 = set(['RenamedBody', - 'RenamedContact_1', - 'Contact_2', - 'Contact_3', - 'Contact_4']) + desired = { + "RenamedBody", + "RenamedContact_1", + "Contact_2", + "Contact_3", + "Contact_4", + } assert desired == set(mesh.GetBoundaries()) - # Test the number and names of contacts def test_contacts(self, Medtronic3389_electrode): + """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 = set(['Body', - 'Contact_1', - 'Contact_2', - 'Contact_3', - 'Contact_4', - ]) + desired = { + "Body", + "Contact_1", + "Contact_2", + "Contact_3", + "Contact_4", + } assert desired == set(mesh.GetBoundaries()) - # Test volume of the entire electrode def test_electrode_volume(self, Medtronic3389_electrode): + """Test volume of the entire electrode.""" electrode = Medtronic3389_electrode total_length = electrode._parameters.total_length @@ -92,21 +100,21 @@ def test_electrode_volume(self, Medtronic3389_electrode): 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) + 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) - # Test volume of all the contacts def test_contacts_volume(self, Medtronic3389_electrode): + """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 + desired = (contact_length * radius**2 * np.pi) * n_contacts actual = electrode._contacts().mass tolerance = 1e-5 diff --git a/tests/test_medtronic3391.py b/tests/test_medtronic3391.py index b2fb758f..a539277a 100644 --- a/tests/test_medtronic3391.py +++ b/tests/test_medtronic3391.py @@ -1,11 +1,12 @@ -from ossdbs.electrodes import Medtronic3391 -import pytest import netgen import ngsolve import numpy as np +import pytest + +from ossdbs.electrodes import Medtronic3391 -class TestMedtronic3391(): +class TestMedtronic3391: """ FILE_PREFIX = os.path.join(os.path.dirname(os.path.abspath(__file__)), @@ -51,40 +52,47 @@ def test_geometry_default(self): def Medtronic3391_electrode(self): return Medtronic3391() - # Test whether set_contact_names() works def test_rename_boundaries(self, Medtronic3391_electrode): + """Test whether set_contact_names() works.""" electrode = Medtronic3391_electrode - electrode.set_contact_names({'Body': 'RenamedBody', - 'Contact_1': 'RenamedContact_1', - 'NonExistingPart': 'NonExistingPart'}) + 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 = set(['RenamedBody', - 'RenamedContact_1', - 'Contact_2', - 'Contact_3', - 'Contact_4']) + desired = { + "RenamedBody", + "RenamedContact_1", + "Contact_2", + "Contact_3", + "Contact_4", + } assert desired == set(mesh.GetBoundaries()) - # Test the number and names of contacts def test_contacts(self, Medtronic3391_electrode): + """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 = set(['Body', - 'Contact_1', - 'Contact_2', - 'Contact_3', - 'Contact_4', - ]) + desired = { + "Body", + "Contact_1", + "Contact_2", + "Contact_3", + "Contact_4", + } assert desired == set(mesh.GetBoundaries()) - # Test volume of the entire electrode def test_electrode_volume(self, Medtronic3391_electrode): + """Test volume of the entire electrode.""" electrode = Medtronic3391_electrode total_length = electrode._parameters.total_length @@ -92,20 +100,20 @@ def test_electrode_volume(self, Medtronic3391_electrode): 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) + 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) - # Test volume of all the contacts def test_contacts_volume(self, Medtronic3391_electrode): + """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 + desired = (contact_length * radius**2 * np.pi) * n_contacts actual = electrode._contacts().mass tolerance = 1e-5 diff --git a/tests/test_medtronicsensightB33005.py b/tests/test_medtronicsensightB33005.py new file mode 100644 index 00000000..1b050665 --- /dev/null +++ b/tests/test_medtronicsensightB33005.py @@ -0,0 +1,90 @@ +import netgen +import ngsolve +import numpy as np +import pytest + +from ossdbs.electrodes import MedtronicSenSightB33005 + + +class TestMedtronicSenSightB33005: + @pytest.fixture + def MedtronicSenSightB33005_electrode(self): + return MedtronicSenSightB33005() + + def test_rename_boundaries(self, MedtronicSenSightB33005_electrode): + """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()) + + def test_contacts(self, MedtronicSenSightB33005_electrode): + """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()) + + def test_electrode_volume(self, MedtronicSenSightB33005_electrode): + """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 + + np.testing.assert_allclose(actual, desired, atol=tolerance) + + def test_contacts_volume(self, MedtronicSenSightB33005_electrode): + """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) diff --git a/tests/test_medtronicsensightB33015.py b/tests/test_medtronicsensightB33015.py new file mode 100644 index 00000000..9cb62442 --- /dev/null +++ b/tests/test_medtronicsensightB33015.py @@ -0,0 +1,90 @@ +import netgen +import ngsolve +import numpy as np +import pytest + +from ossdbs.electrodes import MedtronicSenSightB33015 + + +class TestMedtronicSenSightB33015: + @pytest.fixture + def MedtronicSenSightB33015_electrode(self): + return MedtronicSenSightB33015() + + def test_rename_boundaries(self, MedtronicSenSightB33015_electrode): + """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()) + + def test_contacts(self, MedtronicSenSightB33015_electrode): + """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()) + + def test_electrode_volume(self, MedtronicSenSightB33015_electrode): + """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 + + np.testing.assert_allclose(actual, desired, atol=tolerance) + + def test_contacts_volume(self, MedtronicSenSightB33015_electrode): + """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) diff --git a/tests/test_microelectrode.py b/tests/test_microelectrode.py new file mode 100644 index 00000000..e7e6335e --- /dev/null +++ b/tests/test_microelectrode.py @@ -0,0 +1,77 @@ +import netgen +import ngsolve +import numpy as np +import pytest + +from ossdbs.electrodes import MicroElectrode + + +class TestMicroElectrode: + @pytest.fixture + def MicroElectrode_electrode(self): + return MicroElectrode() + + def test_rename_boundaries(self, MicroElectrode_electrode): + """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()) + + def test_contacts(self, MicroElectrode_electrode): + """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()) + + def test_electrode_volume(self, MicroElectrode_electrode): + """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 + + 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): + """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) diff --git a/tests/test_microprobescustomrodent.py b/tests/test_microprobescustomrodent.py index 3d5e1566..16a9ecd5 100644 --- a/tests/test_microprobescustomrodent.py +++ b/tests/test_microprobescustomrodent.py @@ -1,11 +1,12 @@ -from ossdbs.electrodes import MicroProbesRodentElectrode -import pytest import netgen import ngsolve import numpy as np +import pytest +from ossdbs.electrodes import MicroProbesRodentElectrode -class TestMicroProbesCustomRodent(): + +class TestMicroProbesCustomRodent: """ FILE_PREFIX = os.path.join(os.path.dirname(os.path.abspath(__file__)), @@ -51,58 +52,65 @@ def test_geometry_default(self): def MicroProbesRodentElectrode_electrode(self): return MicroProbesRodentElectrode() - # Test whether set_contact_names() works def test_rename_boundaries(self, MicroProbesRodentElectrode_electrode): + """Test whether set_contact_names() works.""" electrode = MicroProbesRodentElectrode_electrode - electrode.set_contact_names({'Body': 'RenamedBody', - 'Contact_1': 'RenamedContact_1', - 'NonExistingPart': 'NonExistingPart'}) + 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 = set(['RenamedBody', - 'RenamedContact_1', - ]) + desired = { + "RenamedBody", + "RenamedContact_1", + } assert desired == set(mesh.GetBoundaries()) - # Test the number and names of contacts def test_contacts(self, MicroProbesRodentElectrode_electrode): + """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 = set(['Body', - 'Contact_1', - ]) + desired = { + "Body", + "Contact_1", + } assert desired == set(mesh.GetBoundaries()) - # Test volume of the entire electrode def test_electrode_volume(self, MicroProbesRodentElectrode_electrode): + """Test volume of the entire electrode.""" electrode = MicroProbesRodentElectrode_electrode total_length = electrode._parameters.total_length lead_radius = electrode._parameters.lead_radius - height = total_length - lead_radius + contact_radius = electrode._parameters.contact_radius + height = total_length - contact_radius - desired = (height * lead_radius ** 2 * np.pi) + (4 / 3 * np.pi * lead_radius ** 3 * 0.5) + desired = (height * lead_radius**2 * np.pi) + ( + 4 / 3 * np.pi * contact_radius**3 * 0.5 + ) actual = electrode.geometry.mass - tolerance = 1e-3 + tolerance = 1e-5 np.testing.assert_allclose(actual, desired, atol=tolerance) - # Test volume of all the contacts def test_contacts_volume(self, MicroProbesRodentElectrode_electrode): + """Test volume of all the contacts.""" electrode = MicroProbesRodentElectrode_electrode - lead_radius = electrode._parameters.lead_radius contact_radius = electrode._parameters.contact_radius - height = contact_radius - lead_radius - desired = (height * lead_radius ** 2 * np.pi) + (4 / 3 * np.pi * lead_radius ** 3 * 0.5) + desired = 4 / 3 * np.pi * contact_radius**3 * 0.5 actual = electrode._contacts().mass - tolerance = 1e-3 + tolerance = 1e-5 np.testing.assert_allclose(actual, desired, atol=tolerance) diff --git a/tests/test_microprobessnex100.py b/tests/test_microprobessnex100.py index e7c02088..97d7b017 100644 --- a/tests/test_microprobessnex100.py +++ b/tests/test_microprobessnex100.py @@ -1,11 +1,12 @@ -from ossdbs.electrodes import MicroProbesSNEX100 -import pytest import netgen import ngsolve import numpy as np +import pytest + +from ossdbs.electrodes import MicroProbesSNEX100 -class TestMicroProbesSNEX_100(): +class TestMicroProbesSNEX_100: """ FILE_PREFIX = os.path.join(os.path.dirname(os.path.abspath(__file__)), @@ -51,53 +52,55 @@ def test_geometry_default(self): def MicroProbesSNEX100_electrode(self): return MicroProbesSNEX100() - # Test whether set_contact_names() works def test_rename_boundaries(self, MicroProbesSNEX100_electrode): + """Test whether set_contact_names() works.""" electrode = MicroProbesSNEX100_electrode - electrode.set_contact_names({'Body': 'RenamedBody', - 'Contact_1': 'RenamedContact_1', - 'NonExistingPart': 'NonExistingPart'}) + 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 = set(['RenamedBody', - 'RenamedContact_1', - 'Contact_2' - ]) + desired = {"RenamedBody", "RenamedContact_1", "Contact_2"} assert desired == set(mesh.GetBoundaries()) - # Test the number and names of contacts def test_contacts(self, MicroProbesSNEX100_electrode): + """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 = set(['Body', - 'Contact_1', - 'Contact_2', - ]) + desired = { + "Body", + "Contact_1", + "Contact_2", + } assert desired == set(mesh.GetBoundaries()) - # Test volume of the entire electrode def test_electrode_volume(self, MicroProbesSNEX100_electrode): + """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 - ) + 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 + 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 @@ -105,10 +108,12 @@ def test_electrode_volume(self, MicroProbesSNEX100_electrode): 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)) + 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 @@ -116,8 +121,8 @@ def test_electrode_volume(self, MicroProbesSNEX100_electrode): np.testing.assert_allclose(actual, desired, atol=tolerance) - # Test volume of all the contacts def test_contacts_volume(self, MicroProbesSNEX100_electrode): + """Test volume of all the contacts.""" electrode = MicroProbesSNEX100_electrode outer_electrode_radius = electrode._parameters.outer_electrode_diameter * 0.5 @@ -126,10 +131,12 @@ def test_contacts_volume(self, MicroProbesSNEX100_electrode): 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)) + 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 diff --git a/tests/test_neuropaceDL344_10.py b/tests/test_neuropaceDL344_10.py new file mode 100644 index 00000000..0c9d2657 --- /dev/null +++ b/tests/test_neuropaceDL344_10.py @@ -0,0 +1,79 @@ +import netgen +import ngsolve +import numpy as np +import pytest + +from ossdbs.electrodes import NeuroPaceDL344_10 + + +class TestNeuroPaceDL344_10: + @pytest.fixture + def NeuroPaceDL344_10_electrode(self): + return NeuroPaceDL344_10() + + def test_rename_boundaries(self, NeuroPaceDL344_10_electrode): + """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()) + + def test_contacts(self, NeuroPaceDL344_10_electrode): + """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()) + + def test_electrode_volume(self, NeuroPaceDL344_10_electrode): + """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 + + 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): + """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) diff --git a/tests/test_neuropaceDL344_3_5.py b/tests/test_neuropaceDL344_3_5.py new file mode 100644 index 00000000..44709c96 --- /dev/null +++ b/tests/test_neuropaceDL344_3_5.py @@ -0,0 +1,79 @@ +import netgen +import ngsolve +import numpy as np +import pytest + +from ossdbs.electrodes import NeuroPaceDL344_3_5 + + +class TestNeuroPaceDL344_3_5: + @pytest.fixture + def NeuroPaceDL344_3_5_electrode(self): + return NeuroPaceDL344_3_5() + + def test_rename_boundaries(self, NeuroPaceDL344_3_5_electrode): + """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()) + + def test_contacts(self, NeuroPaceDL344_3_5_electrode): + """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()) + + def test_electrode_volume(self, NeuroPaceDL344_3_5_electrode): + """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 + + 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): + """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) diff --git a/tests/test_pinsmedicall301.py b/tests/test_pinsmedicall301.py index 1edc59fe..369cf16e 100644 --- a/tests/test_pinsmedicall301.py +++ b/tests/test_pinsmedicall301.py @@ -1,11 +1,12 @@ -from ossdbs.electrodes import PINSMedicalL301 -import pytest import netgen import ngsolve import numpy as np +import pytest + +from ossdbs.electrodes import PINSMedicalL301 -class TestPINSMedicalL301(): +class TestPINSMedicalL301: """ FILE_PREFIX = os.path.join(os.path.dirname(os.path.abspath(__file__)), @@ -51,40 +52,47 @@ def test_geometry_default(self): def PINSMedicalL301_electrode(self): return PINSMedicalL301() - # Test whether set_contact_names() works def test_rename_boundaries(self, PINSMedicalL301_electrode): + """Test whether set_contact_names() works.""" electrode = PINSMedicalL301_electrode - electrode.set_contact_names({'Body': 'RenamedBody', - 'Contact_1': 'RenamedContact_1', - 'NonExistingPart': 'NonExistingPart'}) + 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 = set(['RenamedBody', - 'RenamedContact_1', - 'Contact_2', - 'Contact_3', - 'Contact_4']) + desired = { + "RenamedBody", + "RenamedContact_1", + "Contact_2", + "Contact_3", + "Contact_4", + } assert desired == set(mesh.GetBoundaries()) - # Test the number and names of contacts def test_contacts(self, PINSMedicalL301_electrode): + """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 = set(['Body', - 'Contact_1', - 'Contact_2', - 'Contact_3', - 'Contact_4', - ]) + desired = { + "Body", + "Contact_1", + "Contact_2", + "Contact_3", + "Contact_4", + } assert desired == set(mesh.GetBoundaries()) - # Test volume of the entire electrode def test_electrode_volume(self, PINSMedicalL301_electrode): + """Test volume of the entire electrode.""" electrode = PINSMedicalL301_electrode total_length = electrode._parameters.total_length @@ -92,20 +100,20 @@ def test_electrode_volume(self, PINSMedicalL301_electrode): 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) + 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) - # Test volume of all the contacts def test_contacts_volume(self, PINSMedicalL301_electrode): + """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 + desired = (contact_length * radius**2 * np.pi) * n_contacts actual = electrode._contacts().mass tolerance = 1e-5 diff --git a/tests/test_pinsmedicall302.py b/tests/test_pinsmedicall302.py index 0d4722bf..7f88dd9b 100644 --- a/tests/test_pinsmedicall302.py +++ b/tests/test_pinsmedicall302.py @@ -1,11 +1,12 @@ -from ossdbs.electrodes import PINSMedicalL302 -import pytest import netgen import ngsolve import numpy as np +import pytest + +from ossdbs.electrodes import PINSMedicalL302 -class TestPINSMedicalL302(): +class TestPINSMedicalL302: """ FILE_PREFIX = os.path.join(os.path.dirname(os.path.abspath(__file__)), @@ -51,40 +52,47 @@ def test_geometry_default(self): def PINSMedicalL302_electrode(self): return PINSMedicalL302() - # Test whether set_contact_names() works def test_rename_boundaries(self, PINSMedicalL302_electrode): + """Test whether set_contact_names() works.""" electrode = PINSMedicalL302_electrode - electrode.set_contact_names({'Body': 'RenamedBody', - 'Contact_1': 'RenamedContact_1', - 'NonExistingPart': 'NonExistingPart'}) + 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 = set(['RenamedBody', - 'RenamedContact_1', - 'Contact_2', - 'Contact_3', - 'Contact_4']) + desired = { + "RenamedBody", + "RenamedContact_1", + "Contact_2", + "Contact_3", + "Contact_4", + } assert desired == set(mesh.GetBoundaries()) - # Test the number and names of contacts def test_contacts(self, PINSMedicalL302_electrode): + """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 = set(['Body', - 'Contact_1', - 'Contact_2', - 'Contact_3', - 'Contact_4', - ]) + desired = { + "Body", + "Contact_1", + "Contact_2", + "Contact_3", + "Contact_4", + } assert desired == set(mesh.GetBoundaries()) - # Test volume of the entire electrode def test_electrode_volume(self, PINSMedicalL302_electrode): + """Test volume of the entire electrode.""" electrode = PINSMedicalL302_electrode total_length = electrode._parameters.total_length @@ -92,20 +100,20 @@ def test_electrode_volume(self, PINSMedicalL302_electrode): 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) + 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) - # Test volume of all the contacts def test_contacts_volume(self, PINSMedicalL302_electrode): + """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 + desired = (contact_length * radius**2 * np.pi) * n_contacts actual = electrode._contacts().mass tolerance = 1e-5 diff --git a/tests/test_pinsmedicall303.py b/tests/test_pinsmedicall303.py index 76aeba5e..d39d6644 100644 --- a/tests/test_pinsmedicall303.py +++ b/tests/test_pinsmedicall303.py @@ -1,11 +1,12 @@ -from ossdbs.electrodes import PINSMedicalL303 -import pytest import netgen import ngsolve import numpy as np +import pytest + +from ossdbs.electrodes import PINSMedicalL303 -class TestPINSMedicalL303(): +class TestPINSMedicalL303: """ FILE_PREFIX = os.path.join(os.path.dirname(os.path.abspath(__file__)), @@ -51,40 +52,47 @@ def test_geometry_default(self): def PINSMedicalL303_electrode(self): return PINSMedicalL303() - # Test whether set_contact_names() works def test_rename_boundaries(self, PINSMedicalL303_electrode): + """Test whether set_contact_names() works.""" electrode = PINSMedicalL303_electrode - electrode.set_contact_names({'Body': 'RenamedBody', - 'Contact_1': 'RenamedContact_1', - 'NonExistingPart': 'NonExistingPart'}) + 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 = set(['RenamedBody', - 'RenamedContact_1', - 'Contact_2', - 'Contact_3', - 'Contact_4']) + desired = { + "RenamedBody", + "RenamedContact_1", + "Contact_2", + "Contact_3", + "Contact_4", + } assert desired == set(mesh.GetBoundaries()) - # Test the number and names of contacts def test_contacts(self, PINSMedicalL303_electrode): + """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 = set(['Body', - 'Contact_1', - 'Contact_2', - 'Contact_3', - 'Contact_4', - ]) + desired = { + "Body", + "Contact_1", + "Contact_2", + "Contact_3", + "Contact_4", + } assert desired == set(mesh.GetBoundaries()) - # Test volume of the entire electrode def test_electrode_volume(self, PINSMedicalL303_electrode): + """Test volume of the entire electrode.""" electrode = PINSMedicalL303_electrode total_length = electrode._parameters.total_length @@ -92,20 +100,20 @@ def test_electrode_volume(self, PINSMedicalL303_electrode): 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) + 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) - # Test volume of all the contacts def test_contacts_volume(self, PINSMedicalL303_electrode): + """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 + desired = (contact_length * radius**2 * np.pi) * n_contacts actual = electrode._contacts().mass tolerance = 1e-5