@@ -167,14 +167,23 @@ def time_frequency(
167
167
time_centers = np .mean (times , axis = 1 ) * float (fs )
168
168
169
169
# Interpolate the values in gram over the time grid.
170
- gram_interpolator = interp1d (
171
- times [:, 0 ] * fs ,
172
- gram [:, :n_times ],
173
- kind = "previous" ,
174
- bounds_error = False ,
175
- fill_value = (gram [:, 0 ], gram [:, - 1 ]),
176
- )
177
- signal = gram_interpolator (np .arange (length ))
170
+ if n_times > 1 :
171
+ interpolator = interp1d (
172
+ times [:, 0 ] * fs ,
173
+ gram [:, :n_times ],
174
+ kind = "previous" ,
175
+ bounds_error = False ,
176
+ fill_value = (gram [:, 0 ], gram [:, - 1 ]),
177
+ )
178
+ else :
179
+ # NOTE: This is a special case where there is only one time interval.
180
+ # scipy 1.10 and above handle this case directly with the interp1d above,
181
+ # but older scipy's do not. This is a workaround for that.
182
+ #
183
+ # In the 0.9 release, we can bump the minimum scipy to 1.10 and remove this
184
+ interpolator = _const_interpolator (gram [:, 0 ])
185
+
186
+ signal = interpolator (np .arange (length ))
178
187
179
188
# Check if there is at least one element on each frequency that has a value above the threshold
180
189
# to justify processing, for optimisation.
@@ -202,6 +211,17 @@ def time_frequency(
202
211
return output
203
212
204
213
214
+ def _const_interpolator (value ):
215
+ """Return a function that returns `value`
216
+ no matter the input.
217
+ """
218
+
219
+ def __interpolator (x ):
220
+ return value
221
+
222
+ return __interpolator
223
+
224
+
205
225
def _fast_synthesize (frequency , n_dec , fs , function , length ):
206
226
"""Efficiently synthesize a signal.
207
227
Generate one cycle, and simulate arbitrary repetitions
0 commit comments