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])
fig, axes = plt.subplots(2, 1, constrained_layout=True) tmin, tmax = 10, 300 # exclude the initial burn-in period from the plots # We'll make a copy of the dipole before smoothing in order to compare window_len = 20 # convolve with a 20 ms-long Hamming window dpl_smooth = dpl[trial_idx].copy().smooth(window_len) # Overlay the traces for comparison. The function plot_dipole can plot a list # of dipoles at once dpl_list = [dpl[trial_idx], dpl_smooth] plot_dipole(dpl_list, tmin=tmin, tmax=tmax, ax=axes[0], show=False) axes[0].set_xlim((1, 399)) axes[0].legend(['orig', 'smooth']) plot_psd(dpl[trial_idx], fmin=1., fmax=1e3, tmin=tmin, ax=axes[1], show=False) axes[1].set_xscale('log') plt.tight_layout() ############################################################################### # The next step is to add a simultaneous 10 Hz :term:`distal` drive with a # lower within-burst spread of spike times (``burst_std``) compared with the # proximal one. The different arrival times of spikes at opposite ends of # the pyramidal cells will tend to produce bursts of 15-30 Hz power known # as beta frequency events. location = 'distal' burst_std = 15 weights_ampa_d = {'L2_pyramidal': 5.4e-5, 'L5_pyramidal': 5.4e-5} syn_delays_d = {'L2_pyramidal': 5., 'L5_pyramidal': 5.} net.add_bursty_drive( 'alpha_dist', tstart=50., burst_rate=10, burst_std=burst_std, numspikes=2, spike_isi=10, n_drive_cells=10, location=location, weights_ampa=weights_ampa_d,
net.add_tonic_bias(cell_type='L5_pyramidal', amplitude=6.) dpls = simulate_dipole(net, n_trials=1) dpls[trial_idx].plot() ############################################################################### # Notice that the Layer 5 pyramidal neurons now fire nearly synchronously, # leading to a synchronous activation of the inhibitory basket neurons, # resulting in a low-latency IPSP back onto the pyramidal cells. The duration # of the IPSP is ~20 ms, after which the combined effect of the tonic bias and # Poisson drive is to bring the pyramidal cells back to firing threshold, # creating a ~50 Hz PING rhythm. This type of synchronous rhythm is sometimes # referred to as “strong” PING. net.cell_response.plot_spikes_raster() ############################################################################### # Although the simulated dipole signal demonstrates clear periodicity, its # frequency is lower compared with the "weak" PING simulation above. from hnn_core.viz import plot_psd plot_psd(dpls[trial_idx], fmin=20., fmax=100., tmin=tmin) ############################################################################### # References # ---------- # .. [1] Lee, S. & Jones, S. R. Distinguishing mechanisms of gamma frequency # oscillations in human current source signals using a computational # model of a laminar neocortical network. Frontiers in human # neuroscience (2013) # # .. [2] https://jonescompneurolab.github.io/hnn-tutorials/gamma/gamma