From c8b0f6a85de4a59789bbd7c8c6163c2ed690dac1 Mon Sep 17 00:00:00 2001 From: Sander Roet Date: Fri, 16 Aug 2024 12:11:28 +0200 Subject: [PATCH] deal with new ruff version and next try for tutorial-test.yml (#224) * next try at tutorial-tests.yml * Update tutorial-tests.yml * fix ruff issues in ipynb * also run ruff format on ipynb * also update the pre-commit hook version * also update minimal coverage to 87% --- .github/workflows/coverage.yml | 2 +- .github/workflows/tutorial-tests.yml | 43 ++++--------- .pre-commit-config.yaml | 4 +- .../defocus_gradient_analysis.ipynb | 64 ++++++++++++------- 4 files changed, 56 insertions(+), 57 deletions(-) diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index 18233a61..68b3bd53 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -44,7 +44,7 @@ jobs: path: coverage.xml repo_token: ${{ secrets.GITHUB_TOKEN }} pull_request_number: ${{ steps.get-pr.outputs.PR }} - minimum_coverage: 86 + minimum_coverage: 87 show_missing: True fail_below_threshold: True link_missing_lines: True diff --git a/.github/workflows/tutorial-tests.yml b/.github/workflows/tutorial-tests.yml index 8f1c2626..5a9e1ebf 100644 --- a/.github/workflows/tutorial-tests.yml +++ b/.github/workflows/tutorial-tests.yml @@ -1,60 +1,43 @@ name: Test Tutorial # following example: https://securitylab.github.com/research/github-actions-preventing-pwn-requests/ on: - workflow_run: - workflows: ["Unit tests"] - types: - - completed + push: + branches: + - main + jobs: test-tutorial: - if: > - github.event.workflow_run.event == 'pull_request' && - github.event.workflow_run.conclusion == 'success' runs-on: [self-hosted, linux, x64, gpu] container: image: continuumio/miniconda3 options: --runtime=nvidia --gpus all - permissions: - # Read the action that triggered this one - actions: read - # Allow to write check runs - checks: write - # Read and update commit statuses - statuses: write steps: - name: Pull code uses: actions/checkout@v4 - with: - repository: github.event.workflow_run.head_repository - ref: github.event.workflow_run.head_sha - - name: Pull wiki - uses: actions/checkout@v4 - with: - # Only check the wiki of the calling repo - repository: ${{github.repository}}.wiki - path: wiki - name: Install dependencies, code, and list everything run: | conda install -y -c conda-forge python=3 cupy cuda-version=11.8 python -m pip install coverage mdextractor #mdextractor is new and might need to be replaced later python -m pip install .[dev] conda list + - name: Goto directory + run: | + cd docs/tutorials - name: Grab files needed for tests run: | - mkdir wiki/dataset - mkdir wiki/templates - mkdir wiki/results_80S - mkdir wiki/results_60S - cd wiki/templates - cp ../data/6qzp_60S wiki/templates/ + mkdir dataset + mkdir templates + mkdir results_80S + mkdir results_60S + cd templates + cp ../data/6qzp_60S.mrc . curl https://files.wwpdb.org/pub/emdb/structures/EMD-2938/map/emd_2938.map.gz -o emd_2938.map.gz gunzip emd_2938.map.gz mv emd_2938.map emd_2938.mrc cd ../dataset curl -L -O -J -H "X-Dataverse-key:${{ secrets.DATAVERSE_API_TOKEN }}" https://dataverse.nl/api/access/datafiles/384731,384724,384706,384718 unzip dataverse_files.zip - mv tutorial/* . cd ../ - name: Run Tutorial test run: | diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 1ad2fa01..18fdffa8 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,10 +1,10 @@ repos: - repo: https://github.com/astral-sh/ruff-pre-commit # Ruff version. - rev: v0.4.8 + rev: v0.6.0 hooks: # Run the linter. - id: ruff args: [ --fix ] # Run the formatter. - - id: ruff-format \ No newline at end of file + - id: ruff-format diff --git a/docs/benchmarks/defocus_gradient_analysis.ipynb b/docs/benchmarks/defocus_gradient_analysis.ipynb index 993b41f1..f7c4baca 100644 --- a/docs/benchmarks/defocus_gradient_analysis.ipynb +++ b/docs/benchmarks/defocus_gradient_analysis.ipynb @@ -13,8 +13,8 @@ "import numpy as np\n", "from scipy.spatial.distance import cdist\n", "from scipy.optimize import curve_fit\n", - "from scipy.stats import t\n", - "sns.set(style='ticks', context='notebook')" + "\n", + "sns.set(style=\"ticks\", context=\"notebook\")" ] }, { @@ -32,12 +32,12 @@ "metadata": {}, "outputs": [], "source": [ - "regular = starfile.read('tm_patch_def_reg/9x9_ts_27_particles.star')\n", - "inverted = starfile.read('tm_patch_def_inv/9x9_ts_27_particles.star')\n", + "regular = starfile.read(\"tm_patch_def_reg/9x9_ts_27_particles.star\")\n", + "inverted = starfile.read(\"tm_patch_def_inv/9x9_ts_27_particles.star\")\n", "\n", "# divide by the standard deviation of the search to express in nr. of sigma\n", - "scores_reg = regular['rlnLCCmax'] / regular['rlnSearchStd']\n", - "scores_inv = inverted['rlnLCCmax'] / inverted['rlnSearchStd']" + "scores_reg = regular[\"rlnLCCmax\"] / regular[\"rlnSearchStd\"]\n", + "scores_inv = inverted[\"rlnLCCmax\"] / inverted[\"rlnSearchStd\"]" ] }, { @@ -47,7 +47,7 @@ "metadata": {}, "outputs": [], "source": [ - "coord_cols = ['rlnCoordinateX', 'rlnCoordinateY', 'rlnCoordinateZ']\n", + "coord_cols = [\"rlnCoordinateX\", \"rlnCoordinateY\", \"rlnCoordinateZ\"]\n", "coords_reg = np.array(regular[coord_cols])\n", "coords_inv = np.array(inverted[coord_cols])" ] @@ -89,7 +89,7 @@ } ], "source": [ - "cdist(coords_reg, coords_inv, metric='euclidean').min(axis=0)" + "cdist(coords_reg, coords_inv, metric=\"euclidean\").min(axis=0)" ] }, { @@ -120,36 +120,52 @@ "source": [ "x_size = 510\n", "\n", + "\n", "def quadratic(x, a_2, a_1, a_0):\n", - " return a_2 * x ** 2 + a_1 * x + a_0\n", + " return a_2 * x**2 + a_1 * x + a_0\n", "\n", - "def plot_fit_ci(x, s, func, ax1, ax2, l):\n", + "\n", + "def plot_fit_ci(x, s, func, ax1, ax2, label):\n", " p, cov = curve_fit(func, x, s)\n", " sigma = np.sqrt(np.diagonal(cov))\n", " xs = np.linspace(min(x), max(x))\n", " bound_upper = func(xs, *(p + sigma))\n", " bound_lower = func(xs, *(p - sigma))\n", - " trans = plt.gca().transData\n", - " ax1.scatter(x, s, s=10, alpha=.7)\n", - " ax2.plot(xs, func(xs, *p), label=l)\n", - " ax2.fill_between(xs, bound_lower, bound_upper,\n", - " color = 'black', alpha = 0.07)\n", + " _ = plt.gca().transData\n", + " ax1.scatter(x, s, s=10, alpha=0.7)\n", + " ax2.plot(xs, func(xs, *p), label=label)\n", + " ax2.fill_between(xs, bound_lower, bound_upper, color=\"black\", alpha=0.07)\n", + "\n", "\n", - "fig, ax = plt.subplots(1, 2, figsize=(10,5))\n", + "fig, ax = plt.subplots(1, 2, figsize=(10, 5))\n", "ax1, ax2 = ax\n", - "plot_fit_ci(coords_reg[:, 0] - x_size / 2 , scores_reg, quadratic, ax1, ax2, 'Default defocus handedness')\n", - "plot_fit_ci(coords_inv[:, 0] - x_size / 2 , scores_inv, quadratic, ax1, ax2, 'Inverted defocus handedness')\n", + "plot_fit_ci(\n", + " coords_reg[:, 0] - x_size / 2,\n", + " scores_reg,\n", + " quadratic,\n", + " ax1,\n", + " ax2,\n", + " \"Default defocus handedness\",\n", + ")\n", + "plot_fit_ci(\n", + " coords_inv[:, 0] - x_size / 2,\n", + " scores_inv,\n", + " quadratic,\n", + " ax1,\n", + " ax2,\n", + " \"Inverted defocus handedness\",\n", + ")\n", "ax1.set_xlim(-x_size / 2 + 10, x_size / 2 - 10)\n", - "ax1.set_xlabel('Centered x-coordinate')\n", - "ax1.set_ylabel(r'Relative $LCC_{max}$ ($\\sigma$)')\n", + "ax1.set_xlabel(\"Centered x-coordinate\")\n", + "ax1.set_ylabel(r\"Relative $LCC_{max}$ ($\\sigma$)\")\n", "ax1.set_ylim(15, 26)\n", "ax2.set_xlim(-x_size / 2 + 10, x_size / 2 - 10)\n", - "ax2.set_xlabel('Centered x-coordinate')\n", - "ax2.set_ylabel(r'Relative $LCC_{max}$ ($\\sigma$)')\n", + "ax2.set_xlabel(\"Centered x-coordinate\")\n", + "ax2.set_ylabel(r\"Relative $LCC_{max}$ ($\\sigma$)\")\n", "ax2.set_ylim(19, 22)\n", "plt.legend()\n", "plt.tight_layout()\n", - "plt.savefig('x_vs_defocus.svg')\n" + "plt.savefig(\"x_vs_defocus.svg\")" ] }, { @@ -177,7 +193,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.11.5" + "version": "3.10.12" } }, "nbformat": 4,