Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Jan 13, 2025
1 parent 8f6c07f commit cf595cb
Show file tree
Hide file tree
Showing 14 changed files with 39 additions and 45 deletions.
2 changes: 1 addition & 1 deletion examples/general/plot_22_quality.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@
scores,
times,
threshold=0.7,
title="Scalp Coupling Index " "Quality Evaluation",
title="Scalp Coupling Index Quality Evaluation",
)

# %%
Expand Down
8 changes: 4 additions & 4 deletions mne_nirs/channels/_channels.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def drop_sources(raw, sources):
all_str = all([isinstance(src, int) for src in sources])
except TypeError:
raise ValueError(
"'ch_names' must be iterable, got " f"type {type(sources)} ({sources})."
f"'ch_names' must be iterable, got type {type(sources)} ({sources})."
)

if not all_str:
Expand Down Expand Up @@ -139,7 +139,7 @@ def drop_detectors(raw, detectors):
all_str = all([isinstance(det, int) for det in detectors])
except TypeError:
raise ValueError(
"'ch_names' must be iterable, got " f"type {type(detectors)} ({detectors})."
f"'ch_names' must be iterable, got type {type(detectors)} ({detectors})."
)

if not all_str:
Expand Down Expand Up @@ -183,7 +183,7 @@ def pick_sources(raw, sources):
all_str = all([isinstance(src, int) for src in sources])
except TypeError:
raise ValueError(
"'ch_names' must be iterable, got " f"type {type(sources)} ({sources})."
f"'ch_names' must be iterable, got type {type(sources)} ({sources})."
)

if not all_str:
Expand Down Expand Up @@ -227,7 +227,7 @@ def pick_detectors(raw, detectors):
all_str = all([isinstance(det, int) for det in detectors])
except TypeError:
raise ValueError(
"'ch_names' must be iterable, got " f"type {type(detectors)} ({detectors})."
f"'ch_names' must be iterable, got type {type(detectors)} ({detectors})."
)

