Skip to content

Commit 30933fd

Browse files
committed
style: single quotes to double around strings
1 parent 42f2df8 commit 30933fd

17 files changed

Lines changed: 300 additions & 301 deletions

cebl/sig/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
"""Signal processing.
22
"""
3-
43
from .bandpass import *
54
from .cwt import *
65
from .psd import *

cebl/sig/bandpass.py

Lines changed: 139 additions & 139 deletions
Large diffs are not rendered by default.

cebl/sig/psd.py

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def getPowers(self):
3333
def getFreqsPowers(self):
3434
return self.freqs, self.powers
3535

36-
def plotPower(self, scale='log', ax=None, **kwargs):
36+
def plotPower(self, scale="log", ax=None, **kwargs):
3737
"""Plot a PSD estimate on a log scale.
3838
3939
Returns
@@ -47,40 +47,40 @@ def plotPower(self, scale='log', ax=None, **kwargs):
4747
scale = scale.lower()
4848
if ax is None:
4949
fig = plt.figure()
50-
result['fig'] = fig
50+
result["fig"] = fig
5151
ax = fig.add_subplot(1, 1, 1)
52-
result['ax'] = ax
52+
result["ax"] = ax
5353

5454
ax.grid()
55-
ax.set_title('Power Spectral Density')
56-
ax.set_xlabel(r'Freqency ($Hz$)')
55+
ax.set_title("Power Spectral Density")
56+
ax.set_xlabel(r"Freqency ($Hz$)")
5757
ax.set_xlim((np.min(self.freqs), np.max(self.freqs)))
58-
if scale in ('linear', 'log'):
59-
ax.set_ylabel(r'Power Density ($\mu V^2 / Hz$)')
60-
elif scale in ('db', 'decibels'):
61-
ax.set_ylabel(r'Power Density (dB)')
62-
if scale == 'log':
63-
ax.set_yscale('log')
64-
65-
if scale in ('linear', 'log'):
58+
if scale in ("linear", "log"):
59+
ax.set_ylabel(r"Power Density ($\mu V^2 / Hz$)")
60+
elif scale in ("db", "decibels"):
61+
ax.set_ylabel(r"Power Density (dB)")
62+
if scale == "log":
63+
ax.set_yscale("log")
64+
65+
if scale in ("linear", "log"):
6666
scaledPowers = self.powers
67-
elif scale in ('db', 'decibels'):
67+
elif scale in ("db", "decibels"):
6868
scaledPowers = 10.0*np.log10(self.powers/np.max(self.powers))
6969
else:
70-
raise RuntimeError('Invalid scale %s.' % str(scale))
70+
raise RuntimeError("Invalid scale %s." % str(scale))
7171

7272
lines = ax.plot(self.freqs, scaledPowers, **kwargs)
73-
result['lines'] = lines
73+
result["lines"] = lines
7474

7575
return result
7676

7777

7878
class WelchPSD(PSDBase):
79-
"""PSD smoothed using Welch's method.
79+
"""PSD smoothed using Welch"s method.
8080
"""
8181

