Renamed an attribute in daqconfigs. Small bugfix in lasp_calibrate.py

This commit is contained in:
Anne de Jong 2020-03-09 15:50:46 +01:00
parent 6acf45a909
commit 04c3631a72
3 changed files with 39 additions and 6 deletions

View File

@ -51,7 +51,7 @@ class DAQConfiguration:
en_format: index of the format in the list of sample formats en_format: index of the format in the list of sample formats
en_input_rate: index of enabled input sampling frequency [Hz] en_input_rate: index of enabled input sampling frequency [Hz]
in the list of frequencies. in the list of frequencies.
en_input_channels: list of channel indices which are used to input_channel_configs: list of channel indices which are used to
acquire data from. acquire data from.
input_sensitivity: List of sensitivity values, in units of [Pa^-1] input_sensitivity: List of sensitivity values, in units of [Pa^-1]
input_gain_settings: If a DAQ supports it, list of indices which input_gain_settings: If a DAQ supports it, list of indices which
@ -76,17 +76,49 @@ class DAQConfiguration:
en_input_rate: int en_input_rate: int
en_output_rate: int en_output_rate: int
en_input_channels: list input_channel_configs: list = None
monitor_gen: bool = False monitor_gen: bool = False
def __post_init__(self):
"""
We do a check here to see whether the list of enabled channels is
contiguous. Non-contiguous is not yet implemented in RtAudio backend.
"""
en_input = self.input_channel_configs
first_ch_enabled_found = False
ch_disabled_found_after = False
print(en_input)
for ch in en_input:
if ch.channel_enabled:
first_ch_enabled_found = True
if ch_disabled_found_after:
raise ValueError('Error: non-contiguous array of channels'
' found. This is not yet implemented in'
' backend')
else:
if first_ch_enabled_found:
ch_disabled_found_after = True
def firstEnabledInputChannelNumber(self):
"""
Returns the channel number of the first enabled channel. Returns -1 if
no channels are enabled.
"""
for i, ch in enumerate(self.input_channel_configs):
if ch.channel_enabled:
return i
return -1
def getEnabledChannels(self): def getEnabledChannels(self):
en_channels = [] en_channels = []
for chan in self.en_input_channels: for chan in self.input_channel_configs:
if chan.channel_enabled: if chan.channel_enabled:
en_channels.append(chan) en_channels.append(chan)
return en_channels return en_channels
def getSensitivities(self): def getEnabledChannelSensitivities(self):
return np.array( return np.array(
[float(channel.sensitivity) for channel in [float(channel.sensitivity) for channel in
self.getEnabledChannels()]) self.getEnabledChannels()])

View File

@ -85,7 +85,7 @@ class AvStream:
self.channel_names.append(channelconfig.channel_name) self.channel_names.append(channelconfig.channel_name)
rtaudio_inputparams = {'deviceid': device.index, rtaudio_inputparams = {'deviceid': device.index,
'nchannels': self.nchannels, 'nchannels': self.nchannels,
'firstchannel': 0} 'firstchannel': firstchannel}
# Here, we override the sample format in case of duplex mode. # Here, we override the sample format in case of duplex mode.
self.sampleformat = daqconfig.en_input_sample_format self.sampleformat = daqconfig.en_input_sample_format

View File

@ -50,10 +50,11 @@ prms = P_REF*10**(args.spl/20)
sens = Vrms / prms sens = Vrms / prms
print(f'Computed sensitivity: {sens[args.channel]:.5} V/Pa') print(f'Computed sensitivity: {sens[args.channel]:.5e} V/Pa')
if args.fn: if args.fn:
print('Searching for files in directory to apply sensitivity value to...') print('Searching for files in directory to apply sensitivity value to...')
dir_ = os.path.dirname(args.fn) dir_ = os.path.dirname(args.fn)
if len(dir_) == 0: dir_ = '.'
for f in os.listdir(dir_): for f in os.listdir(dir_):
yn = input(f'Apply sensitivity to {f}? [Y/n]') yn = input(f'Apply sensitivity to {f}? [Y/n]')
if yn in ['', 'Y', 'y']: if yn in ['', 'Y', 'y']: