Skip to content

Commit

Permalink
Update to use script to generate doc images
Browse files Browse the repository at this point in the history
  • Loading branch information
TomDonoghue committed Apr 20, 2020
1 parent 3adb6fe commit cb290c1
Show file tree
Hide file tree
Showing 10 changed files with 82 additions and 4 deletions.
4 changes: 2 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ any identified peaks, reflecting periodic components.

Example output for the report of a FOOOF fit on an individual power spectrum:

.. image:: https://raw.githubusercontent.com/fooof-tools/fooof/master/doc/img/FOOOF_report.png
.. image:: https://raw.githubusercontent.com/fooof-tools/fooof/master/doc/img/FOOOF_report.pdf

**Defining the model Settings**

Expand Down Expand Up @@ -264,7 +264,7 @@ We can fit this which can be fit as:
Example output from using FOOOFGroup across a group of power spectra:

.. image:: https://raw.githubusercontent.com/fooof-tools/fooof/master/doc/img/FOOOFGroup_report.png
.. image:: https://raw.githubusercontent.com/fooof-tools/fooof/master/doc/img/FOOOFGroup_report.pdf

**Other Functionality**

Expand Down
5 changes: 4 additions & 1 deletion doc/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ check:
make SPHINXOPTS="-n" html
make linkcheck

## make install:
# Create the plots used in the FOOOF documentation
plots:
python make_doc_plots.py

# Build the html site, and push it to gh-pages branch of repo to deploy
install:
rm -rf _build/doctrees _build/tmp_html
Expand Down
2 changes: 1 addition & 1 deletion doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@
'../motivations/concepts',
'../motivations/measurements']),
'within_subsection_order': FileNameSortKey,
'default_thumb_file': 'img/spectrum.png',
'default_thumb_file': 'img/spectrum.pdf',
'backreferences_dir': 'generated', # Where to drop linking files between examples & API
'doc_module': ('fooof',),
'reference_url': {'fooof': None}
Expand Down
Binary file added doc/img/FOOOFGroup_report.pdf
Binary file not shown.
Binary file removed doc/img/FOOOFGroup_report.png
Binary file not shown.
Binary file added doc/img/FOOOF_report.pdf
Binary file not shown.
Binary file removed doc/img/FOOOF_report.png
Binary file not shown.
Binary file added doc/img/spectrum.pdf
Binary file not shown.
Binary file removed doc/img/spectrum.png
Binary file not shown.
75 changes: 75 additions & 0 deletions doc/make_doc_plots.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
"""Create the images for the FOOOF documentation."""

import shutil

import numpy as np
import matplotlib.pyplot as plt

from fooof import FOOOF, FOOOFGroup
from fooof.sim.gen import gen_power_spectrum
from fooof.plts.utils import check_ax
from fooof.plts.spectra import plot_spectrum
from fooof.utils.download import load_fooof_data

###################################################################################################
###################################################################################################

def main():

## Individual Model Plot

# Download examples data files needed for this example
freqs = load_fooof_data('freqs.npy', folder='data')
spectrum = load_fooof_data('spectrum.npy', folder='data')

# Initialize and fit an example power spectrum model
fm = FOOOF(peak_width_limits=[1, 6], max_n_peaks=6, min_peak_height=0.2, verbose=False)
fm.fit(freqs, spectrum, [3, 40])

# Save out the report
fm.save_report('FOOOF_report.pdf', 'img')

## Group Plot

# Download examples data files needed for this example
freqs = load_fooof_data('group_freqs.npy', folder='data')
spectra = load_fooof_data('group_powers.npy', folder='data')

# Initialize and fit a group of example power spectrum models
fg = FOOOFGroup(peak_width_limits=[1, 6], max_n_peaks=6, min_peak_height=0.2, verbose=False)
fg.fit(freqs, spectra, [3, 30])

# Save out the report
fg.save_report('FOOOFGroup_report.pdf', 'img')

## Make the icon plot

# Simulate an example power spectrum
fs, ps = gen_power_spectrum([4, 35], [0, 1], [[10, 0.3, 1],[22, 0.15, 1.25]], nlv=0.01)

def custom_style(ax, log_freqs, log_powers):
"""Custom styler-function for the icon plot."""

# Set the top and right side frame & ticks off
ax.spines['right'].set_visible(False)
ax.spines['top'].set_visible(False)

# Set linewidth of remaining spines
ax.spines['left'].set_linewidth(10)
ax.spines['bottom'].set_linewidth(10)
ax.set_xticks([], [])
ax.set_yticks([], [])

# Create and save out the plot
plot_spectrum(fs, ps, log_freqs=False, log_powers=True, lw=12, alpha=0.8,
color='grey', plot_style=custom_style, ax=check_ax(None, [6, 6]))
plt.tight_layout()
plt.savefig('img/spectrum.pdf')

## Clean Up

# Remove the data folder
shutil.rmtree('data')

if __name__ == "__main__":
main()

0 comments on commit cb290c1

Please sign in to comment.