From 8f5a5123363a40d873ae5672854c4dcae6756a41 Mon Sep 17 00:00:00 2001 From: JacobTh98 <62538704+JacobTh98@users.noreply.github.com> Date: Wed, 25 Oct 2023 13:15:25 +0200 Subject: [PATCH] Implemented CI (#13) * 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 --- .github/workflows/lint_nb.yml | 46 ++++++++++++++ .github/workflows/run_nb.yml | 60 +++++++++++++++++++ .../dft_eigensignals_columns.ipynb | 6 +- .../dft_windowing_tutorial_graphics.ipynb | 23 ++++--- dft/parametric_windows.ipynb | 8 +-- requirements.txt | 6 ++ 6 files changed, 130 insertions(+), 19 deletions(-) create mode 100644 .github/workflows/lint_nb.yml create mode 100644 .github/workflows/run_nb.yml create mode 100644 requirements.txt diff --git a/.github/workflows/lint_nb.yml b/.github/workflows/lint_nb.yml new file mode 100644 index 0000000..cd2e1ad --- /dev/null +++ b/.github/workflows/lint_nb.yml @@ -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 \ No newline at end of file diff --git a/.github/workflows/run_nb.yml b/.github/workflows/run_nb.yml new file mode 100644 index 0000000..b788047 --- /dev/null +++ b/.github/workflows/run_nb.yml @@ -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 \ No newline at end of file diff --git a/dft/dft_windowing_tutorial/dft_eigensignals_columns.ipynb b/dft/dft_windowing_tutorial/dft_eigensignals_columns.ipynb index 4b0b9ee..7fbf358 100644 --- a/dft/dft_windowing_tutorial/dft_eigensignals_columns.ipynb +++ b/dft/dft_windowing_tutorial/dft_eigensignals_columns.ipynb @@ -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": { @@ -103,7 +103,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.6" + "version": "3.10.12" } }, "nbformat": 4, diff --git a/dft/dft_windowing_tutorial/dft_windowing_tutorial_graphics.ipynb b/dft/dft_windowing_tutorial/dft_windowing_tutorial_graphics.ipynb index 53c30cc..d1fc467 100644 --- a/dft/dft_windowing_tutorial/dft_windowing_tutorial_graphics.ipynb +++ b/dft/dft_windowing_tutorial/dft_windowing_tutorial_graphics.ipynb @@ -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" ] }, { @@ -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", @@ -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", @@ -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", @@ -2369,9 +2368,9 @@ ], "metadata": { "kernelspec": { - "display_name": "mydsp", + "display_name": "Python 3 (ipykernel)", "language": "python", - "name": "mydsp" + "name": "python3" }, "language_info": { "codemirror_mode": { @@ -2383,7 +2382,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.8.12" + "version": "3.10.12" } }, "nbformat": 4, diff --git a/dft/parametric_windows.ipynb b/dft/parametric_windows.ipynb index b653f26..3a2688b 100644 --- a/dft/parametric_windows.ipynb +++ b/dft/parametric_windows.ipynb @@ -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" ] }, { @@ -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", diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..ba4322f --- /dev/null +++ b/requirements.txt @@ -0,0 +1,6 @@ +numpy +sympy +scipy +matplotlib +ipykernel +soundfile \ No newline at end of file