Skip to content

Commit

Permalink
Rename scale to scalings
Browse files Browse the repository at this point in the history
  • Loading branch information
cbrnr committed Dec 13, 2024
1 parent 59463b5 commit 2759f79
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
18 changes: 9 additions & 9 deletions mne/io/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1501,7 +1501,7 @@ def resample(
return self, events

@verbose
def rescale(self, scale, *, verbose=None):
def rescale(self, scalings, *, verbose=None):
"""Rescale channels.
.. warning::
Expand All @@ -1512,8 +1512,8 @@ def rescale(self, scale, *, verbose=None):
Parameters
----------
scale : int | float | dict
The scaling factor by which to multiply the data. If a float, the same
scalings : int | float | dict
The scaling factor(s) by which to multiply the data. If a float, the same
scaling factor is applied to all channels (this works only if all channels
are of the same type). If a dict, the keys must be valid channel types and
the values the scaling factors to apply to the corresponding channels.
Expand All @@ -1539,26 +1539,26 @@ def rescale(self, scale, *, verbose=None):
>>> raw.rescale({"eeg": 1e-6}) # doctest: +SKIP
"""
_validate_type(scale, (int, float, dict), "scale")
_validate_type(scalings, (int, float, dict), "scalings")
_check_preload(self, "raw.rescale")

channel_types = self.get_channel_types(unique=True)

if isinstance(scale, int | float):
if isinstance(scalings, int | float):
if len(channel_types) == 1:
self.apply_function(lambda x: x * scale, channel_wise=False)
self.apply_function(lambda x: x * scalings, channel_wise=False)
else:
raise ValueError(
"If scale is a scalar, all channels must be of the same type. "
"If scalings is a scalar, all channels must be of the same type. "
"Consider passing a dict instead."
)
else:
for ch_type in scale.keys():
for ch_type in scalings.keys():
if ch_type not in channel_types:
raise ValueError(
f'Channel type "{ch_type}" is not present in the Raw file.'
)
for ch_type, ch_scale in scale.items():
for ch_type, ch_scale in scalings.items():
self.apply_function(
lambda x: x * ch_scale, picks=ch_type, channel_wise=False
)
Expand Down
2 changes: 1 addition & 1 deletion mne/io/tests/test_raw.py
Original file line number Diff line number Diff line change
Expand Up @@ -1069,7 +1069,7 @@ def test_rescale():
"""Test rescaling channels."""
raw = read_raw_fif(raw_fname, preload=True) # multiple channel types

with pytest.raises(ValueError, match="If scale is a scalar, all channels"):
with pytest.raises(ValueError, match="If scalings is a scalar, all channels"):
raw.rescale(2) # need to use dict

orig = raw.get_data(picks="eeg")
Expand Down

0 comments on commit 2759f79

Please sign in to comment.