Skip to content

Commit

Permalink
Implemented CI (#13)
Browse files Browse the repository at this point in the history
* Added github workflows.
* Changed: np.int()->int()
* Changed metadata [conda env:mypy] -> ipykernel
* Typo $\Re\{x_1[k]}$ -> $\Re\{x_1[k]\}$
* Changed python versions and checkoutversions
  • Loading branch information
JacobTh98 authored Oct 25, 2023
1 parent d6b9fed commit 8f5a512
Show file tree
Hide file tree
Showing 6 changed files with 130 additions and 19 deletions.
46 changes: 46 additions & 0 deletions .github/workflows/lint_nb.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: Linting Notebooks with Black

on:
push:
branches:
- dev # Change this to your repository's main branch
pull_request:
branches:
- dev
jobs:
lint:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.10" # Change this to your desired Python version

- name: Install dependencies
run: |
pip install black==23.1.0 nbformat black[jupyter]
continue-on-error: false

- name: Find notebooks
id: find-notebooks
run: |
find . -name "*.ipynb" > notebooks.txt
continue-on-error: true

- name: Lint notebooks
run: |
cat notebooks.txt | xargs -I {} black --line-length 88 --check {}
continue-on-error: true

- name: Check lint results
run: |
if grep -q "would reformat" notebooks.txt; then
echo "Linting issues found. Run 'black' to auto-format the notebooks."
exit 1
else
echo "All notebooks are properly formatted."
fi
60 changes: 60 additions & 0 deletions .github/workflows/run_nb.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
name: Run Notebooks

on:
push:
branches:
- dev # Change this to your repository's main branch
pull_request:
branches:
- dev
schedule:
- cron: "0 0 * * 0" # Run every Sunday at midnight UTC (4 week interval)

jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.10", "3.11", "3.12"]

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}

# Testing matrix by printing the current Python version:
- name: Display Python version
run: python -c "import sys; print(sys.version)"

- name: Install dependencies
run: pip install jupyter nbconvert
- run: pip install -r requirements.txt

- name: Find notebooks
id: find-notebooks
run: |
find . -name "*.ipynb" > notebooks.txt
cat notebooks.txt
shell: bash

- name: Execute notebooks
run: |
cat notebooks.txt | while read -r notebook; do
jupyter nbconvert --to notebook --execute --inplace "$notebook"
done
continue-on-error: false
shell: bash

- name: Check for errors
run: |
if grep "raise Exception(" *.ipynb; then
echo "Error found in notebook(s)."
exit 1
else
echo "No errors found in notebooks."
fi
shell: bash
6 changes: 3 additions & 3 deletions dft/dft_windowing_tutorial/dft_eigensignals_columns.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,9 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python [conda env:mypy] *",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "conda-env-mypy-py"
"name": "python3"
},
"language_info": {
"codemirror_mode": {
Expand All @@ -103,7 +103,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.6"
"version": "3.10.12"
}
},
"nbformat": 4,
Expand Down
23 changes: 11 additions & 12 deletions dft/dft_windowing_tutorial/dft_windowing_tutorial_graphics.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,13 @@
"metadata": {},
"outputs": [],
"source": [
"import random as rd\n",
"\n",
"import matplotlib.pyplot as plt\n",
"from mpl_toolkits.axes_grid1 import make_axes_locatable\n",
"import numpy as np\n",
"import random as rd\n",
"from scipy.special import diric\n",
"import scipy.signal.windows as windows"
"import scipy.signal.windows as windows\n",
"from mpl_toolkits.axes_grid1 import make_axes_locatable\n",
"from scipy.special import diric"
]
},
{
Expand Down Expand Up @@ -1649,9 +1650,7 @@
"cell_type": "code",
"execution_count": null,
"id": "3ecd3531",
"metadata": {
"scrolled": false
},
"metadata": {},
"outputs": [],
"source": [
"fig, ax = plt.subplots(nrows=1, ncols=1, figsize=(7, 4))\n",
Expand Down Expand Up @@ -1718,7 +1717,7 @@
"ax1.grid(True)\n",
"ax1.set_title(r\"$10\\mathrm{exp}\\left(\\frac{2\\pi}{8}\\cdot 2k\\right)$\")\n",
"ax1.set_xlabel(\"$k$\")\n",
"ax1.set_ylabel(\"$\\Re\\{x_1[k]}$\")\n",
"ax1.set_ylabel(\"$\\Re\\{x_1[k]\\}$\")\n",
"ax2.stem(k, np.real(x2), basefmt=\"C0\", markerfmt=\"none\")\n",
"ax2.plot(k, np.real(x2), ls=\"none\", marker=\"o\", mec=\"C0\", mfc=\"C0\", ms=7, clip_on=False)\n",
"ax2.set_xticks(np.arange(0, N, 2))\n",
Expand Down Expand Up @@ -2177,7 +2176,7 @@
"ax1.set_ylim(-10, 10)\n",
"ax1.set_title(r\"$10\\mathrm{exp}\\left(\\frac{2\\pi}{8}\\cdot 2k\\right)$\")\n",
"ax1.set_xlabel(\"$k$\")\n",
"ax1.set_ylabel(\"$\\Re\\{x_1[k]}$\")\n",
"ax1.set_ylabel(\"$\\Re\\{x_1[k]\\}$\")\n",
"ax2.stem(k, np.real(x2), basefmt=\"C0\", markerfmt=\"none\")\n",
"ax2.plot(k, np.real(x2), ls=\"none\", marker=\"o\", mec=\"C0\", mfc=\"C0\", ms=7, clip_on=False)\n",
"ax2.set_xticks(np.arange(0, N, 2))\n",
Expand Down Expand Up @@ -2369,9 +2368,9 @@
],
"metadata": {
"kernelspec": {
"display_name": "mydsp",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "mydsp"
"name": "python3"
},
"language_info": {
"codemirror_mode": {
Expand All @@ -2383,7 +2382,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.12"
"version": "3.10.12"
}
},
"nbformat": 4,
Expand Down
8 changes: 4 additions & 4 deletions dft/parametric_windows.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,14 @@
"metadata": {},
"outputs": [],
"source": [
"import numpy as np\n",
"import matplotlib.pyplot as plt\n",
"import numpy as np\n",
"from matplotlib.patches import Circle\n",
"from numpy.fft import fft, fftshift, ifft\n",
"from scipy.signal import tf2zpk\n",
"\n",
"# from scipy.fft import fft, fftshift, ifft\n",
"from scipy.signal.windows import chebwin, kaiser, dpss\n",
"from scipy.signal import tf2zpk"
"from scipy.signal.windows import chebwin, dpss, kaiser"
]
},
{
Expand Down Expand Up @@ -342,7 +342,7 @@
"# how Slepian and the Kaiser-Bessel approximation converge, but never are exactly the same\n",
"L = 1\n",
"\n",
"M = np.int(2**6 * L)\n",
"M = int(2**6 * L)\n",
"Nz = 2**6 * M # zeropadding of window -> quasi-cont resolution of W for DTFT\n",
"k = np.arange(M)\n",
"bw = 2 * np.pi / (45 * L) # for dpss\n",
Expand Down
6 changes: 6 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
numpy
sympy
scipy
matplotlib
ipykernel
soundfile

0 comments on commit 8f5a512

Please sign in to comment.