Added loads of comments and readability improvements.

This commit is contained in:
Anne de Jong 2018-12-29 15:34:24 +01:00
parent 21d9efc139
commit 505add6ae1
15 changed files with 55 additions and 58 deletions

1
.gitignore vendored
View File

@ -23,3 +23,4 @@ lasp_octave_fir.*
lasp/ui_*
resources_rc.py
lasp/device/lasp_daqdevice.c
.ropeproject

View File

@ -30,7 +30,8 @@ endif(LASP_FLOAT STREQUAL "double")
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)
# ##################### END Cmake variables converted to a macro
@ -53,7 +54,7 @@ if(LASP_DEBUG)
# Add the __FILENAME__ macro
# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D__FILENAME__='\"$(subst ${CMAKE_SOURCE_DIR}/,,$(abspath $<))\"'")
else()
message("Building release code")
message("Building LASP for release")
set(CMAKE_BUILD_TYPE Release)
set(CYTHON_ANNOTATE OFF)
set(CYTHON_NO_DOCSTRINGS ON)

View File

@ -20,6 +20,7 @@ Atomic increment:
"""
from threading import Lock
class Atomic:
def __init__(self, val):
self._val = val
@ -35,7 +36,6 @@ class Atomic:
self._val -= toadd
return self
def __bool__(self):
with self._lock:
return self._val
@ -48,4 +48,3 @@ class Atomic:
def __call__(self):
with self._lock:
return self._val

View File

@ -29,7 +29,8 @@ class AvStream:
self.nchannels = len(daq.channels_en)
self.samplerate = daq.input_rate
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:
raise RuntimeError(f'Could not initialize DAQ device: {str(e)}')

View File

@ -7,16 +7,7 @@ Common definitions used throughout the code.
"""
__all__ = ['P_REF', 'FreqWeighting', 'TimeWeighting', 'getTime', 'calfile',
'W_REF', 'U_REF', 'I_REF', 'DEFAULT_FIGSIZE_H', 'DEFAULT_FIGSIZE_W',
'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
'W_REF', 'U_REF', 'I_REF']
# Reference sound pressure level
P_REF = 2e-5
@ -28,7 +19,6 @@ I_REF = 1e-12 # 1 picoWatt/ m^2
U_REF = 5e-8
# Todo: fix This
# calfile = '/home/anne/wip/UMIK-1/cal/7027430_90deg.txt'
calfile = None

View File

@ -9,16 +9,14 @@ import numpy as np
LASP_NUMPY_FLOAT_TYPE = np.float64
def zeros(shape):
return np.zeros(shape, dtype=LASP_NUMPY_FLOAT_TYPE)
def ones(shape):
return np.ones(shape, dtype=LASP_NUMPY_FLOAT_TYPE)
def empty(shape):
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'

View File

@ -12,7 +12,7 @@ The ASCEE hdf5 measurement file format contains the following fields:
'samplerate': The audio data sample rate in Hz.
'nchannels': The number of audio channels in the file
'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.
- 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.
"""
__all__ = ['Measurement', 'scaleBlockSens']
from contextlib import contextmanager
import h5py as h5
@ -42,7 +41,6 @@ import numpy as np
from .lasp_config import LASP_NUMPY_FLOAT_TYPE
import wave
import os
import numbers
class BlockIter:
@ -177,7 +175,9 @@ class Measurement:
# Sensitivity
try:
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:
self._sens = np.ones(self.nchannels)

View File

@ -6,7 +6,8 @@ Author: J.A. de Jong - ASCEE
Provides the FIR implementation of the octave filter bank
"""
__all__ = ['OctaveFilterBank']
__all__ = ['OctaveFilterBank', 'ThirdOctaveFilterBank']
from .filter.bandpass_fir import OctaveBankDesigner, ThirdOctaveBankDesigner
from .wrappers import Decimator, FilterBank as pyxFilterBank
import numpy as np
@ -28,7 +29,6 @@ class FilterBank:
assert np.isclose(fs, 48000), "Only sampling frequency" \
" available is 48 kHz"
maxdecimation = self.decimation(self.xs[0])
self.decimators = []
for dec in maxdecimation:

View File

@ -23,10 +23,17 @@ class Playback:
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'
if not ext in fn1:
if fn1[-3:] != ext:
fn = fn1 + ext
else:
fn = fn1

View File

@ -22,7 +22,7 @@ class Dummy:
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
levels in dB(A/C/Z).
@ -39,6 +39,8 @@ class SLM:
"""
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])
else:
self._lp = Dummy()
@ -69,6 +71,8 @@ class SLM:
Args:
data:
returns:
level values as a function of time
"""
assert data.ndim == 2
assert data.shape[1] == 1

View File

@ -15,7 +15,6 @@ from lasp.lasp_common import (PLOT_COLORS_LIST, PLOT_NOCOLORS_LIST,
DEFAULT_FIGSIZE_H, DEFAULT_FIGSIZE_W)
class Figure:
def __init__(self, **kwargs):
ncols = kwargs.pop('ncols', 1)

View File

@ -1,3 +1,6 @@
"""
This file contains the Cython wrapper functions to
"""
include "config.pxi"
setTracerLevel(15)

View File

@ -1,6 +0,0 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from .config import report_quality
from .report_tools import *
__all__ = ['report_quality']