Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pytta/_h5utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def int_parser(attr):
np.int32,
np.int64,
int,
np.int0)):
np.intp)):
return int(attr)
else:
return attr
Expand Down
4 changes: 2 additions & 2 deletions pytta/classes/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -490,8 +490,8 @@ def CF(self):

@CF.setter
def CF(self, newCF):
if isinstance(newCF, float) or isinstance(newCF, int):
self._CF = newCF
if isinstance(newCF, (int, float, np.integer, np.floating)):
self._CF = float(newCF)
else:
raise TypeError('Channel correction factor must be a number.')
return
Expand Down
18 changes: 9 additions & 9 deletions pytta/classes/signal.py
Original file line number Diff line number Diff line change
Expand Up @@ -941,14 +941,14 @@ def __truediv__(self, other):
raise ValueError("Both signal-like objects must have the \
same number of channels.")
result_freqSignal = np.zeros(self.freqSignal.shape,
dtype=np.complex_)
dtype=np.complex128)
for channel in range(other.numChannels):
result_freqSignal[:, channel] = \
currentFreqSignal[:, channel] \
/ otherFreqSignal[:, channel]
else:
result_freqSignal = np.zeros(self.freqSignal.shape,
dtype=np.complex_)
dtype=np.complex128)
for channel in range(self.numChannels):
result_freqSignal[:, channel] = \
currentFreqSignal[:, channel] \
Expand Down Expand Up @@ -998,14 +998,14 @@ def __mul__(self, other):
raise ValueError("Both signal-like objects must have the \
same number of channels.")
result_freqSignal = np.zeros(self.freqSignal.shape,
dtype=np.complex_)
dtype=np.complex128)
for channel in range(other.numChannels):
result_freqSignal[:, channel] = \
currentFreqSignal[:, channel] \
* otherFreqSignal[:, channel]
else:
result_freqSignal = np.zeros(self.freqSignal.shape,
dtype=np.complex_)
dtype=np.complex128)
for channel in range(self.numChannels):
result_freqSignal[:, channel] = \
currentFreqSignal[:, channel] \
Expand Down Expand Up @@ -1144,7 +1144,7 @@ def _ifft(self):
"""
# spectrum denormalization
if self.signalType == 'power':
adjustedFreqSignal = np.zeros(self._freqSignal.shape, dtype=np.complex_)
adjustedFreqSignal = np.zeros(self._freqSignal.shape, dtype=np.complex128)
# * N/2 for AC
adjustedFreqSignal[1:, :] = \
self._freqSignal * len(self._freqSignal)
Expand Down Expand Up @@ -1762,8 +1762,8 @@ def _crossfade_spectruns(self, a, b, freqLims, freqVector):
leftWin,
np.ones(totalSamples-len(leftWin)-f0idx)))

aFreqSignal = np.zeros(a.shape, dtype=np.complex_)
bFreqSignal = np.zeros(b.shape, dtype=np.complex_)
aFreqSignal = np.zeros(a.shape, dtype=np.complex128)
bFreqSignal = np.zeros(b.shape, dtype=np.complex128)

for chIndex in range(a.shape[1]):
aFreqSignal[:,chIndex] = a[:,chIndex] * fullRightWin
Expand Down Expand Up @@ -1791,14 +1791,14 @@ def _calc_csd_tf(self, sig1, sig2, samplingRate, windowName,


def _make_rms_spectra(freqSignal):
newFreqSignal = np.zeros(freqSignal.shape, dtype=np.complex_)
newFreqSignal = np.zeros(freqSignal.shape, dtype=np.complex128)
newFreqSignal[1:, :] = freqSignal[1:, :] / 2**(1/2)
newFreqSignal[0, :] = freqSignal[0, :]
return newFreqSignal


def _make_pk_spectra(freqSignal):
newFreqSignal = np.zeros(freqSignal.shape, dtype=np.complex_)
newFreqSignal = np.zeros(freqSignal.shape, dtype=np.complex128)
newFreqSignal[1:, :] = freqSignal[1:, :] * 2**(1/2)
newFreqSignal[0, :] = freqSignal[0, :]
return newFreqSignal
Expand Down
2 changes: 1 addition & 1 deletion pytta/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ def resample(signal, newSamplingRate):
Resample the timeSignal of the input SignalObj to the
given sample rate using the scipy.signal.resample() function
"""
newSignalSize = np.int(signal.timeLength*newSamplingRate)
newSignalSize = int(signal.timeLength*newSamplingRate)
resampled = ss.resample(signal.timeSignal[:], newSignalSize)
newSignal = SignalObj(resampled, "time", newSamplingRate)
return newSignal
Expand Down
31 changes: 31 additions & 0 deletions tests/test_calibration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
"""
Test for SignalObj.calib_pressure: the correction factor is the reference
rms over the rms of the calibrator recording. On NumPy 2 that ratio is a
NumPy float32, which the channel must accept.
"""
import os
import unittest

os.environ.setdefault('MPLBACKEND', 'Agg')

import numpy as np

import pytta

FS = 48000


class TestCalibration(unittest.TestCase):

def test_correction_factor_from_a_calibrator(self):
tt = np.arange(FS) / FS
calibrator = pytta.SignalObj(
0.1 * np.sqrt(2) * np.sin(2 * np.pi * 1000 * tt), 'time', FS)
sig = pytta.SignalObj(np.ones(FS), 'time', FS)
sig.calib_pressure(0, calibrator, refPrms=1.0)
self.assertAlmostEqual(sig.channels[1].CF, 10, places=5)
self.assertTrue(np.allclose(sig.timeSignal, 10, rtol=1e-5))


if __name__ == '__main__':
unittest.main()