From 7b00e3b2bd98ee8cb4d0e494073c7682d9605a4f Mon Sep 17 00:00:00 2001 From: "J.A. de Jong - Redu-Sone B.V., ASCEE V.O.F" Date: Thu, 11 Nov 2021 21:29:08 +0100 Subject: [PATCH] Better output of SLM for plotting as a line --- lasp/lasp_slm.py | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/lasp/lasp_slm.py b/lasp/lasp_slm.py index 4c3f853..71c627e 100644 --- a/lasp/lasp_slm.py +++ b/lasp/lasp_slm.py @@ -8,6 +8,7 @@ from .wrappers import Slm as pyxSlm import numpy as np from .lasp_common import (TimeWeighting, FreqWeighting, P_REF) from .filter import SPLFilterDesigner +import logging __all__ = ['SLM', 'Dummy'] @@ -168,15 +169,33 @@ class SLM: def return_as_dict(self, dat): """ - Helper function used to + Helper function used to return resulting data in a proper way. + + Returns a dictionary with the following keys: + 'data': The y-values of Lmax, Lpeak, etc + 'overall': The overall value, in [dB] **COULD BE NOT PART OF + OUTPUT** + 'x': The exponents of the octave, such that the midband frequency + corresponds to 1000*G**(x/b), where b is the bands, either 1, 3, or + 6 + 'mid': The center frequencies of each band, as a numpy float array + 'nom': The nominal frequency array text, as textual output corresponding + to the frequencies in x, they are '16', .. up to '16k' + """ output = {} - for i, x in enumerate(self.xs): - # '31.5' to '16k' - output[self.nom_txt[i]] = { 'data': dat[i], - 'x': x} + output['nom'] = self.nom_txt + output['x'] = list(self.xs) + output['mid'] = self.fbdesigner.fm(list(self.xs)) + logging.debug(list(self.xs)) + logging.debug(output['mid']) + # Indiced at 0, as pyxSLM always returns 2D arrays. + if self.include_overall and self.fbdesigner is not None: - output['overall'] = {'data': dat[i+1], 'x': 0} + output['overall'] = dat[-1] + output['y'] = np.asarray(dat[:-1,0]) + else: + output['y'] = np.asarray(dat[:,0]) return output def Leq(self):