|
| 1 | +""" |
| 2 | +Reporting & Referencing |
| 3 | +======================= |
| 4 | +
|
| 5 | +This example covers utilities for getting reporting information and referencing use of the module. |
| 6 | +
|
| 7 | +This page is a hands-on example of the reporting and referencing information on the |
| 8 | +`Reference page <https://fooof-tools.github.io/fooof/reference.html>`_. |
| 9 | +""" |
| 10 | + |
| 11 | +################################################################################################### |
| 12 | + |
| 13 | +# Import FOOOF model objects |
| 14 | +from fooof import FOOOF, FOOOFGroup |
| 15 | + |
| 16 | +# Import simulation functions to create some example data |
| 17 | +from fooof.sim import gen_power_spectrum, gen_group_power_spectra |
| 18 | + |
| 19 | +# Import utilities to print out information for reporting |
| 20 | +from fooof.utils.reports import methods_report_info, methods_report_text |
| 21 | + |
| 22 | +################################################################################################### |
| 23 | +# Checking Module Version |
| 24 | +# ----------------------- |
| 25 | +# |
| 26 | +# It's useful and important to keep track of which version of the module you are using, |
| 27 | +# and to report this information when referencing use of the tool. |
| 28 | +# |
| 29 | +# There are several ways to check the version of the the module that you are using, |
| 30 | +# including checking what is installed in the Python environment you are using. |
| 31 | +# |
| 32 | +# From within Python, you can also check the version of the module by checking |
| 33 | +# `__version__`, as shown below: |
| 34 | +# |
| 35 | + |
| 36 | +################################################################################################### |
| 37 | + |
| 38 | +# Check the version of the module |
| 39 | +from fooof import __version__ as fooof_version |
| 40 | +print('Current fooof version:', fooof_version) |
| 41 | + |
| 42 | +################################################################################################### |
| 43 | +# Getting Model Reporting Information |
| 44 | +# ----------------------------------- |
| 45 | +# |
| 46 | +# To assist with reporting information, the module has the following utilities: |
| 47 | +# - the :func:`~.methods_report_info`, which prints out methods reporting information |
| 48 | +# - the :func:`~.methods_report_text`, which prints out a template of methods reporting text |
| 49 | +# |
| 50 | +# Both of the these functions take as input a model object, and use the object to |
| 51 | +# collect and return information related to the model fits. |
| 52 | +# |
| 53 | +# Note that not all information may be returned by the model - these methods only have access |
| 54 | +# to the current object. This means it is also important that if you use these functions, |
| 55 | +# you use them with objects that match the settings and data used in the analysis to be reported. |
| 56 | +# |
| 57 | +# In the following, we will explore an example of using these functions for an example model fit. |
| 58 | +# |
| 59 | + |
| 60 | +################################################################################################### |
| 61 | + |
| 62 | +# Initialize model object |
| 63 | +fooof_obj = FOOOF() |
| 64 | + |
| 65 | +################################################################################################### |
| 66 | + |
| 67 | +# Print out all the methods information for reporting |
| 68 | +methods_report_info(fooof_obj) |
| 69 | + |
| 70 | +################################################################################################### |
| 71 | +# |
| 72 | +# You might notice that the above function prints out several different sections, |
| 73 | +# some of which might look familiar. |
| 74 | +# |
| 75 | +# The settings information, for example, is the same as printed using the |
| 76 | +# # - :meth:`~fooof.FOOOF.print_settings` method. |
| 77 | +# |
| 78 | +# Next, let's check out the text version of the methods report. |
| 79 | +# |
| 80 | + |
| 81 | +################################################################################################### |
| 82 | + |
| 83 | +# Generate methods text, with methods information inserted |
| 84 | +methods_report_text(fooof_obj) |
| 85 | + |
| 86 | +################################################################################################### |
| 87 | +# Addtional Examples |
| 88 | +# ~~~~~~~~~~~~~~~~~~ |
| 89 | +# |
| 90 | +# In the above examples, not all the information was printed, as not all information was |
| 91 | +# available in the example object (for example, it had no data). |
| 92 | +# |
| 93 | +# In the next example, let's see how the ouputs look for an example object with model fit results. |
| 94 | +# |
| 95 | + |
| 96 | +################################################################################################### |
| 97 | + |
| 98 | +# Simulate an example power spectrum |
| 99 | +freqs, powers = gen_power_spectrum([1, 50], [0, 10, 1], [10, 0.25, 2], freq_res=0.25) |
| 100 | + |
| 101 | +# Initialize model object |
| 102 | +fm = FOOOF(min_peak_height=0.1, peak_width_limits=[1, 6], aperiodic_mode='knee') |
| 103 | +fm.fit(freqs, powers) |
| 104 | + |
| 105 | +################################################################################################### |
| 106 | + |
| 107 | +# Generate methods text, with methods information inserted |
| 108 | +methods_report_info(fm) |
| 109 | + |
| 110 | +################################################################################################### |
| 111 | + |
| 112 | +# Generate methods text, with methods information inserted |
| 113 | +methods_report_text(fm) |
| 114 | + |
| 115 | +################################################################################################### |
| 116 | +# |
| 117 | +# The report text is meant as a template / example that could be added to a methods section. |
| 118 | +# |
| 119 | +# Note that there may be missing information that needs to be filled in (indicated by 'XX's), |
| 120 | +# and you can and should consider this a template to be edited as needed. |
| 121 | +# |
| 122 | + |
| 123 | +################################################################################################### |
| 124 | +# Other Model Objects |
| 125 | +# ~~~~~~~~~~~~~~~~~~~ |
| 126 | +# |
| 127 | +# Note that the reporting functions work with any model object. |
| 128 | +# |
| 129 | +# For example, next we will use them on a :class:`~fooof.FOOOFGroup` object. |
| 130 | +# |
| 131 | + |
| 132 | +################################################################################################### |
| 133 | + |
| 134 | +# Simulate an example group of power spectra |
| 135 | +freqs, powers = gen_group_power_spectra(10, [1, 75], [0, 1], [10, 0.25, 2]) |
| 136 | + |
| 137 | +################################################################################################### |
| 138 | + |
| 139 | +# Initialize and fit group model object |
| 140 | +fg = FOOOFGroup(max_n_peaks=4, peak_threshold=1.75) |
| 141 | +fg.fit(freqs, powers) |
| 142 | + |
| 143 | +################################################################################################### |
| 144 | + |
| 145 | +# Generate the methods report information |
| 146 | +methods_report_info(fg) |
| 147 | + |
| 148 | +################################################################################################### |
| 149 | + |
| 150 | +# Generate the methods report text |
| 151 | +methods_report_text(fg) |
| 152 | + |
| 153 | +################################################################################################### |
| 154 | +# |
| 155 | +# That concludes the example of using the helper utilities for generating methods reports! |
| 156 | +# |
0 commit comments