Bugfix of channel names in measurement. Set default frequency weighting to Z, in stead of A, on advice of Casper

This commit is contained in:
Anne de Jong 2021-05-20 22:17:22 +02:00
parent 377291ccf4
commit b3ce37591f
3 changed files with 20 additions and 12 deletions

View File

@ -336,11 +336,11 @@ class FreqWeighting:
""" """
Frequency weighting types Frequency weighting types
""" """
Z = ('Z', 'Z-weighting')
A = ('A', 'A-weighting') A = ('A', 'A-weighting')
C = ('C', 'C-weighting') C = ('C', 'C-weighting')
Z = ('Z', 'Z-weighting')
types = (A, C, Z) types = (A, C, Z)
default = A default = Z
default_index = 0 default_index = 0
@staticmethod @staticmethod

View File

@ -208,11 +208,16 @@ class Measurement:
self.N = (self.nblocks * self.blocksize) self.N = (self.nblocks * self.blocksize)
self.T = self.N / self.samplerate self.T = self.N / self.samplerate
# Due to a previous bug, the channel names were not stored
# consistently, i.e. as 'channel_names' and later camelcase.
try: try:
self._channel_names = f.attrs['channel_names'] self._channelNames = f.attrs['channel_names']
except KeyError: except KeyError:
# No channel names found in measurement file try:
self._channel_names = [f'Unnamed {i}' for i in range(self.nchannels)] self._channelNames = f.attrs['channelNames']
except KeyError:
# No channel names found in measurement file
self._channelNames = [f'Unnamed {i}' for i in range(self.nchannels)]
# comment = read-write thing # comment = read-write thing
try: try:
@ -232,7 +237,6 @@ class Measurement:
self._time = f.attrs['time'] self._time = f.attrs['time']
try: try:
qtys_json = f.attrs['qtys'] qtys_json = f.attrs['qtys']
# Load quantity data # Load quantity data
@ -244,10 +248,14 @@ class Measurement:
self._qtys = [SIQtys.default for i in range(self.nchannels)] self._qtys = [SIQtys.default for i in range(self.nchannels)]
def setAttribute(self, atrname, value): def setAttribute(self, atrname, value):
"""
Set an attribute in the measurement file, and keep a local copy in
memory for efficient accessing.
"""
with self.file('r+') as f: with self.file('r+') as f:
# Update comment attribute in the file # Update comment attribute in the file
f.attrs[atrname] = value f.attrs[atrname] = value
setattr(self, '_' + atrname, value) setattr(self, '_' + atrname, value)
@property @property
def name(self): def name(self):
@ -256,7 +264,7 @@ class Measurement:
@property @property
def channelNames(self): def channelNames(self):
return self._channel_names return self._channelNames
@channelNames.setter @channelNames.setter
def channelNames(self, newchnames): def channelNames(self, newchnames):

View File

@ -27,16 +27,16 @@ setup(
long_description_content_type="text/markdown", long_description_content_type="text/markdown",
# ext_modules=[CMakeExtension('lasp/wrappers.so'), # ext_modules=[CMakeExtension('lasp/wrappers.so'),
# ], # ],
package_data={'lasp': ['wrappers.so']}, #package_data={'lasp': ['wrappers.so']},
author='J.A. de Jong - ASCEE', author='J.A. de Jong - ASCEE',
author_email="j.a.dejong@ascee.nl", author_email="j.a.dejong@ascee.nl",
install_requires=['matplotlib>=1.0', install_requires=['matplotlib>=1.0',
'scipy>=1.0', 'numpy>=1.0', 'h5py', 'scipy>=1.0', 'numpy>=1.0', 'h5py==3.2.0',
'dataclasses_json', 'dataclasses_json', 'cython',
], ],
license='MIT', license='MIT',
description="Library for Acoustic Signal Processing", description="Library for Acoustic Signal Processing",
keywords="", keywords="",
url="https://www.ascee.nl/lasp/", # project home page, if any url="https://www.ascee.nl/lasp/", # project home page
) )