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

Fix edge refinement #49

Merged
merged 136 commits into from
Nov 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
136 commits
Select commit Hold shift + click to select a range
7733612
make edge names to be refined clearer
j-zimmermann Jul 10, 2024
172da99
idea for edge markers
j-zimmermann Jul 16, 2024
b90db58
refine directed contacts, add tests scripts for mesh
j-zimmermann Jul 17, 2024
ac50843
update mesh example
Jul 23, 2024
ba37d63
change refinement of directed contacts (abbott_stjude & medtronic)
kenichi-maeda Jul 24, 2024
43b3487
only label outer edges
Jul 25, 2024
8824626
clean edge refinement
Jul 25, 2024
0a29d64
unoriented base contact
kenichi-maeda Jul 30, 2024
798b447
work on directed contacts
j-zimmermann Aug 7, 2024
cca1741
comments on rotation
j-zimmermann Aug 8, 2024
5ce00cb
reproduce bug
kenichi-maeda Aug 8, 2024
ee27831
remove one rotation
j-zimmermann Aug 8, 2024
58cfe45
adjust rotation of electrode
j-zimmermann Aug 12, 2024
7a77ad5
use non-standard direction in example
j-zimmermann Aug 12, 2024
e612670
updated version of rotation in comment, agrees without?
j-zimmermann Aug 12, 2024
e417c68
add default in comments
j-zimmermann Aug 12, 2024
12c4d1c
WIP: angle not correct
j-zimmermann Aug 13, 2024
6227d49
fix rotation / spin issue
j-zimmermann Aug 13, 2024
1ad10c7
test examples that don't work
j-zimmermann Aug 14, 2024
41fc438
a better check for the orientation
j-zimmermann Aug 14, 2024
b0efd6e
enable log to file
j-zimmermann Aug 14, 2024
2c3e3aa
example with custom electrode
j-zimmermann Aug 18, 2024
95acb13
more flexibility in interface
j-zimmermann Aug 19, 2024
ac44073
set default output path
j-zimmermann Aug 19, 2024
77c050f
write StimSets mesh to results directory (no cleanup yet)
j-zimmermann Aug 19, 2024
880ec90
merge updated tests
j-zimmermann Aug 21, 2024
f646d92
update output
j-zimmermann Aug 21, 2024
1d0a543
GMRES did not converge properly
j-zimmermann Aug 22, 2024
946a285
new benchmark
j-zimmermann Aug 22, 2024
72db5b7
fix geometry issue
j-zimmermann Aug 25, 2024
8b323e2
new test for electrode edges
j-zimmermann Aug 25, 2024
6135b18
test for multiple electrodes
j-zimmermann Aug 25, 2024
a5cb005
scripts to debug meshes / geo issues
j-zimmermann Aug 25, 2024
bedb1f2
ignore more files
j-zimmermann Aug 25, 2024
e6590eb
handle output path correctly
j-zimmermann Aug 26, 2024
19743d6
permit free choice of ground contact
j-zimmermann Aug 26, 2024
b2b30c9
update ci to only use ruff
j-zimmermann Aug 27, 2024
370fa88
export field too if needed
j-zimmermann Aug 27, 2024
1f74f9c
FIX: active grounding check and VTA threshold
Kinway25 Aug 28, 2024
0188cbb
export vtk from input
j-zimmermann Aug 28, 2024
f4dd2d3
adjust spin angle of all directed electrodes
j-zimmermann Aug 28, 2024
7830f1f
adjust spin angle of cartesia electrodes, needs to be checked
j-zimmermann Aug 28, 2024
93cb806
remove superfluous rotations
j-zimmermann Aug 28, 2024
2a988f2
add tests for spin direction of directed electrodes
j-zimmermann Aug 29, 2024
12fd83d
export also electrode mesh
j-zimmermann Aug 29, 2024
79ba4cd
fix face naming for microelectrode
Aug 30, 2024
549dac7
Merge branch 'main' into fix_edge_refinement
j-zimmermann Aug 30, 2024
e971683
expose voxel size
j-zimmermann Aug 30, 2024
111e709
all electrode contacts need to be in brain
j-zimmermann Aug 30, 2024
80db23a
update OOC results
j-zimmermann Aug 31, 2024
ed93fbe
add informative output to AMR
j-zimmermann Aug 31, 2024
c65f4ba
fix medtronic contacts
j-zimmermann Sep 2, 2024
3a7e3b8
fix abbott electrode
j-zimmermann Sep 2, 2024
855be31
fix vercise electrode
j-zimmermann Sep 2, 2024
09f0125
update dixi electrodes
j-zimmermann Sep 2, 2024
eca4611
fix neuropace
j-zimmermann Sep 2, 2024
ed368e3
fixed pins medical
j-zimmermann Sep 2, 2024
9e72b70
define lead diameter for all electrodes, make export more robust
j-zimmermann Sep 2, 2024
daf066b
clearer error message for wrong input parameter
j-zimmermann Sep 2, 2024
a42dbf6
catch zero-thickness of encap layer better
j-zimmermann Sep 2, 2024
ba39743
fix MicroProbes
j-zimmermann Sep 2, 2024
c9bf592
update tests
j-zimmermann Sep 2, 2024
ad3813e
fix microelectrode
j-zimmermann Sep 2, 2024
ee17f82
UPD: higher precision for grounded current
Kinway25 Sep 5, 2024
0189a51
add utilities for VTA
j-zimmermann Sep 6, 2024
bcf35e4
update output message
j-zimmermann Sep 7, 2024
ffd76d9
base setting for convergence study
j-zimmermann Sep 7, 2024
7664654
rename activation threshold to make unit clear
j-zimmermann Sep 7, 2024
d77ce36
add VTA volume computation and export
j-zimmermann Sep 7, 2024
1272d18
update test case for new lattice resolution
j-zimmermann Sep 7, 2024
122d3a3
update input file parameter name
j-zimmermann Sep 7, 2024
5fbc486
catch case when no activation threshold is provided
j-zimmermann Sep 7, 2024
f84e241
catch points outside lattice
j-zimmermann Sep 8, 2024
770cbb8
catch points outside lattice
j-zimmermann Sep 8, 2024
7a3029c
update AMR impedance handling
j-zimmermann Sep 8, 2024
28c4d89
add base parameters for PAM
j-zimmermann Sep 8, 2024
2b286aa
expose electrode parameters
j-zimmermann Sep 8, 2024
733aaee
structure for convergence study
j-zimmermann Sep 9, 2024
48339b0
initialise point models when final mesh is ready
j-zimmermann Sep 9, 2024
74d303d
no large files in release
j-zimmermann Sep 9, 2024
00e45ea
add material mesh refinement
j-zimmermann Sep 9, 2024
ee82754
update AMR routine with more output and better control
j-zimmermann Sep 10, 2024
0e1cb35
update file handler and convergence routine
j-zimmermann Sep 10, 2024
d781ec1
catch NEURON error (WIP)
j-zimmermann Sep 10, 2024
7335a13
use gzipped file
j-zimmermann Sep 11, 2024
3474927
remove line
j-zimmermann Sep 11, 2024
81b3987
change deprecated numpy function
j-zimmermann Sep 11, 2024
06b3f28
overwrite impedances only when computed
j-zimmermann Sep 11, 2024
3a7f9c2
add metrics for PAM
j-zimmermann Sep 14, 2024
2dba40f
add VCM report
j-zimmermann Sep 14, 2024
27462ed
PAM files
j-zimmermann Sep 14, 2024
068c5ec
make sure directory exists
j-zimmermann Sep 14, 2024
72e6325
full layout for convergence study
j-zimmermann Sep 14, 2024
40a8a0a
full layout for convergence study vercise
j-zimmermann Sep 14, 2024
bf17774
update case grounding
j-zimmermann Sep 14, 2024
9af3463
update case grounding
j-zimmermann Sep 14, 2024
bbd76a5
fix typo
j-zimmermann Sep 14, 2024
1787834
add PAM layout
j-zimmermann Sep 14, 2024
75053a4
update currents
j-zimmermann Sep 14, 2024
4da91fe
add PAM layout
j-zimmermann Sep 14, 2024
62ffa29
adjust lattice shape
j-zimmermann Sep 14, 2024
adf167d
adjust lattice shape
j-zimmermann Sep 14, 2024
30d56d9
updated PAM files
j-zimmermann Sep 15, 2024
ceff225
added Vercise PAM files
j-zimmermann Sep 15, 2024
dee980b
typo
j-zimmermann Sep 15, 2024
9c512de
Revert "added Vercise PAM files"
j-zimmermann Sep 15, 2024
737c0f0
added Vercise PAM files
j-zimmermann Sep 15, 2024
10fdfd8
add monopolar case
j-zimmermann Sep 16, 2024
1c8229b
add point refinement
j-zimmermann Sep 17, 2024
6d3af2d
update PAM convergence study
j-zimmermann Sep 28, 2024
9ecfdf5
run for new PAM model
j-zimmermann Sep 28, 2024
6f0c4c2
final VTA layout
j-zimmermann Oct 7, 2024
512ffe8
add comparison in time domain for not-activated neurons
j-zimmermann Oct 7, 2024
dc3201a
just Jacobi is more stable
j-zimmermann Oct 7, 2024
ded60f3
update preconditioner
j-zimmermann Oct 10, 2024
edf55e9
update preconditioner
j-zimmermann Oct 10, 2024
d244467
update preconditioner
j-zimmermann Oct 10, 2024
765c22b
add new pam studies
j-zimmermann Oct 10, 2024
4199a98
preconditioner is set by string not set
j-zimmermann Oct 11, 2024
97a1ace
update source code to catch bug
j-zimmermann Oct 13, 2024
7c4c451
deprecate Python 3.8 because of EOL
j-zimmermann Oct 14, 2024
0129f0b
truncate time-domain output vector
j-zimmermann Oct 15, 2024
a7d3ead
fix indexing error
j-zimmermann Oct 16, 2024
1a0893f
run truncation test
j-zimmermann Oct 19, 2024
4de6d21
split export function
j-zimmermann Oct 22, 2024
a16263a
FIX: correct position of the first contact
Kinway25 Oct 24, 2024
7766bcf
Merge branch 'fix_edge_refinement' of github.com:SFB-ELAINE/OSS-DBSv2…
j-zimmermann Oct 24, 2024
744a849
add mesh scripts
j-zimmermann Oct 24, 2024
a6d81f7
stimsets overview
j-zimmermann Oct 24, 2024
b4f5fe4
update reference meshes
j-zimmermann Oct 24, 2024
3604211
add issue template
j-zimmermann Oct 29, 2024
c4a1cb1
update wire for microprobes electrode (#58)
JPPayonk Nov 3, 2024
71f10ab
update convergence results
j-zimmermann Nov 3, 2024
b630536
Merge branch 'fix_edge_refinement' of github.com:SFB-ELAINE/OSS-DBSv2…
j-zimmermann Nov 3, 2024
f3cc6de
update preconditioner
j-zimmermann Nov 3, 2024
32610c5
update default Lead-DBS
j-zimmermann Nov 4, 2024
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
16 changes: 16 additions & 0 deletions .github/ISSUE_TEMPLATE
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
* OSS-DBS version (either Lead-DBS or development, then please add which branch / commit):
* If installed through Lead-DBS, please state the version:
* Python version:
* Operating System:

### Description

Describe what you were trying to get done.
Tell us what happened, what went wrong, and what you expected to happen.

### What I Did

```
Paste the command(s) you ran and the output.
If there was a crash, please include the traceback here.
```
6 changes: 1 addition & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,8 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
python-version: ["3.9", "3.10", "3.11", "3.12"]
platform: [ubuntu-latest, macos-latest]
exclude:
- platform: macos-latest
python-version: 3.8

steps:
- uses: actions/checkout@v4

Expand Down
9 changes: 8 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,11 @@ impedance.csv
*.nii.gz
*.nii
success_*.txt
fail_*.txt
fail_*.txt
test_input_cases_results.csv
*.stp
ngmesh.ini
examples/StimulationSignalAPI/*.pdf
x86_64/

meshsizes.txt
10 changes: 3 additions & 7 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,9 @@ repos:
hooks:
- id: validate-pyproject

- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: v0.0.282
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.6.2
hooks:
- id: ruff
args: [--fix]

- repo: https://github.com/psf/black
rev: 23.7.0
hooks:
- id: black
- id: ruff-format
2 changes: 1 addition & 1 deletion examples/Collapse_VTA/inputCollapse.json
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,6 @@
},
"OutputPath": "Results",
"SaveImpedance": true,
"ActivationThresholdVTA": 0.2,
"ActivationThresholdVTA[V-per-m]": 0.2,
"ExportVTK": true
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
# gold standard:
# impedance error 0.1% and maximum element size equal
# to mesh size

import json
import logging
import os
from copy import deepcopy

import ngsolve
import numpy as np

import ossdbs


def remove_file_handler(logger):
"""Remove file handler from logger instance."""
for h in logger.handlers:
if isinstance(h, logging.FileHandler):
logger.removeHandler(h)


def save_input_dict(base_input_dict):
"""Save input dictionary for convergence run."""
input_dict = deepcopy(base_input_dict)
input_dict["OutputPath"] = "./"

with open(
os.path.join(base_input_dict["OutputPath"], "input_dict.json"), "w"
) as fp:
json.dump(input_dict, fp, indent=2)


BASE_CONTACT = {
"Contact_ID": 1,
"Active": False,
"Current[A]": 0.0,
"Voltage[V]": 0.0,
"Floating": False,
}

ossdbs.set_logger(logging.INFO)
_logger = logging.getLogger("ossdbs")

electrode_name = "Medtronic3389"

with open("oss_dbs_parameters.json") as fp:
base_input_dict = json.load(fp)


# add electrode
base_input_dict["Electrodes"][0]["Name"] = electrode_name

# initially no adaptive refinement
base_input_dict["Mesh"]["AdaptiveMeshRefinement"] = {}
base_input_dict["Mesh"]["AdaptiveMeshRefinement"]["Active"] = False

# mri image
mri_image, _ = ossdbs.load_images(base_input_dict)
# pathway info
pw = ossdbs.point_analysis.Pathway(base_input_dict["PointModel"]["Pathway"]["FileName"])
pw.write_netgen_meshsize_file(
meshsize=min(mri_image.voxel_sizes), filename="meshsizes.txt"
)

# first refinement level: Default
base_input_dict["Mesh"]["MeshingHypothesis"]["Type"] = "Default"
base_input_dict["Mesh"]["MeshingHypothesis"]["MaxMeshSize"] = 1e6
base_input_dict["OutputPath"] = "Results_PAM_default"
electrodes = ossdbs.api.generate_electrodes(base_input_dict)
brain_model = ossdbs.api.build_brain_model(base_input_dict, mri_image)
try:
geometry = ossdbs.ModelGeometry(brain_model, electrodes)
except RuntimeError:
brain_model = ossdbs.api.build_brain_model(
base_input_dict, mri_image, rotate_initial_geo=True
)
geometry = ossdbs.ModelGeometry(brain_model, electrodes)


solver = ossdbs.api.prepare_solver(base_input_dict)
dielectric_properties = ossdbs.api.prepare_dielectric_properties(base_input_dict)
materials = base_input_dict["MaterialDistribution"]["MRIMapping"]
conductivity = ossdbs.ConductivityCF(
mri_image,
brain_model.brain_region,
dielectric_properties,
materials,
geometry.encapsulation_layers,
complex_data=base_input_dict["EQSMode"],
)


with ngsolve.TaskManager():
volume_conductor = ossdbs.api.prepare_volume_conductor_model(
base_input_dict, geometry, conductivity, solver
)
print(volume_conductor.mesh.ngsolvemesh.ne)
print("Save material")
volume_conductor.export_material_distribution_to_vtk()

# refinement level: default and refinement around pathway
base_input_dict["Mesh"]["MeshingHypothesis"]["MeshSizeFilename"] = "meshsizes.txt"
base_input_dict["OutputPath"] = "Results_PAM_default_meshsize"
with ngsolve.TaskManager():
volume_conductor = ossdbs.api.prepare_volume_conductor_model(
base_input_dict, geometry, conductivity, solver
)
print(volume_conductor.mesh.ngsolvemesh.ne)
print("Save material")
volume_conductor.export_material_distribution_to_vtk()
# reset mesh size file name
base_input_dict["Mesh"]["MeshingHypothesis"]["MeshSizeFilename"] = ""


# fourth refinement: material refinement
base_input_dict["OutputPath"] = "Results_PAM_material_refinement"
with ngsolve.TaskManager():
volume_conductor = ossdbs.api.prepare_volume_conductor_model(
base_input_dict, geometry, conductivity, solver
)
# two refinement steps
volume_conductor.refine_mesh_by_material(2)
print(volume_conductor.mesh.ngsolvemesh.ne)
print("Save material")
volume_conductor.export_material_distribution_to_vtk()

# sixth refinement: more edge refinement
base_input_dict["Mesh"]["MeshingHypothesis"]["Type"] = "Default"
lead_diameter = ossdbs.electrodes.default_electrode_parameters[
electrode_name
].lead_diameter
perimeter = np.pi * lead_diameter
edge_size = perimeter / 50.0
print(edge_size)
base_input_dict["Electrodes"][0]["Contacts"][0]["MaxMeshSizeEdge"] = edge_size
base_input_dict["Electrodes"][0]["Contacts"][1]["MaxMeshSizeEdge"] = edge_size
base_input_dict["OutputPath"] = "Results_PAM_fine_edge_refinement"
ossdbs.api.set_contact_and_encapsulation_layer_properties(base_input_dict, geometry)


with ngsolve.TaskManager():
volume_conductor = ossdbs.api.prepare_volume_conductor_model(
base_input_dict, geometry, conductivity, solver
)
geo = volume_conductor.mesh.ngsolvemesh.ngmesh.GetGeometry()
for edge in geo.shape.edges:
print(edge.name, edge.maxh)
print(volume_conductor.mesh.ngsolvemesh.ne)
print("Save material")
volume_conductor.export_material_distribution_to_vtk()
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
{
"BrainRegion": {
"Center": {"x[mm]": 13.5035, "y[mm]": -9.49908, "z[mm]": -9.87216},
"Dimension": {"x[mm]": 60, "y[mm]": 60, "z[mm]": 80},
"Shape": "Ellipsoid"
},
"Electrodes": [
{
"Name": "",
"Rotation[Degrees]": 0.15176099498051523,
"Direction": {
"x[mm]": 0.0,
"y[mm]": 0.0,
"z[mm]": 1.0
},
"TipPosition": {
"x[mm]": 12.956271802141353,
"y[mm]": -9.901870551007098,
"z[mm]": -12.01710780157648
},
"EncapsulationLayer": {
"Thickness[mm]": 0.0,
"Material": "Gray matter",
"DielectricModel": "ColeCole4",
"DielectricParameters": null,
"MaxMeshSize": 0.1
},
"Contacts": [
{
"Contact_ID": 1,
"Active": false,
"Current[A]": 0.0,
"Voltage[V]": 0.0,
"Floating": true,
"SurfaceImpedance[Ohmm]": {"real": 0.0, "imag": 0.0}
},
{
"Contact_ID": 2,
"Active": false,
"Current[A]": 0.012,
"Voltage[V]": 0.0,
"Floating": true,
"SurfaceImpedance[Ohmm]": {"real": 0.0, "imag": 0.0}
},
{
"Contact_ID": 3,
"Active": false,
"Current[A]": -0.004,
"Voltage[V]": 0.0,
"Floating": true,
"SurfaceImpedance[Ohmm]": {"real": 0.0, "imag": 0.0}
},
{
"Contact_ID": 4,
"Active": false,
"Current[A]": -0.008,
"Voltage[V]": 0.0,
"Floating": true,
"SurfaceImpedance[Ohmm]": {"real": 0.0, "imag": 0.0}
}
]
}
],
"Surfaces": [
{"Name": "BrainSurface", "Active": true, "Current[A]": 0.0, "Voltage[V]": 0.0}
],
"MaterialDistribution": {
"MRIPath": "../../PAM/segmask.nii.gz",
"MRIMapping": {
"Blood": 4,
"Gray matter": 1,
"White matter": 2,
"CSF": 3,
"Unknown": 0
},
"DiffusionTensorActive": false,
"DTIPath": ""
},
"DielectricModel": {"Type": "ColeCole4", "CustomParameters": null},
"Mesh": {
"LoadMesh": false,
"LoadPath": "",
"MeshingHypothesis": {"Type": "Default"},
"HPRefinement": {"Active": false, "Levels": 2, "Factor": 0.125},
"AdaptiveMeshRefinement": {
"Active": false,
"MaxIterations": 10,
"ErrorTolerance": 0.1
},
"MeshSize": {"Edges": {}, "Faces": {}, "Volumes": {}},
"SaveMesh": false,
"SavePath": "mesh"
},
"EQSMode": false,
"FEMOrder": 2,
"StimulationSignal": {
"Type": "Rectangle",
"ListOfFrequencies": [10000],
"Frequency[Hz]": 130.0,
"PulseWidth[us]": 30.0,
"PulseTopWidth[us]": 0.0,
"CounterPulseWidth[us]": 0.0,
"InterPulseWidth[us]": 0.0,
"SpectrumMode": "OctaveBand",
"CounterAmplitude": 1.0,
"CutoffFrequency": 250000.0,
"CurrentControlled": true
},
"Solver": {
"Type": "CG",
"Preconditioner": "local",
"PreconditionerKwargs": {},
"MaximumSteps": 5000,
"Precision": 1e-10
},
"PointModel": {
"Pathway": {
"Active": true,
"FileName": "../../PAM/Allocated_axons.h5",
"ExportField": false
},
"Lattice": {
"Active": false,
"Center": {"x[mm]": 0, "y[mm]": 0, "z[mm]": 0},
"Shape": {"x": 10, "y": 10, "z": 10},
"Direction": {"x[mm]": 0, "y[mm]": 0, "z[mm]": 1},
"PointDistance[mm]": 0.1,
"CollapseVTA": false,
"ExportField": false
},
"VoxelLattice": {
"Active": false,
"Shape": {"x": 10, "y": 10, "z": 10},
"TimeDomain": false,
"ExportField": false
}
},
"OutputPath": "Results_rh",
"ComputeImpedance": false,
"ExportVTK": true,
"ExportFrequency": null,
"ExportElectrode": false,
"ModelSide": 0,
"CalcAxonActivation": true,
"ActivationThresholdVTA[V-per-m]": 200.0,
"FailFlag": "rh",
"OutOfCore": false,
"PathwayFile": "../../PAM/Allocated_axons_parameters.json",
"StimSets": {"Active": false, "StimSetsFile": null}
}
Loading
Loading