Ejemplo n.º 1
0
def test_dipole_visualization():
    """Test dipole visualisations."""
    hnn_core_root = op.dirname(hnn_core.__file__)
    params_fname = op.join(hnn_core_root, 'param', 'default.json')
    params = read_params(params_fname)
    params.update({'N_pyr_x': 3,
                   'N_pyr_y': 3,
                   'tstop': 100.})
    net = Network(params)
    weights_ampa_p = {'L2_pyramidal': 5.4e-5, 'L5_pyramidal': 5.4e-5}
    syn_delays_p = {'L2_pyramidal': 0.1, 'L5_pyramidal': 1.}

    net.add_bursty_drive(
        'beta_prox', tstart=0., burst_rate=25, burst_std=5,
        numspikes=1, spike_isi=0, repeats=11, location='proximal',
        weights_ampa=weights_ampa_p, synaptic_delays=syn_delays_p, seedcore=14)

    dpls = simulate_dipole(net, n_trials=2, postproc=False)
    fig = dpls[0].plot()  # plot the first dipole alone
    axes = fig.get_axes()[0]
    dpls[0].copy().smooth(window_len=10).plot(ax=axes)  # add smoothed versions
    dpls[0].copy().savgol_filter(h_freq=30).plot(ax=axes)  # on top

    # test decimation options
    plot_dipole(dpls[0], decim=2)
    for dec in [-1, [2, 2.]]:
        with pytest.raises(ValueError,
                           match='each decimation factor must be a positive'):
            plot_dipole(dpls[0], decim=dec)

    # test plotting multiple dipoles as overlay
    fig = plot_dipole(dpls)

    # multiple TFRs get averaged
    fig = plot_tfr_morlet(dpls, freqs=np.arange(23, 26, 1.), n_cycles=3)

    with pytest.raises(RuntimeError,
                       match="All dipoles must be scaled equally!"):
        plot_dipole([dpls[0].copy().scale(10), dpls[1].copy().scale(20)])
    with pytest.raises(RuntimeError,
                       match="All dipoles must be scaled equally!"):
        plot_psd([dpls[0].copy().scale(10), dpls[1].copy().scale(20)])
    with pytest.raises(RuntimeError,
                       match="All dipoles must be sampled equally!"):
        dpl_sfreq = dpls[0].copy()
        dpl_sfreq.sfreq /= 10
        plot_psd([dpls[0], dpl_sfreq])
