-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a PPU component #71
Open
tmichela
wants to merge
7
commits into
master
Choose a base branch
from
ppu
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
ba8d0b4
first draft of a ppu component
tmichela 50399e4
add unit tests
tmichela 38359f2
docs
tmichela f107703
docs
tmichela 4aea70e
do not drop train IDs missing from the run data, this might still be …
tmichela 44e92b5
support for the dipole ppu-like device
tmichela b2af097
allow filtering trains on other datas
tmichela File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
|
||
from .scantool import Scantool # noqa | ||
from .ppu import PPU | ||
from .pulses import XrayPulses, OpticalLaserPulses, DldPulses # noqa | ||
from .scan import Scan |
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,88 @@ | ||
import pandas as pd | ||
import pytest | ||
|
||
from extra_data.reader import DataCollection | ||
from extra.components import PPU | ||
from extra.components.ppu import _find_ppu | ||
|
||
|
||
def test_find_ppu(ppu_run): | ||
source = _find_ppu(ppu_run, ppu_run['HED_DIPOLE_PPU/MDL/PPU_TRIGGER']) | ||
assert source.source == 'HED_DIPOLE_PPU/MDL/PPU_TRIGGER' | ||
|
||
source = _find_ppu(ppu_run, ppu_run['HED_DIPOLE_PPU/MDL/PPU_TRIGGER', 'trainTrigger.sequenceStart']) | ||
assert source.source == 'HED_DIPOLE_PPU/MDL/PPU_TRIGGER' | ||
|
||
source = _find_ppu(ppu_run, 'HED_DIPOLE_PPU/MDL/PPU_TRIGGER') | ||
assert source.source == 'HED_DIPOLE_PPU/MDL/PPU_TRIGGER' | ||
|
||
source = _find_ppu(ppu_run, 'ppu-hed') | ||
assert source.source == 'HED_XTD6_PPU/MDL/PPU_TRIGGER' | ||
|
||
source = _find_ppu(ppu_run, 'XTD6') | ||
assert source.source == 'HED_XTD6_PPU/MDL/PPU_TRIGGER' | ||
|
||
source = _find_ppu(ppu_run.select('HED_XTD6_PPU*')) | ||
assert source.source == 'HED_XTD6_PPU/MDL/PPU_TRIGGER' | ||
|
||
# fails with multiple PPUs | ||
with pytest.raises(KeyError) as excinfo: | ||
_find_ppu(ppu_run) | ||
assert 'Multiple PPU' in str(excinfo.value) | ||
|
||
# fails with invalid device type | ||
with pytest.raises(KeyError) as excinfo: | ||
_find_ppu(ppu_run, 1) | ||
assert 'not int' in str(excinfo.value) | ||
|
||
# fails with 0 PPUs | ||
with pytest.raises(KeyError) as excinfo: | ||
_find_ppu(ppu_run.select('*TIMESERVER')) | ||
assert 'Could not find a PPU' in str(excinfo.value) | ||
|
||
# too many match | ||
with pytest.raises(KeyError) as excinfo: | ||
_find_ppu(ppu_run, 'PPU') | ||
assert 'Multiple PPUs found matching' in str(excinfo.value) | ||
|
||
# no match | ||
with pytest.raises(KeyError) as excinfo: | ||
_find_ppu(ppu_run, 'PPU2') | ||
assert 'Couldn\'t identify a PPU' in str(excinfo.value) | ||
|
||
|
||
def test_train_ids(ppu_run): | ||
# single trigger sequence | ||
ppu = PPU(ppu_run, 'ppu-hed') | ||
train_ids = ppu.train_ids() | ||
assert isinstance(train_ids, list) | ||
assert len(train_ids) == 10 | ||
train_ids = ppu.train_ids(labelled=True) | ||
assert isinstance(train_ids, pd.Series) | ||
assert train_ids.size == 10 # 10 trains in total | ||
assert train_ids.index.unique().size == 1 # single trigger sequence | ||
|
||
# multiple trigger sequences | ||
ppu = PPU(ppu_run, 'ppu-dipole') | ||
train_ids = ppu.train_ids() | ||
assert isinstance(train_ids, list) | ||
assert len(train_ids) == 3 | ||
train_ids = ppu.train_ids(labelled=True) | ||
assert isinstance(train_ids, pd.Series) | ||
assert train_ids.index.unique().size == 3 # 3 trigger sequence | ||
assert train_ids.size == 3 # 1 train per sequence | ||
|
||
|
||
def test_trains(ppu_run): | ||
ppu = PPU(ppu_run, 'ppu-dipole') | ||
reduced_run = ppu.trains() | ||
assert isinstance(reduced_run, DataCollection) | ||
assert len(reduced_run.train_ids) == 3 | ||
assert reduced_run.train_ids == [10015, 10045, 10075] | ||
|
||
# split per sequence | ||
reduced_run = ppu.trains(split_sequence=True) | ||
assert isinstance(reduced_run, list) | ||
assert len(reduced_run) == 3 | ||
assert len(reduced_run[0].train_ids) == 1 | ||
assert reduced_run[0].train_ids == [10015] |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm sure this is overly pedantic / redundant, but maybe:
assert isinstance(reduced_run[0], DataCollection)
in analogy to thesplit_sequence == False
case