8282
def __init__(self, s, sampRate=1.0, span=3.0, overlap=0.5, windowFunc=windows.hann, pad=False):
83-
"""Construct a new PSD using Welch's method.
83+
"""Construct a new PSD using Welch"s method.
8484
8585
Args:
8686
s: Numpy array with shape (observations[,dimensions])
@@ -126,10 +126,10 @@ def __init__(self, s, sampRate=1.0, span=3.0, overlap=0.5, windowFunc=windows.ha
126126

127127
# check span parameter
128128
if wObs > nObs:
129-
raise RuntimeError('Span of %.2f exceedes length of input %.2f.' %
129+
raise RuntimeError("Span of %.2f exceedes length of input %.2f." %
130130
(span, nObs/float(sampRate)))
131131
if wObs < 7:
132-
raise RuntimeError('Span of %.2f is too small.' % span)
132+
raise RuntimeError("Span of %.2f is too small." % span)
133133

134134
if pad:
135135
# find next largest power of two
@@ -161,7 +161,7 @@ def __init__(self, s, sampRate=1.0, span=3.0, overlap=0.5, windowFunc=windows.ha
161161
dft = dft[:,:int(np.ceil(nPad/2.0)),:]
162162

163163
# scale to power/Hz
164-
# numpy fft doesn't support complex64 so can't preserve float32 dtype XXX - idfah
164+
# numpy fft doesn"t support complex64 so can"t preserve float32 dtype XXX - idfah
165165
dftmag = np.abs(dft).astype(s.dtype, copy=False)
166166
powers = 2.0*(dftmag**2)/scaleDenom
167167

@@ -362,16 +362,16 @@ def __init__(self, s, sampRate=1.0, order=20, freqs=None, **kwargs):
362362

363363
# wrapper around class constructors
364364
# pylint: disable=invalid-name
365-
def PowerSpectralDensity(s, method='welch', **kwargs):
365+
def PowerSpectralDensity(s, method="welch", **kwargs):
366366
method = method.lower()
367-
if method == 'welch':
367+
if method == "welch":
368368
return WelchPSD(s, **kwargs)
369-
elif method in ('raw', 'fft'):
369+
elif method in ("raw", "fft"):
370370
return RawPSD(s, **kwargs)
371-
elif method in ('ar', 'autoreg'):
371+
elif method in ("ar", "autoreg"):
372372
return AutoRegPSD(s, **kwargs)
373373
else:
374-
raise RuntimeError('Unknown PSD estimation method: ' + str(method))
374+
raise RuntimeError("Unknown PSD estimation method: " + str(method))
375375

376376
def PSD(*args, **kwargs):
377377
return PowerSpectralDensity(*args, **kwargs)
@@ -389,26 +389,26 @@ def demoPSD():
389389
noise2 = np.random.normal(loc=0.0, scale=0.2, size=s.shape)
390390

391391
y = np.vstack((np.sin(2*f1*np.pi*s)+noise1, 10.0*np.sin(2*f2*np.pi*s)+noise2)).T
392-
print('True max power: ', np.mean(y**2, axis=0))
392+
print("True max power: ", np.mean(y**2, axis=0))
393393

394-
scale = 'log'
394+
scale = "log"
395395

396396
raw = RawPSD(y, sampRate)
397-
ax = raw.plotPower(scale=scale, label='raw')['ax']
398-
print('Raw max power: ', np.max(raw.getPowers()*sampRate, axis=0))
397+
ax = raw.plotPower(scale=scale, label="raw")["ax"]
398+
print("Raw max power: ", np.max(raw.getPowers()*sampRate, axis=0))
399399

400400
welch = WelchPSD(y, sampRate, span=4)
401-
welch.plotPower(scale=scale, ax=ax, label='welch')
402-
print('Welch max power: ', np.max(welch.getPowers()*sampRate, axis=0))
401+
welch.plotPower(scale=scale, ax=ax, label="welch")
402+
print("Welch max power: ", np.max(welch.getPowers()*sampRate, axis=0))
403403

404404
autoreg = AutoRegPSD(y, sampRate, order=10)
405-
autoreg.plotPower(scale=scale, ax=ax, label='autoreg')
406-
print('AR max power: ', np.max(autoreg.getPowers()*sampRate, axis=0))
405+
autoreg.plotPower(scale=scale, ax=ax, label="autoreg")
406+
print("AR max power: ", np.max(autoreg.getPowers()*sampRate, axis=0))
407407

408408
ax.legend()
409409

410410
ax.autoscale(tight=True)
411411

412-
if __name__ == '__main__':
412+
if __name__ == "__main__":
413413
demoPSD()
414414
plt.show()

cebl/sig/resamp.py

Lines changed: 43 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def upsample(s, factor):
4747

4848
s = util.colmat(s)
4949

50-
sup = s.repeat(factor).reshape((-1, s.shape[1]), order='F')
50+
sup = s.repeat(factor).reshape((-1, s.shape[1]), order="F")
5151

5252
if flattenOut:
5353
sup = sup.ravel()
@@ -65,7 +65,7 @@ def decimate(s, factor, lowpassFrac=0.625, **kwargs):
6565

6666
return downsample(sFiltered, factor)
6767

68-
def interpolate(s, factor, order=8, filtType='lanczos'):
68+
def interpolate(s, factor, order=8, filtType="lanczos"):
6969
"""Interpolate (upsample) a discrete signal by a given factor using a
7070
Finite Impulse Response (FIR) filter.
7171
@@ -107,8 +107,8 @@ def interpolate(s, factor, order=8, filtType='lanczos'):
107107
New observations (length 4*2=8): |**|**|**|**
108108
"""
109109
if order % 2 != 0:
110-
raise RuntimeError('Invalid order: ' + str(order) +
111-
' Must be an even integer.')
110+
raise RuntimeError("Invalid order: " + str(order) +
111+
" Must be an even integer.")
112112

113113
# ensure we have a numpy array
114114
s = np.asarray(s)
@@ -136,19 +136,19 @@ def interpolate(s, factor, order=8, filtType='lanczos'):
136136
taps = np.linspace(-radius, radius, newOrder+1).astype(s.dtype, copy=False)
137137

138138
# generate FIR filter
139-
if filtType == 'lanczos':
139+
if filtType == "lanczos":
140140
impulseResponse = np.sinc(taps) * windows.lanczos(newOrder+1).astype(s.dtype, copy=False)
141-
elif filtType == 'sinc-blackman':
141+
elif filtType == "sinc-blackman":
142142
impulseResponse = np.sinc(taps) * windows.blackman(newOrder+1).astype(s.dtype, copy=False)
143143
else:
144-
raise RuntimeError('Invalid filtType: ' + str(filtType))
144+
raise RuntimeError("Invalid filtType: " + str(filtType))
145145

146146
# convolve with FIR filter to smooth across zero padding
147147
# NOTE: there is potential for performance improvement here since
148148
# zeros could be excluded from the computation XXX - idfah
149149
# spsig.fftconvolve might also be faster for long signals XXX - idfah
150150
return np.apply_along_axis(lambda v:
151-
np.convolve(v, impulseResponse, mode='same'),
151+
np.convolve(v, impulseResponse, mode="same"),
152152
axis=0, arr=sl)
153153

154154
def resample(s, factorDown, factorUp=1, interpKwargs=None, **decimKwargs):
@@ -207,11 +207,11 @@ def demoInterpolate():
207207
sLanczos8 = interpolate(s, factor, order=8)
208208
sLanczos16 = interpolate(s, factor, order=16)
209209

210-
plt.plot(t, s, marker='o', color='lightgrey', linewidth=3, label='Original')
211-
plt.plot(tInterp, sLanczos4, color='blue', label='Lanczos4')
212-
plt.plot(tInterp, sLanczos8, color='red', label='Lanczos8')
213-
plt.plot(tInterp, sLanczos16, color='green', label='Lanczos16')
214-
plt.title('Interpolation of a Random Walk')
210+
plt.plot(t, s, marker="o", color="lightgrey", linewidth=3, label="Original")
211+
plt.plot(tInterp, sLanczos4, color="blue", label="Lanczos4")
212+
plt.plot(tInterp, sLanczos8, color="red", label="Lanczos8")
213+
plt.plot(tInterp, sLanczos16, color="green", label="Lanczos16")
214+
plt.title("Interpolation of a Random Walk")
215215
plt.legend()
216216
plt.tight_layout()
217217

@@ -229,69 +229,69 @@ def demoResample():
229229
fig = plt.figure()
230230

231231
##axChirp = fig.add_subplot(4, 1, 1)
232-
##axChirp.plot(f, chirp, color='black')
233-
##axChirp.set_title('Chirp')
234-
##axChirp.set_xlabel('Frequency (Hz)')
235-
##axChirp.set_ylabel('Signal')
232+
##axChirp.plot(f, chirp, color="black")
233+
##axChirp.set_title("Chirp")
234+
##axChirp.set_xlabel("Frequency (Hz)")
235+
##axChirp.set_ylabel("Signal")
236236
##axChirp.autoscale(tight=True)
237237

238238
#axChirpTwiny = axChirp.twiny()
239239
#axChirpTwiny.plot(t, chirp, alpha=0.0)
240-
#axChirpTwiny.set_xlabel('Time (s)')
240+
#axChirpTwiny.set_xlabel("Time (s)")
241241

242242
fDown = downsample(f, factor)
243243
chirpDown = downsample(chirp, factor)
244244

245245
axDown = fig.add_subplot(2, 2, 1)
246-
axDown.plot(f, chirp, color='lightgrey', linewidth=2)
247-
axDown.plot(fDown, chirpDown, color='red')
246+
axDown.plot(f, chirp, color="lightgrey", linewidth=2)
247+
axDown.plot(fDown, chirpDown, color="red")
248248
axDown.vlines(nyquist/factor, -1.0, 1.0, linewidth=2,
249-
linestyle='--', color='green', label='New Nyquist')
250-
axDown.set_title('Downsample factor %d' % factor)
251-
axDown.set_xlabel('Frequency (Hz)')
252-
axDown.set_ylabel('Signal')
249+
linestyle="--", color="green", label="New Nyquist")
250+
axDown.set_title("Downsample factor %d" % factor)
251+
axDown.set_xlabel("Frequency (Hz)")
252+
axDown.set_ylabel("Signal")
253253
axDown.autoscale(tight=True)
254254

255255
chirpDeci = decimate(chirp, factor)
256256
axDeci = fig.add_subplot(2, 2, 3)
257-
axDeci.plot(f, chirp, color='lightgrey', linewidth=2)
258-
axDeci.plot(fDown, chirpDeci, color='red')
257+
axDeci.plot(f, chirp, color="lightgrey", linewidth=2)
258+
axDeci.plot(fDown, chirpDeci, color="red")
259259
axDeci.vlines(nyquist/factor, -1.0, 1.0, linewidth=2,
260-
linestyle='--', color='green', label='New Nyquist')
261-
axDeci.set_title('Decimation factor %d' % factor)
262-
axDeci.set_xlabel('Frequency (Hz)')
263-
axDeci.set_ylabel('Signal')
260+
linestyle="--", color="green", label="New Nyquist")
261+
axDeci.set_title("Decimation factor %d" % factor)
262+
axDeci.set_xlabel("Frequency (Hz)")
263+
axDeci.set_ylabel("Signal")
264264
axDeci.autoscale(tight=True)
265265

266266
fInterp = np.linspace(0.0, nyquist, 2.0*sampRate*factor, endpoint=False)
267267
chirpInterp = interpolate(chirp, factor)
268268

269269
axInterp = fig.add_subplot(2, 2, 2)
270-
axInterp.plot(f, chirp, color='lightgrey', linewidth=2)
271-
axInterp.plot(fInterp, chirpInterp, color='red')
270+
axInterp.plot(f, chirp, color="lightgrey", linewidth=2)
271+
axInterp.plot(fInterp, chirpInterp, color="red")
272272
#axInterp.vlines(nyquist*factor, -1.0, 1.0, linewidth=2,
273-
# linestyle='--', color='green', label='New Nyquist')
274-
axInterp.set_title('Interpolation factor %d' % factor)
275-
axInterp.set_xlabel('Frequency (Hz)')
276-
axInterp.set_ylabel('Signal')
273+
# linestyle="--", color="green", label="New Nyquist")
274+
axInterp.set_title("Interpolation factor %d" % factor)
275+
axInterp.set_xlabel("Frequency (Hz)")
276+
axInterp.set_ylabel("Signal")
277277
axInterp.autoscale(tight=True)
278278

279279
fResamp = np.linspace(0.0, nyquist, 2.0*sampRate*(2.0/factor), endpoint=False)
280280
chirpResamp = resample(chirp, factorUp=2, factorDown=factor)
281281

282282
axResamp = fig.add_subplot(2, 2, 4)
283-
axResamp.plot(f, chirp, color='lightgrey', linewidth=2)
284-
axResamp.plot(fResamp, chirpResamp, color='red')
283+
axResamp.plot(f, chirp, color="lightgrey", linewidth=2)
284+
axResamp.plot(fResamp, chirpResamp, color="red")
285285
axResamp.vlines((2.0/factor)*nyquist, -1.0, 1.0, linewidth=2,
286-
linestyle='--', color='green', label='New Nyquist')
287-
axResamp.set_title('Resample factor 2/%d' % factor)
288-
axResamp.set_xlabel('Frequency (Hz)')
289-
axResamp.set_ylabel('Signal')
286+
linestyle="--", color="green", label="New Nyquist")
287+
axResamp.set_title("Resample factor 2/%d" % factor)
288+
axResamp.set_xlabel("Frequency (Hz)")
289+
axResamp.set_ylabel("Signal")
290290
axResamp.autoscale(tight=True)
291291

