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:
parent
64821f8c6f
commit
a8c71f7aa0
@ -27,7 +27,7 @@ class AvStream:
|
||||
self.daqconfig = daqconfig
|
||||
try:
|
||||
daq = DAQDevice(daqconfig)
|
||||
self.nchannels = len(daq.channels_enabled)
|
||||
self.nchannels = len(daq.channels_en)
|
||||
self.samplerate = daq.input_rate
|
||||
self.blocksize = daq.blocksize
|
||||
except Exception as e:
|
||||
|
@ -1,5 +1,5 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
import numpy as np
|
||||
from .wrappers import Window as wWindow
|
||||
"""
|
||||
@ -7,14 +7,14 @@ Common definitions used throughout the code.
|
||||
"""
|
||||
|
||||
__all__ = ['P_REF', 'FreqWeighting', 'TimeWeighting', 'getTime', 'calfile',
|
||||
'sens']
|
||||
]
|
||||
|
||||
# Reference sound pressure level
|
||||
P_REF = 2e-5
|
||||
|
||||
# Todo: fix This
|
||||
calfile = '/home/anne/wip/UMIK-1/cal/7027430_90deg.txt'
|
||||
sens = 0.053690387255872614
|
||||
# calfile = '/home/anne/wip/UMIK-1/cal/7027430_90deg.txt'
|
||||
calfile = None
|
||||
|
||||
|
||||
class Window:
|
||||
|
@ -94,7 +94,7 @@ def getSampWidth(dtype):
|
||||
|
||||
|
||||
def exportAsWave(fn, fs, data, force=False):
|
||||
if not '.wav' in fn[-4:]:
|
||||
if '.wav' not in fn[-4:]:
|
||||
fn += '.wav'
|
||||
|
||||
nchannels = data.shape[1]
|
||||
@ -239,7 +239,8 @@ class Measurement:
|
||||
|
||||
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:
|
||||
with self.file() as f:
|
||||
@ -293,6 +294,7 @@ class Measurement:
|
||||
raise ValueError('Invalid sensitivity value(s) given')
|
||||
with self.file('r+') as f:
|
||||
f.attrs['sensitivity'] = sens
|
||||
self._sens = sens
|
||||
|
||||
def exportAsWave(self, fn=None, force=False, sampwidth=None):
|
||||
"""
|
||||
|
@ -15,17 +15,19 @@ from .lasp_atomic import Atomic
|
||||
from threading import Thread, Condition
|
||||
import h5py
|
||||
|
||||
|
||||
class Playback:
|
||||
"""
|
||||
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'
|
||||
if not ext in fn1:
|
||||
fn = fn1 + ext
|
||||
fn = fn1 + ext
|
||||
else:
|
||||
fn = fn1
|
||||
|
||||
@ -40,7 +42,7 @@ class Playback:
|
||||
if video:
|
||||
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.nchannels = f.attrs['nchannels']
|
||||
self.blocksize = f.attrs['blocksize']
|
||||
@ -48,8 +50,8 @@ class Playback:
|
||||
if verbose:
|
||||
print('Sample rate: ', self.samplerate)
|
||||
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:
|
||||
try:
|
||||
@ -64,12 +66,16 @@ class Playback:
|
||||
return self._nblocks*self._blocksize/self._samplerate
|
||||
|
||||
def start(self):
|
||||
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)
|
||||
with h5py.File(self._fn, 'r') as f:
|
||||
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
|
||||
if self._video:
|
||||
self._vd = f['video']
|
||||
@ -93,7 +99,7 @@ class Playback:
|
||||
"""
|
||||
aframectr = self._aframectr()
|
||||
if aframectr < self.nblocks:
|
||||
outdata[:,0] = self._ad[aframectr,:,self.channel]
|
||||
outdata[:, 0] = self._ad[aframectr, :, self.channel]
|
||||
self._aframectr += 1
|
||||
else:
|
||||
self._running <<= False
|
||||
@ -116,11 +122,10 @@ class Playback:
|
||||
print('Sleep video...')
|
||||
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'):
|
||||
self._running <<= False
|
||||
|
||||
frame_ctr += 1
|
||||
print('Ending video playback thread')
|
||||
cv.destroyAllWindows()
|
||||
|
||||
|
@ -8,7 +8,7 @@ from .wrappers import SPLowpass
|
||||
from .lasp_computewidget import ComputeWidget
|
||||
import numpy as np
|
||||
from .lasp_config import zeros
|
||||
from .lasp_common import (FreqWeighting, sens, calfile,
|
||||
from .lasp_common import (FreqWeighting, calfile,
|
||||
TimeWeighting, getTime, P_REF)
|
||||
from .lasp_weighcal import WeighCal
|
||||
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
|
||||
# robust variant.
|
||||
weighcal = WeighCal(fw, nchannels=1,
|
||||
fs=fs, calfile=calfile,
|
||||
sens=sens)
|
||||
fs=fs, calfile=calfile)
|
||||
praw = meas.praw()[istart:istop, [channel]]
|
||||
|
||||
weighted = weighcal.filter_(praw)
|
||||
@ -260,8 +259,7 @@ class SlmWidget(ComputeWidget, Ui_SlmWidget):
|
||||
praw = meas.praw()[istart:istop, [channel]]
|
||||
|
||||
weighcal = WeighCal(fw, nchannels=1,
|
||||
fs=fs, calfile=calfile,
|
||||
sens=sens)
|
||||
fs=fs, calfile=calfile)
|
||||
|
||||
weighted = weighcal.filter_(praw)
|
||||
|
||||
|
@ -19,11 +19,11 @@ class WeighCal:
|
||||
"""
|
||||
Frequency weighting and calibration FIR filter
|
||||
"""
|
||||
|
||||
def __init__(self, fw=FreqWeighting.default,
|
||||
nchannels=1,
|
||||
fs=48000.,
|
||||
calfile=None,
|
||||
sens=1.0):
|
||||
calfile=None):
|
||||
"""
|
||||
Initialize the frequency weighting and calibration FIR filters.
|
||||
|
||||
@ -32,13 +32,12 @@ class WeighCal:
|
||||
nchannels: Number of channels for the input data
|
||||
fs: Sampling frequency [Hz]
|
||||
calfile: Calibration file to load.
|
||||
sens: Sensitivity in units [\f$ Pa^{-1} \f$]
|
||||
"""
|
||||
|
||||
self.nchannels = nchannels
|
||||
self.fs = fs
|
||||
self.fw = fw
|
||||
self.sens = sens
|
||||
|
||||
self.calfile = calfile
|
||||
|
||||
# Frequencies used for the filter design
|
||||
@ -83,7 +82,7 @@ class WeighCal:
|
||||
filtered = []
|
||||
for chan in range(nchan):
|
||||
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:
|
||||
filtered = filtered[:, np.newaxis]
|
||||
return filtered
|
||||
|
Loading…
Reference in New Issue
Block a user