Skip to content

Commit 3660958

Browse files
committed
add data str report
1 parent ff76ffb commit 3660958

File tree

2 files changed

+57
-0
lines changed

2 files changed

+57
-0
lines changed

specparam/reports/strings.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,56 @@ def gen_version_str(concise=False):
118118
return output
119119

120120

121+
def gen_data_str(data, concise=False):
122+
"""Generate a string representation summarizing current data.
123+
124+
Parameters
125+
----------
126+
data : Data
127+
Data object to summarize data for.
128+
Can also be any derived data object (e.g. Data2D).
129+
concise : bool, optional, default: False
130+
Whether to print the report in concise mode.
131+
132+
Returns
133+
-------
134+
output : str
135+
Formatted string of data summary.
136+
"""
137+
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+
148+
if not data.has_data:
149+
150+
no_data_str = "No data currently loaded in the object."
151+
str_lst = [DIVIDER,'', no_data_str, '', DIVIDER]
152+
153+
else:
154+
155+
str_lst = [
156+
157+
DIVIDER,
158+
'',
159+
'The data object contains {}'.format(n_spectra_str),
160+
'with a frequency range of {} Hz'.format(data.freq_range),
161+
'and a frequency resolution of {} Hz.'.format(data.freq_res),
162+
'',
163+
DIVIDER,
164+
]
165+
166+
output = _format(str_lst, concise)
167+
168+
return output
169+
170+
121171
def gen_modes_str(modes, description=False, concise=False):
122172
"""Generate a string representation of fit modes.
123173

specparam/tests/reports/test_strings.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,13 @@ def test_gen_version_str():
1414

1515
assert gen_version_str()
1616

17+
def test_gen_data_str(tdata, tdata2d, tdata2dt, tdata3d):
18+
19+
assert gen_data_str(tdata)
20+
assert gen_data_str(tdata2d)
21+
assert gen_data_str(tdata2dt)
22+
assert gen_data_str(tdata3d)
23+
1724
def test_gen_modes_str(tfm):
1825

1926
assert gen_modes_str(tfm.modes)

0 commit comments

Comments
 (0)