Exemple #1
0
def test_dipole_simulation():
    """Test data produced from simulate_dipole() call."""
    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': 25,
        'dipole_smooth_win': 5,
        't_evprox_1': 5,
        't_evdist_1': 10,
        't_evprox_2': 20
    })
    net = Network(params, add_drives_from_params=True)
    with pytest.raises(ValueError, match="Invalid number of simulations: 0"):
        simulate_dipole(net, n_trials=0)
    with pytest.raises(TypeError, match="record_vsoma must be bool, got int"):
        simulate_dipole(net, n_trials=1, record_vsoma=0)
    with pytest.raises(TypeError, match="record_isoma must be bool, got int"):
        simulate_dipole(net, n_trials=1, record_vsoma=False, record_isoma=0)

    # test Network.copy() returns 'bare' network after simulating
    dpl = simulate_dipole(net, n_trials=1)[0]
    net_copy = net.copy()
    assert len(net_copy.external_drives['evprox1']['events']) == 0
    assert len(net_copy.cell_response.vsoma) == 0

    # test that Dipole.copy() returns the expected exact copy
    assert_allclose(dpl.data['agg'], dpl.copy().data['agg'])

    # Test raster plot with no spikes
    params['tstop'] = 0.1
    net = Network(params)
    simulate_dipole(net, n_trials=1, postproc=False)
    net.cell_response.plot_spikes_raster()
Exemple #2
0
# predefined drives without the drives API shown previously).
net = Network(params, add_drives_from_params=True)

###############################################################################
# Instantiating the network comes with a predefined set of connections that
# reflect the canonical neocortical microcircuit. ``net.connectivity``
# is a list of dictionaries which detail every cell-cell, and drive-cell
# connection.
print(len(net.connectivity))
print(net.connectivity[0:2])

###############################################################################
# Data recorded during simulations are stored under
# :class:`~hnn_core.Cell_Response`. To test multiple network structures, we can
# create a copy of the original network. The copied network is then simulated.
net_erp = net.copy()
dpl_erp = simulate_dipole(net_erp, n_trials=1)
net_erp.cell_response.plot_spikes_raster()

###############################################################################
# We can modify the connectivity list to test the effect of different
# connectivity patterns. For example, we can remove all layer 2 inhibitory
# connections. In the default network, the src_gids of each connection are
# all the same cell type.. Connections are stored under ``conn['gid_pairs']``
# as a dictionary indexed by src_gid:
# ``{src_gid1: [target_gid1, target_gid2], ...]``. Each src_gid indexes a
# list with its target gids
new_connectivity = [
    conn for conn in net.connectivity if conn['src_type'] != 'L2_basket'
]
net.connectivity = new_connectivity
                         sharex=True,
                         figsize=(6, 6),
                         constrained_layout=True)
plot_dipole(dpls, ax=axes[0], layer='agg', show=False)
net.cell_response.plot_spikes_hist(ax=axes[1],
                                   spike_types=['evprox', 'evdist'])

###############################################################################
# Now, let us try to make the exogenous driving inputs to the cells
# synchronous and see what happens. This is achieved by setting the parameter
# ``sync_within_trial`` to ``True``. Using the ``copy``-method, we can create
# a clone of the network defined above, and then modify the drive dynamics for
# each drive. Making a copy removes any existing outputs from the network
# such as spiking information and voltages at the soma.

net_sync = net.copy()
net_sync.external_drives['evdist1']['dynamics']['sync_within_trial'] = True
net_sync.external_drives['evprox1']['dynamics']['sync_within_trial'] = True
net_sync.external_drives['evprox2']['dynamics']['sync_within_trial'] = True

###############################################################################
# You may interrogate current values defining the spike event time dynamics by
print(net_sync.external_drives['evdist1']['dynamics'])

###############################################################################
# Finally, let's simulate this network.
dpls_sync = simulate_dipole(net_sync, n_trials=1)

trial_idx = 0
dpls_sync[trial_idx].plot()
net_sync.cell_response.plot_spikes_hist()