Fix SourceChGain/SourceChOffset handling in BCI2k reader#13869
Fix SourceChGain/SourceChOffset handling in BCI2k reader#13869HansujaB wants to merge 9 commits intomne-tools:mainfrom
Conversation
nordme
left a comment
There was a problem hiding this comment.
Hi @HansujaB ! Thanks for the PR!
I think that the unit parser test function is a good idea, and in general we want to have complete test coverage of our code, so I think checking scaling is a good idea too. Actually, I would expand the coverage of the existing test you wrote to check error raising in the parsing function. Generally, an important feature of test functions is providing meaningful information about the type of failure that occurs when a test fails (so that other maintainers can figure what went wrong). pytest.raises() calls are useful for that purpose. I added an example below.
| assert _parse_value_with_unit("0.1muV", unit_scale=volt_scale) == (0.1, 1e-6) | ||
| assert _parse_value_with_unit("2mV", unit_scale=volt_scale) == (2.0, 1e-3) | ||
| assert _parse_value_with_unit("-3.5µV", unit_scale=volt_scale) == (-3.5, 1e-6) | ||
|
|
There was a problem hiding this comment.
| with pytest.raises(ValueError, match="Could not parse numeric value"): | |
| _parse_value_with_unit("....", unit_scale=volt_scale) | |
There was a problem hiding this comment.
Hi @nordme , Thanks a lot for reviewing the PR , will push the changes after expanding the test fns in some time.
Also do we need changes in examples/io/bci2k.py notebook as well?
| def _parse_value_with_unit(token, unit_scale=None): | ||
| """Split a numeric token with optional unit into value and scale.""" | ||
| text = str(token).strip().replace("µ", "u") | ||
| m = re.search(r"([-+]?\d*\.?\d+(?:[eE][-+]?\d+)?)\s*([a-zA-Z]*)", text) |
There was a problem hiding this comment.
I think you could get away with something much simpler, like r"[a-zA-Z]+$" to match the unit, then cut the string before/after result.start() to get the numeric and unit parts.
There was a problem hiding this comment.
for more information, see https://pre-commit.ci

Reference issue
Fixes #13851
What does this implement/fix?
*listparameters correctly by treating the first token as list length.SourceChOffsetandSourceChGaincalibration per channel so EEG data is returned in volts.Tests
SourceChOffset == ["0", "0"]SourceChGain == ["0.1muV", "0.1muV"]Questions
examples/io/read_bci2k.pyas well?