if not all_str:
Expand Down
2 changes: 1 addition & 1 deletion mne_nirs/channels/_roi.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def picks_pair_to_idx(raw, sd_pairs, on_missing="error"):
pair_name = "S" + str(pair[0]) + "_D" + str(pair[1]) + " "
pair_picks = np.where([pair_name in ch for ch in ch_names])[0]
if len(pair_picks) == 0:
msg = "No matching channels found for source %s " "detector %s" % (
msg = "No matching channels found for source %s detector %s" % (
pair[0],
pair[1],
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,7 @@ def data_path(
.. footbibliography::
"""
dataset_params = dict(
archive_name="2021-fNIRS-Audio-visual-speech-"
"Broad-vs-restricted-regions.zip",
archive_name="2021-fNIRS-Audio-visual-speech-Broad-vs-restricted-regions.zip",
hash="md5:16cac6565880dae6aed9b69100399d0b",
url="https://osf.io/xwerv/download?version=1",
folder_name="fNIRS-audio-visual-speech",
Expand All @@ -77,7 +76,7 @@ def data_path(

# Do some wrangling to deal with nested directories
bad_name = os.path.join(
dpath, "2021-fNIRS-Audio-visual-speech-" "Broad-vs-restricted-regions"
dpath, "2021-fNIRS-Audio-visual-speech-Broad-vs-restricted-regions"
)
if os.path.isdir(bad_name):
os.rename(bad_name, dpath + ".true")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def data_path(
dpath = str(dpath)

# Do some wrangling to deal with nested directories
bad_name = os.path.join(dpath, "2021-fNIRS-Analysis-Methods-" "Passive-Auditory")
bad_name = os.path.join(dpath, "2021-fNIRS-Analysis-Methods-Passive-Auditory")
if os.path.isdir(bad_name):
os.rename(bad_name, dpath + ".true")
shutil.rmtree(dpath)
Expand Down
18 changes: 9 additions & 9 deletions mne_nirs/io/snirf/_snirf.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,17 @@ def write_raw_snirf(raw, fname, add_montage=False):
"""
supported_types = ["fnirs_cw_amplitude", "fnirs_od", "hbo", "hbr"]
picks = _picks_to_idx(raw.info, supported_types, exclude=[])
assert len(picks) == len(
raw.ch_names
), "Data must only be of type fnirs_cw_amplitude, fnirs_od, hbo or hbr"
assert len(picks) == len(raw.ch_names), (
"Data must only be of type fnirs_cw_amplitude, fnirs_od, hbo or hbr"
)
if ("fnirs_cw_amplitude" in raw) or ("fnirs_od" in raw):
assert (
len(np.unique(raw.info.get_channel_types())) == 1
), "All channels must be of the same type"
assert len(np.unique(raw.info.get_channel_types())) == 1, (
"All channels must be of the same type"
)
elif ("hbo" in raw) or ("hbr" in raw):
assert (
len(np.unique(raw.info.get_channel_types())) <= 2
), "Channels must be of type hbo and hbr"
assert len(np.unique(raw.info.get_channel_types())) <= 2, (
"Channels must be of type hbo and hbr"
)

with h5py.File(fname, "w") as f:
nirs = f.create_group("/nirs")
Expand Down
2 changes: 1 addition & 1 deletion mne_nirs/preprocessing/_mayer.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def quantify_mayer_fooof(
# or raw data, I just haven't tried this. Let me know if this works
# for you and we can ease this restriction.
raise RuntimeError(
"Mayer wave estimation should be run on " "haemoglobin concentration data."
"Mayer wave estimation should be run on haemoglobin concentration data."
)

df = pd.DataFrame()
Expand Down
2 changes: 1 addition & 1 deletion mne_nirs/signal_enhancement/_negative_correlation.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def enhance_negative_correlation(raw):

if (not len(hbo_channels)) & (not len(hbr_channels)):
raise RuntimeError(
"enhance_negative_correlation should " "be run on haemoglobin data."
"enhance_negative_correlation should be run on haemoglobin data."
)

if len(hbo_channels) != len(hbr_channels):
Expand Down
4 changes: 2 additions & 2 deletions mne_nirs/simulation/_simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,10 @@ def simulate_nirs_raw(
frame_times = np.arange(sig_dur * sfreq) / sfreq

assert len(amplitude) == len(annot_desc), (
"Same number of amplitudes as " "annotations required."
"Same number of amplitudes as annotations required."
)
assert len(amplitude) == len(stim_dur), (
"Same number of amplitudes as " "durations required."
"Same number of amplitudes as durations required."
)

onset = 0.0
Expand Down
18 changes: 8 additions & 10 deletions mne_nirs/statistics/_glm_level_first.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ def save(self, fname, overwrite=False):
fname = str(fname)
if not fname.endswith("glm.h5"):
raise OSError(
"The filename must end with glm.h5, " f"instead received {fname}"
f"The filename must end with glm.h5, instead received {fname}"
)
write_hdf5(fname, self._get_state(), overwrite=overwrite, title="mnepython")

Expand Down Expand Up @@ -240,7 +240,7 @@ def data(self, data):
raise TypeError("Data names and channel names do not match")
for d in data:
if type(data[d]) is not nilearn.glm.regression.RegressionResults:
raise TypeError("Dictionary items must be" " nilearn RegressionResults")
raise TypeError("Dictionary items must be nilearn RegressionResults")

self._data = data

Expand Down Expand Up @@ -430,11 +430,11 @@ def to_dataframe_region_of_interest(

if isinstance(weighted, dict):
if weighted.keys() != group_by.keys():
raise KeyError("Keys of group_by and weighted " "must be the same")
raise KeyError("Keys of group_by and weighted must be the same")
for key in weighted.keys():
if len(weighted[key]) != len(group_by[key]):
raise ValueError(
"The length of the keys for group_by " "and weighted must match"
"The length of the keys for group_by and weighted must match"
)
if (np.array(weighted[key]) < 0).any():
raise ValueError("Weights must be positive values")
Expand Down Expand Up @@ -567,8 +567,8 @@ def surface_projection(
df_use = df.query("Condition in @condition")
if len(df_use) == 0:
raise KeyError(
f'condition={repr(condition)} not found in conditions: '
f'{sorted(set(df["Condition"]))}'
f"condition={repr(condition)} not found in conditions: "
f"{sorted(set(df['Condition']))}"
)
df = df_use
df = df.query("Chroma in @chroma").copy()
Expand Down Expand Up @@ -639,7 +639,7 @@ def data(self, data):
raise TypeError("Data must be a nilearn glm contrast type")
if data.effect.size != len(self.info.ch_names):
raise TypeError(
"Data results must be the same length " "as the number of channels"
"Data results must be the same length as the number of channels"
)

self._data = data
Expand Down Expand Up @@ -853,9 +853,7 @@ def _state_to_glm(glm):
glm["data"][channel]["model"]["design"],
)
else:
raise OSError(
"Unknown model type " f"{glm['data'][channel]['modelname']}"
)
raise OSError(f"Unknown model type {glm['data'][channel]['modelname']}")

for key in glm["data"][channel]["model"]:
model.__setattr__(key, glm["data"][channel]["model"][key])
Expand Down
2 changes: 1 addition & 1 deletion mne_nirs/tests/test_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
def examples_path():
if not os.path.isdir("BIDS-NIRS-Tapping"):
os.system(
"git clone --depth 1 " "https://github.com/rob-luke/BIDS-NIRS-Tapping.git"
"git clone --depth 1 https://github.com/rob-luke/BIDS-NIRS-Tapping.git"
)

if os.path.isdir("examples"):
Expand Down
7 changes: 2 additions & 5 deletions mne_nirs/visualisation/_plot_3d_montage.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,14 +138,11 @@ def plot_3d_montage(
if bad:
src_det_names = None
logger.info(
"Could not automatically map source/detector names to "
"10-20 locations."
"Could not automatically map source/detector names to 10-20 locations."
)
else:
src_det_names = locs
logger.info(
"Source-detector names automatically mapped to 10-20 " "locations"
)
logger.info("Source-detector names automatically mapped to 10-20 locations")

head_mri_t = _get_trans(trans, "head", "mri")[0]
del trans
Expand Down
6 changes: 3 additions & 3 deletions mne_nirs/visualisation/_plot_GLM_surface_projection.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,9 @@ def plot_glm_surface_projection(
info = deepcopy(inst if isinstance(inst, Info) else inst.info)
if not (info.ch_names == list(statsmodel_df["ch_name"].values)):
raise RuntimeError(
'MNE data structure does not match dataframe '
f'results.\nMNE = {info.ch_names}.\n'
f'GLM = {list(statsmodel_df["ch_name"].values)}'
"MNE data structure does not match dataframe "
f"results.\nMNE = {info.ch_names}.\n"
f"GLM = {list(statsmodel_df['ch_name'].values)}"
)

ea = EvokedArray(np.tile(statsmodel_df[value].values.T, (1, 1)).T, info.copy())
Expand Down
6 changes: 3 additions & 3 deletions mne_nirs/visualisation/_plot_GLM_topo.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,9 +275,9 @@ def plot_glm_group_topo(
assert len(np.unique(statsmodel_df["Chroma"])) == 1, "Only one Chroma allowed"

if "Condition" in statsmodel_df.columns:
assert (
len(np.unique(statsmodel_df["Condition"])) == 1
), "Only one condition allowed"
assert len(np.unique(statsmodel_df["Condition"])) == 1, (
"Only one condition allowed"
)
c = np.unique(statsmodel_df["Condition"])[0]
else:
c = "Contrast"
Expand Down

0 comments on commit cf595cb

Please sign in to comment.