Skip to content

Commit

Permalink
FIX: Test
Browse files Browse the repository at this point in the history
  • Loading branch information
larsoner committed Oct 28, 2024
1 parent 9f4234d commit b3b3f2e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
11 changes: 10 additions & 1 deletion mne/io/snirf/_snirf.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,7 @@ def natural_keys(text):
# append time delay
ch_name = f"{ch_name} bin{fnirs_time_delays[bin_idx - 1]}"
ch_type = "fnirs_td_gated_amplitude"
need_data_scale = True
else:
assert snirf_data_type == SNIRF_TD_MOMENTS_AMPLITUDE
moment_idx = int(
Expand All @@ -316,6 +317,7 @@ def natural_keys(text):
f"{ch_name} moment{fnirs_moment_orders[moment_idx - 1]}"
)
ch_type = "fnirs_td_moments_amplitude"
need_data_scale = True

elif snirf_data_type == SNIRF_PROCESSED:
dt_id = _correct_shape(
Expand All @@ -333,7 +335,14 @@ def natural_keys(text):
)
suffix = str(fnirs_wavelengths[wve_idx - 1])
else:
if dt_id not in ("hbo", "hbr"):
raise RuntimeError(
"read_raw_snirf can only handle processed "
"data in the form of optical density or "
f"HbO/HbR, but got type f{dt_id}"
)
suffix = dt_id.lower()
need_data_scale = True
ch_name = f"{ch_name} {suffix}"
ch_type = dt_id
chnames.append(ch_name)
Expand All @@ -351,7 +360,7 @@ def natural_keys(text):
scale = _get_dataunit_scaling(snirf_data_unit)
if scale is not None:
for ch in info["chs"]:
ch["cal"] = 1.0 / scale
ch["cal"] = scale

subject_info = {}
names = np.array(dat.get("nirs/metaDataTags/SubjectID"))
Expand Down
15 changes: 10 additions & 5 deletions mne/io/snirf/tests/test_snirf.py
Original file line number Diff line number Diff line change
Expand Up @@ -427,14 +427,19 @@ def test_snirf_kernel(kind):
if kind == "hb":
# Test data import
assert raw._data.shape == (180 * 2, 14)
assert raw.copy().pick("hbo")._data.shape == (180, 14)
assert raw.copy().pick("hbr")._data.shape == (180, 14)
hbo_data = raw.get_data("hbo")
hbr_data = raw.get_data("hbr")
assert hbo_data.shape == hbr_data.shape == (180, 14)
hbo_norm = np.nanmedian(np.linalg.norm(hbo_data, axis=-1))
hbr_norm = np.nanmedian(np.linalg.norm(hbr_data, axis=-1))
assert 1 < hbr_norm < hbo_norm < 3
n_nan = 20
else:
assert raw._data.shape == (1080, 14)
assert (
raw.copy().pick("fnirs_td_moments_amplitude")._data.shape == raw._data.shape
)
data = raw.get_data("fnirs_td_moments_amplitude")
assert data.shape == raw._data.shape
norm = np.nanmedian(np.linalg.norm(data, axis=-1))
assert 1e5 < norm < 1e6 # TODO: 429256, is this reasonable Molars!??
n_nan = 60

assert_allclose(raw.info["sfreq"], 8.257638)
Expand Down

0 comments on commit b3b3f2e

Please sign in to comment.