Compare commits

...

3 Commits

4 changed files with 101 additions and 11 deletions

View File

@ -28,6 +28,26 @@ typedef struct Fft_s {
#endif
void load_fft_wisdom(const char* wisdom) {
#ifdef LASP_FFT_BACKEND_FFTPACK
#elif defined LASP_FFT_BACKEND_FFTW
if(wisdom) {
int rv= fftw_import_wisdom_from_string(wisdom);
if(rv != 1) {
fprintf(stderr, "Error loading FFTW wisdom");
}
}
#endif
}
char* store_fft_wisdom() {
#ifdef LASP_FFT_BACKEND_FFTPACK
return NULL;
#elif defined LASP_FFT_BACKEND_FFTW
return fftw_export_wisdom_to_string();
#endif
}
Fft* Fft_create(const us nfft) {
fsTRACE(15);
if(nfft == 0) {

View File

@ -11,6 +11,23 @@
#include "lasp_types.h"
#include "lasp_mat.h"
/**
* Load wisdom data from a NULL-terminated character string. Note that at this
* point in time this is only used by the FFTW fft backend.
*
* @param[in] wisdom: Wisdom string
*/
void load_fft_wisdom(const char* wisdom);
/**
* Creates a NULL-terminated string containing FFTW wisdom, or state knowledge
* from other libraries.
*
* @returns A NULL-terminated string. *Should be deallocated after being used*
*/
char* store_fft_wisdom(void);
/**
* Perform forward FFT's on real time data.
*

View File

@ -1,19 +1,25 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import os
import platform
import shelve
import appdirs
import numpy as np
from .wrappers import Window as wWindow
import appdirs, os, shelve
"""
Common definitions used throughout the code.
"""
__all__ = ['P_REF', 'FreqWeighting', 'TimeWeighting', 'getTime',
'getFreq', 'lasp_shelve',
'W_REF', 'U_REF', 'I_REF']
__all__ = [
'P_REF', 'FreqWeighting', 'TimeWeighting', 'getTime', 'getFreq',
'lasp_shelve', 'this_lasp_shelve', 'W_REF', 'U_REF', 'I_REF'
]
lasp_appdir = appdirs.user_data_dir('Lasp', 'ASCEE')
if not os.path.exists(lasp_appdir):
try:
os.mkdir(lasp_appdir)
@ -29,7 +35,8 @@ class lasp_shelve:
def __enter__(self):
if lasp_shelve.shelve is None:
assert lasp_shelve.refcount == 0
lasp_shelve.shelve = shelve.open(os.path.join(lasp_appdir, 'config.shelve'))
lasp_shelve.shelve = shelve.open(
os.path.join(lasp_appdir, 'config.shelve'))
lasp_shelve.refcount += 1
return lasp_shelve.shelve
@ -39,6 +46,27 @@ class lasp_shelve:
lasp_shelve.shelve.close()
lasp_shelve.shelve = None
class this_lasp_shelve:
refcount = 0
shelve = None
def __enter__(self):
if this_lasp_shelve.shelve is None:
assert lasp_shelve.refcount == 0
node = platform.node()
this_lasp_shelve.shelve = shelve.open(
os.path.join(lasp_appdir, f'{node}_config.shelve'))
this_lasp_shelve.refcount += 1
return this_lasp_shelve.shelve
def __exit__(self, type, value, traceback):
this_lasp_shelve.refcount -= 1
if this_lasp_shelve.refcount == 0:
this_lasp_shelve.shelve.close()
this_lasp_shelve.shelve = None
# Reference sound pressure level
P_REF = 2e-5
@ -82,12 +110,14 @@ class TimeWeighting:
fast = (0.125, 'Fast (0.125 s)')
slow = (1.0, 'Slow (1.0 s)')
tens = (10., '10 s')
infinite = (0, 'Infinite')
types = (none, uufast, ufast, fast, slow, tens)
types_all = (none, uufast, ufast, fast, slow, tens, infinite)
default = fast
default_index = 3
@staticmethod
def fillComboBox(cb):
def fillComboBox(cb, all_=False):
"""
Fill TimeWeightings to a combobox
@ -95,13 +125,17 @@ class TimeWeighting:
cb: QComboBox to fill
"""
cb.clear()
for tw in TimeWeighting.types:
if all_:
types = TimeWeighting.types_all
else:
types = TimeWeighting.types
for tw in types:
cb.addItem(tw[1], tw)
cb.setCurrentIndex(TimeWeighting.default_index)
@staticmethod
def getCurrent(cb):
return TimeWeighting.types[cb.currentIndex()]
return TimeWeighting.types_all[cb.currentIndex()]
class FreqWeighting:
"""

View File

@ -67,14 +67,15 @@ cdef extern from "lasp_python.h":
__all__ = ['AvPowerSpectra', 'SosFilterBank', 'FilterBank', 'Siggen',
'sweep_flag_forward', 'sweep_flag_backward', 'sweep_flag_linear',
'sweep_flag_exponential', 'sweep_flag_hyperbolic']
'sweep_flag_exponential', 'sweep_flag_hyperbolic',
'load_fft_wisdom', 'store_fft_wisdom']
setTracerLevel(15)
cdef extern from "cblas.h":
int openblas_get_num_threads()
void openblas_set_num_threads(int)
# If we touch this variable: we get segfaults when running from
# Spyder!
# openblas_set_num_threads(8)
@ -86,6 +87,8 @@ def cls():
# cls()
cdef extern from "lasp_fft.h":
void c_load_fft_wisdom "load_fft_wisdom" (const char* wisdom)
char* c_store_fft_wisdom "store_fft_wisdom" ()
ctypedef struct c_Fft "Fft"
c_Fft* Fft_create(us nfft)
void Fft_free(c_Fft*)
@ -93,8 +96,24 @@ cdef extern from "lasp_fft.h":
void Fft_ifft(c_Fft*,cmat * freqdata,dmat* timedata) nogil
us Fft_nfft(c_Fft*)
def load_fft_wisdom(const unsigned char[::1] wisdom):
c_load_fft_wisdom(<const char*> &wisdom[0])
from cpython cimport PyBytes_FromString
from libc.stdlib cimport free
def store_fft_wisdom():
cdef char* wisdom = c_store_fft_wisdom()
if wisdom != NULL:
try:
bts = PyBytes_FromString(wisdom)
finally:
free(wisdom)
return bts
else:
return None
cdef class Fft:
cdef:
c_Fft* _fft