.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/bos2016/power_spectra.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note Click :ref:`here ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_bos2016_power_spectra.py: Power Spectra (Bos 2016) ======================== Here we calculate the power spectra of the :cite:t:`potjans2014` microcircuit model including modifications made in :cite:t:`bos2016`. This example reproduces Fig. 1E in :cite:t:`bos2016`. .. GENERATED FROM PYTHON SOURCE LINES 10-22 .. code-block:: default import nnmt import numpy as np import matplotlib as mpl import matplotlib.pyplot as plt import matplotlib.gridspec as gridspec import matplotlib.ticker plt.style.use('frontiers.mplstyle') mpl.rcParams.update({'legend.fontsize': 'medium', # old: 5.0 was too small 'axes.titlepad': 0.0}) .. GENERATED FROM PYTHON SOURCE LINES 23-24 First, create an instance of the network model class `Microcircuit`. .. GENERATED FROM PYTHON SOURCE LINES 24-30 .. code-block:: default microcircuit = nnmt.models.Microcircuit( network_params= '../../tests/fixtures/integration/config/Bos2016_network_params.yaml', analysis_params= '../../tests/fixtures/integration/config/Bos2016_analysis_params.yaml') .. GENERATED FROM PYTHON SOURCE LINES 31-33 The frequency resolution used in the original publication was quite high. Here, we reduce the frequency resolution for faster execution. .. GENERATED FROM PYTHON SOURCE LINES 33-42 .. code-block:: default reduce_frequency_resolution = True if reduce_frequency_resolution: microcircuit.change_parameters(changed_analysis_params={'df': 5}, overwrite=True) derived_analysis_params = ( microcircuit._calculate_dependent_analysis_parameters()) microcircuit.analysis_params.update(derived_analysis_params) .. GENERATED FROM PYTHON SOURCE LINES 43-44 Calculate all necessary quantities and finally the power spectra. .. GENERATED FROM PYTHON SOURCE LINES 44-56 .. code-block:: default # calculate working point for exponentially shape post synaptic currents nnmt.lif.exp.working_point(microcircuit, method='taylor') # calculate the transfer function nnmt.lif.exp.transfer_function(microcircuit, method='taylor') # calculate the delay distribution matrix nnmt.network_properties.delay_dist_matrix(microcircuit) # calculate the effective connectivity matrix nnmt.lif.exp.effective_connectivity(microcircuit) # calculate the power spectra power_spectra = nnmt.lif.exp.power_spectra(microcircuit) .. GENERATED FROM PYTHON SOURCE LINES 57-58 Read the simulated power spectra from the publicated data for comparison. .. GENERATED FROM PYTHON SOURCE LINES 58-65 .. code-block:: default fix_path = '../../tests/fixtures/integration/data/' result = nnmt.input_output.load_h5(fix_path + 'Bos2016_publicated_and_converted_data.h5') simulated_power_spectra_1_window = result['fig_microcircuit']['1'] simulated_power_spectra_20_window = result['fig_microcircuit']['20'] .. GENERATED FROM PYTHON SOURCE LINES 66-67 Plotting mean-field prediction and simulated results together. .. GENERATED FROM PYTHON SOURCE LINES 67-127 .. code-block:: default # two column figure, 180 mm wide width = 180. / 25.4 height = 90. / 25.4 fig = plt.figure(figsize=(width, height)) grid_specification = gridspec.GridSpec(2, 4, figure=fig) for layer in [0, 1, 2, 3]: for pop in [0, 1]: j = layer*2+pop ax = fig.add_subplot(grid_specification[pop, layer]) ax.plot(simulated_power_spectra_1_window['freq_sim'], simulated_power_spectra_1_window[f'power{j}'], color=(0.8, 0.8, 0.8), label='simulation') ax.plot(simulated_power_spectra_20_window['freq_sim'], simulated_power_spectra_20_window[f'power{j}'], color=(0.5, 0.5, 0.5), label='simulation avg.') ax.plot(microcircuit.analysis_params['omegas']/(2*np.pi), power_spectra[:, j], color='black', zorder=2, label='prediction') ax.set_xlim([10.0, 400.0]) ax.set_ylim([1e-6, 1e0]) ax.set_yscale('log') population_name = microcircuit.network_params['populations'][j] if population_name == '23E': ax.set_title('2/3E') elif population_name == '23I': ax.set_title('2/3I') else: ax.set_title(population_name) if pop == 1 and layer == 0: ax.set_xlabel(r'frequency $\omega/2\pi\quad(1/\mathrm{s})$') else: ax.set_xticklabels([]) ax.set_xticks([100, 200, 300]) y_minor = matplotlib.ticker.LogLocator( base = 10.0, subs = np.arange(1.0, 10.0) * 0.1, numticks = 10) ax.yaxis.set_minor_locator(y_minor) ax.yaxis.set_minor_formatter(matplotlib.ticker.NullFormatter()) ax.set_yticks([]) if j == 0 or j== 1: ax.set_yticks([1e-5,1e-3,1e-1]) if j == 0: ax.set_ylabel(r'power spectrum $|C(\omega)|\quad(1/\mathrm{s}^2)$') ax.legend() plt.savefig('figures/power_spectra_Bos2016.png') .. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 0.000 seconds) .. _sphx_glr_download_auto_examples_bos2016_power_spectra.py: .. only :: html .. container:: sphx-glr-footer :class: sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: power_spectra.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: power_spectra.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_