Skip to content

Commit 9495ea8

Browse files
committed
Unify scripts to check probes + autogen CN library
1 parent 71d3e30 commit 9495ea8

5 files changed

Lines changed: 128 additions & 34 deletions

.github/workflows/check_for_changes_in_NP_jsons.yml

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,19 +38,16 @@ jobs:
3838
pip install ./probeinterface
3939
4040
41-
- name: Generate full NP library
41+
- name: Generate full NP library and check for changes
4242
run: |
4343
cd scripts/
44+
# generate full library
4445
python ../probeinterface/resources/generate_neuropixels_library.py
45-
46-
# Check for any new probes
47-
- name: Run local script
48-
run: |
49-
cd scripts/
50-
python check_for_json_changes_in_NP_probes.py
46+
# check for json changes (except probeinterface version)
47+
python check_for_json_changes_in_probes.py ../imec/ ./neuropixels_library_generated/
48+
# clean up
5149
rm -r neuropixels_library_generated/
5250
cd ..
53-
5451
rm -r ./probeinterface
5552
5653
- name: Commit changes if any
File renamed without changes.
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
name: Generate Cambridge Neurotech library
2+
3+
on:
4+
schedule:
5+
- cron: '0 1 * * 1' # Every Monday at 01:00 UTC
6+
workflow_dispatch:
7+
8+
# Grant permissions for the job to write to contents (push) and create PRs.
9+
permissions:
10+
contents: write
11+
pull-requests: write
12+
13+
jobs:
14+
build-and-pr:
15+
runs-on: ubuntu-latest
16+
steps:
17+
18+
- name: Check out local repository
19+
uses: actions/checkout@v4
20+
21+
# Set up a Python environment
22+
- name: Set up Python
23+
uses: actions/setup-python@v5
24+
with:
25+
python-version: '3.10'
26+
27+
# Clone dev version of probeinterface
28+
- name: Clone external repositories
29+
run: |
30+
# probeinterface
31+
git clone https://github.com/samuelgarcia/probeinterface ./probeinterface
32+
# for now, we checkout the two-sided branch
33+
cd probeinterface
34+
git checkout two_side_probes
35+
cd ..
36+
37+
# cambridge neurotech probe maps
38+
git clone https://github.com/cambridge-neurotech/probe_maps.git ./probe_maps
39+
40+
- name: Install probeinterface and matplotlib
41+
run: pip install ./probeinterface matplotlib
42+
43+
- name: Generate full cambridge library and check for changes
44+
run: |
45+
cd scripts/
46+
python ../probeinterface/resources/generate_cambridgeneurotech_library.py ../probe_maps/ ./cambridge_library_generated/
47+
48+
# check for json changes (except probeinterface version)
49+
python check_for_json_changes_in_probes.py ../cambridgeneurotech/ ./cambridge_library_generated/
50+
# clean up
51+
rm -r cambridge_library_generated/
52+
cd ..
53+
rm -r ./probeinterface
54+
55+
- name: Commit changes if any
56+
id: commit
57+
run: |
58+
git config --local user.email "action@github.com"
59+
git config --local user.name "GitHub Action"
60+
61+
git add cambridgeneurotech/*
62+
63+
# Only commit if there are changes
64+
if git diff --staged --quiet; then
65+
echo "No changes to commit"
66+
echo "changes=false" >> $GITHUB_OUTPUT
67+
else
68+
git commit -m "Update json files for NP probes"
69+
echo "changes=true" >> $GITHUB_OUTPUT
70+
fi
71+
72+
- name: Create pull request to add probes
73+
if: steps.commit.outputs.changes == 'true'
74+
uses: peter-evans/create-pull-request@v7
75+
with:
76+
title: "Update Cambridge Neurotech json files"
77+
body: "This PR updates the Neuropixel probes in probeinterace library, based on new data from the ProbeTable repository or because of a new ProbeInterface release."
78+
branch-suffix: short-commit-hash
79+
base: "main"

scripts/check_for_json_changes_in_NP_probes.py

Lines changed: 0 additions & 26 deletions
This file was deleted.
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
from argparse import ArgumentParser
2+
from pathlib import Path
3+
import shutil
4+
5+
6+
parser = ArgumentParser(description="Check for JSON changes in probes from manufacturer")
7+
8+
parser.add_argument(
9+
"old_dir",
10+
type=str,
11+
help="Path to the old probes directory",
12+
)
13+
14+
parser.add_argument(
15+
"new_dir",
16+
type=str,
17+
help="Path to the new probes directory",
18+
)
19+
20+
21+
if __name__ == "__main__":
22+
args = parser.parse_args()
23+
old_dir = Path(args.old_dir)
24+
new_dir = Path(args.new_dir)
25+
for temp_probe_directory in new_dir.iterdir():
26+
probe_name = str(temp_probe_directory.name)
27+
28+
temp_probe_json_path = temp_probe_directory / (probe_name + '.json')
29+
old_probe_json_path = old_dir / probe_name / (probe_name + '.json')
30+
31+
if old_probe_json_path.is_file():
32+
with open(temp_probe_json_path, 'r') as f1, open(old_probe_json_path, 'r') as f2:
33+
# Read in json files
34+
lines1 = f1.readlines()
35+
lines2 = f2.readlines()
36+
37+
# We don't want to update the probes just because of a probeinterface version update.
38+
# The probeinterface version is stored on the 3rd line of the json file, so we only
39+
# compare the json files from line 3 and down.
40+
if lines1[3:] == lines2[3:]:
41+
continue
42+
else:
43+
shutil.copy(f"{temp_probe_json_path}", f"../imec/{probe_name}")
44+

0 commit comments

Comments
 (0)