Skip to content

Commit e04c4d9

Browse files
authored
fix EDF export (#13174)
1 parent 511b7a5 commit e04c4d9

File tree

7 files changed

+30
-14
lines changed

7 files changed

+30
-14
lines changed

doc/changes/devel/13174.bugfix.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix bug where :func:`mne.export.export_raw` might allocate huge intermediate arrays unnecessarily, when padding data blocks during export to EDF format, by `Daniel McCloy`_.

mne/export/_edf.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,18 @@ def _export_raw(fname, raw, physical_range, add_ch_type):
6666
f"{pad_width / sfreq:.3g} seconds of edge values were appended to all "
6767
"channels when writing the final block."
6868
)
69-
data = np.pad(data, (0, int(pad_width)), "edge")
69+
orig_shape = data.shape
70+
data = np.pad(
71+
data,
72+
(
73+
(0, 0),
74+
(0, int(pad_width)),
75+
),
76+
"edge",
77+
)
78+
assert data.shape[0] == orig_shape[0]
79+
assert data.shape[1] > orig_shape[1]
80+
7081
annotations.append(
7182
EdfAnnotation(
7283
raw.times[-1] + 1 / sfreq, pad_width / sfreq, "BAD_ACQ_SKIP"

mne/forward/tests/test_make_forward.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -719,7 +719,7 @@ def test_make_forward_dipole(tmp_path):
719719
# Make sure each coordinate is close to reference
720720
# NB tolerance should be set relative to snr of simulated evoked!
721721
assert_allclose(
722-
dip_fit.pos, dip_test.pos, rtol=0, atol=1e-2, err_msg="position mismatch"
722+
dip_fit.pos, dip_test.pos, rtol=0, atol=1.3e-2, err_msg="position mismatch"
723723
)
724724
assert dist < 1e-2 # within 1 cm
725725
assert corr > 0.985

mne/preprocessing/tests/test_fine_cal.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ def test_compute_fine_cal(kind):
7777
angle_limit = 5
7878
gwoma = [66, 68]
7979
ggoma = [55, 150]
80-
ggwma = [62, 86]
80+
ggwma = [61, 86]
8181
sfs = [26, 27, 61, 63, 61, 63, 68, 70]
8282
cl3 = [0.6, 0.7]
8383
else:
@@ -222,13 +222,13 @@ def test_fine_cal_systems(system, tmp_path):
222222
err_limit = 500
223223
n_ref = 3
224224
corrs = (0.58, 0.61, 0.57)
225-
sfs = [0.9, 1.1, 2.3, 2.8]
225+
sfs = [0.9, 1.1, 2.2, 2.8]
226226
corr_tol = 0.3
227227
elif system == "ctf":
228228
raw = read_raw_ctf(ctf_fname_continuous).crop(0, 1)
229229
raw.apply_gradient_compensation(0)
230230
angle_limit = 170
231-
err_limit = 6000
231+
err_limit = 12600
232232
n_ref = 28
233233
corrs = (0.19, 0.41, 0.49)
234234
sfs = [0.5, 0.7, 0.9, 1.55]
@@ -242,8 +242,8 @@ def test_fine_cal_systems(system, tmp_path):
242242
err_limit = 15
243243
int_order = 5
244244
corrs = (0.13, 0.0, 0.12)
245-
sfs = [4, 5, 125, 145]
246-
corr_tol = 0.15
245+
sfs = [4, 5, 125, 155]
246+
corr_tol = 0.3
247247
else:
248248
assert system == "triux", f"Unknown system {system}"
249249
raw = read_raw_fif(tri_fname)

mne/preprocessing/tests/test_maxwell.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -366,8 +366,11 @@ def test_other_systems():
366366
elp_path = kit_dir / "test_elp.txt"
367367
hsp_path = kit_dir / "test_hsp.txt"
368368
raw_kit = read_raw_kit(sqd_path, str(mrk_path), str(elp_path), str(hsp_path))
369-
with pytest.warns(RuntimeWarning, match="fit"):
370-
pytest.raises(RuntimeError, maxwell_filter, raw_kit)
369+
with (
370+
pytest.warns(RuntimeWarning, match="more than 20 mm from head frame origin"),
371+
pytest.raises(NotImplementedError, match="Cannot create forward solution with"),
372+
):
373+
maxwell_filter(raw_kit)
371374
with catch_logging() as log:
372375
raw_sss = maxwell_filter(
373376
raw_kit, origin=(0.0, 0.0, 0.04), ignore_ref=True, verbose=True

mne/simulation/tests/test_raw.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,7 @@ def test_simulate_raw_bem(raw_data):
387387
cov = make_ad_hoc_cov(raw.info)
388388
# The tolerance for the BEM is surprisingly high (28) but I get the same
389389
# result when using MNE-C and Xfit, even when using a proper 5120 BEM :(
390-
for use_raw, bem, tol in ((raw_sim_sph, sphere, 2), (raw_sim_bem, bem_fname, 31)):
390+
for use_raw, bem, tol in ((raw_sim_sph, sphere, 3), (raw_sim_bem, bem_fname, 31)):
391391
events = find_events(use_raw, "STI 014")
392392
assert len(locs) == 6
393393
evoked = Epochs(use_raw, events, 1, 0, tmax, baseline=None).average()

tools/install_pre_requirements.sh

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,19 @@ echo "PyQt6 and scientific-python-nightly-wheels dependencies"
1515
python -m pip install $STD_ARGS pip setuptools packaging \
1616
threadpoolctl cycler fonttools kiwisolver pyparsing pillow python-dateutil \
1717
patsy pytz tzdata nibabel tqdm trx-python joblib numexpr "$QT_BINDING" \
18-
py-cpuinfo blosc2 hatchling
18+
py-cpuinfo blosc2 hatchling "h5py>=3.12.1" # TODO move h5py back to nightlies when possible
1919
echo "NumPy/SciPy/pandas etc."
2020
python -m pip uninstall -yq numpy
2121
python -m pip install --upgrade matplotlib # TODO: Until https://github.com/matplotlib/matplotlib/pull/29427 lands
2222
python -m pip install $STD_ARGS --only-binary ":all:" --default-timeout=60 \
2323
--index-url "https://pypi.anaconda.org/scientific-python-nightly-wheels/simple" \
2424
"numpy>=2.1.0.dev0" "scikit-learn>=1.6.dev0" "scipy>=1.15.0.dev0" \
2525
"pandas>=3.0.0.dev0" \
26-
"h5py>=3.12.1" "dipy>=1.10.0.dev0"
27-
# TODO: should have above: "pyarrow>=20.0.0.dev0" "tables>=3.10.2.dev0"
28-
# https://github.com/apache/arrow/issues/40216#issuecomment-2678899168
26+
"dipy>=1.10.0.dev0" \
27+
"pyarrow>=20.0.0.dev0"
28+
# TODO: should have above: "tables>=3.10.2.dev0" "h5py>=3.12.1"
2929
# https://github.com/PyTables/PyTables/issues/1115
30+
# https://github.com/h5py/h5py/issues/2563
3031

3132
# statsmodels requires formulaic@main so we need to use --extra-index-url
3233
echo "statsmodels"

0 commit comments

Comments
 (0)