Better output of SLM for plotting as a line

This commit is contained in:
Anne de Jong 2021-11-11 21:29:08 +01:00
parent accde58b5b
commit 7b00e3b2bd

View File

@ -8,6 +8,7 @@ from .wrappers import Slm as pyxSlm
import numpy as np import numpy as np
from .lasp_common import (TimeWeighting, FreqWeighting, P_REF) from .lasp_common import (TimeWeighting, FreqWeighting, P_REF)
from .filter import SPLFilterDesigner from .filter import SPLFilterDesigner
import logging
__all__ = ['SLM', 'Dummy'] __all__ = ['SLM', 'Dummy']
@ -168,15 +169,33 @@ class SLM:
def return_as_dict(self, dat): 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 = {} output = {}
for i, x in enumerate(self.xs): output['nom'] = self.nom_txt
# '31.5' to '16k' output['x'] = list(self.xs)
output[self.nom_txt[i]] = { 'data': dat[i], output['mid'] = self.fbdesigner.fm(list(self.xs))
'x': x} 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: 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 return output
def Leq(self): def Leq(self):