-
Notifications
You must be signed in to change notification settings - Fork 4
/
om_basics.py
45 lines (38 loc) · 1.33 KB
/
om_basics.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
"""
Created on Mon Nov 25 2013.
@author: - E. Olivi
"""
import openmeeg as om
from os import path as op
def load_headmodel(name, prefix='data'):
"""Load a headmodel.
read the geometry, conductivities and sources
eventually.
"""
cond_file = op.join(prefix, name, name + '.cond')
geom_file = op.join(prefix, name, name + '.geom')
patches_file = op.join(prefix, name, name + '.patches')
dip_file = op.join(prefix, name, name + '.dip')
tdcs_file = op.join(prefix, name, name + '.hdtdcs')
pot_file = op.join(prefix, name, name + '.pot')
geom = om.Geometry()
geom.read(str(geom_file), str(cond_file))
sensors = om.Sensors()
sensors.load(str(patches_file))
model = {'geometry': geom, 'sensors': sensors}
if op.exists(dip_file):
dipoles = om.Matrix(str(dip_file))
model['dipsources'] = dipoles
if op.exists(tdcs_file):
tdcs = om.Sensors(str(tdcs_file), geom)
model['tdcssources'] = tdcs
if op.exists(pot_file):
pot = om.Matrix(str(pot_file))
model['potentials'] = pot
return model
def forward_problem(m):
"""Compute a Forward problem given a model with geometry and sources."""
hm = om.HeadMat(m['geometry'])
hm.invert() # invert in place (no copy)
dsm = om.DipSourceMat(m['geometry'], m['dipsources'])
return hm * dsm