Skip to content

Commit b5a0386

Browse files
committed
add option to not clear results with add data
1 parent 092f970 commit b5a0386

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

fooof/objs/fit.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ def _reset_data_results(self, clear_freqs=False, clear_spectrum=False, clear_res
286286
self._peak_fit = None
287287

288288

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

308-
# If any data is already present, then clear data & results
311+
# If any data is already present, then clear previous data
312+
# Also clear results, is results are present, unless indicated not to
309313
# This is to ensure object consistency of all data & results
310-
if np.any(self.freqs):
311-
self._reset_data_results(True, True, True)
314+
self._reset_data_results(clear_freqs=self.has_data,
315+
clear_spectrum=self.has_data,
316+
clear_results=self.has_model and clear_results)
312317

313318
self.freqs, self.power_spectrum, self.freq_range, self.freq_res = \
314319
self._prepare_data(freqs, power_spectrum, freq_range, 1, self.verbose)

0 commit comments

Comments
 (0)