コード例 #1
0
ファイル: test_feed.py プロジェクト: tbardouille/hnn-core
def test_extfeed():
    """Test the different external feeds."""

    params = Params()
    p_common, p_unique = create_pext(params,
                                     params['tstop'])

    # feed name must be valid and unambiguous
    p_bogus = {'prng_seedcore': 0}
    pytest.raises(ValueError, ExtFeed,
                  'invalid_feed', None, p_bogus, 0)
    pytest.raises(ValueError, ExtFeed,
                  'ev', None, p_bogus, 0)  # ambiguous

    # XXX 'unique' external feeds are always created; why?
    for feed_type in ['extpois', 'extgauss']:
        feed = ExtFeed(feed_type=feed_type,
                       target_cell_type='L2_basket',
                       params=p_unique[feed_type],
                       gid=0)
        print(feed)  # test repr
    # XXX but 'common' (rhythmic) feeds are not
    for ii in range(len(p_common)):  # len == 0 for def. params
        feed = ExtFeed(feed_type='common',
                       target_cell_type=None,
                       params=p_common[ii],
                       gid=0)
        print(feed)  # test repr
コード例 #2
0
ファイル: test_compare_hnn.py プロジェクト: bloyl/hnn-core
def test_hnn_core():
    """Test to check if MNE neuron does not break."""
    # small snippet of data on data branch for now. To be deleted
    # later. Data branch should have only commit so it does not
    # pollute the history.
    data_url = ('https://raw.githubusercontent.com/hnnsolver/'
                'hnn-core/test_data/dpl.txt')
    if not op.exists('dpl.txt'):
        _fetch_file(data_url, 'dpl.txt')
    dpl_master = loadtxt('dpl.txt')

    hnn_core_root = op.join(op.dirname(hnn_core.__file__), '..')

    params_fname = op.join(hnn_core_root, 'param', 'default.json')
    params = Params(params_fname)

    net = Network(params, n_jobs=1)
    dpl = simulate_dipole(net)[0]

    fname = './dpl2.txt'
    dpl.write(fname)

    dpl_pr = loadtxt(fname)
    assert_array_equal(dpl_pr[:, 2], dpl_master[:, 2])  # L2
    assert_array_equal(dpl_pr[:, 3], dpl_master[:, 3])  # L5
コード例 #3
0
def test_params():
    """Test params object."""
    hnn_core_root = op.join(op.dirname(hnn_core.__file__), '..')
    params_fname = op.join(hnn_core_root, 'param', 'default.json')
    params = Params(params_fname)
    print(params)
    print(params['L2Pyr*'])
コード例 #4
0
ファイル: test_network.py プロジェクト: bloyl/hnn-core
def test_network():
    """Test network object."""
    hnn_core_root = op.join(op.dirname(hnn_core.__file__), '..')
    params_fname = op.join(hnn_core_root, 'param', 'default.json')
    params = Params(params_fname)
    net = Network(deepcopy(params))
    for p in params:
        assert params[p] == net.params[p]
    assert len(params) == len(net.params)
    print(net)
    print(net.cells[:2])
コード例 #5
0
ファイル: test_params.py プロジェクト: tbardouille/hnn-core
def test_base_params():
    """Test default params object matches base params"""
    param_url = ('https://raw.githubusercontent.com/jonescompneurolab/'
                 'hnn-core/test_data/base.json')
    params_base_fname = op.join(hnn_core_root, 'param', 'base.json')
    if not op.exists(params_base_fname):
        _fetch_file(param_url, params_base_fname)

    params_base = read_params(params_base_fname)
    params = Params()
    assert params == params_base
コード例 #6
0
ファイル: test_dipole.py プロジェクト: bloyl/hnn-core
def test_dipole():
    """Test params object."""
    hnn_core_root = op.join(op.dirname(hnn_core.__file__), '..')
    params_fname = op.join(hnn_core_root, 'param', 'default.json')
    params = Params(params_fname)

    times = np.random.random(6000)
    data = np.random.random((6000, 3))
    dipole = Dipole(times, data)
    dipole.baseline_renormalize(params)
    dipole.convert_fAm_to_nAm()
    dipole.scale(params['dipole_scalefctr'])
    dipole.smooth(params['dipole_smooth_win'] / params['dt'])
    dipole.plot(layer='agg')
    dipole.write('/tmp/dpl1.txt')
