Skip to content

Commit

Permalink
add option to not clear results with add data
Browse files Browse the repository at this point in the history
  • Loading branch information
TomDonoghue committed Jul 19, 2020
1 parent 092f970 commit b5a0386
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions fooof/objs/fit.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ def _reset_data_results(self, clear_freqs=False, clear_spectrum=False, clear_res
self._peak_fit = None


def add_data(self, freqs, power_spectrum, freq_range=None):
def add_data(self, freqs, power_spectrum, freq_range=None, clear_results=True):
"""Add data (frequencies, and power spectrum values) to the current object.
Parameters
Expand All @@ -298,17 +298,22 @@ def add_data(self, freqs, power_spectrum, freq_range=None):
freq_range : list of [float, float], optional
Frequency range to restrict power spectrum to.
If not provided, keeps the entire range.
clear_results : bool, optional, default: True
Whether to clear prior results, if any are present in the object.
This should only be set to False if data for the current results are being re-added.
Notes
-----
If called on an object with existing data and/or results
they will be cleared by this method call.
"""

# If any data is already present, then clear data & results
# If any data is already present, then clear previous data
# Also clear results, is results are present, unless indicated not to
# This is to ensure object consistency of all data & results
if np.any(self.freqs):
self._reset_data_results(True, True, True)
self._reset_data_results(clear_freqs=self.has_data,
clear_spectrum=self.has_data,
clear_results=self.has_model and clear_results)

self.freqs, self.power_spectrum, self.freq_range, self.freq_res = \
self._prepare_data(freqs, power_spectrum, freq_range, 1, self.verbose)
Expand Down

0 comments on commit b5a0386

Please sign in to comment.