In [6]:
import numpy as np
import casadi as ca
import matplotlib.pyplot as plt
import pickle as pc
import time
import sys
import getopt
sys.path.insert(1,'../src')
from setData import data_in
from setInvProb import data_out
from setOptProb import opt_out
from setVisualization import visualize

We start by adding some data from an hdf file. You will also need the python package h5py. The data object keeps the loaded data, electrode geometry, ground truth, and offers some pre-processing functions.


In [ ]:
# Data path/filename
t_ind = 38
data_path = '../data/'
file_name = data_path + 'data_sim_low.hdf5'

data_options = {'flag_cell': True, 'flag_electode': False}
data = data_in(file_name, **data_options)

Next we define the inverse problem parameters as a dictionary. Parameter's not specified will be filled with default values.


In [ ]:
localization_options = {'p_vres':20, 'p_jlen':0, 'p_erad': 5, 't_ind': 38, 'flag_depthweighted': False}
loc = data_out(data, **localization_options)

Now we are ready to use different source localization methods.


In [ ]:
loc.cmp_sloreta()

And visualize the results


In [ ]:
loc.xres = loc.res[:, t_ind]
vis = visualize(data=data, loc=loc)
vis.show_snapshot()

Alternatively we can use the optimization methods built on top of CasADi package. And initialize the problem.


In [ ]:
optimization_options = {'p_vres':10, 'p_jlen':0, 'p_erad': 10,
                        'solver': p_solver,
                        'hessian': p_hessian,
                        'linsol': p_linsol,
                        'method': p_method,
                        't_ind': 35, 't_int': 1, 
                        'sigma': float(p_sparse),
                        'flag_depthweighted': bool(int(p_norm)),
                        'flag_parallel': False,
                        'datafile_name': 'output_file',
                        'flag_lift_mask': False,
                        'flag_data_mask': True,
                        'flag_callback': True,
                        'flag_callback_plot': True,
                        'callback_steps': 40,
                        'p_dyn': float(p_dynamic)
                        }
opt = opt_out(data, **optimization_options)

And use the optimization method as described in the thesis "Source localization for high-density microelectrode arrays" by Cem Uran.


In [ ]:
opt.set_optimization_variables_thesis()