|
11 | 11 | from ...utils import verbose |
12 | 12 | from ..base import BaseRaw |
13 | 13 |
|
14 | | -_VOLT_SCALE = {"v": 1.0, "mv": 1e-3, "muv": 1e-6, "uv": 1e-6, "nv": 1e-9} |
15 | | -_FREQ_SCALE = {"hz": 1.0, "khz": 1e3} |
| 14 | +_VOLT_SCALE = {"v": 1.0, "mv": 1e-3, "muv": 1e-6, "uv": 1e-6, "nv": 1e-9, "": 1e-6} |
| 15 | +_FREQ_SCALE = {"hz": 1.0, "khz": 1e3, "": 1.0} |
16 | 16 |
|
17 | 17 |
|
18 | | -def _parse_value_with_unit(token, unit_scale=None): |
| 18 | +def _parse_value_with_unit(token, unit_scale): |
19 | 19 | """Split a numeric token with optional unit into value and scale.""" |
20 | 20 | text = str(token).strip().replace("µ", "u") |
21 | | - m = re.search(r"([-+]?\d*\.?\d+(?:[eE][-+]?\d+)?)\s*([a-zA-Z]*)", text) |
22 | | - if m is None: |
23 | | - raise ValueError(f"Could not parse numeric value from {token!r}") |
24 | | - num = float(m.group(1)) |
25 | | - unit = m.group(2).lower() |
26 | | - if unit_scale is None: |
27 | | - scale = 1.0 |
| 21 | + m = re.search(r"[a-zA-Z]+$", text) |
| 22 | + if m: |
| 23 | + num = float(text[:m.start()]) |
| 24 | + unit = m.group().lower() |
28 | 25 | else: |
29 | | - scale = unit_scale.get(unit, 1.0) |
30 | | - return num, scale |
| 26 | + num = float(text) |
| 27 | + unit = "" |
| 28 | + if unit not in unit_scale: |
| 29 | + raise ValueError(f"Unrecognized unit '{unit}' in token '{token}'.") |
| 30 | + return num, unit_scale[unit] |
31 | 31 |
|
32 | 32 |
|
33 | 33 | def _parse_bci2k_header(fname): |
@@ -182,7 +182,7 @@ def _read_bci2k_data(fname, info_dict): |
182 | 182 | raise ValueError( |
183 | 183 | "Expected SourceChOffset and SourceChGain lengths to match SourceCh." |
184 | 184 | ) |
185 | | - offsets_arr = np.array([_parse_value_with_unit(val)[0] for val in offsets]) |
| 185 | + offsets_arr = np.array([float(val) for val in offsets]) |
186 | 186 | gain_parsed = [_parse_value_with_unit(val, unit_scale=_VOLT_SCALE) for val in gains] |
187 | 187 | gains_arr = np.array([val for val, _ in gain_parsed]) |
188 | 188 | gain_scales = np.array([scale for _, scale in gain_parsed]) |
|
0 commit comments