@@ -53,13 +53,22 @@ def filter_string(waveform):
53
53
54
54
def load_analysis (fname ):
55
55
th_match = re .compile ('Threshold \(dB SPL\): ([\w.-]+)' )
56
- freq_match = re .compile ('Frequency \(kHz\): ([\d.]+)' )
56
+ freq_match = re .compile ('Frequency \(kHz\): ([\d.]+)|Stimulus: ([.\w]+)? ' )
57
57
with open (fname ) as fh :
58
58
text = fh .readline ()
59
59
th = th_match .search (text ).group (1 )
60
60
th = None if th == 'None' else float (th )
61
61
text = fh .readline ()
62
- freq = float (freq_match .search (text ).group (1 ))
62
+
63
+ match = freq_match .search (text )
64
+ if match .group (1 ) is not None :
65
+ freq = float (match .group (1 ))
66
+ else :
67
+ freq = match .group (2 )
68
+ if freq == 'click' :
69
+ freq = - 1
70
+ else :
71
+ freq = float (freq )
63
72
64
73
for line in fh :
65
74
if line .startswith ('NOTE' ):
@@ -108,8 +117,6 @@ def parse_peaks(peaks, threshold):
108
117
109
118
class Parser (object ):
110
119
111
- filename_template = '{filename}-{frequency}kHz-{user}analyzed.txt'
112
-
113
120
def __init__ (self , file_format , filter_settings , user = None ):
114
121
'''
115
122
Parameters
@@ -124,24 +131,13 @@ def __init__(self, file_format, filter_settings, user=None):
124
131
'''
125
132
self ._file_format = file_format
126
133
self ._filter_settings = filter_settings
127
- self ._user = user
134
+ self ._rater = user
128
135
self ._module_name = f'abr.parsers.{ file_format } '
129
136
self ._module = importlib .import_module (self ._module_name )
130
137
131
138
def load (self , fs ):
132
139
return fs .get_series (self ._filter_settings )
133
140
134
- def get_save_filename (self , filename , frequency ):
135
- # Round frequency to nearest 8 places to minimize floating-point
136
- # errors.
137
- user_name = self ._user + '-' if self ._user else ''
138
- frequency = round (frequency * 1e-3 , 8 )
139
- save_filename = self .filename_template .format (
140
- filename = filename .with_suffix ('' ),
141
- frequency = frequency ,
142
- user = user_name )
143
- return Path (save_filename )
144
-
145
141
def save (self , model ):
146
142
# Assume that all waveforms were filtered identically
147
143
filter_history = filter_string (model .waveforms [- 1 ])
@@ -157,14 +153,21 @@ def save(self, model):
157
153
columns = '\t ' .join (columns )
158
154
spreadsheet = '\n ' .join (waveform_string (w ) \
159
155
for w in reversed (model .waveforms ))
156
+
157
+ if model .freq == - 1 :
158
+ stimulus = 'Stimulus: click'
159
+ else :
160
+ stimulus = f'Stimulus: { model .freq * 1e-3 :.2f} kHz'
161
+
160
162
content = CONTENT .format (threshold = model .threshold ,
161
- frequency = model . freq * 1e-3 ,
163
+ stimulus = stimulus ,
162
164
filter_history = filter_history ,
163
165
columns = columns ,
164
166
spreadsheet = spreadsheet ,
165
167
version = abr .__version__ )
166
168
167
- filename = self .get_save_filename (model .filename , model .freq )
169
+
170
+ filename = model .dataset .get_analyzed_filename (self ._rater )
168
171
with open (filename , 'w' ) as fh :
169
172
fh .writelines (content )
170
173
@@ -173,12 +176,12 @@ def iter_all(self, path):
173
176
174
177
def find_processed (self , path ):
175
178
for ds in self .iter_all (path ):
176
- if self . get_save_filename ( ds . filename , ds . frequency ).exists ():
179
+ if ds . get_analyzed_filename ( self . _rater ).exists ():
177
180
yield ds
178
181
179
182
def find_unprocessed (self , path ):
180
183
for ds in self .iter_all (path ):
181
- if not self . get_save_filename ( ds . filename , ds . frequency ).exists ():
184
+ if not ds . get_analyzed_filename ( self . _rater ).exists ():
182
185
yield ds
183
186
184
187
def find_analyses (self , study_directory ):
@@ -215,9 +218,9 @@ def load_analyses(self, study_directory):
215
218
216
219
CONTENT = '''
217
220
Threshold (dB SPL): {threshold:.2f}
218
- Frequency (kHz): {frequency:.2f }
221
+ {stimulus }
219
222
Filter history (zpk format): {filter_history}
220
- file_format_version: 0.0.2
223
+ file_format_version: 0.0.3
221
224
code_version: {version}
222
225
NOTE: Negative latencies indicate no peak. NaN for amplitudes indicate peak was unscorable.
223
226
{columns}
0 commit comments