-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into neuromodulatorsExtraction
- Loading branch information
Showing
8 changed files
with
149 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
name: Version Check | ||
|
||
on: | ||
pull_request: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
checks: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: Setup Python | ||
uses: actions/setup-python@v4 | ||
with: | ||
python-version: '3.11' | ||
cache: 'pip' | ||
cache-dependency-path: 'pyproject.toml' | ||
- name: Install dependencies | ||
run: | | ||
pip install --editable . | ||
pip install packaging | ||
- name: Fetch versions | ||
run: | | ||
git fetch origin --tags | ||
previous_version=$(git describe --tags --match="[0-9]*" origin/main) | ||
latest_version=$(pip show project_extraction | awk '/^Version: / {sub("^Version: ", ""); print}') | ||
echo "Version tag on main: $previous_version" | ||
echo "Version tag on this branch: $latest_version" | ||
echo "PREVIOUS_VERSION=$previous_version" >> $GITHUB_ENV | ||
echo "LATEST_VERSION=$latest_version" >> $GITHUB_ENV | ||
- name: Assert version | ||
run: | | ||
python <<EOP | ||
import sys; from packaging import version | ||
sys.exit(int(version.parse("$PREVIOUS_VERSION") >= version.parse("$LATEST_VERSION"))) | ||
EOP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
name: Version Tag | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
deploy: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
with: | ||
ref: ${{ github.head_ref }} | ||
fetch-depth: 0 | ||
- name: Setup Python | ||
uses: actions/setup-python@v4 | ||
with: | ||
python-version: '3.11' | ||
cache: 'pip' | ||
cache-dependency-path: 'pyproject.toml' | ||
- name: Install dependencies | ||
run: | | ||
pip install --editable . | ||
- name: Fetch version | ||
run: | | ||
latest_version=$(pip show project_extraction | awk '/^Version: / {sub("^Version: ", ""); print}') | ||
echo "LATEST_VERSION=$latest_version" >> $GITHUB_ENV | ||
- name: Create tag | ||
run: | | ||
git config --local user.email "[email protected]" | ||
git config --local user.name "GitHub Action" | ||
git tag -a "$LATEST_VERSION" HEAD -m "Version v$LATEST_VERSION" | ||
- name: Push changes | ||
uses: ad-m/github-push-action@master | ||
with: | ||
force: true | ||
tags: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
"""Bpod extractor for nate_optoBiasedChoiceWorld task. | ||
This is the same as biasedChoiceWorld with the addition of one dataset, `laserStimulation.intervals`; The times the | ||
laser was on. | ||
The pipeline task subclasses, OptoTrialsBpod and OptoTrialsNidq, aren't strictly necessary. They simply assert that the | ||
laserStimulation datasets were indeed saved and registered by the Bpod extractor class. | ||
""" | ||
import numpy as np | ||
import ibllib.io.raw_data_loaders as raw | ||
from ibllib.io.extractors.base import BaseBpodTrialsExtractor, run_extractor_classes | ||
from ibllib.io.extractors.bpod_trials import BiasedTrials | ||
from ibllib.pipes.behavior_tasks import ChoiceWorldTrialsNidq, ChoiceWorldTrialsBpod | ||
|
||
|
||
class OptoTrialsBpod(ChoiceWorldTrialsBpod): | ||
"""Extract bpod only trials and laser stimulation data.""" | ||
|
||
@property | ||
def signature(self): | ||
signature = super().signature | ||
signature['output_files'].append(('*laserStimulation.intervals.npy', self.output_collection, True)) | ||
return signature | ||
|
||
|
||
class OptoTrialsNidq(ChoiceWorldTrialsNidq): | ||
"""Extract trials and laser stimulation data aligned to NI-DAQ clock.""" | ||
|
||
@property | ||
def signature(self): | ||
signature = super().signature | ||
signature['output_files'].append(('*laserStimulation.intervals.npy', self.output_collection, True)) | ||
return signature | ||
|
||
|
||
class TrialsOpto(BaseBpodTrialsExtractor): | ||
var_names = BiasedTrials.var_names + ('laser_intervals',) | ||
save_names = BiasedTrials.save_names + ('_ibl_laserStimulation.intervals.npy',) | ||
|
||
def _extract(self, extractor_classes=None, **kwargs) -> dict: | ||
settings = self.settings.copy() | ||
if 'OPTO_STIM_STATES' in settings: | ||
# It seems older versions did not distinguish start and stop states | ||
settings['OPTO_TTL_STATES'] = settings['OPTO_STIM_STATES'][:1] | ||
settings['OPTO_STOP_STATES'] = settings['OPTO_STIM_STATES'][1:] | ||
assert {'OPTO_STOP_STATES', 'OPTO_TTL_STATES', 'PROBABILITY_OPTO_STIM'} <= set(settings) | ||
# Get all detected TTLs. These are stored for QC purposes | ||
self.frame2ttl, self.audio = raw.load_bpod_fronts(self.session_path, data=self.bpod_trials) | ||
# Extract common biased choice world datasets | ||
out, _ = run_extractor_classes( | ||
[BiasedTrials], session_path=self.session_path, bpod_trials=self.bpod_trials, | ||
settings=settings, save=False, task_collection=self.task_collection) | ||
|
||
# Extract laser dataset | ||
laser_intervals = [] | ||
for trial in filter(lambda t: t['opto_stimulation'], self.bpod_trials): | ||
states = trial['behavior_data']['States timestamps'] | ||
# Assumes one of these states per trial: takes the timestamp of the first matching state | ||
start = next((v[0][0] for k, v in states.items() if k in settings['OPTO_TTL_STATES']), np.nan) | ||
stop = next((v[0][0] for k, v in states.items() if k in settings['OPTO_STOP_STATES']), np.nan) | ||
laser_intervals.append((start, stop)) | ||
out['laser_intervals'] = np.array(laser_intervals, dtype=np.float64) | ||
|
||
return {k: out[k] for k in self.var_names} # Ensures all datasets present and ordered |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
{ | ||
"samuel_cuedBiasedChoiceWorld": "BiasedTrials", | ||
"nate_optoBiasedChoiceWorld": "EphysTrials", | ||
"_iblrig_tasks_neuromodulatorChoiceWorld": "projects.neuromodulators.TrialsTableNeuromodulator" | ||
"nate_optoBiasedChoiceWorld": "projects.nate_optoBiasedChoiceWorld.TrialsOpto" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters