Commit 9b5cfcae authored by Andrew Quinn's avatar Andrew Quinn
Browse files

Merge branch 'spectrogram' into 'master'

STFT submodule

See merge request !72
parents ac1d0d38 f98f0d48
Loading
Loading
Loading
Loading
Loading
+8 −20
Original line number Diff line number Diff line
@@ -9,9 +9,9 @@ before_script:
stages:
  - build

build35:
build37:
  stage: build
  image: python:3.6
  image: python:3.7
  script:
    - flake8
    - make clean
@@ -22,9 +22,9 @@ build35:
      - dist/
    expire_in: 1 week

build36:
build38:
  stage: build
  image: python:3.6
  image: python:3.8
  script:
    - flake8
    - make clean
@@ -35,9 +35,9 @@ build36:
      - dist/
    expire_in: 1 week

build37:
build39:
  stage: build
  image: python:3.7
  image: python:3.9
  script:
    - flake8
    - make clean
@@ -48,22 +48,10 @@ build37:
      - dist/
    expire_in: 1 week

build38:
  stage: build
  image: python:3.8
  script:
    - flake8
    - make clean
    - make all
    - pytest
  artifacts:
    paths:
      - dist/
    expire_in: 1 week

build39:
build310:
  stage: build
  image: python:3.9
  image: python:3.10
  script:
    - flake8
    - make clean
+1 −3
Original line number Diff line number Diff line
@@ -9,9 +9,7 @@ from .mvar_metrics import * # noqa: F401, F403
from .diags import *  # noqa: F401, F403
from .plotting import *  # noqa: F401, F403
from .circular_plots import *  # noqa: F401, F403
from .stats import *  # noqa: F401, F403
from .tutorial_utils import *  # noqa: F401, F403
from .simulate import *  # noqa: F401, F403
from .orthogonalise import *  # noqa: F401, F403
from .utils import *  # noqa: F401, F403
from .wavelet import *  # noqa: F401, F403
from . import stft, wavelet, orthogonalise, stats  # noqa: F401, F403

sails/stft.py

0 → 100644
+2168 −0

File added.

Preview size limit exceeded, changes collapsed.

+63 −0
Original line number Diff line number Diff line
#!/usr/bin/python

# vim: set expandtab ts=4 sw=4:

"""Test STFT Module."""

import unittest

import numpy as np
from scipy import signal


class TestSTFTAgainstScipy(unittest.TestCase):
    """Compare simple periodogram outputs against scipy."""

    def test_simple_periodogram_nperseg(self):
        """Ensure nperseg results are consistent."""
        from ..stft import periodogram

        # Run test 5 times
        for ii in range(5):
            xx = np.random.randn(4096,)
            f, pxx = signal.welch(xx, nperseg=2**(4+ii))
            f2, pxx2 = periodogram(xx, nperseg=2**(4+ii))

            assert(np.allclose(pxx, pxx2))

    def test_simple_periodogram_window_type(self):
        """Ensure window type results are consistent."""
        from ..stft import periodogram

        window_tests = ['hann', 'hamming', 'boxcar', 'tukey', 'blackman']

        for ii in range(5):
            xx = np.random.randn(4096,)
            f, pxx = signal.welch(xx, nperseg=128, window=window_tests[ii])
            f2, pxx2 = periodogram(xx, nperseg=128, window_type=window_tests[ii])

            assert(np.allclose(pxx, pxx2))

    def test_simple_periodogram_nfft(self):
        """Ensure nfft results are consistent."""
        from ..stft import periodogram

        for ii in range(5):
            xx = np.random.randn(4096,)
            f, pxx = signal.welch(xx, nfft=2**(ii+4), nperseg=16)
            f2, pxx2 = periodogram(xx, nfft=2**(ii+4), nperseg=16)

            assert(np.allclose(pxx, pxx2))

    def test_simple_periodogram_scaling(self):
        """Ensure scaling results are consistent."""
        from ..stft import periodogram

        scaling_tests = ['density', 'spectrum']

        for ii in range(len(scaling_tests)):
            xx = np.random.randn(4096,)
            f, pxx = signal.welch(xx, nperseg=128, scaling=scaling_tests[ii])
            f2, pxx2 = periodogram(xx, nperseg=128, scaling=scaling_tests[ii])

            assert(np.allclose(pxx, pxx2))
+4 −4
Original line number Diff line number Diff line
@@ -55,11 +55,11 @@ setup(

      # Specify the Python versions you support here. In particular, ensure
      # that you indicate whether you support Python 2, Python 3 or both.
      'Programming Language :: Python :: 2',
      'Programming Language :: Python :: 2.7',
      'Programming Language :: Python :: 3',
      'Programming Language :: Python :: 3.4',
      'Programming Language :: Python :: 3.5',
      'Programming Language :: Python :: 3.7',
      'Programming Language :: Python :: 3.8',
      'Programming Language :: Python :: 3.9',
      'Programming Language :: Python :: 3.10',
    ],

    keywords='multivariate autoregressive models spectral',