Skip to content

Commit

Permalink
Merge branch 'main' into interpolate_to
Browse files Browse the repository at this point in the history
  • Loading branch information
antoinecollas authored Feb 10, 2025
2 parents b399feb + 64ed255 commit 47ec126
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 8 deletions.
1 change: 1 addition & 0 deletions doc/changes/devel/13107.newfeature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The :meth:`mne.Info.save` method now has an ``overwrite`` and a ``verbose`` parameter, by `Stefan Appelhoff`_.
13 changes: 11 additions & 2 deletions mne/_fiff/meas_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -1935,15 +1935,24 @@ def _repr_html_(self):
info_template = _get_html_template("repr", "info.html.jinja")
return info_template.render(info=self)

def save(self, fname):
@verbose
def save(self, fname, *, overwrite=False, verbose=None):
"""Write measurement info in fif file.
Parameters
----------
fname : path-like
The name of the file. Should end by ``'-info.fif'``.
%(overwrite)s
.. versionadded:: 1.10
%(verbose)s
See Also
--------
mne.io.write_info
"""
write_info(fname, self)
write_info(fname, self, overwrite=overwrite)


def _simplify_info(info, *, keep=()):
Expand Down
2 changes: 1 addition & 1 deletion mne/_fiff/tests/test_meas_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -975,7 +975,7 @@ def test_field_round_trip(tmp_path):
meas_date=_stamp_to_dt((1, 2)),
)
fname = tmp_path / "temp-info.fif"
write_info(fname, info)
info.save(fname)
info_read = read_info(fname)
assert_object_equal(info, info_read)
with pytest.raises(TypeError, match="datetime"):
Expand Down
11 changes: 6 additions & 5 deletions mne/time_frequency/tfr.py
Original file line number Diff line number Diff line change
Expand Up @@ -4291,19 +4291,20 @@ def _tfr_from_mt(x_mt, weights):
Parameters
----------
x_mt : array, shape (n_channels, n_tapers, n_freqs, n_times)
x_mt : array, shape (..., n_tapers, n_freqs, n_times)
The complex-valued multitaper coefficients.
weights : array, shape (n_tapers, n_freqs)
The weights to use to combine the tapered estimates.
Returns
-------
tfr : array, shape (n_channels, n_freqs, n_times)
tfr : array, shape (..., n_freqs, n_times)
The time-frequency power estimates.
"""
weights = weights[np.newaxis, :, :, np.newaxis] # add singleton channel & time dims
# add singleton dim for time and any dims preceding the tapers
weights = weights[..., np.newaxis]
tfr = weights * x_mt
tfr *= tfr.conj()
tfr = tfr.real.sum(axis=1)
tfr *= 2 / (weights * weights.conj()).real.sum(axis=1)
tfr = tfr.real.sum(axis=-3)
tfr *= 2 / (weights * weights.conj()).real.sum(axis=-3)
return tfr

0 comments on commit 47ec126

Please sign in to comment.