Ejemplo n.º 2
0
def test_add_drives():
    """Test methods for adding drives to a Network."""
    hnn_core_root = op.dirname(hnn_core.__file__)
    params_fname = op.join(hnn_core_root, 'param', 'default.json')
    params = read_params(params_fname)
    net = Network(params, legacy_mode=False)
    net.add_evoked_drive('early_distal',
                         mu=10,
                         sigma=1,
                         numspikes=1,
                         location='distal')

    # evoked
    with pytest.raises(ValueError,
                       match='Standard deviation cannot be negative'):
        net.add_evoked_drive('evdist1',
                             mu=10,
                             sigma=-1,
                             numspikes=1,
                             location='distal')
    with pytest.raises(ValueError,
                       match='Number of spikes must be greater than zero'):
        net.add_evoked_drive('evdist1',
                             mu=10,
                             sigma=1,
                             numspikes=0,
                             location='distal')

    # Test Network._attach_drive()
    with pytest.raises(ValueError,
                       match=r'Allowed drive target locations are'):
        net.add_evoked_drive('evdist1',
                             mu=10,
                             sigma=1,
                             numspikes=1,
                             location='bogus_location')
    with pytest.raises(ValueError, match='Drive early_distal already defined'):
        net.add_evoked_drive('early_distal',
                             mu=10,
                             sigma=1,
                             numspikes=1,
                             location='distal')

    # Poisson
    with pytest.raises(ValueError,
                       match='End time of Poisson drive cannot be negative'):
        net.add_poisson_drive('tonic_drive',
                              tstart=0,
                              tstop=-1,
                              location='distal',
                              rate_constant=10.)
    with pytest.raises(ValueError,
                       match='Start time of Poisson drive cannot be negative'):
        net.add_poisson_drive('tonic_drive',
                              tstart=-1,
                              location='distal',
                              rate_constant=10.)
    with pytest.raises(ValueError,
                       match='Duration of Poisson drive cannot be negative'):
        net.add_poisson_drive('tonic_drive',
                              tstart=10,
                              tstop=1,
                              location='distal',
                              rate_constant=10.)
    with pytest.raises(ValueError,
                       match='End time of Poisson drive cannot exceed'):
        net.add_poisson_drive('tonic_drive',
                              tstop=params['tstop'] + 1,
                              location='distal',
                              rate_constant=10.)
    with pytest.raises(ValueError, match='Rate constant must be positive'):
        net.add_poisson_drive('tonic_drive',
                              location='distal',
                              rate_constant=0.)

    with pytest.raises(ValueError,
                       match='Rate constants not provided for all target'):
        net.add_poisson_drive('tonic_drive',
                              location='distal',
                              rate_constant={'L2_pyramidal': 10.},
                              weights_ampa={'L5_pyramidal': .01})
    with pytest.raises(ValueError,
                       match='Rate constant provided for unknown target cell'):
        net.add_poisson_drive('tonic_drive',
                              location='distal',
                              rate_constant={
                                  'L2_pyramidal': 10.,
                                  'bogus_celltype': 20.
                              })
    # bursty
    with pytest.raises(ValueError,
                       match='End time of bursty drive cannot be negative'):
        net.add_bursty_drive('bursty_drive',
                             tstop=-1,
                             location='distal',
                             burst_rate=10)
    with pytest.raises(ValueError,
                       match='Start time of bursty drive cannot be negative'):
        net.add_bursty_drive('bursty_drive',
                             tstart=-1,
                             location='distal',
                             burst_rate=10)
    with pytest.raises(ValueError,
                       match='Duration of bursty drive cannot be negative'):
        net.add_bursty_drive('bursty_drive',
                             tstart=10,
                             tstop=1,
                             location='distal',
                             burst_rate=10)
    with pytest.raises(ValueError,
                       match='End time of bursty drive cannot exceed'):
        net.add_bursty_drive('bursty_drive',
                             tstop=params['tstop'] + 1,
                             location='distal',
                             burst_rate=10)

    msg = (r'Burst duration (?s).* cannot be greater than ' 'burst period')
    with pytest.raises(ValueError, match=msg):
        net.add_bursty_drive('bursty_drive',
                             location='distal',
                             burst_rate=10,
                             burst_std=20.,
                             numspikes=4,
                             spike_isi=50)

    # attaching drives
    with pytest.raises(ValueError, match='Drive early_distal already defined'):
        net.add_poisson_drive('early_distal',
                              location='distal',
                              rate_constant=10.)
    with pytest.raises(ValueError,
                       match='Allowed drive target locations are:'):
        net.add_poisson_drive('weird_poisson',
                              location='inbetween',
                              rate_constant=10.)
    with pytest.raises(ValueError,
                       match='Allowed drive target cell types are:'):
        net.add_poisson_drive('cell_unknown',
                              location='proximal',
                              rate_constant=10.,
                              weights_ampa={'CA1_pyramidal': 1.})
    with pytest.raises(ValueError,
                       match='synaptic_delays is either a common float or '
                       'needs to be specified as a dict for each cell'):
        net.add_poisson_drive('cell_unknown',
                              location='proximal',
                              rate_constant=10.,
                              weights_ampa={'L2_pyramidal': 1.},
                              synaptic_delays={'L5_pyramidal': 1.})
