Skip to content

Commit 4e0a0b6

Browse files
authored
Merge pull request #37 from SpikeInterface/auto-build-cambridge-library
Unify scripts to check probes + autogen CN library
2 parents 71d3e30 + ccda32f commit 4e0a0b6

File tree

5 files changed

+124
-34
lines changed

5 files changed

+124
-34
lines changed

.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: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
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/spikeinterface/probeinterface ./probeinterface
32+
33+
# cambridge neurotech probe maps
34+
git clone https://github.com/cambridge-neurotech/probe_maps.git ./probe_maps
35+
36+
- name: Install probeinterface and matplotlib
37+
run: pip install ./probeinterface matplotlib
38+
39+
- name: Generate full cambridge library and check for changes
40+
run: |
41+
cd scripts/
42+
python ../probeinterface/resources/generate_cambridgeneurotech_library.py ../probe_maps/ ./cambridge_library_generated/
43+
44+
# check for json changes (except probeinterface version)
45+
python check_for_json_changes_in_probes.py ../cambridgeneurotech/ ./cambridge_library_generated/
46+
# clean up
47+
rm -r cambridge_library_generated/
48+
cd ..
49+
rm -r ./probeinterface
50+
51+
- name: Commit changes if any
52+
id: commit
53+
run: |
54+
git config --local user.email "action@github.com"
55+
git config --local user.name "GitHub Action"
56+
57+
git add cambridgeneurotech/*
58+
59+
# Only commit if there are changes
60+
if git diff --staged --quiet; then
61+
echo "No changes to commit"
62+
echo "changes=false" >> $GITHUB_OUTPUT
63+
else
64+
git commit -m "Update json files for NP probes"
65+
echo "changes=true" >> $GITHUB_OUTPUT
66+
fi
67+
68+
- name: Create pull request to add probes
69+
if: steps.commit.outputs.changes == 'true'
70+
uses: peter-evans/create-pull-request@v7
71+
with:
72+
title: "Update Cambridge Neurotech json files"
73+
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."
74+
branch-suffix: short-commit-hash
75+
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)