コード例 #7
0
def test_base_params():
    """Test params object with base params"""
    param_url = ('https://raw.githubusercontent.com/jonescompneurolab/'
                 'hnn-core/test_data/base.json')
    params_base_fname = op.join(hnn_core_root, 'param', 'base.json')
    if not op.exists(params_base_fname):
        _fetch_file(param_url, params_base_fname)

    params_base = read_params(params_base_fname)
    params = Params()
    assert params == params_base

    # unsupported extension
    pytest.raises(ValueError, read_params, 'params.txt')
    # empty file
    empty_fname = op.join(hnn_core_root, 'param', 'empty.json')
    with open(empty_fname, 'w') as json_data:
        json.dump({}, json_data)
    pytest.raises(ValueError, read_params, empty_fname)
    # non dict type
    pytest.raises(ValueError, Params, [])
    pytest.raises(ValueError, Params, 'sdfdfdf')
コード例 #8
0
top=Inches(0.25)
height = Inches(7)
width=Inches(10)
prs = Presentation()
title_slide_layout = prs.slide_layouts[0]
slide = prs.slides.add_slide(title_slide_layout)
title = slide.shapes.title
subtitle = slide.placeholders[1]
title.text = "NEW (r) fits"
subtitle.text = "plot_from_hnn.py"

#-------------------------------------
# get default
#-------------------------------------
dict_param=m.get_dict_param(my_param_out_dir,'default_Sarah')
default_params=Params(dict_param)
net_default = Network(default_params)
dpls_default = simulate_dipole(net_default, n_trials=1)


# time delay
delays=[0,2,4,6,8,10,15,20,30,40,50,60,70,80,100,120,140,160,180,200,220,240,250,300,400,500,600]#[50, 100, 150, 200, 300, 400, 500, 600]
delayed_input_type=['default_Sarah']#,'Supra_ERPYesSupraT']# also try triple later?