Ejemplo n.º 3
0
def test_add_drives():
    """Test methods for adding drives to a Network."""
    hnn_core_root = op.dirname(hnn_core.__file__)
    params_fname = op.join(hnn_core_root, 'param', 'default.json')
    params = read_params(params_fname)
    net = Network(params, legacy_mode=False)

    # Ensure weights and delays are updated
    weights_ampa = {'L2_basket': 1.0, 'L2_pyramidal': 3.0, 'L5_pyramidal': 4.0}
    syn_delays = {'L2_basket': 1.0, 'L2_pyramidal': 2.0, 'L5_pyramidal': 4.0}

    n_drive_cells = 10
    cell_specific = False  # default for bursty drive
    net.add_bursty_drive(
        'bursty', location='distal', burst_rate=10,
        weights_ampa=weights_ampa, synaptic_delays=syn_delays,
        n_drive_cells=n_drive_cells)

    assert net.external_drives['bursty']['n_drive_cells'] == n_drive_cells
    assert net.external_drives['bursty']['cell_specific'] == cell_specific
    conn_idxs = pick_connection(net, src_gids='bursty')
    for conn_idx in conn_idxs:
        drive_conn = net.connectivity[conn_idx]
        target_type = drive_conn['target_type']
        assert drive_conn['nc_dict']['A_weight'] == weights_ampa[target_type]
        assert drive_conn['nc_dict']['A_delay'] == syn_delays[target_type]

    n_drive_cells = 'n_cells'  # default for evoked drive
    cell_specific = True
    net.add_evoked_drive(
        'evoked_dist', mu=1.0, sigma=1.0, numspikes=1.0,
        weights_ampa=weights_ampa, location='distal',
        synaptic_delays=syn_delays, cell_specific=True)

    n_dist_targets = 235  # 270 with legacy mode
    assert (net.external_drives['evoked_dist']
                               ['n_drive_cells'] == n_dist_targets)
    assert net.external_drives['evoked_dist']['cell_specific'] == cell_specific
    conn_idxs = pick_connection(net, src_gids='evoked_dist')
    for conn_idx in conn_idxs:
        drive_conn = net.connectivity[conn_idx]
        target_type = drive_conn['target_type']
        assert drive_conn['nc_dict']['A_weight'] == weights_ampa[target_type]
        assert drive_conn['nc_dict']['A_delay'] == syn_delays[target_type]

    n_drive_cells = 'n_cells'  # default for poisson drive
    cell_specific = True
    net.add_poisson_drive(
        'poisson', rate_constant=1.0, weights_ampa=weights_ampa,
        location='distal', synaptic_delays=syn_delays,
        cell_specific=cell_specific)

    n_dist_targets = 235  # 270 with non-legacy mode
    assert (net.external_drives['poisson']
                               ['n_drive_cells'] == n_dist_targets)
    assert net.external_drives['poisson']['cell_specific'] == cell_specific
    conn_idxs = pick_connection(net, src_gids='poisson')
    for conn_idx in conn_idxs:
        drive_conn = net.connectivity[conn_idx]
        target_type = drive_conn['target_type']
        assert drive_conn['nc_dict']['A_weight'] == weights_ampa[target_type]
        assert drive_conn['nc_dict']['A_delay'] == syn_delays[target_type]

    # evoked
    with pytest.raises(ValueError,
                       match='Standard deviation cannot be negative'):
        net.add_evoked_drive('evdist1', mu=10, sigma=-1, numspikes=1,
                             location='distal')
    with pytest.raises(ValueError,
                       match='Number of spikes must be greater than zero'):
        net.add_evoked_drive('evdist1', mu=10, sigma=1, numspikes=0,
                             location='distal')

    # Test Network._attach_drive()
    with pytest.raises(ValueError,
                       match=r'Allowed drive target locations are'):
        net.add_evoked_drive('evdist1', mu=10, sigma=1, numspikes=1,
                             location='bogus_location')
    with pytest.raises(ValueError,
                       match='Drive evoked_dist already defined'):
        net.add_evoked_drive('evoked_dist', mu=10, sigma=1, numspikes=1,
                             location='distal')
    with pytest.raises(ValueError,
                       match='No target cell types have been given a synaptic '
                       'weight'):
        net.add_evoked_drive('evdist1', mu=10, sigma=1, numspikes=1,
                             location='distal')
    with pytest.raises(ValueError,
                       match='When adding a distal drive, synaptic weight '
                       'cannot be defined for the L5_basket cell type'):
        net.add_evoked_drive('evdist1', mu=10, sigma=1, numspikes=1,
                             location='distal', weights_ampa={'L5_basket': 1.},
                             synaptic_delays={'L5_basket': .1})
    with pytest.raises(ValueError,
                       match='If cell_specific is True, n_drive_cells'):
        net.add_evoked_drive('evdist1', mu=10, sigma=1, numspikes=1,
                             location='distal', n_drive_cells=10,
                             cell_specific=True, weights_ampa=weights_ampa,
                             synaptic_delays=syn_delays)
    with pytest.raises(ValueError,
                       match='If cell_specific is False, n_drive_cells'):
        net.add_evoked_drive('evdist1', mu=10, sigma=1, numspikes=1,
                             location='distal', n_drive_cells='n_cells',
                             cell_specific=False, weights_ampa=weights_ampa,
                             synaptic_delays=syn_delays)
    with pytest.raises(ValueError,
                       match='Number of drive cells must be greater than 0'):
        net.add_evoked_drive('evdist1', mu=10, sigma=1, numspikes=1,
                             location='distal', n_drive_cells=0,
                             cell_specific=False, weights_ampa=weights_ampa,
                             synaptic_delays=syn_delays)

    # Poisson
    with pytest.raises(ValueError,
                       match='End time of Poisson drive cannot be negative'):
        net.add_poisson_drive('poisson1', tstart=0, tstop=-1,
                              location='distal', rate_constant=10.)
    with pytest.raises(ValueError,
                       match='Start time of Poisson drive cannot be negative'):
        net.add_poisson_drive('poisson1', tstart=-1,
                              location='distal', rate_constant=10.)
    with pytest.raises(ValueError,
                       match='Duration of Poisson drive cannot be negative'):
        net.add_poisson_drive('poisson1', tstart=10, tstop=1,
                              location='distal', rate_constant=10.)
    with pytest.raises(ValueError,
                       match='Rate constant must be positive'):
        net.add_poisson_drive('poisson1', location='distal',
                              rate_constant=0.,
                              weights_ampa=weights_ampa,
                              synaptic_delays=syn_delays)

    with pytest.raises(ValueError,
                       match='Rate constants not provided for all target'):
        net.add_poisson_drive('poisson1', location='distal',
                              rate_constant={'L2_pyramidal': 10.},
                              weights_ampa=weights_ampa,
                              synaptic_delays=syn_delays)
    with pytest.raises(ValueError,
                       match='Rate constant provided for unknown target cell'):
        net.add_poisson_drive('poisson1', location='distal',
                              rate_constant={'L2_pyramidal': 10.,
                                             'bogus_celltype': 20.},
                              weights_ampa={'L2_pyramidal': .01,
                                            'bogus_celltype': .01},
                              synaptic_delays=0.1)

    with pytest.raises(ValueError,
                       match='Drives specific to cell types are only '
                       'possible with cell_specific=True'):
        net.add_poisson_drive('poisson1', location='distal',
                              rate_constant={'L2_basket': 10.,
                                             'L2_pyramidal': 11.,
                                             'L5_basket': 12.,
                                             'L5_pyramidal': 13.},
                              n_drive_cells=1, cell_specific=False,
                              weights_ampa=weights_ampa,
                              synaptic_delays=syn_delays)

    # bursty
    with pytest.raises(ValueError,
                       match='End time of bursty drive cannot be negative'):
        net.add_bursty_drive('bursty_drive', tstop=-1,
                             location='distal', burst_rate=10)
    with pytest.raises(ValueError,
                       match='Start time of bursty drive cannot be negative'):
        net.add_bursty_drive('bursty_drive', tstart=-1,
                             location='distal', burst_rate=10)
    with pytest.raises(ValueError,
                       match='Duration of bursty drive cannot be negative'):
        net.add_bursty_drive('bursty_drive', tstart=10, tstop=1,
                             location='distal', burst_rate=10)

    msg = (r'Burst duration (?s).* cannot be greater than '
           'burst period')
    with pytest.raises(ValueError, match=msg):
        net.add_bursty_drive('bursty_drive', location='distal',
                             burst_rate=10, burst_std=20., numspikes=4,
                             spike_isi=50)

    # attaching drives
    with pytest.raises(ValueError,
                       match='Drive evoked_dist already defined'):
        net.add_poisson_drive('evoked_dist', location='distal',
                              rate_constant=10.,
                              weights_ampa=weights_ampa,
                              synaptic_delays=syn_delays)
    with pytest.raises(ValueError,
                       match='Allowed drive target locations are:'):
        net.add_poisson_drive('weird_poisson', location='inbetween',
                              rate_constant=10.,
                              weights_ampa=weights_ampa,
                              synaptic_delays=syn_delays)
    with pytest.raises(ValueError,
                       match='Allowed drive target cell types are:'):
        net.add_poisson_drive('cell_unknown', location='proximal',
                              rate_constant=10.,
                              weights_ampa={'CA1_pyramidal': 1.},
                              synaptic_delays=.01)
    with pytest.raises(ValueError,
                       match='synaptic_delays is either a common float or '
                       'needs to be specified as a dict for each of the cell'):
        net.add_poisson_drive('cell_unknown', location='proximal',
                              rate_constant=10.,
                              weights_ampa={'L2_pyramidal': 1.},
                              synaptic_delays={'L5_pyramidal': 1.})
Ejemplo n.º 4
0
# time with unique randomization. The drive is only connected to the proximal
# (dendritic) AMPA synapses on L2/3 and L5 pyramidal neurons.
params['tstop'] = 310
net = Network(params)

location = 'proximal'
burst_std = 20
weights_ampa_p = {'L2_pyramidal': 5.4e-5, 'L5_pyramidal': 5.4e-5}
syn_delays_p = {'L2_pyramidal': 0.1, 'L5_pyramidal': 1.}

net.add_bursty_drive('alpha_prox',
                     tstart=50.,
                     burst_rate=10,
                     burst_std=burst_std,
                     numspikes=2,
                     spike_isi=10,
                     repeats=10,
                     location=location,
                     weights_ampa=weights_ampa_p,
                     synaptic_delays=syn_delays_p,
                     seedcore=14)

# simulate the dipole, but do not automatically scale or smooth the result
dpl = simulate_dipole(net, n_trials=1, postproc=False)

trial_idx = 0  # single trial simulated, choose the first index
# to emulate a larger patch of cortex, we can apply a simple scaling factor
dpl[trial_idx].scale(3000)

###############################################################################
# Prior to plotting, we can choose to smooth the dipole waveform (note that the
Ejemplo n.º 5
0
def test_add_drives():
    """Test methods for adding drives to a Network."""
    hnn_core_root = op.dirname(hnn_core.__file__)
    params_fname = op.join(hnn_core_root, 'param', 'default.json')
    params = read_params(params_fname)
    net = Network(params, legacy_mode=False)

    # Ensure weights and delays are updated
    weights_ampa = {'L2_basket': 1.0, 'L2_pyramidal': 3.0, 'L5_pyramidal': 4.0}
    syn_delays = {'L2_basket': 1.0, 'L2_pyramidal': 2.0, 'L5_pyramidal': 4.0}

    n_drive_cells = 10
    cell_specific = False  # default for bursty drive
    net.add_bursty_drive('bursty',
                         location='distal',
                         burst_rate=10,
                         weights_ampa=weights_ampa,
                         synaptic_delays=syn_delays,
                         n_drive_cells=n_drive_cells)

    assert net.external_drives['bursty']['n_drive_cells'] == n_drive_cells
    assert net.external_drives['bursty']['cell_specific'] == cell_specific
    conn_idxs = pick_connection(net, src_gids='bursty')
    for conn_idx in conn_idxs:
        drive_conn = net.connectivity[conn_idx]
        target_type = drive_conn['target_type']
        assert drive_conn['nc_dict']['A_weight'] == weights_ampa[target_type]
        assert drive_conn['nc_dict']['A_delay'] == syn_delays[target_type]

    n_drive_cells = 'n_cells'  # default for evoked drive
    cell_specific = True
    net.add_evoked_drive('evoked_dist',
                         mu=1.0,
                         sigma=1.0,
                         numspikes=1.0,
                         weights_ampa=weights_ampa,
                         location='distal',
                         synaptic_delays=syn_delays,
                         cell_specific=True)

    n_dist_targets = 235  # 270 with legacy mode
    assert (
        net.external_drives['evoked_dist']['n_drive_cells'] == n_dist_targets)
    assert net.external_drives['evoked_dist']['cell_specific'] == cell_specific
    conn_idxs = pick_connection(net, src_gids='evoked_dist')
    for conn_idx in conn_idxs:
        drive_conn = net.connectivity[conn_idx]
        target_type = drive_conn['target_type']
        assert drive_conn['nc_dict']['A_weight'] == weights_ampa[target_type]
        assert drive_conn['nc_dict']['A_delay'] == syn_delays[target_type]

    n_drive_cells = 'n_cells'  # default for poisson drive
    cell_specific = True
    net.add_poisson_drive('poisson',
                          rate_constant=1.0,
                          weights_ampa=weights_ampa,
                          location='distal',
                          synaptic_delays=syn_delays,
                          cell_specific=cell_specific)

    n_dist_targets = 235  # 270 with non-legacy mode
    assert (net.external_drives['poisson']['n_drive_cells'] == n_dist_targets)
    assert net.external_drives['poisson']['cell_specific'] == cell_specific
    conn_idxs = pick_connection(net, src_gids='poisson')
    for conn_idx in conn_idxs:
        drive_conn = net.connectivity[conn_idx]
        target_type = drive_conn['target_type']
        assert drive_conn['nc_dict']['A_weight'] == weights_ampa[target_type]
        assert drive_conn['nc_dict']['A_delay'] == syn_delays[target_type]

    # Test probabalistic drive connections.
    # drive with cell_specific=False
    n_drive_cells = 10
    probability = 0.5  # test that only half of possible connections are made
    weights_nmda = {'L2_basket': 1.0, 'L2_pyramidal': 3.0, 'L5_pyramidal': 4.0}
    net.add_bursty_drive('bursty_prob',
                         location='distal',
                         burst_rate=10,
                         weights_ampa=weights_ampa,
                         weights_nmda=weights_nmda,
                         synaptic_delays=syn_delays,
                         n_drive_cells=n_drive_cells,
                         probability=probability)

    for cell_type in weights_ampa.keys():
        conn_idxs = pick_connection(net,
                                    src_gids='bursty_prob',
                                    target_gids=cell_type)
        gid_pairs_comparison = net.connectivity[conn_idxs[0]]['gid_pairs']
        for conn_idx in conn_idxs:
            conn = net.connectivity[conn_idx]
            num_connections = np.sum(
                [len(gids) for gids in conn['gid_pairs'].values()])
            # Ensures that AMPA and NMDA connections target the same gids.
            # Necessary when weights of both are non-zero.
            assert gid_pairs_comparison == conn['gid_pairs']
            assert num_connections == \
                np.around(len(net.gid_ranges[cell_type]) * n_drive_cells *
                          probability).astype(int)

    # drives with cell_specific=True
    probability = {'L2_basket': 0.1, 'L2_pyramidal': 0.25, 'L5_pyramidal': 0.5}
    net.add_evoked_drive('evoked_prob',
                         mu=1.0,
                         sigma=1.0,
                         numspikes=1.0,
                         weights_ampa=weights_ampa,
                         weights_nmda=weights_nmda,
                         location='distal',
                         synaptic_delays=syn_delays,
                         cell_specific=True,
                         probability=probability)

    for cell_type in weights_ampa.keys():
        conn_idxs = pick_connection(net,
                                    src_gids='evoked_prob',
                                    target_gids=cell_type)
        gid_pairs_comparison = net.connectivity[conn_idxs[0]]['gid_pairs']
        for conn_idx in conn_idxs:
            conn = net.connectivity[conn_idx]
            num_connections = np.sum(
                [len(gids) for gids in conn['gid_pairs'].values()])
            assert gid_pairs_comparison == conn['gid_pairs']
            assert num_connections == \
                np.around(len(net.gid_ranges[cell_type]) *
                          probability[cell_type]).astype(int)

    # evoked
    with pytest.raises(ValueError,
                       match='Standard deviation cannot be negative'):
        net.add_evoked_drive('evdist1',
                             mu=10,
                             sigma=-1,
                             numspikes=1,
                             location='distal')
    with pytest.raises(ValueError,
                       match='Number of spikes must be greater than zero'):
        net.add_evoked_drive('evdist1',
                             mu=10,
                             sigma=1,
                             numspikes=0,
                             location='distal')

    # Test Network._attach_drive()
    with pytest.raises(ValueError,
                       match=r'Allowed drive target locations are'):
        net.add_evoked_drive('evdist1',
                             mu=10,
                             sigma=1,
                             numspikes=1,
                             location='bogus_location')
    with pytest.raises(ValueError, match='Drive evoked_dist already defined'):
        net.add_evoked_drive('evoked_dist',
                             mu=10,
                             sigma=1,
                             numspikes=1,
                             location='distal')
    with pytest.raises(ValueError,
                       match='No target cell types have been given a synaptic '
                       'weight'):
        net.add_evoked_drive('evdist1',
                             mu=10,
                             sigma=1,
                             numspikes=1,
                             location='distal')
    with pytest.raises(ValueError,
                       match='When adding a distal drive, synaptic weight '
                       'cannot be defined for the L5_basket cell type'):
        net.add_evoked_drive('evdist1',
                             mu=10,
                             sigma=1,
                             numspikes=1,
                             location='distal',
                             weights_ampa={'L5_basket': 1.},
                             synaptic_delays={'L5_basket': .1})
    with pytest.raises(ValueError,
                       match='If cell_specific is True, n_drive_cells'):
        net.add_evoked_drive('evdist1',
                             mu=10,
                             sigma=1,
                             numspikes=1,
                             location='distal',
                             n_drive_cells=10,
                             cell_specific=True,
                             weights_ampa=weights_ampa,
                             synaptic_delays=syn_delays)
    with pytest.raises(ValueError,
                       match='If cell_specific is False, n_drive_cells'):
        net.add_evoked_drive('evdist1',
                             mu=10,
                             sigma=1,
                             numspikes=1,
                             location='distal',
                             n_drive_cells='n_cells',
                             cell_specific=False,
                             weights_ampa=weights_ampa,
                             synaptic_delays=syn_delays)
    with pytest.raises(ValueError,
                       match='Number of drive cells must be greater than 0'):
        net.add_evoked_drive('evdist1',
                             mu=10,
                             sigma=1,
                             numspikes=1,
                             location='distal',
                             n_drive_cells=0,
                             cell_specific=False,
                             weights_ampa=weights_ampa,
                             synaptic_delays=syn_delays)

    # Poisson
    with pytest.raises(ValueError,
                       match='End time of Poisson drive cannot be negative'):
        net.add_poisson_drive('poisson1',
                              tstart=0,
                              tstop=-1,
                              location='distal',
                              rate_constant=10.)
    with pytest.raises(ValueError,
                       match='Start time of Poisson drive cannot be negative'):
        net.add_poisson_drive('poisson1',
                              tstart=-1,
                              location='distal',
                              rate_constant=10.)
    with pytest.raises(ValueError,
                       match='Duration of Poisson drive cannot be negative'):
        net.add_poisson_drive('poisson1',
                              tstart=10,
                              tstop=1,
                              location='distal',
                              rate_constant=10.)
    with pytest.raises(ValueError, match='Rate constant must be positive'):
        net.add_poisson_drive('poisson1',
                              location='distal',
                              rate_constant=0.,
                              weights_ampa=weights_ampa,
                              synaptic_delays=syn_delays)

    with pytest.raises(ValueError,
                       match='Rate constants not provided for all target'):
        net.add_poisson_drive('poisson1',
                              location='distal',
                              rate_constant={'L2_pyramidal': 10.},
                              weights_ampa=weights_ampa,
                              synaptic_delays=syn_delays)
    with pytest.raises(ValueError,
                       match='Rate constant provided for unknown target cell'):
        net.add_poisson_drive('poisson1',
                              location='distal',
                              rate_constant={
                                  'L2_pyramidal': 10.,
                                  'bogus_celltype': 20.
                              },
                              weights_ampa={
                                  'L2_pyramidal': .01,
                                  'bogus_celltype': .01
                              },
                              synaptic_delays=0.1)

    with pytest.raises(ValueError,
                       match='Drives specific to cell types are only '
                       'possible with cell_specific=True'):
        net.add_poisson_drive('poisson1',
                              location='distal',
                              rate_constant={
                                  'L2_basket': 10.,
                                  'L2_pyramidal': 11.,
                                  'L5_basket': 12.,
                                  'L5_pyramidal': 13.
                              },
                              n_drive_cells=1,
                              cell_specific=False,
                              weights_ampa=weights_ampa,
                              synaptic_delays=syn_delays)

    # bursty
    with pytest.raises(ValueError,
                       match='End time of bursty drive cannot be negative'):
        net.add_bursty_drive('bursty_drive',
                             tstop=-1,
                             location='distal',
                             burst_rate=10)
    with pytest.raises(ValueError,
                       match='Start time of bursty drive cannot be negative'):
        net.add_bursty_drive('bursty_drive',
                             tstart=-1,
                             location='distal',
                             burst_rate=10)
    with pytest.raises(ValueError,
                       match='Duration of bursty drive cannot be negative'):
        net.add_bursty_drive('bursty_drive',
                             tstart=10,
                             tstop=1,
                             location='distal',
                             burst_rate=10)

    msg = (r'Burst duration (?s).* cannot be greater than ' 'burst period')
    with pytest.raises(ValueError, match=msg):
        net.add_bursty_drive('bursty_drive',
                             location='distal',
                             burst_rate=10,
                             burst_std=20.,
                             numspikes=4,
                             spike_isi=50)

    # attaching drives
    with pytest.raises(ValueError, match='Drive evoked_dist already defined'):
        net.add_poisson_drive('evoked_dist',
                              location='distal',
                              rate_constant=10.,
                              weights_ampa=weights_ampa,
                              synaptic_delays=syn_delays)
    with pytest.raises(ValueError,
                       match='Allowed drive target locations are:'):
        net.add_poisson_drive('weird_poisson',
                              location='inbetween',
                              rate_constant=10.,
                              weights_ampa=weights_ampa,
                              synaptic_delays=syn_delays)
    with pytest.raises(ValueError,
                       match='Allowed drive target cell types are:'):
        net.add_poisson_drive('cell_unknown',
                              location='proximal',
                              rate_constant=10.,
                              weights_ampa={'CA1_pyramidal': 1.},
                              synaptic_delays=.01)
    with pytest.raises(ValueError,
                       match='synaptic_delays is either a common float or '
                       'needs to be specified as a dict for each of the cell'):
        net.add_poisson_drive('cell_unknown',
                              location='proximal',
                              rate_constant=10.,
                              weights_ampa={'L2_pyramidal': 1.},
                              synaptic_delays={'L5_pyramidal': 1.})
    with pytest.raises(ValueError,
                       match=r'probability must be in the range \(0\,1\)'):
        net.add_bursty_drive('cell_unknown',
                             location='distal',
                             burst_rate=10,
                             weights_ampa={'L2_pyramidal': 1.},
                             synaptic_delays={'L2_pyramidal': 1.},
                             probability=2.0)

    with pytest.raises(TypeError,
                       match="probability must be an instance of "
                       r"float or dict, got \<class 'str'\> instead"):
        net.add_bursty_drive('cell_unknown2',
                             location='distal',
                             burst_rate=10,
                             weights_ampa={'L2_pyramidal': 1.},
                             synaptic_delays={'L2_pyramidal': 1.},
                             probability='1.0')

    with pytest.raises(ValueError,
                       match='probability is either a common '
                       'float or needs to be specified as a dict for '
                       'each of the cell'):
        net.add_bursty_drive('cell_unknown2',
                             location='distal',
                             burst_rate=10,
                             weights_ampa={'L2_pyramidal': 1.},
                             synaptic_delays={'L2_pyramidal': 1.},
                             probability={'L5_pyramidal': 1.})

    with pytest.raises(TypeError,
                       match="probability must be an instance of "
                       r"float, got \<class 'str'\> instead"):
        net.add_bursty_drive('cell_unknown2',
                             location='distal',
                             burst_rate=10,
                             weights_ampa={'L2_pyramidal': 1.},
                             synaptic_delays={'L2_pyramidal': 1.},
                             probability={'L2_pyramidal': '1.0'})

    with pytest.raises(ValueError,
                       match=r'probability must be in the range \(0\,1\)'):
        net.add_bursty_drive('cell_unknown3',
                             location='distal',
                             burst_rate=10,
                             weights_ampa={'L2_pyramidal': 1.},
                             synaptic_delays={'L2_pyramidal': 1.},
                             probability={'L2_pyramidal': 2.0})
