Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ repos:
- id: check-merge-conflict

- repo: https://github.com/pycqa/isort
rev: 5.13.2
rev: 6.0.1
hooks:
- id: isort

Expand All @@ -32,13 +32,13 @@ repos:
- id: rst-inline-touching-normal

- repo: https://github.com/codespell-project/codespell
rev: v2.3.0
rev: v2.4.1
hooks:
- id: codespell


- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.8.6
rev: v0.11.4
hooks:
- id: ruff
name: ruff linter
Expand Down
6 changes: 2 additions & 4 deletions nigsp/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,7 @@ def check_mtx_dim(fname, data, shape=None):
raise ValueError(f"{fname} is empty!")
if data.ndim > 3:
raise NotImplementedError(
"Only matrices up to 3D are supported, but "
f"given matrix is {data.ndim}D."
f"Only matrices up to 3D are supported, but given matrix is {data.ndim}D."
)
if shape is not None:
if data.ndim > 2:
Expand All @@ -176,8 +175,7 @@ def check_mtx_dim(fname, data, shape=None):
)
if shape == "square" and data.shape[0] != data.shape[1]:
raise ValueError(
f"Square matrix required, but {fname} matrix has "
f"shape {data.shape}."
f"Square matrix required, but {fname} matrix has shape {data.shape}."
)

return data
Expand Down
15 changes: 8 additions & 7 deletions nigsp/operations/nifti.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,9 @@ def apply_mask(data, mask):
f"with shape {mask.shape}"
)
if (data.ndim - mask.ndim) > 1:
LGR.warning(f"Returning volume with {data.ndim-mask.ndim+1} dimensions.")
LGR.warning(f"Returning volume with {data.ndim - mask.ndim + 1} dimensions.")
else:
LGR.info(f"Returning {data.ndim-mask.ndim+1}D array.")
LGR.info(f"Returning {data.ndim - mask.ndim + 1}D array.")

mask = mask != 0
return data[mask]
Expand Down Expand Up @@ -149,8 +149,7 @@ def unmask(data, mask, shape=None, asdata=None):

if shape[: mask.ndim] != mask.shape:
raise ValueError(
f"Cannot unmask data into shape {shape} using mask "
f"with shape {mask.shape}"
f"Cannot unmask data into shape {shape} using mask with shape {mask.shape}"
)
if data.ndim > 1 and (data.shape[0] != mask.sum()):
raise ValueError(
Expand Down Expand Up @@ -216,10 +215,10 @@ def apply_atlas(data, atlas, mask=None):
f"with shape {data.shape}"
)
if (data.ndim - atlas.ndim) > 1:
LGR.warning(f"returning volume with {data.ndim-atlas.ndim+1} dimensions.")
LGR.warning(f"returning volume with {data.ndim - atlas.ndim + 1} dimensions.")
else:
LGR.info(
f"Returning {data.ndim-atlas.ndim+1}D array of signal averages "
f"Returning {data.ndim - atlas.ndim + 1}D array of signal averages "
f"in atlas {atlas}."
)

Expand Down Expand Up @@ -297,7 +296,9 @@ def unfold_atlas(data, atlas, mask=None):
f"with {len(labels)} parcels"
)

LGR.info(f"Unmasking data into atlas-like volume of {3+data.ndim-1} dimensions.")
LGR.info(
f"Unmasking data into atlas-like volume of {3 + data.ndim - 1} dimensions."
)
out = np.zeros_like(atlas, dtype="float32")

for ax in range(1, data.ndim):
Expand Down
16 changes: 8 additions & 8 deletions nigsp/operations/surrogates.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ def test_significance(
raise ValueError(
"Provided empirical data and surrogate data shapes "
f"do not agree, with shapes {data.shape} and "
f"{surr.shape[:data.ndim]} (last axis excluded)"
f"{surr.shape[: data.ndim]} (last axis excluded)"
)
if not (surr[..., -1] == data).all():
# Check that data was not appended yet.
Expand Down Expand Up @@ -332,16 +332,16 @@ def test_significance(
LGR.info(f"Adopting {method} testing method.")
# Testing both tails requires to split p
if method == "frequentist":
LGR.info(f"Testing for p={p} two-tails (p={p/2} each tail)")
LGR.info(f"Testing for p={p} two-tails (p={p / 2} each tail)")
p = p / 2
# If there aren't enough surrogates, send a warning message on the real p
# Then update p
if 1 / surr.shape[-1] > p:
LGR.warning(
"The generated surrogates are not enough to test for "
f"the selected p ({p*2} two-tails), since at least "
f"{ceil(1/p)-1} surrogates are required for the selected "
f"p value. Testing for p={1/surr.shape[-1]} two-tails instead."
f"the selected p ({p * 2} two-tails), since at least "
f"{ceil(1 / p) - 1} surrogates are required for the selected "
f"p value. Testing for p={1 / surr.shape[-1]} two-tails instead."
)
p = 1 / surr.shape[-1]

Expand All @@ -355,7 +355,7 @@ def test_significance(
LGR.warning(
"The provided subjects are not enough to test for "
f"p={p_bernoulli} one-tail at the group level, since "
f"at least {ceil(1/p_bernoulli)} subjects are required."
f"at least {ceil(1 / p_bernoulli)} subjects are required."
)
p_bernoulli = 1 / surr.shape[1]
# If there aren't enough surrogates, send a warning message on the real p
Expand All @@ -364,13 +364,13 @@ def test_significance(
LGR.warning(
"The generated surrogates are not enough to test for "
f"p={p} two-tails at the subject level. "
f"{ceil(1/p)-1} surrogates are required for p={p}."
f"{ceil(1 / p) - 1} surrogates are required for p={p}."
)
p = 1 / surr.shape[-1]

LGR.info(
f"Testing for p={p_bernoulli} one-tail at the group level and "
f"at p={p*2} two-tails (p={p} each tail) at the subject level."
f"at p={p * 2} two-tails (p={p} each tail) at the subject level."
)
else:
raise NotImplementedError(
Expand Down
6 changes: 3 additions & 3 deletions nigsp/operations/timeseries.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ def median_cutoff_frequency_idx(energy):
if energy.ndim == 2:
energy = energy.mean(axis=-1)
half_tot_auc = _trapezoid_compat(energy, axis=0) / 2
LGR.debug(f"Total AUC = {half_tot_auc*2}, targeting half of total AUC")
LGR.debug(f"Total AUC = {half_tot_auc * 2}, targeting half of total AUC")

# Compute the AUC from first to one to last frequency,
# skipping first component because AUC(1)=0.
Expand Down Expand Up @@ -395,7 +395,7 @@ def graph_filter(timeseries, eigenvec, freq_idx, keys=["low", "high"]): # noqa:
f"eigenvector matrix of shape {eigenvec.shape}."
)

LGR.info(f"Splitting graph into {len(freq_idx)+1} parts")
LGR.info(f"Splitting graph into {len(freq_idx) + 1} parts")

# Check that there is the right amount of keys
if len(keys) > len(freq_idx) + 1:
Expand All @@ -413,7 +413,7 @@ def graph_filter(timeseries, eigenvec, freq_idx, keys=["low", "high"]): # noqa:
)

for i in range(len(keys), len(freq_idx) + 1):
keys = keys + [f"key-{i+1:03d}"]
keys = keys + [f"key-{i + 1:03d}"]

# Add 0 and None to freq_idx to have full indexes
freq_idx = [0] + freq_idx + [None]
Expand Down