.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/intermediate_usage_example/intermediate_usage_example.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_intermediate_usage_example_intermediate_usage_example.py: Intermediate usage example ========================== Here we show how to use NNMT to calculate the power spectra of the :cite:t:`potjans2014` microcircuit model. .. GENERATED FROM PYTHON SOURCE LINES 8-14 .. code-block:: default import numpy as np import matplotlib.pyplot as plt import nnmt .. GENERATED FROM PYTHON SOURCE LINES 15-18 First we try loading previous results, which makes running this script for the second time much faster. If there are no stored results, we instantiate a microcircuit model. .. GENERATED FROM PYTHON SOURCE LINES 18-24 .. code-block:: default try: network = nnmt.models.Network(file='microcircuit.h5') except IOError: network = nnmt.models.Microcircuit('network_params.yaml', 'analysis_params.yaml') .. GENERATED FROM PYTHON SOURCE LINES 25-27 We compute the working point, which only requires the network parameters defined in ``network_params.yaml`` (see minimal example as well). .. GENERATED FROM PYTHON SOURCE LINES 27-30 .. code-block:: default print('Compute working point') nnmt.lif.exp.working_point(network) .. GENERATED FROM PYTHON SOURCE LINES 31-35 Then we continue by computing the transfer function, the delay distribution matrix, the effective connectivity, and finally the power spectrum. This requires the definition of the analysis frequencies in ``analysis_params.yaml``. .. GENERATED FROM PYTHON SOURCE LINES 35-44 .. code-block:: default print('Compute transfer function') nnmt.lif.exp.transfer_function(network) print('Compute delay_dist_matrix') nnmt.network_properties.delay_dist_matrix(network) print('Compute effective connectivity') nnmt.lif.exp.effective_connectivity(network) print('Compute power spectra') nnmt.lif.exp.power_spectra(network) .. GENERATED FROM PYTHON SOURCE LINES 45-46 We retrieve the analysis frequencies and power spectra and plot the results .. GENERATED FROM PYTHON SOURCE LINES 46-59 .. code-block:: default freqs = network.analysis_params['omegas'] / 2 / np.pi spectra = network.results['lif.exp.power_spectra'].T for i in range(8): plt.plot(freqs, spectra[i], label=network.network_params['populations'][i]) plt.yscale('log') plt.xlabel('frequency (1/s)') plt.ylabel('power') plt.legend() plt.show() # save results to h5 file network.save('microcircuit.h5') .. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 0.000 seconds) .. _sphx_glr_download_auto_examples_intermediate_usage_example_intermediate_usage_example.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: intermediate_usage_example.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: intermediate_usage_example.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_