Skip to content

Commit

Permalink
update electrode tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kenichi-maeda committed Jun 13, 2024
1 parent a24db4e commit a190d40
Show file tree
Hide file tree
Showing 27 changed files with 1,703 additions and 369 deletions.
51 changes: 28 additions & 23 deletions tests/test_abbottstjudeactivetip6142_6145.py
Original file line number Diff line number Diff line change
@@ -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',
Expand Down Expand Up @@ -52,64 +53,68 @@ 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
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)
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
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)
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

Expand Down
51 changes: 28 additions & 23 deletions tests/test_abbottstjudeactivetip6146_6149.py
Original file line number Diff line number Diff line change
@@ -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',
Expand Down Expand Up @@ -51,64 +52,68 @@ 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
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)
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
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)
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

Expand Down
74 changes: 41 additions & 33 deletions tests/test_abbottstjudedirected6172.py
Original file line number Diff line number Diff line change
@@ -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',
Expand Down Expand Up @@ -51,71 +52,78 @@ 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
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)
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
Expand Down
Loading

0 comments on commit a190d40

Please sign in to comment.