Added loads of comments and readability improvements.
This commit is contained in:
parent
21d9efc139
commit
505add6ae1
1
.gitignore
vendored
1
.gitignore
vendored
@ -23,3 +23,4 @@ lasp_octave_fir.*
|
|||||||
lasp/ui_*
|
lasp/ui_*
|
||||||
resources_rc.py
|
resources_rc.py
|
||||||
lasp/device/lasp_daqdevice.c
|
lasp/device/lasp_daqdevice.c
|
||||||
|
.ropeproject
|
||||||
|
@ -30,7 +30,8 @@ endif(LASP_FLOAT STREQUAL "double")
|
|||||||
|
|
||||||
|
|
||||||
if(NOT DEFINED LASP_DEBUG)
|
if(NOT DEFINED LASP_DEBUG)
|
||||||
message(FATAL_ERROR "LASP_DEBUG flag not defined. Please set -DLASP_DEBUG=TRUE or -DLASP_DEBUG=FALSE")
|
message(FATAL_ERROR "LASP_DEBUG flag not defined. Please set -DLASP_DEBUG=TRUE
|
||||||
|
or -DLASP_DEBUG=FALSE")
|
||||||
endif(NOT DEFINED LASP_DEBUG)
|
endif(NOT DEFINED LASP_DEBUG)
|
||||||
|
|
||||||
# ##################### END Cmake variables converted to a macro
|
# ##################### END Cmake variables converted to a macro
|
||||||
@ -53,7 +54,7 @@ if(LASP_DEBUG)
|
|||||||
# Add the __FILENAME__ macro
|
# Add the __FILENAME__ macro
|
||||||
# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D__FILENAME__='\"$(subst ${CMAKE_SOURCE_DIR}/,,$(abspath $<))\"'")
|
# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D__FILENAME__='\"$(subst ${CMAKE_SOURCE_DIR}/,,$(abspath $<))\"'")
|
||||||
else()
|
else()
|
||||||
message("Building release code")
|
message("Building LASP for release")
|
||||||
set(CMAKE_BUILD_TYPE Release)
|
set(CMAKE_BUILD_TYPE Release)
|
||||||
set(CYTHON_ANNOTATE OFF)
|
set(CYTHON_ANNOTATE OFF)
|
||||||
set(CYTHON_NO_DOCSTRINGS ON)
|
set(CYTHON_NO_DOCSTRINGS ON)
|
||||||
|
@ -20,6 +20,7 @@ Atomic increment:
|
|||||||
"""
|
"""
|
||||||
from threading import Lock
|
from threading import Lock
|
||||||
|
|
||||||
|
|
||||||
class Atomic:
|
class Atomic:
|
||||||
def __init__(self, val):
|
def __init__(self, val):
|
||||||
self._val = val
|
self._val = val
|
||||||
@ -35,7 +36,6 @@ class Atomic:
|
|||||||
self._val -= toadd
|
self._val -= toadd
|
||||||
return self
|
return self
|
||||||
|
|
||||||
|
|
||||||
def __bool__(self):
|
def __bool__(self):
|
||||||
with self._lock:
|
with self._lock:
|
||||||
return self._val
|
return self._val
|
||||||
@ -48,4 +48,3 @@ class Atomic:
|
|||||||
def __call__(self):
|
def __call__(self):
|
||||||
with self._lock:
|
with self._lock:
|
||||||
return self._val
|
return self._val
|
||||||
|
|
@ -29,7 +29,8 @@ class AvStream:
|
|||||||
self.nchannels = len(daq.channels_en)
|
self.nchannels = len(daq.channels_en)
|
||||||
self.samplerate = daq.input_rate
|
self.samplerate = daq.input_rate
|
||||||
self.blocksize = daq.blocksize
|
self.blocksize = daq.blocksize
|
||||||
self.sensitivity = np.asarray(daqconfig.input_sensitivity)[daq.channels_en]
|
self.sensitivity = np.asarray(daqconfig.input_sensitivity)[
|
||||||
|
daq.channels_en]
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise RuntimeError(f'Could not initialize DAQ device: {str(e)}')
|
raise RuntimeError(f'Could not initialize DAQ device: {str(e)}')
|
||||||
|
|
||||||
|
@ -7,16 +7,7 @@ Common definitions used throughout the code.
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
__all__ = ['P_REF', 'FreqWeighting', 'TimeWeighting', 'getTime', 'calfile',
|
__all__ = ['P_REF', 'FreqWeighting', 'TimeWeighting', 'getTime', 'calfile',
|
||||||
'W_REF', 'U_REF', 'I_REF', 'DEFAULT_FIGSIZE_H', 'DEFAULT_FIGSIZE_W',
|
'W_REF', 'U_REF', 'I_REF']
|
||||||
'GOLDEN', 'PLOT_COLORS_LIST', 'PLOT_NOCOLORS_LIST']
|
|
||||||
|
|
||||||
PLOT_COLORS_LIST = ['b', 'g', 'r', 'c', 'm', 'y', 'k', '#BE6500']
|
|
||||||
PLOT_NOCOLORS_LIST = ['k', '0.5', 'k', '0.5', '0.5', '0.5', '0.5', 'k']
|
|
||||||
|
|
||||||
DEFAULT_FIGSIZE_W = 8
|
|
||||||
GOLDEN = (np.sqrt(5.)+1)/2
|
|
||||||
DEFAULT_FIGSIZE_H = DEFAULT_FIGSIZE_W/GOLDEN
|
|
||||||
|
|
||||||
|
|
||||||
# Reference sound pressure level
|
# Reference sound pressure level
|
||||||
P_REF = 2e-5
|
P_REF = 2e-5
|
||||||
@ -28,7 +19,6 @@ I_REF = 1e-12 # 1 picoWatt/ m^2
|
|||||||
U_REF = 5e-8
|
U_REF = 5e-8
|
||||||
|
|
||||||
# Todo: fix This
|
# Todo: fix This
|
||||||
# calfile = '/home/anne/wip/UMIK-1/cal/7027430_90deg.txt'
|
|
||||||
calfile = None
|
calfile = None
|
||||||
|
|
||||||
|
|
||||||
|
@ -9,16 +9,14 @@ import numpy as np
|
|||||||
|
|
||||||
LASP_NUMPY_FLOAT_TYPE = np.float64
|
LASP_NUMPY_FLOAT_TYPE = np.float64
|
||||||
|
|
||||||
|
|
||||||
def zeros(shape):
|
def zeros(shape):
|
||||||
return np.zeros(shape, dtype=LASP_NUMPY_FLOAT_TYPE)
|
return np.zeros(shape, dtype=LASP_NUMPY_FLOAT_TYPE)
|
||||||
|
|
||||||
|
|
||||||
def ones(shape):
|
def ones(shape):
|
||||||
return np.ones(shape, dtype=LASP_NUMPY_FLOAT_TYPE)
|
return np.ones(shape, dtype=LASP_NUMPY_FLOAT_TYPE)
|
||||||
|
|
||||||
|
|
||||||
def empty(shape):
|
def empty(shape):
|
||||||
return np.empty(shape, dtype=LASP_NUMPY_FLOAT_TYPE)
|
return np.empty(shape, dtype=LASP_NUMPY_FLOAT_TYPE)
|
||||||
|
|
||||||
class config:
|
|
||||||
default_figsize = (12,7)
|
|
||||||
default_comment_lenght_measoverview = 50
|
|
||||||
default_xlim_freq_plot = (50, 10000)
|
|
||||||
default_ylim_freq_plot = (20, 100)
|
|
||||||
versiontxt = '0.1'
|
|
||||||
|
@ -12,7 +12,7 @@ The ASCEE hdf5 measurement file format contains the following fields:
|
|||||||
'samplerate': The audio data sample rate in Hz.
|
'samplerate': The audio data sample rate in Hz.
|
||||||
'nchannels': The number of audio channels in the file
|
'nchannels': The number of audio channels in the file
|
||||||
'sensitivity': (Optionally) the stored sensitivity of the record channels.
|
'sensitivity': (Optionally) the stored sensitivity of the record channels.
|
||||||
This can be a single value, or an array of sensitivities for
|
This can be a single value, or a list of sensitivities for
|
||||||
each channel. Both representations are allowed.
|
each channel. Both representations are allowed.
|
||||||
|
|
||||||
- Datasets:
|
- Datasets:
|
||||||
@ -32,9 +32,8 @@ that can be stored for the integer bit depth to get a number between -1.0 and
|
|||||||
|
|
||||||
The video dataset can possibly be not present in the data.
|
The video dataset can possibly be not present in the data.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
__all__ = ['Measurement', 'scaleBlockSens']
|
__all__ = ['Measurement', 'scaleBlockSens']
|
||||||
from contextlib import contextmanager
|
from contextlib import contextmanager
|
||||||
import h5py as h5
|
import h5py as h5
|
||||||
@ -42,7 +41,6 @@ import numpy as np
|
|||||||
from .lasp_config import LASP_NUMPY_FLOAT_TYPE
|
from .lasp_config import LASP_NUMPY_FLOAT_TYPE
|
||||||
import wave
|
import wave
|
||||||
import os
|
import os
|
||||||
import numbers
|
|
||||||
|
|
||||||
|
|
||||||
class BlockIter:
|
class BlockIter:
|
||||||
@ -177,7 +175,9 @@ class Measurement:
|
|||||||
# Sensitivity
|
# Sensitivity
|
||||||
try:
|
try:
|
||||||
sens = f.attrs['sensitivity']
|
sens = f.attrs['sensitivity']
|
||||||
self._sens = sens*np.ones(self.nchannels) if isinstance(sens, float) else sens
|
self._sens = sens * \
|
||||||
|
np.ones(self.nchannels) if isinstance(
|
||||||
|
sens, float) else sens
|
||||||
except KeyError:
|
except KeyError:
|
||||||
self._sens = np.ones(self.nchannels)
|
self._sens = np.ones(self.nchannels)
|
||||||
|
|
||||||
@ -198,7 +198,7 @@ class Measurement:
|
|||||||
Args:
|
Args:
|
||||||
mode: Opening mode for the file. Should either be 'r', or 'r+'
|
mode: Opening mode for the file. Should either be 'r', or 'r+'
|
||||||
"""
|
"""
|
||||||
if mode not in ('r','r+'):
|
if mode not in ('r', 'r+'):
|
||||||
raise ValueError('Invalid file opening mode.')
|
raise ValueError('Invalid file opening mode.')
|
||||||
with h5.File(self.fn, mode) as f:
|
with h5.File(self.fn, mode) as f:
|
||||||
yield f
|
yield f
|
||||||
|
@ -6,7 +6,8 @@ Author: J.A. de Jong - ASCEE
|
|||||||
Provides the FIR implementation of the octave filter bank
|
Provides the FIR implementation of the octave filter bank
|
||||||
|
|
||||||
"""
|
"""
|
||||||
__all__ = ['OctaveFilterBank']
|
__all__ = ['OctaveFilterBank', 'ThirdOctaveFilterBank']
|
||||||
|
|
||||||
from .filter.bandpass_fir import OctaveBankDesigner, ThirdOctaveBankDesigner
|
from .filter.bandpass_fir import OctaveBankDesigner, ThirdOctaveBankDesigner
|
||||||
from .wrappers import Decimator, FilterBank as pyxFilterBank
|
from .wrappers import Decimator, FilterBank as pyxFilterBank
|
||||||
import numpy as np
|
import numpy as np
|
||||||
@ -28,7 +29,6 @@ class FilterBank:
|
|||||||
assert np.isclose(fs, 48000), "Only sampling frequency" \
|
assert np.isclose(fs, 48000), "Only sampling frequency" \
|
||||||
" available is 48 kHz"
|
" available is 48 kHz"
|
||||||
|
|
||||||
|
|
||||||
maxdecimation = self.decimation(self.xs[0])
|
maxdecimation = self.decimation(self.xs[0])
|
||||||
self.decimators = []
|
self.decimators = []
|
||||||
for dec in maxdecimation:
|
for dec in maxdecimation:
|
||||||
|
@ -23,10 +23,17 @@ class Playback:
|
|||||||
|
|
||||||
def __init__(self, fn1, channel=0, video=True, verbose=True):
|
def __init__(self, fn1, channel=0, video=True, verbose=True):
|
||||||
"""
|
"""
|
||||||
|
Initialize a Playback class for playing back audio
|
||||||
|
|
||||||
|
Args:
|
||||||
|
fn1: Filename of the measurement file
|
||||||
|
channel: channel index to play back
|
||||||
|
video: if True and video is available in the measurement file,
|
||||||
|
video will also be shown
|
||||||
|
verbose: print out status messages to stdout
|
||||||
"""
|
"""
|
||||||
ext = '.h5'
|
ext = '.h5'
|
||||||
if not ext in fn1:
|
if fn1[-3:] != ext:
|
||||||
fn = fn1 + ext
|
fn = fn1 + ext
|
||||||
else:
|
else:
|
||||||
fn = fn1
|
fn = fn1
|
||||||
|
@ -25,7 +25,7 @@ class ReverbTime:
|
|||||||
|
|
||||||
"""
|
"""
|
||||||
assert level.ndim == 2, 'Invalid number of dimensions in level'
|
assert level.ndim == 2, 'Invalid number of dimensions in level'
|
||||||
assert level.shape[1] == 1,'Invalid number of channels, should be 1'
|
assert level.shape[1] == 1, 'Invalid number of channels, should be 1'
|
||||||
self._level = level
|
self._level = level
|
||||||
# Number of time samples
|
# Number of time samples
|
||||||
self._N = self._level.shape[0]
|
self._N = self._level.shape[0]
|
||||||
|
@ -22,7 +22,7 @@ class Dummy:
|
|||||||
|
|
||||||
class SLM:
|
class SLM:
|
||||||
"""
|
"""
|
||||||
Multi-channel sound Level Meter. Input data: time data with a certain
|
Multi-channel Sound Level Meter. Input data: time data with a certain
|
||||||
sampling frequency. Output: time-weighted (fast/slow) sound pressure
|
sampling frequency. Output: time-weighted (fast/slow) sound pressure
|
||||||
levels in dB(A/C/Z).
|
levels in dB(A/C/Z).
|
||||||
|
|
||||||
@ -39,6 +39,8 @@ class SLM:
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
if tw[0] is not TimeWeighting.none[0]:
|
if tw[0] is not TimeWeighting.none[0]:
|
||||||
|
# Initialize the single-pole low-pass filter for given time-
|
||||||
|
# weighting value.
|
||||||
self._lp = SPLowpass(fs, tw[0])
|
self._lp = SPLowpass(fs, tw[0])
|
||||||
else:
|
else:
|
||||||
self._lp = Dummy()
|
self._lp = Dummy()
|
||||||
@ -69,6 +71,8 @@ class SLM:
|
|||||||
|
|
||||||
Args:
|
Args:
|
||||||
data:
|
data:
|
||||||
|
returns:
|
||||||
|
level values as a function of time
|
||||||
"""
|
"""
|
||||||
assert data.ndim == 2
|
assert data.ndim == 2
|
||||||
assert data.shape[1] == 1
|
assert data.shape[1] == 1
|
||||||
|
@ -15,7 +15,6 @@ from lasp.lasp_common import (PLOT_COLORS_LIST, PLOT_NOCOLORS_LIST,
|
|||||||
DEFAULT_FIGSIZE_H, DEFAULT_FIGSIZE_W)
|
DEFAULT_FIGSIZE_H, DEFAULT_FIGSIZE_W)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class Figure:
|
class Figure:
|
||||||
def __init__(self, **kwargs):
|
def __init__(self, **kwargs):
|
||||||
ncols = kwargs.pop('ncols', 1)
|
ncols = kwargs.pop('ncols', 1)
|
||||||
|
@ -1,3 +1,6 @@
|
|||||||
|
"""
|
||||||
|
This file contains the Cython wrapper functions to
|
||||||
|
"""
|
||||||
include "config.pxi"
|
include "config.pxi"
|
||||||
|
|
||||||
setTracerLevel(15)
|
setTracerLevel(15)
|
||||||
|
@ -1,6 +0,0 @@
|
|||||||
#!/usr/bin/env python3
|
|
||||||
# -*- coding: utf-8 -*-
|
|
||||||
from .config import report_quality
|
|
||||||
from .report_tools import *
|
|
||||||
|
|
||||||
__all__ = ['report_quality']
|
|
Loading…
Reference in New Issue
Block a user