292292
fig.tight_layout()
293293

294-
if __name__ == '__main__':
294+
if __name__ == "__main__":
295295
demoInterpolate()
296296
demoResample()
297297
plt.show()

cebl/sig/smooth.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def movingAverage(s, width=2, kernelFunc=windows.boxcar, **kwargs):
3737

3838
return np.apply_along_axis(
3939
np.convolve, axis=0, arr=s,
40-
v=kernel, mode='same')
40+
v=kernel, mode="same")
4141

4242
def savitzkyGolay(s, *args, **kwargs):
4343
"""Savitzky Golay filter.
@@ -113,33 +113,33 @@ def demoSmooth():
113113
fig = plt.figure()
114114

115115
axMA = fig.add_subplot(2, 2, 1)
116-
axMA.plot(x, y+sep, color='grey', linewidth=3)
116+
axMA.plot(x, y+sep, color="grey", linewidth=3)
117117
axMA.plot(x, yMA+sep)
118-
axMA.set_title('Moving Average %d' % maWidth)
118+
axMA.set_title("Moving Average %d" % maWidth)
119119
axMA.autoscale(tight=True)
120120

121121
axGA = fig.add_subplot(2, 2, 2)
122-
axGA.plot(x, y+sep, color='grey', linewidth=3)
122+
axGA.plot(x, y+sep, color="grey", linewidth=3)
123123
axGA.plot(x, yGA+sep)
124-
axGA.set_title('Gaussian Moving Average %d' % gaWidth)
124+
axGA.set_title("Gaussian Moving Average %d" % gaWidth)
125125
axGA.autoscale(tight=True)
126126

127127
axSG = fig.add_subplot(2, 2, 3)
128-
axSG.plot(x, y+sep, color='grey', linewidth=3)
128+
axSG.plot(x, y+sep, color="grey", linewidth=3)
129129
axSG.plot(x, ySG+sep)
130-
axSG.set_title('Savitzky-Golay %d %d' % (sgWidth, sgOrder))
130+
axSG.set_title("Savitzky-Golay %d %d" % (sgWidth, sgOrder))
131131
axSG.autoscale(tight=True)
132132

133133
axWN = fig.add_subplot(2, 2, 4)
134-
axWN.plot(x, y+sep, color='grey', linewidth=3)
134+
axWN.plot(x, y+sep, color="grey", linewidth=3)
135135
axWN.plot(x, yWN+sep)
136-
axWN.set_title('Wiener %d %3.2f' % (wnSize, wnNoise))
137-
#axWN.set_title('Wiener')
136+
axWN.set_title("Wiener %d %3.2f" % (wnSize, wnNoise))
137+
#axWN.set_title("Wiener")
138138
axWN.autoscale(tight=True)
139139

140140
fig.tight_layout()
141141

142142

143-
if __name__ == '__main__':
143+
if __name__ == "__main__":
144144
demoSmooth()
145145
plt.show()

0 commit comments

Comments
 (0)