Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modernize Python compatibilities and bump lspopt version #9

Closed
wants to merge 34 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
73bd42b
Prepared for PyPI release
hbldh Jun 19, 2019
5362fdc
Fix for axure-pipelines.yml
hbldh Jun 19, 2019
5407ff3
Version 1.1.0 - Fixes #1
hbldh Jun 19, 2019
27b3300
Fix for incorrect trove classifier.
hbldh Jun 19, 2019
6ba11aa
Create Dependabot config file
dependabot-preview[bot] Sep 25, 2020
99e665f
Merge pull request #3 from hbldh/dependabot/add-v2-config-file
hbldh Sep 25, 2020
0bc758d
Github Actions for lspopt
hbldh Sep 28, 2020
0795d2a
CHANGELOG and version bump
hbldh Sep 28, 2020
473d28f
Add changelog to sdist
hoechenberger Jun 7, 2022
4e20b79
Merge pull request #5 from hoechenberger/patch-1
hbldh Jun 8, 2022
46401bf
Version 1.2.0 - Source Dist fix
hbldh Jun 8, 2022
8040b4e
CI Test modification
hbldh Jun 8, 2022
3de36be
CI Test modification
hbldh Jun 8, 2022
e27d570
Update README.md
hbldh Jun 8, 2022
c03e5be
Update README.md
hbldh Jun 8, 2022
73be156
Updated link to paper
hbldh Jun 8, 2022
0b1f4fe
Delete dependabot.yml
hbldh Jan 24, 2023
57662af
Update build_and_test.yml
hbldh Jan 24, 2023
4303dac
Version 1.3.0
hbldh Jan 24, 2023
6867aa9
Update CHANGELOG.md
hbldh Jan 24, 2023
c13df6e
replace pkg_resources with importlib.resources
remrama Dec 29, 2024
255c200
Merge pull request #8 from remrama/pkg_to_importlib
hbldh Dec 29, 2024
9218aa1
fix README typo
remrama Jan 7, 2025
667c6dd
ignore local python environments
remrama Jan 7, 2025
4495181
workflow tests python 3.8-3.12
remrama Jan 7, 2025
a34d8ba
add .toml file
remrama Jan 7, 2025
23a7c98
update python versions in setup.py
remrama Jan 7, 2025
e6fde75
remove __future__ and unused imports
remrama Jan 7, 2025
b20e86b
bump version and update changelog
remrama Jan 7, 2025
5109ada
float --> str python versions
remrama Jan 7, 2025
158ce0d
bump all gh-action versions
remrama Jan 7, 2025
22c847e
add windows and macos tests
remrama Jan 7, 2025
abb4464
update changelog
remrama Jan 7, 2025
04cf84c
bump gh-action versions in pypi workflow
remrama Jan 7, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .github/ISSUE_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
### Description

Describe what you were trying to get done.
Tell us what happened, what went wrong, and what you expected to happen.

### What I Did

```
Paste the command(s) you ran and the output.
If there was a crash, please include the traceback here.
```
45 changes: 45 additions & 0 deletions .github/workflows/build_and_test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: Build and Test

on:
push:
branches: [ master, develop ]
pull_request:
branches: [ master, develop ]

jobs:
build_linux:
name: "Build and test"
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
python-version: ["3.9", "3.10", "3.11", "3.12"]
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Upgrade pip. setuptools and wheel
run: python -m pip install --upgrade pip setuptools wheel

- name: Install development dependencies
run: pip install flake8 pytest pytest-cov
- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
- name: Install package as editable
run: pip install -e .
- name: Test with pytest
run: |
pytest tests --junitxml=junit/test-results-${{ matrix.os }}-${{ matrix.python-version }}.xml --cov=com --cov-report=xml --cov-report=html
- name: Upload pytest test results
uses: actions/upload-artifact@v4
with:
name: pytest-results-${{ matrix.os }}-${{ matrix.python-version }}
path: junit/test-results-${{ matrix.os }}-${{ matrix.python-version }}.xml
# Use always() to always run this step to publish test results when there are test failures
if: ${{ always() }}
31 changes: 31 additions & 0 deletions .github/workflows/pypi-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# This workflows will upload a Python Package using Twine when a release is created
# For more information see: https://help.github.com/en/actions/language-and-framework-guides/using-python-with-github-actions#publishing-to-package-registries

