From b3ce37591fc116c6aba237def7c36321aadc6346 Mon Sep 17 00:00:00 2001 From: "J.A. de Jong - Redu-Sone B.V., ASCEE V.O.F" Date: Thu, 20 May 2021 22:17:22 +0200 Subject: [PATCH] Bugfix of channel names in measurement. Set default frequency weighting to Z, in stead of A, on advice of Casper --- lasp/lasp_common.py | 4 ++-- lasp/lasp_measurement.py | 20 ++++++++++++++------ setup.py | 8 ++++---- 3 files changed, 20 insertions(+), 12 deletions(-) diff --git a/lasp/lasp_common.py b/lasp/lasp_common.py index f6003c9..10a1b31 100644 --- a/lasp/lasp_common.py +++ b/lasp/lasp_common.py @@ -336,11 +336,11 @@ class FreqWeighting: """ Frequency weighting types """ + Z = ('Z', 'Z-weighting') A = ('A', 'A-weighting') C = ('C', 'C-weighting') - Z = ('Z', 'Z-weighting') types = (A, C, Z) - default = A + default = Z default_index = 0 @staticmethod diff --git a/lasp/lasp_measurement.py b/lasp/lasp_measurement.py index 5f96d0d..3373a26 100644 --- a/lasp/lasp_measurement.py +++ b/lasp/lasp_measurement.py @@ -208,11 +208,16 @@ class Measurement: self.N = (self.nblocks * self.blocksize) 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: - self._channel_names = f.attrs['channel_names'] + self._channelNames = f.attrs['channel_names'] except KeyError: - # No channel names found in measurement file - self._channel_names = [f'Unnamed {i}' for i in range(self.nchannels)] + try: + 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 try: @@ -232,7 +237,6 @@ class Measurement: self._time = f.attrs['time'] - try: qtys_json = f.attrs['qtys'] # Load quantity data @@ -244,10 +248,14 @@ class Measurement: self._qtys = [SIQtys.default for i in range(self.nchannels)] 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: # Update comment attribute in the file f.attrs[atrname] = value - setattr(self, '_' + atrname, value) + setattr(self, '_' + atrname, value) @property def name(self): @@ -256,7 +264,7 @@ class Measurement: @property def channelNames(self): - return self._channel_names + return self._channelNames @channelNames.setter def channelNames(self, newchnames): diff --git a/setup.py b/setup.py index 322e3f6..409e566 100644 --- a/setup.py +++ b/setup.py @@ -27,16 +27,16 @@ setup( long_description_content_type="text/markdown", # ext_modules=[CMakeExtension('lasp/wrappers.so'), # ], - package_data={'lasp': ['wrappers.so']}, + #package_data={'lasp': ['wrappers.so']}, author='J.A. de Jong - ASCEE', author_email="j.a.dejong@ascee.nl", install_requires=['matplotlib>=1.0', - 'scipy>=1.0', 'numpy>=1.0', 'h5py', - 'dataclasses_json', + 'scipy>=1.0', 'numpy>=1.0', 'h5py==3.2.0', + 'dataclasses_json', 'cython', ], license='MIT', description="Library for Acoustic Signal Processing", keywords="", - url="https://www.ascee.nl/lasp/", # project home page, if any + url="https://www.ascee.nl/lasp/", # project home page )