## pick a param file and tripple those inputs
param_files=['default_Sarah']#,'Supra_ERPYesSupraT']
add10=False
triple_pulse=False
    
    
keep_dpls=[]
コード例 #9
0
def test_external_drive_times():
    """Test the different external drives."""

    params = Params()
    p_common, p_unique = create_pext(params, params['tstop'])

    # drive name must be valid and unambiguous
    p_bogus = {'prng_seedcore': 0}
    pytest.raises(ValueError, drive_event_times, 'invalid_drive', None,
                  p_bogus, 0)
    pytest.raises(ValueError, drive_event_times, 'ev', None, p_bogus,
                  0)  # ambiguous

    # 'unique' external drives are always created
    for drive_type in ['extpois', 'extgauss']:
        event_times = drive_event_times(drive_type=drive_type,
                                        target_cell_type='L2_basket',
                                        params=p_unique[drive_type],
                                        gid=0)

    # but 'common' (rhythmic) drives are not
    for ii in range(len(p_common)):  # len == 0 for def. params
        event_times = drive_event_times(drive_type='common',
                                        target_cell_type=None,
                                        params=p_common[ii],
                                        gid=0)
        # parameters should lead to 0 input spikes for default params
        assert len(event_times) == 0
        # check that ei.p_ext matches params
        loc = p_common[ii]['loc'][:4]  # loc=prox or dist
        for layer in ['L2', 'L5']:
            key = 'input_{}_A_weight_{}Pyr_ampa'.format(loc, layer)
            assert p_common[ii][layer + 'Pyr_ampa'][0] == params[key]

    # validate poisson input time interval
    p_extpois = p_unique['extpois']
    p_extpois['L2_basket'] = (1., 1., 0., 0.)
    with pytest.raises(ValueError, match='The end time for Poisson input'):
        p_extpois['t_interval'] = (p_extpois['t_interval'][0], -1)
        event_times = drive_event_times(drive_type='extpois',
                                        target_cell_type='L2_basket',
                                        params=p_extpois,
                                        gid=0)
    with pytest.raises(ValueError, match='The start time for Poisson'):
        p_extpois['t_interval'] = (-1, 5)
        event_times = drive_event_times(drive_type='extpois',
                                        target_cell_type='L2_basket',
                                        params=p_extpois,
                                        gid=0)

    # checks the poisson spike train generation
    prng = np.random.RandomState()
    lamtha = 50.
    event_times = _create_extpois(t0=0, T=100000, lamtha=lamtha, prng=prng)
    event_intervals = np.diff(event_times)
    assert pytest.approx(event_intervals.mean(), abs=1.) == 1000 * 1 / lamtha

    with pytest.raises(ValueError, match='The start time for Poisson'):
        _create_extpois(t0=-5, T=5, lamtha=lamtha, prng=prng)
    with pytest.raises(ValueError, match='The end time for Poisson'):
        _create_extpois(t0=50, T=20, lamtha=lamtha, prng=prng)
    with pytest.raises(ValueError, match='Rate must be > 0'):
        _create_extpois(t0=0, T=1000, lamtha=-5, prng=prng)

    # check "common" input
    t0 = 0
    t0_stdev = 5
    tstop = 100
    f_input = 20.
    events_per_cycle = 3
    cycle_events_isi = 7
    events_jitter_std = 5.
    repeats = 2
    prng, prng2 = _get_prng(seed=0, gid=5, sync_evinput=False)
    with pytest.raises(ValueError, match='distribution not recognized'):
        _create_bursty_input(distribution='blah',
                             t0=t0,
                             t0_stdev=t0_stdev,
                             tstop=tstop,
                             f_input=f_input,
                             events_jitter_std=events_jitter_std,
                             repeats=repeats,
                             prng=prng,
                             prng2=prng2)
    event_times = _create_bursty_input(distribution='normal',
                                       t0=t0,
                                       t0_stdev=t0_stdev,
                                       tstop=tstop,
                                       f_input=f_input,
                                       events_jitter_std=events_jitter_std,
                                       events_per_cycle=events_per_cycle,
                                       cycle_events_isi=cycle_events_isi,
                                       repeats=repeats,
                                       prng=prng,
                                       prng2=prng2)

    events_per_cycle = 5
    cycle_events_isi = 20
    with pytest.raises(ValueError,
                       match=r'Burst duration (?s).* cannot be greater than'):
        _create_bursty_input(distribution='normal',
                             t0=t0,
                             t0_stdev=t0_stdev,
                             tstop=tstop,
                             f_input=f_input,
                             events_jitter_std=events_jitter_std,
                             events_per_cycle=events_per_cycle,
                             cycle_events_isi=cycle_events_isi,
                             repeats=repeats,
                             prng=prng,
                             prng2=prng2)
コード例 #10
0
slide = prs.slides.add_slide(title_slide_layout)
title = slide.shapes.title
subtitle = slide.placeholders[1]
title.text = "NEW (r) fits"
subtitle.text = "plot_from_hnn.py"


## pick a param file and tripple those inputs
param_files=['default']#,'Supra_ERPYesSupraT']
add10=True
    
for p in param_files:
    dict_param=m.get_dict_param(my_param_out_dir,p)
    base_params=[]
    these_params=[]
    base_params = Params(dict_param)
    these_params=Params(dict_param)

    #adjust params for sarah's model (don't have a base for supra)
    if OG_HNN==False:
        #find where sarah and default are different
        param_to_comp=['thesis_erp_100%','default']
        dict_param=m.get_dict_param(my_param_out_dir,param_to_comp[0])
        comp1=Params(dict_param)
        dict_param=m.get_dict_param(my_param_out_dir,param_to_comp[1])
        comp2=Params(dict_param)
          
        paramoi=[]
        for pt in comp1:
            if comp1[pt]!= comp2[pt]:
                paramoi.append(pt)
コード例 #11
0
#          Sam Neymotin <*****@*****.**>

import os.path as op

###############################################################################
# Let us import hnn_core