name: Upload Python Package

on:
release:
types: [created]

jobs:
deploy:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.x'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install setuptools wheel twine
- name: Build and publish
env:
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
run: |
python setup.py sdist bdist_wheel
twine upload dist/*
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -117,3 +117,6 @@ docs/_build/
# PyBuilder
target/

# Environments
.conda/
.vscode/
35 changes: 0 additions & 35 deletions .travis.yml

This file was deleted.

79 changes: 79 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
# Changelog
All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [1.4.0] - 2025-01-07

### Added

- Support for Python 3.12
- Support for `pip>=25`
- Support for `numpy>=2`
- Support for Windows and macOS

### Removed

- Support for Python 3.7 and 3.8
- Unused imports


## [1.3.0] - 2023-01-24

### Changed

- Modified test matrix in CI

### Removed

- Support for Python 2.7 and 3.6.
- Dependency on `six`.


## [1.2.0] - 2022-06-08

### Added

- New plot file

### Fixed

- Source distribution was broken on PyPI. Modified `MANIFEST.in` to correct that (#5 and #6)
- Url to missing plot file
- Fixed some incorrect int declarations using `1e3` notation

### Removed

- Removed Pipfile

## [1.1.1] - 2020-09-28

### Added

- Added `CHANGELOG.md`

### Changed

- Change CI from Azure Devops to Github Actions


## [1.1.0] - 2019-06-19

### Added

- First PyPI-released version


## [1.0.0] - 2016-08-22

### Added

- Regarded as a feature-complete, stable library.


[Unreleased]: https://github.com/hbldh/lspopt/compare/v1.3.0...HEAD
[1.3.0]: https://github.com/hbldh/lspopt/compare/v1.2.0...v1.3.0
[1.2.0]: https://github.com/hbldh/lspopt/compare/v1.1.1...v1.2.0
[1.1.1]: https://github.com/hbldh/lspopt/compare/v1.1.0...v1.1.1
[1.1.0]: https://github.com/hbldh/lspopt/compare/v1.0.0...v1.1.0
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2015 Henrik Blidh
Copyright (c) 2022 Henrik Blidh

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
8 changes: 8 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
include LICENSE
include README.md
include HISTORY.md
include requirements.txt
include Pipfile
include CHANGELOG.md
include lspopt/data/c.npy
include lspopt/data/weights.npy
32 changes: 18 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# LSPOpt

[![Build Status](https://travis-ci.org/hbldh/lspopt.svg)](https://travis-ci.org/hbldh/lspopt)
[![Coverage Status](https://coveralls.io/repos/github/hbldh/lspopt/badge.svg?branch=master)](https://coveralls.io/github/hbldh/lspopt?branch=master)
![Build and Test](https://github.com/hbldh/lspopt/workflows/Build%20and%20Test/badge.svg)
[![PyPI version](https://img.shields.io/pypi/v/lspopt.svg)](https://pypi.org/project/lspopt/)
[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/ambv/black)

This module is a Python implementation of the multitaper window method
described in [\[1\]](#references) for estimating Wigner spectra for certain locally
Expand All @@ -22,24 +23,25 @@ Abstract from [\[1\]](#references):

Install via pip:

pip install git+https://github.com/hbldh/lspopt.git#egg=lspopt
pip install lspopt

If you prefer to use `conda`, see [instructions in this repo](https://github.com/conda-forge/lspopt-feedstock).

## Testing

Test with `nosetests`:
Test with `pytest`:

nosetests tests/
pytest tests/

Tests are run at every commit to GitHub and the results of this, as well as test
coverage, can be studied at [Travis CI](https://travis-ci.org/hbldh/lspopt).
See test badge at the top of this README for link to test coverage and reports.

## Usage

To generate the taper windows only, use the `lspopt` method:

```python
from lspopt import lspopt
H, w = lspopt(N=256, c_parameter=20.0)
H, w = lspopt(n=256, c_parameter=20.0)
```

There is also a convenience method for using the [SciPy spectrogram method](https://docs.scipy.org/doc/scipy/reference/generated/scipy.signal.spectrogram.html#scipy.signal.spectrogram)
Expand All @@ -64,13 +66,13 @@ import matplotlib.pyplot as plt

from lspopt.lsp import spectrogram_lspopt

fs = 10e3
N = 1e5
fs = 10000
N = 100000
amp = 2 * np.sqrt(2)
noise_power = 0.001 * fs / 2
time = np.arange(N) / fs
freq = np.linspace(1e3, 2e3, N)
x = amp * chirp(time, 1e3, 2.0, 6e3, method='quadratic') + \
freq = np.linspace(1000, 2000, N)
x = amp * chirp(time, 1000, 2.0, 6000, method='quadratic') + \
np.random.normal(scale=np.sqrt(noise_power), size=time.shape)

f, t, Sxx = spectrogram(x, fs)
Expand All @@ -87,14 +89,16 @@ ax.pcolormesh(t, f, Sxx)
ax.set_ylabel('Frequency [Hz]')
ax.set_xlabel('Time [sec]')

plt.tight_layout()
plt.show()
```

![Spectrogram plot](https://hbldh.github.com/lspopt/images/plot.png)
![Spectrogram plot](https://github.com/hbldh/lspopt/blob/master/plot.png "Top: Using SciPy's spectrogram method. Bottom: Using LSPOpt's spectrogram solution.")

*Top: Using SciPy's spectrogram method. Bottom: Using LSPOpt's spectrogram solution.*

## References

\[1\] [Hansson-Sandsten, M. (2011). Optimal multitaper Wigner spectrum
estimation of a class of locally stationary processes using Hermite functions.
EURASIP Journal on Advances in Signal Processing, 2011, 10.](http://asp.eurasipjournals.com/content/pdf/1687-6180-2011-980805.pdf)
EURASIP Journal on Advances in Signal Processing, 2011, 10.](https://dx.doi.org/10.1155/2011/980805)
19 changes: 8 additions & 11 deletions generate_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,6 @@

"""

from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals
from __future__ import absolute_import

import six
import numpy as np
from scipy.signal import chirp, spectrogram
Expand All @@ -26,21 +21,21 @@


def generate_chirp_spectrogram_plot():
fs = 10e3
N = 1e5
fs = 10000
N = 100000
amp = 2 * np.sqrt(2)
noise_power = 0.001 * fs / 2
time = np.arange(N) / fs
freq = np.linspace(1e3, 2e3, N)
x = amp * chirp(time, 1e3, 2.0, 6e3, method='quadratic') + \
freq = np.linspace(1000, 2000, N)
x = amp * chirp(time, 1000, 2.0, 6000, method='quadratic') + \
np.random.normal(scale=np.sqrt(noise_power), size=time.shape)

f, t, Sxx = spectrogram(x, fs)

ax = plt.subplot(211)
ax.pcolormesh(t, f, Sxx)
ax.set_ylabel('Frequency [Hz]')
ax.set_xlabel('Time [sec]')
ax.set_xlabel('Time [sec]', labelpad=10)

f, t, Sxx = spectrogram_lspopt(x, fs, c_parameter=20.0)

Expand All @@ -49,6 +44,7 @@ def generate_chirp_spectrogram_plot():
ax.set_ylabel('Frequency [Hz]')
ax.set_xlabel('Time [sec]')

plt.tight_layout()
plt.show()


Expand Down Expand Up @@ -100,11 +96,12 @@ def generate_lsp_processes_figures():
ax.set_ylim([-1.5, 1.5])
ax.set_xlabel('t')

plt.tight_layout()
plt.show()


def main():
#generate_chirp_spectrogram_plot()
generate_chirp_spectrogram_plot()
generate_lsp_processes_figures()

if __name__ == "__main__":
Expand Down
Loading
Loading