Finite element model from labels¶
The main problems in shamo depend on a finite element model to serve as a support for the computation. Generating such a model can be achieved in a few lines of code.
To start, we import the FEM
class and initialize a model with a name and a parent directory.
[ ]:
from shamo import FEM
model = FEM("fem_from_labels_sensors-circle", "../../derivatives")
Mesh generation¶
Several methods can be used ot generate the mesh:
mesh_from_array()
mesh_from_nii()
mesh_from_masks()
mesh_from_niis()
All those methods skip the step of generating surfaces and allow us to directly produce a high definition mesh from the segmented image. Here, we start from a labelled volume created from the well known Suzanne model from Blender.
Note
Several parameters can be used to refine the mesh. Make sure to tweak them to obtain the mesh you want.
[ ]:
from pathlib import Path
data_path = Path("../../rawdata/suzanne")
model.mesh_from_nii(
data_path / "suzanne_labels.nii",
["wm", "gm", "scalp"],
max_facet_distance=0.25,
max_cell_circumradius=5.0,
min_facet_angle=20,
)
After this first step, a mesh built of triangles and tetrahedra and annotated with the name of the tissues is saved to the directory of the object.
Sensors additions¶
Sensors can be added to the mesh with the following methods:
add_point_sensor()
and the partialsadd_point_sensor_on()
andadd_point_sensor_in()
add_point_sensors()
and the partialsadd_point_sensors_on()
andadd_point_sensors_in()
add_point_sensors_from_tsv()
and the partialsadd_point_sensors_from_tsv_on()
andadd_point_sensors_from_tsv_in()
In the case of Suzanne, the electrodes are defined in a TSV file with the format:
Name |
X |
Y |
Z |
---|---|---|---|
NZ |
1.65 |
-42.78 |
-7.54 |
… |
… |
… |
… |
[ ]:
import numpy as np
from pathlib import Path
model.add_circle_sensors_from_tsv_on(data_path / "suzanne_sensors.tsv", "scalp", 0.005)