import hnn_core
from hnn_core import simulate_dipole, Params, Network

hnn_core_root = op.join(op.dirname(hnn_core.__file__), '..')

###############################################################################
# Then we read the parameters file
params_fname = op.join(hnn_core_root, 'param', 'default.json')
params = Params(params_fname)
print(params)

###############################################################################
# This is a lot of parameters! We can also filter the
# parameters using unix-style wildcard characters
print(params['L2Pyr_soma*'])

###############################################################################
# Now let's simulate the dipole
# You can simulate multiple trials in parallel by using n_jobs > 1
net = Network(params)
dpls = simulate_dipole(net, n_jobs=1, n_trials=2)

###############################################################################
# and then plot it
コード例 #12
0
ファイル: plot_simulate_alpha.py プロジェクト: bloyl/hnn-core
import os.path as op

###############################################################################
# Let us import hnn_core

import hnn_core
from hnn_core import simulate_dipole, Params, Network

###############################################################################
# Then we setup the directories and Neuron
hnn_core_root = op.join(op.dirname(hnn_core.__file__), '..')

###############################################################################
# Then we read the default parameters file
params_fname = op.join(hnn_core_root, 'param', 'default.json')
params = Params(params_fname)
print(params)

###############################################################################
# Now, we update a few parameters
params.update({
    'dipole_scalefctr': 150000.0,
    'dipole_smooth_win': 0,
    'tstop': 710.0,
    't0_input_prox': 2000.0,
    'tstop_input_prox': 710.0,
    't0_input_dist': 50.0,
    'tstop_input_dist': 1001.0,
    't_evprox_1': 1000,
    'sigma_t_evprox_1': 2.5,
    't_evprox_2': 2000.0,
コード例 #13
0
plt.figure()
plt.plot(1e3 * stc.times, stc.data[pick_vertex, :].T * 1e9, 'ro-')
plt.xlabel('time (ms)')
plt.ylabel('%s value (nAM)' % method)
plt.xlim((0, 150))
plt.axhline(0)
plt.show()

###############################################################################
# Now, let us try to simulate the same with MNE-neuron

import os.path as op

import hnn_core
from hnn_core import simulate_dipole, Params, Network

hnn_core_root = op.join(op.dirname(hnn_core.__file__), '..')

params_fname = op.join(hnn_core_root, 'param', 'N20.json')
params = Params(params_fname)

net = Network(params)
dpl = simulate_dipole(net)

import matplotlib.pyplot as plt
fig, axes = plt.subplots(2, 1, sharex=True, figsize=(6, 6))
dpl[0].plot(ax=axes[0])
net.plot_input(ax=axes[1])
net.plot_spikes()
コード例 #14
0
prs = Presentation()
title_slide_layout = prs.slide_layouts[0]
slide = prs.slides.add_slide(title_slide_layout)
title = slide.shapes.title
subtitle = slide.placeholders[1]
title.text = "TEP Predictions GUI"
subtitle.text = "plot_tep_predictions_from_gui.py"

#-------------------------------------
# get default
#-------------------------------------
if supra:
    dict_param=m.get_dict_param(my_param_out_dir,'supra_Sarah')
else:
    dict_param=m.get_dict_param(my_param_out_dir,'default_Sarah')
default_params=Params(dict_param)
net_default = Network(default_params)
dpls_default = simulate_dipole(net_default, n_trials=1)
# m.core_output_basic(dpls_default,net,name,False,False,True, False)

all_times=[0, 1, 2, 3, 4, 5, 6, 7, 10, 12, 15, 20, 40, 60, 80, 100, 120, 140, 160, 180, 200, 220, 240, 280, 300, 340, 400]

for time_i in all_times:
    if supra:
        file_dir='TEPpred_supra_Sarah_2_'+str(time_i)+'ms'
        name='suprax2 delay:'+str(time_i)+'ms'
    else:
        file_dir='TEPpred_degfault_Sarah_2_'+str(time_i)+'ms'
        name='defaultx2 delay:'+str(time_i)+'ms'
    dict_param=m.get_dict_param(my_param_out_dir,file_dir)
    these_params=[]