Skip to content

Commit 5493d0b

Browse files
committed
add print function to data object
1 parent 3660958 commit 5493d0b

File tree

2 files changed

+23
-10
lines changed

2 files changed

+23
-10
lines changed

specparam/data/data.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from specparam.data import SpectrumMetaData, ModelChecks
1010
from specparam.utils.spectral import trim_spectrum
1111
from specparam.utils.checks import check_input_options
12+
from specparam.reports.strings import gen_data_str
1213
from specparam.modutils.errors import DataError, InconsistentDataError
1314
from specparam.modutils.docs import docs_get_section, replace_docstring_sections
1415
from specparam.plts.settings import PLT_COLORS
@@ -162,6 +163,18 @@ def plot(self, plt_log=False, **plt_kwargs):
162163
log_powers=False, **data_kwargs)
163164

164165

166+
def print(self, concise):
167+
"""Print out a data summary.
168+
169+
Parameters
170+
----------
171+
concise : bool, optional, default: False
172+
Whether to print the report in a concise mode, or not.
173+
"""
174+
175+
print(gen_data_str(self, concise))
176+
177+
165178
def set_checks(self, check_freqs=None, check_data=None):
166179
"""Set check statuses, which control if an error is raised based on check on the inputs.
167180

specparam/reports/strings.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -135,23 +135,23 @@ def gen_data_str(data, concise=False):
135135
Formatted string of data summary.
136136
"""
137137

138-
# Get number of spectra, checking attributes for {Data3D, Data2DT, Data2D, Data}
139-
if getattr(data, 'n_events', None):
140-
n_spectra_str = '{} spectrograms with {} windows each'.format(data.n_events, data.n_time_windows)
141-
elif getattr(data, 'n_time_windows', None):
142-
n_spectra_str = '1 spectrogram with {} windows'.format(data.n_time_windows)
143-
elif getattr(data, 'n_spectra', None):
144-
n_spectra_str = '{} power spectra'.format(data.n_spectra)
145-
else:
146-
n_spectra_str = '1 power spectrum'
147-
148138
if not data.has_data:
149139

150140
no_data_str = "No data currently loaded in the object."
151141
str_lst = [DIVIDER,'', no_data_str, '', DIVIDER]
152142

153143
else:
154144

145+
# Get number of spectra, checking attributes for {Data3D, Data2DT, Data2D, Data}
146+
if getattr(data, 'n_events', None):
147+
n_spectra_str = '{} spectrograms with {} windows each'.format(data.n_events, data.n_time_windows)
148+
elif getattr(data, 'n_time_windows', None):
149+
n_spectra_str = '1 spectrogram with {} windows'.format(data.n_time_windows)
150+
elif getattr(data, 'n_spectra', None):
151+
n_spectra_str = '{} power spectra'.format(data.n_spectra)
152+
else:
153+
n_spectra_str = '1 power spectrum'
154+
155155
str_lst = [
156156

157157
DIVIDER,

0 commit comments

Comments
 (0)