Skip to content

Commit

Permalink
deal with new ruff version and next try for tutorial-test.yml (#224)
Browse files Browse the repository at this point in the history
* 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%
  • Loading branch information
sroet authored Aug 16, 2024
1 parent 171f4de commit c8b0f6a
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 57 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
43 changes: 13 additions & 30 deletions .github/workflows/tutorial-tests.yml
Original file line number Diff line number Diff line change
@@ -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: |
Expand Down
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -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
- id: ruff-format
64 changes: 40 additions & 24 deletions docs/benchmarks/defocus_gradient_analysis.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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\")"
]
},
{
Expand All @@ -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\"]"
]
},
{
Expand All @@ -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])"
]
Expand Down Expand Up @@ -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)"
]
},
{
Expand Down Expand Up @@ -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\")"
]
},
{
Expand Down Expand Up @@ -177,7 +193,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.5"
"version": "3.10.12"
}
},
"nbformat": 4,
Expand Down

0 comments on commit c8b0f6a

Please sign in to comment.