Repository navigation
Fix Maxwell routed channel mapping #1909
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
Open
Arthur031221
wants to merge
2
commits into
NeuralEnsemble:master
Choose a base branch
from
Arthur031221:fix-maxwell-routed-mapping-s75
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 all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,57 @@ | ||
| import tempfile | ||
| import unittest | ||
| from pathlib import Path | ||
|
|
||
| import numpy as np | ||
|
|
||
| try: | ||
| import h5py | ||
| except ImportError: | ||
| h5py = None | ||
|
|
||
| from neo.rawio.baserawio import BaseRawWithBufferApiIO, _signal_stream_dtype | ||
|
|
||
|
|
||
| class BufferReader(BaseRawWithBufferApiIO): | ||
| def _get_analogsignal_buffer_description(self, block_index, seg_index, buffer_id): | ||
| return self.description | ||
|
|
||
|
|
||
| @unittest.skipIf(h5py is None, "requires h5py") | ||
| class TestHDF5BufferSelection(unittest.TestCase): | ||
| def test_stream_selection_applied_once(self): | ||
| samples = np.arange(30, dtype="uint16").reshape(6, 5) | ||
| with tempfile.TemporaryDirectory() as directory: | ||
| filename = Path(directory) / "signals.h5" | ||
| with h5py.File(filename, "w") as file: | ||
| file["time_first"] = samples | ||
| file["channel_first"] = samples.T | ||
| for time_axis, dataset in [(0, "time_first"), (1, "channel_first")]: | ||
| for buffer_slice in [ | ||
| None, | ||
| slice(0, -1), | ||
| slice(-1, None), | ||
| np.array([0, 2, 4]), | ||
| np.array([True, False, True, False, True]), | ||
| ]: | ||
| with self.subTest(time_axis=time_axis, buffer_slice=buffer_slice): | ||
| reader = BufferReader() | ||
| reader.header = { | ||
| "signal_streams": np.array([("signals", "0", "0")], dtype=_signal_stream_dtype) | ||
| } | ||
| reader.description = { | ||
| "type": "hdf5", | ||
| "file_path": str(filename), | ||
| "hdf5_path": dataset, | ||
| "time_axis": time_axis, | ||
| } | ||
| reader._stream_buffer_slice = {"0": buffer_slice} | ||
| expected = samples[1:4] | ||
| if buffer_slice is not None: | ||
| expected = expected[:, buffer_slice] | ||
| for channel_indexes in [None, [0], slice(0, 1), [-1, 0]]: | ||
| selected = expected if channel_indexes is None else expected[:, channel_indexes] | ||
| np.testing.assert_array_equal( | ||
| reader._get_analogsignal_chunk(0, 0, 1, 4, 0, channel_indexes), selected | ||
| ) | ||
| reader._hdf5_analogsignal_buffers[0][0]["0"].close() |
This file contains hidden or 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
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 think we will need a discussion about this. We typically don't have folks edit the baserawio unless there is an obvious bug. Could you explain why we need to delete this?
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.
The two deleted lines are the first of two identical selections. In the HDF5 branch of
_get_analogsignal_chunk,raw_sigs[:, buffer_slice]runs, then the shared code after the if/elif chain (# this is a pre slicing when the stream does not contain all channels in the buffer) runs it again on the already selected array. That's harmless forNoneorslice(None), butslice(0, -1), an index array or a boolean mask fails or returns too few columns.Nothing hits this today because
maxwellrawio.pyis the only HDF5 buffer reader and it sets_stream_buffer_slice[stream_id]toslice(None)for every stream. This PR drops repeated and unmapped channel IDs from the header, so it has to drop the matching raw rows through_stream_buffer_slice, which makes it the first to set a real selection there.With
h5pydata throughBaseRawWithBufferApiIO,test_baserawio.pyfrom this branch fails 6 subtests on current master, fortime_axis0 and 1.slice(0, -1)gives (3, 3) instead of (3, 4), and the index array and boolean mask raiseIndexError. With the three lines put back here, 7 of the 15 Maxwell synthetic subtests fail.If you'd rather keep this PR to
maxwellrawio.py, I can move thebaserawio.pychange and its test into a separate PR and rebase this one on it.