Sensitivity applied in measurement praw() function, removed from WeighCal class. CalFile standard set to None, as we use MM210 from now on. Bugfix in measurement sensitivity setter. Started cleaning up of real time power spectra widget.

This commit is contained in:
Anne de Jong 2018-07-31 11:23:24 +02:00 committed by J.A. de Jong - ASCEE
parent 64821f8c6f
commit a8c71f7aa0
6 changed files with 49 additions and 45 deletions

View File

@ -27,7 +27,7 @@ class AvStream:
self.daqconfig = daqconfig self.daqconfig = daqconfig
try: try:
daq = DAQDevice(daqconfig) daq = DAQDevice(daqconfig)
self.nchannels = len(daq.channels_enabled) self.nchannels = len(daq.channels_en)
self.samplerate = daq.input_rate self.samplerate = daq.input_rate
self.blocksize = daq.blocksize self.blocksize = daq.blocksize
except Exception as e: except Exception as e:

View File

@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
#!/usr/bin/env python3 #!/usr/bin/env python3
# -*- coding: utf-8 -*-
import numpy as np import numpy as np
from .wrappers import Window as wWindow from .wrappers import Window as wWindow
""" """
@ -7,14 +7,14 @@ Common definitions used throughout the code.
""" """
__all__ = ['P_REF', 'FreqWeighting', 'TimeWeighting', 'getTime', 'calfile', __all__ = ['P_REF', 'FreqWeighting', 'TimeWeighting', 'getTime', 'calfile',
'sens'] ]
# Reference sound pressure level # Reference sound pressure level
P_REF = 2e-5 P_REF = 2e-5
# Todo: fix This # Todo: fix This
calfile = '/home/anne/wip/UMIK-1/cal/7027430_90deg.txt' # calfile = '/home/anne/wip/UMIK-1/cal/7027430_90deg.txt'
sens = 0.053690387255872614 calfile = None
class Window: class Window:

View File

@ -94,7 +94,7 @@ def getSampWidth(dtype):
def exportAsWave(fn, fs, data, force=False): def exportAsWave(fn, fs, data, force=False):
if not '.wav' in fn[-4:]: if '.wav' not in fn[-4:]:
fn += '.wav' fn += '.wav'
nchannels = data.shape[1] nchannels = data.shape[1]
@ -239,7 +239,8 @@ class Measurement:
def praw(self, block=None): def praw(self, block=None):
""" """
Returns the raw uncalibrated data, converted to floating point format. Returns the uncalibrated acoustic pressure signal, converted to floating
point acoustic pressure values [Pa].
""" """
if block is not None: if block is not None:
with self.file() as f: with self.file() as f:
@ -293,6 +294,7 @@ class Measurement:
raise ValueError('Invalid sensitivity value(s) given') raise ValueError('Invalid sensitivity value(s) given')
with self.file('r+') as f: with self.file('r+') as f:
f.attrs['sensitivity'] = sens f.attrs['sensitivity'] = sens
self._sens = sens
def exportAsWave(self, fn=None, force=False, sampwidth=None): def exportAsWave(self, fn=None, force=False, sampwidth=None):
""" """

View File

@ -15,17 +15,19 @@ from .lasp_atomic import Atomic
from threading import Thread, Condition from threading import Thread, Condition
import h5py import h5py
class Playback: class Playback:
""" """
Play back a single channel from a Play back a single channel from a
""" """
def __init__(self, fn1, channel = 0, video=True, verbose=True):
def __init__(self, fn1, channel=0, video=True, verbose=True):
""" """
""" """
ext = '.h5' ext = '.h5'
if not ext in fn1: if not ext in fn1:
fn = fn1 + ext fn = fn1 + ext
else: else:
fn = fn1 fn = fn1
@ -40,7 +42,7 @@ class Playback:
if video: if video:
self._video_queue = queue.Queue() self._video_queue = queue.Queue()
with h5py.File(fn,'r') as f: with h5py.File(fn, 'r') as f:
self.samplerate = f.attrs['samplerate'] self.samplerate = f.attrs['samplerate']
self.nchannels = f.attrs['nchannels'] self.nchannels = f.attrs['nchannels']
self.blocksize = f.attrs['blocksize'] self.blocksize = f.attrs['blocksize']
@ -48,8 +50,8 @@ class Playback:
if verbose: if verbose:
print('Sample rate: ', self.samplerate) print('Sample rate: ', self.samplerate)
print('Number of audio frames: ', self.nblocks*self.blocksize) print('Number of audio frames: ', self.nblocks*self.blocksize)
print('Recording time: ', self.nblocks*self.blocksize/self.samplerate) print('Recording time: ', self.nblocks *
self.blocksize/self.samplerate)
if video: if video:
try: try:
@ -64,12 +66,16 @@ class Playback:
return self._nblocks*self._blocksize/self._samplerate return self._nblocks*self._blocksize/self._samplerate
def start(self): def start(self):
with h5py.File(self._fn,'r') as f: with h5py.File(self._fn, 'r') as f:
stream = sd.OutputStream(samplerate = self.samplerate,
blocksize = self.blocksize,
channels = 1,
dtype = 'int32',callback = self.audio_callback)
self._ad = f['audio'] self._ad = f['audio']
dtype = self._ad.dtype
dtype_str = str(dtype)
stream = sd.OutputStream(samplerate=self.samplerate,
blocksize=self.blocksize,
channels=1,
dtype=dtype_str,
callback=self.audio_callback)
self._running <<= True self._running <<= True
if self._video: if self._video:
self._vd = f['video'] self._vd = f['video']
@ -93,7 +99,7 @@ class Playback:
""" """
aframectr = self._aframectr() aframectr = self._aframectr()
if aframectr < self.nblocks: if aframectr < self.nblocks:
outdata[:,0] = self._ad[aframectr,:,self.channel] outdata[:, 0] = self._ad[aframectr, :, self.channel]
self._aframectr += 1 self._aframectr += 1
else: else:
self._running <<= False self._running <<= False
@ -116,11 +122,10 @@ class Playback:
print('Sleep video...') print('Sleep video...')
time.sleep(self.blocksize/self.samplerate/2) time.sleep(self.blocksize/self.samplerate/2)
cv.imshow("Video output. Press 'q' to quit",frame) cv.imshow("Video output. Press 'q' to quit", frame)
if cv.waitKey(1) & 0xFF == ord('q'): if cv.waitKey(1) & 0xFF == ord('q'):
self._running <<= False self._running <<= False
frame_ctr += 1 frame_ctr += 1
print('Ending video playback thread') print('Ending video playback thread')
cv.destroyAllWindows() cv.destroyAllWindows()

