def create_report(subject, params): """ Collect parameters from the dialog and creates an FOOOFReport item """ report_name = params['name'] spectrum_name = params['spectrum_name'] peak_width_low = params['peak_width_low'] peak_width_high = params['peak_width_high'] peak_threshold = params['peak_threshold'] max_n_peaks = params['max_n_peaks'] aperiodic_mode = params['aperiodic_mode'] minfreq = params['minfreq'] maxfreq = params['maxfreq'] spectrum = subject.spectrum.get(spectrum_name) peak_width_limits = [peak_width_low, peak_width_high] peak_threshold = peak_threshold max_n_peaks = max_n_peaks aperiodic_mode = aperiodic_mode freq_range = [minfreq, maxfreq] # As meggie spectrum items can contain data for multiple conditions, # reports are also created for all those conditions, and dict is used. report_content = {} for key, data in spectrum.content.items(): fg = FOOOFGroup(peak_width_limits=peak_width_limits, peak_threshold=peak_threshold, max_n_peaks=max_n_peaks, aperiodic_mode=aperiodic_mode, verbose=False) fg.fit(spectrum.freqs, data, freq_range) logging.getLogger('ui_logger').info('FOOOF results for ' + subject.name + ', ' + 'condition: ' + key) # Log the textual report logging.getLogger('ui_logger').info( gen_results_fg_str(fg, concise=True)) report_content[key] = fg params['conditions'] = list(spectrum.content.keys()) params['ch_names'] = spectrum.ch_names fooof_directory = subject.fooof_report_directory # Create a container item that meggie understands, # and which holds the report data report = FOOOFReport(report_name, fooof_directory, params, report_content) # save report data to fs report.save_content() # and add the report item to subject subject.add(report, 'fooof_report')
def print_results(self, concise=False): """Print out FOOOFGroup results. Parameters ---------- concise : bool, optional, default: False Whether to print the report in a concise mode, or not. """ print(gen_results_fg_str(self, concise))
def save_report_fg(fg, file_name, file_path=None): """Generate and save out as a PDF a report for a FOOOFGroup object. Parameters ---------- fg : FOOOFGroup() object FOOOFGroup object, containing results from fitting a group of power spectra. file_name : str Name to give the saved out file. file_path : str, optional Path to directory in which to save. If not provided, saves to current directory. """ font = _report_settings() # Initialize figure fig = plt.figure(figsize=(16, 20)) gs = gridspec.GridSpec(3, 2, wspace=0.35, hspace=0.25, height_ratios=[0.8, 1.0, 1.0]) # First / top: text results ax0 = plt.subplot(gs[0, :]) results_str = gen_results_fg_str(fg) ax0.text(0.5, 0.7, results_str, font, ha='center', va='center') ax0.set_frame_on(False) ax0.set_xticks([]) ax0.set_yticks([]) # Aperiodic parameters plot ax1 = plt.subplot(gs[1, 0]) plot_fg_ap(fg, ax1) # Goodness of fit plot ax2 = plt.subplot(gs[1, 1]) plot_fg_gf(fg, ax2) # Peak center frequencies plot ax3 = plt.subplot(gs[2, :]) plot_fg_peak_cens(fg, ax3) # Save out the report plt.savefig(fpath(file_path, fname(file_name, 'pdf'))) plt.close()
def save_report_fg(fg, file_name, file_path=None): """Generate and save out a PDF report for a group of power spectrum models. Parameters ---------- fg : FOOOFGroup Object with results from fitting a group of power spectra. file_name : str Name to give the saved out file. file_path : str, optional Path to directory to save to. If None, saves to current directory. """ # Initialize figure _ = plt.figure(figsize=REPORT_FIGSIZE) grid = gridspec.GridSpec(3, 2, wspace=0.4, hspace=0.25, height_ratios=[0.8, 1.0, 1.0]) # First / top: text results ax0 = plt.subplot(grid[0, :]) results_str = gen_results_fg_str(fg) ax0.text(0.5, 0.7, results_str, REPORT_FONT, ha='center', va='center') ax0.set_frame_on(False) ax0.set_xticks([]) ax0.set_yticks([]) # Aperiodic parameters plot ax1 = plt.subplot(grid[1, 0]) plot_fg_ap(fg, ax1) # Goodness of fit plot ax2 = plt.subplot(grid[1, 1]) plot_fg_gf(fg, ax2) # Peak center frequencies plot ax3 = plt.subplot(grid[2, :]) plot_fg_peak_cens(fg, ax3) # Save out the report plt.savefig(fpath(file_path, fname(file_name, SAVE_FORMAT))) plt.close()
def create_report(self, subject, selected_spectrum): """ Collect parameters from the dialog and creates an FOOOFReport item """ report_name = validate_name(self.ui.lineEditName.text()) spectrum = subject.spectrum.get(selected_spectrum) peak_width_low = self.ui.doubleSpinBoxPeakWidthLow.value() peak_width_high = self.ui.doubleSpinBoxPeakWidthHigh.value() peak_threshold = self.ui.doubleSpinBoxPeakThreshold.value() max_n_peaks = self.ui.spinBoxMaxNPeaks.value() aperiodic_mode = self.ui.comboBoxAperiodicMode.currentText() minfreq = self.ui.doubleSpinBoxFreqMin.value() maxfreq = self.ui.doubleSpinBoxFreqMax.value() peak_width_limits = [peak_width_low, peak_width_high] peak_threshold = peak_threshold max_n_peaks = max_n_peaks aperiodic_mode = aperiodic_mode freq_range = [minfreq, maxfreq] # As meggie spectrum items can contain data for multiple conditions, # reports are also created for all those conditions, and dict is used. report_content = {} for key, data in spectrum.content.items(): fg = FOOOFGroup(peak_width_limits=peak_width_limits, peak_threshold=peak_threshold, max_n_peaks=max_n_peaks, aperiodic_mode=aperiodic_mode, verbose=False) @threaded def fit(**kwargs): """ Run fitting in a separate thread so that UI stays responsive """ fg.fit(spectrum.freqs, data, freq_range) fit(do_meanwhile=self.parent.update_ui) logging.getLogger('ui_logger').info('FOOOF results for ' + subject.name + ', ' + 'condition: ' + key) # Log the textual report logging.getLogger('ui_logger').info( gen_results_fg_str(fg, concise=True)) report_content[key] = fg params = { 'conditions': list(spectrum.content.keys()), 'based_on': selected_spectrum, 'ch_names': spectrum.ch_names, } fooof_directory = subject.fooof_report_directory # Create a container item that meggie understands, # and which holds the report data report = FOOOFReport(report_name, fooof_directory, params, report_content) # save report data to fs report.save_content() # and add the report item to subject subject.add(report, 'fooof_report')