Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added a base class #36

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 16 additions & 64 deletions tests/test_abbottstjudeactivetip6142_6145.py
Original file line number Diff line number Diff line change
@@ -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)
80 changes: 16 additions & 64 deletions tests/test_abbottstjudeactivetip6146_6149.py
Original file line number Diff line number Diff line change
@@ -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)
91 changes: 16 additions & 75 deletions tests/test_abbottstjudedirected6172.py
Original file line number Diff line number Diff line change
@@ -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)
Loading
Loading