View File

@ -8,7 +8,7 @@ from .wrappers import SPLowpass
from .lasp_computewidget import ComputeWidget from .lasp_computewidget import ComputeWidget
import numpy as np import numpy as np
from .lasp_config import zeros from .lasp_config import zeros
from .lasp_common import (FreqWeighting, sens, calfile, from .lasp_common import (FreqWeighting, calfile,
TimeWeighting, getTime, P_REF) TimeWeighting, getTime, P_REF)
from .lasp_weighcal import WeighCal from .lasp_weighcal import WeighCal
from .lasp_gui_tools import wait_cursor from .lasp_gui_tools import wait_cursor
@ -197,8 +197,7 @@ class SlmWidget(ComputeWidget, Ui_SlmWidget):
# variables defined at the top. # TODO: Change this to a more # variables defined at the top. # TODO: Change this to a more
# robust variant. # robust variant.
weighcal = WeighCal(fw, nchannels=1, weighcal = WeighCal(fw, nchannels=1,
fs=fs, calfile=calfile, fs=fs, calfile=calfile)
sens=sens)
praw = meas.praw()[istart:istop, [channel]] praw = meas.praw()[istart:istop, [channel]]
weighted = weighcal.filter_(praw) weighted = weighcal.filter_(praw)
@ -260,8 +259,7 @@ class SlmWidget(ComputeWidget, Ui_SlmWidget):
praw = meas.praw()[istart:istop, [channel]] praw = meas.praw()[istart:istop, [channel]]
weighcal = WeighCal(fw, nchannels=1, weighcal = WeighCal(fw, nchannels=1,
fs=fs, calfile=calfile, fs=fs, calfile=calfile)
sens=sens)
weighted = weighcal.filter_(praw) weighted = weighcal.filter_(praw)

View File

@ -19,11 +19,11 @@ class WeighCal:
""" """
Frequency weighting and calibration FIR filter Frequency weighting and calibration FIR filter
""" """
def __init__(self, fw=FreqWeighting.default, def __init__(self, fw=FreqWeighting.default,
nchannels=1, nchannels=1,
fs=48000., fs=48000.,
calfile=None, calfile=None):
sens=1.0):
""" """
Initialize the frequency weighting and calibration FIR filters. Initialize the frequency weighting and calibration FIR filters.
@ -32,13 +32,12 @@ class WeighCal:
nchannels: Number of channels for the input data nchannels: Number of channels for the input data
fs: Sampling frequency [Hz] fs: Sampling frequency [Hz]
calfile: Calibration file to load. calfile: Calibration file to load.
sens: Sensitivity in units [\f$ Pa^{-1} \f$]
""" """
self.nchannels = nchannels self.nchannels = nchannels
self.fs = fs self.fs = fs
self.fw = fw self.fw = fw
self.sens = sens
self.calfile = calfile self.calfile = calfile
# Frequencies used for the filter design # Frequencies used for the filter design
@ -83,7 +82,7 @@ class WeighCal:
filtered = [] filtered = []
for chan in range(nchan): for chan in range(nchan):
filtered.append(self._fbs[chan].filter_(data[:, [chan]])[:, 0]) filtered.append(self._fbs[chan].filter_(data[:, [chan]])[:, 0])
filtered = np.asarray(filtered).transpose()/self.sens filtered = np.asarray(filtered).transpose()
if filtered.ndim == 1: if filtered.ndim == 1:
filtered = filtered[:, np.newaxis] filtered = filtered[:, np.newaxis]
return filtered return filtered