Skip to content

Commit

Permalink
Prerelease 2
Browse files Browse the repository at this point in the history
 - Added `Wavelet` class
 - Faster wavelet recomputation
 - Deprecated `wfiltfn`
 - Added `setup.py` and requirements
  • Loading branch information
OverLordGoldDragon committed Nov 8, 2020
1 parent 8de2300 commit 8314572
Show file tree
Hide file tree
Showing 11 changed files with 354 additions and 211 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ Significant changes to some code structure are expected until v0.6.0, but whatev
- More


## Installation

`pip install git+https://github.com/OverLordGoldDragon/ssqueezepy`, for now; PyPi-available after 0.5.0.

## Differences w.r.t. original

- **Renamed variables/functions**; more Pythonic & readable
Expand All @@ -27,7 +31,3 @@ Significant changes to some code structure are expected until v0.6.0, but whatev

**Other**:
- Dense instead of sparse matrices for `stft_fwd` in [stft_transforms.py](https://github.com/OverLordGoldDragon/ssqueezepy/blob/master/synchrosqueezing/stft_transforms.py), as Numpy doesn't handle latter in ops involved




6 changes: 6 additions & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
setuptools>=41.0.0
twine>=1.15.0
coverage
pytest
pytest-cov
pycode
5 changes: 5 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
numpy
numba
matplotlib
quadpy
termcolor
59 changes: 59 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import os
import re
from setuptools import setup, find_packages

current_path = os.path.abspath(os.path.dirname(__file__))


def read_file(*parts):
with open(os.path.join(current_path, *parts), encoding='utf-8') as reader:
return reader.read()


def get_requirements(*parts):
with open(os.path.join(current_path, *parts), encoding='utf-8') as reader:
return list(map(lambda x: x.strip(), reader.readlines()))


def find_version(*file_paths):
version_file = read_file(*file_paths)
version_matched = re.search(r"^__version__ = ['\"]([^'\"]*)['\"]",
version_file, re.M)
if version_matched:
return version_matched.group(1)
raise RuntimeError('Unable to find version')


setup(
name="ssqueezepy",
version=find_version('ssqueezepy', '__init__.py'),
packages=find_packages(exclude=['tests', 'examples']),
url="https://github.com/OverLordGoldDragon/ssqueezepy",
license="TBD",
author="OverLordGoldDragon",
author_email="16495490+OverLordGoldDragon@users.noreply.github.com",
description=("Synchrosqueezing and wavelet transforms in Python"),
long_description=read_file('README.md'),
long_description_content_type="text/markdown",
keywords=(
"signal-processing python synchrosqueezing wavelet-transform"
),
install_requires=get_requirements('requirements.txt'),
tests_require=["pytest>=4.0", "pytest-cov"],
include_package_data=True,
zip_safe=True,
classifiers=[
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Operating System :: OS Independent",
"Intended Audience :: Developers",
"Intended Audience :: Information Technology",
"Intended Audience :: Science/Research",
"Topic :: Utilities",
"Topic :: Scientific/Engineering",
"Topic :: Scientific/Engineering :: Information Analysis",
"Topic :: Software Development",
"Topic :: Software Development :: Libraries :: Python Modules",
],
)
6 changes: 3 additions & 3 deletions ssqueezepy/__init__.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
from . import ssqueezing
from . import _ssq_cwt
from . import _cwt
from . import synsq_stft
from . import utils
from . import synsq_stft
from . import stft_transforms
from . import experimental

from .ssqueezing import *
from ._ssq_cwt import *
from ._cwt import *
from .utils import *
from .synsq_stft import *
from .stft_transforms import *
from .utils import *


__version__ = '0.5.0rc1'
__version__ = '0.5.0rc2'
14 changes: 5 additions & 9 deletions ssqueezepy/_cwt.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import numpy as np
from numpy.fft import fft, ifft, ifftshift
from .utils import pi, WARN, p2up, adm_cwt, adm_ssq, wfiltfn, wfilth
from .utils import WARN, p2up, adm_cwt, adm_ssq, wfilth
from .utils import padsignal, process_scales
from .algos import replace_at_inf_or_nan
from .wavelets import Wavelet


def cwt(x, wavelet, scales='log', dt=1, nv=None, l1_norm=True,
Expand Down Expand Up @@ -70,23 +71,19 @@ def _process_args(x, scales, dt):
xh = fft(x)

pn = (-1) ** np.arange(N)
# TODO this can be trouble for very large N, fill xi directly instead
# and just move wavelet at scale computation to own function
xi = (2*pi / N) * np.hstack([np.arange(N // 2 + 1),
np.arange(-N // 2 + 1, 0)])
psihfn = wfiltfn(wavelet) # TODO use wfiltfn instead?
psihfn = Wavelet(wavelet, N=N)

# TODO vectorize? can FFT all at once if all `psih` are precomputed
# but keep loop option in case of OOM
for i, a in enumerate(scales):
# sample FT of wavelet at scale `a`
# `* pn` = freq-domain spectral reversal to center time-domain wavelet
psih = psihfn(a * xi) * pn
psih = psihfn(a) * pn

xcpsi = ifftshift(ifft(xh * psih))
Wx[i] = xcpsi

dpsih = (1j * xi / dt) * psih
dpsih = (1j * psihfn.xi / dt) * psih
dxcpsi = ifftshift(ifft(dpsih * xh))
dWx[i] = dxcpsi

Expand All @@ -102,7 +99,6 @@ def _process_args(x, scales, dt):
return Wx, scales, dWx, x_mean


# TODO add one-integral implementation
def icwt(Wx, wavelet, scales='log', one_int=True, x_len=None, x_mean=0,
padtype='symmetric', rpadded=False, l1_norm=True):
"""The inverse continuous wavelet transform of signal Wx via double integral.
Expand Down
5 changes: 3 additions & 2 deletions ssqueezepy/experimental.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import numpy as np
from numpy.fft import fft, ifft, ifftshift
from .utils import pi, wfiltfn, adm_cwt
from .utils import pi, adm_cwt
from .wavelets import Wavelet
from quadpy import quad as quadgk


Expand All @@ -14,7 +15,7 @@ def err_fix(x, wavelet, a0): # primitive code, doesn't work
N = len(x)
xi = (2*pi/N) * np.arange(1, N//2 + 1)

psihfn = wfiltfn(wavelet)
psihfn = Wavelet(wavelet)
# integrate from 0 to w, w spanning same spectrum as psih
# this can be sped up by nature of brick-wall behavior, stopping computing
# after first zero, also computing fewer in total and linearly interpolating
Expand Down
Loading

0 comments on commit 8314572

Please sign in to comment.