Hi everyone,
If I should break this into individual issues, please let me know. The thinking here was to group the issues affecting the desired output.
I’m trying to produce topoplots in 100-ms time steps across the frequencies of interest for my study, looking at relative change from baseline in decibels. Ideally, I’d want them to look something like this (wonky electrode aside):
I’m running into a couple of issues:
RuntimeWarning
when applying a baseline from within theplot_topomap
function.- Conversion to decibels of the bel
"logratio"
power. - Producing a valid colour bar.
Baselining and converting to decibels
In the code where I produce the TFR representation, I apply a baseline directly to the tfr
object.
- Does this baselining persist when outputting to a data frame (
tfr.to_data_frame()
) or when using the plotting functions (e.g.tfr.plot_topomap
)? I would assume so, as
tfr.apply_baseline(baseline, mode="logratio")
Based on the codebase, it seems that mode="logratio"
returns the data in bels. As I would like decibels, I multiply the baselined power values across the board.
- Is it acceptable to multiply in this manner to get decibels if it’s not already available in the function?
times = np.arange(-0.4, 1.1, step=0.1).round(decimals=1)
iter_freqs = [
("sub_theta", 2, 4), # 2 Hz is the minimum due to epoch length
("theta", 4, 7),
("alpha", 8, 12),
("low_beta", 13, 20),
("high_beta", 21, 25)
]
baseline = (-1.25, -0.75)
tfr = epochs.compute_tfr(
method="morlet",
freqs=freqs,
n_cycles=3,
use_fft=True,
return_itc=False,
average=False,
n_jobs=config.n_jobs,
decim=25, # For 50 ms time steps in the output data frame
)
# Compute log ratio power and convert to decibels
log_tfr = tfr.copy().apply_baseline(baseline, mode="logratio")
db = log_tfr.__mul__(10)
for band, fmin, fmax in iter_freqs:
fig, axes = plt.subplots(3, 5, figsize=(12, 8))
axes = axes.flatten()
for i, time in enumerate(times):
im = db.plot_topomap(tmin=time, tmax=time + 0.1, fmin=fmin, fmax=fmax, show=False, axes=axes[i], colorbar=False, vlim=(-3, 3))
axes[i].set_title(f"{time * 1000:.0f} ms")
im_cbar = im.axes[-2].images[-1]
cbar = fig.colorbar(im_cbar, ax=axes, orientation="vertical", shrink=0.6)
cbar.set_label("dB change from baseline")
fig.suptitle(f"Topomap of {band} ({fmin} Hz to {fmax} Hz) frequency band (Participant cndeeg01, {condition} condition)")
plt.show()
RuntimeWarning
When trying to apply mode="logratio"
baseline correction from within the plot_topomap
function, there are multiple warnings thrown out:
RuntimeWarning: invalid value encountered in log10
np.log10(d, out=d)
This doesn’t apply to all plots, it seems, as some of the topoplots are produced, as can be seen in the examples below. In some cases many topoplots are present, in others only a few, and sometimes nothing appears.
- Is this warning connected to the data already having been baselined, and the reapplication (if that’s indeed what’s happening) of
np.log10
is messing things about?
Valid colour bars
Lastly, I attempted to produce valid colour bars which should reflect the range of activity across all subplots, but I’m not sure that I’m getting that. The outputs are varied, as can be seen below.
It’s unclear to me whether the colour bar is only reflecting activity from the last topoplot, as might be indicated from the last image where the range is from 0.00 to 2.00, seemingly missing any of the negative activity. The other two plots could be valid, but I’m not sure how to sanity-check the output here.
Many thanks for any insights into these issues!
MNE 1.9.0
macOS 15.4.1