Ejemplo n.º 6
0
###############################################################################
# Following :ref:`the alpha example
# <sphx_glr_auto_examples_plot_simulate_alpha.py>`, we add a
# ~10 Hz "bursty" drive starting at 50 ms and continuing to the end of the
# simulation. Each burst consists of a pair (2) of spikes, spaced 10 ms apart.
# The occurrence of each burst is jittered by a random, normally distributed
# amount (20 ms standard deviation). We repeat the burst train 10 times, each
# time with unique randomization.
net = Network(params)

weights_ampa = {'L2_pyramidal': 5.4e-5, 'L5_pyramidal': 5.4e-5}
net.add_bursty_drive('bursty',
                     tstart=50.,
                     burst_rate=10,
                     burst_std=20.,
                     numspikes=2,
                     spike_isi=10,
                     repeats=10,
                     location='distal',
                     weights_ampa=weights_ampa,
                     seedcore=4)

###############################################################################
# Finally, to simulate we use the
# :class:`~hnn_core.parallel_backends.MPIBackend` class. This will
# start the simulation across the number of processors (cores) specified by
# ``n_procs`` using MPI. The ``'mpiexec'`` launcher is used from
# ``openmpi``, which must be installed on the system
from hnn_core import MPIBackend

with MPIBackend(n_procs=2, mpi_cmd='mpiexec'):
    dpls = simulate_dipole(net, n_trials=1, postproc=False)
Ejemplo n.º 7
0
    'L5_basket': 2e-5,
    'L5_pyramidal': 2e-5
}
syn_delays_p = {
    'L2_basket': 0.1,
    'L2_pyramidal': 0.1,
    'L5_basket': 1.,
    'L5_pyramidal': 1.
}

net.add_bursty_drive('beta_prox',
                     tstart=0.,
                     burst_rate=10,
                     burst_std=burst_std,
                     numspikes=2,
                     spike_isi=10,
                     repeats=10,
                     location=location,
                     weights_ampa=weights_ampa_p,
                     synaptic_delays=syn_delays_p,
                     seedcore=3)

location = 'distal'
burst_std = 15  # NB Sherman [1] and Law [2] use different values here
weights_ampa_d = {
    'L2_basket': 3.2e-4,
    'L2_pyramidal': 8.e-5,
    'L5_pyramidal': 4e-5
}
syn_delays_d = {
    'L2_basket': 0.5,