Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
39 changes: 39 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: publish

on:
push:
tags:
- "v*"

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: "3.10"
- name: Build sdist and wheel
run: |
python -m pip install --upgrade pip
python -m pip install build
python -m build
- uses: actions/upload-artifact@v4
with:
name: dist
path: dist/*

publish:
needs: build
runs-on: ubuntu-latest
environment:
name: pypi
url: https://pypi.org/p/thinkdsp
permissions:
id-token: write
steps:
- uses: actions/download-artifact@v4
with:
name: dist
path: dist
- uses: pypa/gh-action-pypi-publish@release/v1
24 changes: 24 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,25 @@
.ipynb_checkpoints/
.DS_Store

# Python
__pycache__/
*.py[cod]
*.pyd
.python-version
*.egg-info/
.eggs/

# Virtual environments
.venv/
venv/

# Packaging/build
build/
dist/
.pytest_cache/
.coverage
coverage.xml
htmlcov/

# Poetry
poetry.lock
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2013 Allen B. Downey

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@

[Read *Think DSP* in HTML](http://greenteapress.com/thinkdsp/html/index.html).

## Attribution

This repository packages the `thinkdsp` code from *Think DSP* by Allen B. Downey.
Original code and copyright remain with the author under the MIT License.
Packaging maintenance updates are contributed by `Kim Maxim`.

The premise of this book (and the other books in the Think X series) is that if you know how to program, you can use that skill to learn other things. I am writing this book because I think the conventional approach to digital signal processing is backward: most books (and the classes that use them) present the material bottom-up, starting with mathematical abstractions like phasors.

With a programming-based approach, I can go top-down, which means I can present the most important ideas right away. By the end of the first chapter, you can decompose a sound into its harmonics, modify the harmonics, and generate new sounds.
Expand Down
13 changes: 8 additions & 5 deletions code/thinkdsp.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@
try:
from IPython.display import Audio
except ImportError:
warnings.warn(
"Can't import Audio from IPython.display; " "Wave.make_audio() will not work."
)
Audio = None

PI2 = np.pi * 2

Expand Down Expand Up @@ -73,7 +71,7 @@ def write(self, wave):
wave: Wave
"""
zs = wave.quantize(self.bound, self.dtype)
self.fp.writeframes(zs.tostring())
self.fp.writeframes(zs.tobytes())

def close(self, duration=0):
"""Closes the file.
Expand Down Expand Up @@ -112,7 +110,7 @@ def read_wave(filename="sound.wav"):
xs = np.fromstring(z_str, dtype=np.int8).astype(np.int32)
ys = (xs[2::3] * 256 + xs[1::3]) * 256 + xs[0::3]
else:
ys = np.fromstring(z_str, dtype=dtype_map[sampwidth])
ys = np.frombuffer(z_str, dtype=dtype_map[sampwidth])

# if it's in stereo, just pull out the first channel
if nchannels == 2:
Expand Down Expand Up @@ -1087,6 +1085,11 @@ def play(self, filename="sound.wav"):

def make_audio(self):
"""Makes an IPython Audio object."""
if Audio is None:
raise ImportError(
"IPython is required for Wave.make_audio(). "
"Install with `pip install ipython`."
)
audio = Audio(data=self.ys.real, rate=self.framerate)
return audio

Expand Down
43 changes: 31 additions & 12 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,20 +1,39 @@
[tool.poetry]
name = "thinkdsp"
version = "0.1.0"
description = ""
version = "0.1.1"
description = "DSP utilities from the Think DSP book"
authors = ["Allen Downey <allen.downey@olin.edu>"]
maintainers = ["Kim Maxim <maksimkim005@gmail.com>"]
readme = "README.md"
license = "MIT"
packages = [{ include = "thinkdsp", from = "src" }]
include = ["LICENSE"]
exclude = ["book", "code", ".devcontainer", ".github"]
classifiers = [
"Development Status :: 3 - Alpha",
"Intended Audience :: Education",
"License :: OSI Approved :: MIT License",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3 :: Only",
"Topic :: Multimedia :: Sound/Audio :: Analysis",
"Topic :: Scientific/Engineering :: Mathematics",
]

[tool.poetry.dependencies]
python = "^3.8"
jupyter = "^1.0.0"
numpy = "^1.19.4"
matplotlib = "^3.3.3"
seaborn = "^0.11.0"
pandas = "^1.1.4"
scipy = "^1.5.4"
python = ">=3.9,<4.0"
numpy = ">=1.22.4,<3.0"
Copy link

Copilot AI Feb 13, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The numpy version constraint ">=1.22.4,<3.0" is reasonable, but NumPy 1.22.4 was released in 2022 and requires Python 3.8+. Since the minimum Python version is set to 3.9, consider aligning the numpy minimum version with what's typically available for Python 3.9 environments. NumPy 1.22 dropped support for deprecated functions that might be used in older code. Verify that all numpy usage in the codebase is compatible with numpy 1.22+, particularly the np.fromstring usage (deprecated in favor of np.frombuffer).

Suggested change
numpy = ">=1.22.4,<3.0"
numpy = ">=1.20,<3.0"

Copilot uses AI. Check for mistakes.
scipy = ">=1.13.0,<2.0"
Copy link

Copilot AI Feb 13, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The scipy version constraint ">=1.13.0,<2.0" is very restrictive and may cause compatibility issues. SciPy 1.13.0 was released in May 2024, which means users with older Python environments (even Python 3.9-3.11 that are supported) may not be able to install this package if they have older scipy versions. Consider using a more permissive constraint like ">=1.5.4,<2.0" to match the minimum Python 3.9 requirement, or document why scipy 1.13.0 is specifically required.

Suggested change
scipy = ">=1.13.0,<2.0"
scipy = ">=1.5.4,<2.0"

Copilot uses AI. Check for mistakes.
matplotlib = ">=3.8.0,<4.0"
Copy link

Copilot AI Feb 13, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The matplotlib version constraint ">=3.8.0,<4.0" is quite restrictive. Matplotlib 3.8.0 was released in September 2023, which means users with older Python 3.9-3.11 installations may not be able to use this package. Consider using a more permissive constraint like ">=3.3.3,<4.0" to align with the original requirements seen in the repository, unless matplotlib 3.8.0 features are specifically required.

Suggested change
matplotlib = ">=3.8.0,<4.0"
matplotlib = ">=3.3.3,<4.0"

Copilot uses AI. Check for mistakes.
jupyter = { version = "^1.0.0", optional = true }
pandas = { version = "^1.1.4", optional = true }
Copy link

Copilot AI Feb 13, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The pandas version constraint uses "^1.1.4" which means ">=1.1.4,<2.0.0". However, pandas 1.1.4 was released in 2020 and is quite old. This package may not be compatible with pandas 2.x which was released in April 2023. Consider testing compatibility with pandas 2.x and updating the constraint to ">=1.1.4,<3.0" if compatible, or explicitly documenting the pandas 2.x incompatibility.

Suggested change
pandas = { version = "^1.1.4", optional = true }
pandas = { version = ">=1.1.4,<3.0", optional = true }

Copilot uses AI. Check for mistakes.
seaborn = { version = "^0.11.0", optional = true }

[tool.poetry.dev-dependencies]
[tool.poetry.extras]
notebooks = ["jupyter", "pandas", "seaborn"]

[tool.poetry.group.dev.dependencies]
pytest = "^7.0"

[build-system]
requires = ["poetry>=0.12"]
build-backend = "poetry.masonry.api"
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"
Loading