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
21 changes: 0 additions & 21 deletions .flake8

This file was deleted.

23 changes: 8 additions & 15 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -79,19 +79,12 @@ repos:
- id: prettier
types_or: [css]

- repo: https://github.com/psf/black-pre-commit-mirror
rev: 26.1.0
# Lint and format Python code
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.15.1
hooks:
- id: black

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

- repo: https://github.com/PyCQA/flake8
rev: 7.3.0
hooks:
- id: flake8
args: [--config, .flake8, --verbose, tools]
additional_dependencies: [flake8-bugbear]
- id: ruff-check
# args: [--statistics]
args: [--fix, --show-fixes, --unsafe-fixes]
- id: ruff-format
# args: [--diff]
10 changes: 5 additions & 5 deletions macros/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@

__all__ = [
"define_env",
"generate_converter_table",
"generate_tools_table",
"generate_members_table",
"generate_apps_table",
"generate_beps_table",
"generate_converter_table",
"generate_filename_templates",
"generate_grants_table",
"generate_apps_table",
"generate_members_table",
"generate_tools_table",
"generate_working_groups_table",
"generate_filename_templates",
]
1 change: 0 additions & 1 deletion macros/macros.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ def generate_apps_table():

def generate_filename_templates():
"""Create filename templates for all datatypes of all modalities."""

schema_obj = schema.load_schema()

modalities = schema_obj.rules.modalities
Expand Down
8 changes: 4 additions & 4 deletions macros/main.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
"""This package is used to build elements from data into
"""Package used to build elements from data into
MarkDown format for the specification text.

Functions decorated in "define_env()" are callable throughout the
specification and are run/rendered with the mkdocs plugin "macros".
"""

import os
import sys
from pathlib import Path

code_path = os.path.abspath(os.path.join(os.path.dirname(__file__)))
code_path = str(Path(__file__).parent.resolve())
sys.path.append(code_path)

import macros # noqa E402
import macros # noqa: E402


def define_env(env):
Expand Down
101 changes: 92 additions & 9 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,6 @@ builtin = "clear,rare,en-GB_to_en-US"
ignore-words-list = "Acknowledgements,als,ans,asai,nd,manuel,te,acknowledgements,Varian,mis"
skip = ".git,env,specification,starter_kit,examples,apps,execution,pyproject.toml,data/**.tsv,data/**.json,docs/collaboration/contributors.md,package-lock.json"

[tool.black]
line-length = 79

[tool.isort]
combine_as_imports = true
line_length = 79
profile = "black"
skip_gitignore = true

[tool.djlint]
profile = "django"
blank_line_after_tag = "load,extends,include,endblock,set"
Expand All @@ -58,3 +49,95 @@ use_gitignore = true

[tool.djlint.css]
indent_size = 4

[tool.ruff]
extend-exclude = ["data/datasets/examples", "nilearn/_version.py"]
include = [
"pyproject.toml",
"macros/**/*.py",
"tools/**/*.py",
]
indent-width = 4
line-length = 79

[tool.ruff.format]
docstring-code-format = true
docstring-code-line-length = "dynamic"
indent-style = "space"
line-ending = "auto"
quote-style = "double"
skip-magic-trailing-comma = false

[tool.ruff.lint]
dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$"
fixable = ["ALL"]
ignore = [
"D100",
"D103",
"D104",
"D205",
"E741",
"ERA001",
"N806",
"PERF401",
"PLR2004",
# Avoid linter rules conflicting with the formatter
# https://docs.astral.sh/ruff/formatter/#conflicting-lint-rules
"COM812",
"COM819",
"E111",
"E114",
"E117",
"Q000",
"Q001",
"Q002",
"Q003",
"W191",
]
# List of all the ruff rules (includes why the rule matters)
# https://docs.astral.sh/ruff/rules/
select = [
"ARG",
"B",
"C4",
"C90",
"D",
"E",
"ERA",
"F",
"FLY",
"FURB",
"I",
"N",
"NPY",
"PERF",
"PIE",
"PTH",
"PD",
"PGH",
"PLR",
"RUF",
"SIM",
"UP",
"W",
]
unfixable = []

[tool.ruff.lint.mccabe]
max-complexity = 15

[tool.ruff.lint.per-file-ignores]
"**/{doc}/*" = ["B018", "D103"]

[tool.ruff.lint.pydocstyle]
convention = "numpy"

[tool.ruff.lint.pylint]
# https://docs.astral.sh/ruff/settings/#lint_pylint_max-args
max-args = 15
# https://docs.astral.sh/ruff/settings/#lint_pylint_max-branches
max-branches = 15
# https://docs.astral.sh/ruff/settings/#lint_pylint_max-returns
max-returns = 5
# https://docs.astral.sh/ruff/settings/#lint_pylint_max-statements
max-statements = 100
17 changes: 7 additions & 10 deletions tools/MRIQC_WepAPI_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,9 @@
# MRIQC web API doc: https://mriqc.nimh.nih.gov/docs/api

import datetime

# %%
import json
from json import JSONDecodeError
from pathlib import Path

import matplotlib.pyplot as plt
import numpy as np
Expand Down Expand Up @@ -87,21 +86,22 @@ def fix_scannername(model):
return modelname


def get_data(datafile, drop_duplicates=True):
def get_data(datafile):

datatype = "bold" if "bold" in datafile else "T1w"
results = []
problems = 0

with open(datafile) as f:
for line in f.readlines():
with Path(datafile).open() as f:
for line in f:
try:
results.append(json.loads(line.strip()))
except JSONDecodeError:
problems += 1

print(
f"found {len(results)} results in json, problems decoding {problems} records"
f"found {len(results)} results in json, "
f"problems decoding {problems} records"
)
return results, datatype

Expand Down Expand Up @@ -134,13 +134,11 @@ def clean_data(results, datatype, drop_duplicates=True):
)

results_df = results_df.sort_values(by="month")
# clean up
# results_df = results_df.query('MagneticFieldStrength < 15')

results_df = results_df.assign(
Scanner=[fix_scannername(i) for i in results_df.ManufacturersModelName]
)
fs = np.array(results_df["MagneticFieldStrength"].values.tolist())
fs = np.array(results_df["MagneticFieldStrength"].to_numpy().tolist())

results_df["MagneticFieldStrength"] = np.where(
fs > 100, fs / 10000, fs
Expand Down Expand Up @@ -173,7 +171,6 @@ def clean_data(results, datatype, drop_duplicates=True):
# %%
all_results_df = pd.concat((bold_results_df, t1w_results_df))
all_results_df = all_results_df.sort_values(by="month").reset_index()
all_results_df.shape
all_results_df.to_csv("mriqc_results_summary.csv")

# %%
Expand Down
58 changes: 31 additions & 27 deletions tools/bep_gantt_mermaid_insert.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Creates a Gantt chart for the completed BEPs"""
"""Creates a Gantt chart for the completed BEPs."""

from __future__ import annotations

Expand All @@ -22,7 +22,7 @@ def target_file() -> Path:
def get_bep_timeline() -> pd.DataFrame:
completd_beps = data_dir() / "beps" / "beps_completed.yml"

with open(completd_beps, "r") as f:
with Path(completd_beps).open() as f:
yaml = YAML(typ="safe", pure=True)
data = yaml.load(f)

Expand All @@ -38,30 +38,30 @@ def get_bep_timeline() -> pd.DataFrame:

if StartDoc and StartPR:
df.append(
dict(
BEP=BEP,
Start=StartDoc,
Finish=StartPR,
Resource="Google Doc",
)
{
"BEP": BEP,
"Start": StartDoc,
"Finish": StartPR,
"Resource": "Google Doc",
}
)
if StartPR and Finish:
df.append(
dict(
BEP=BEP,
Start=StartPR,
Finish=Finish,
Resource="Pull Request",
)
{
"BEP": BEP,
"Start": StartPR,
"Finish": Finish,
"Resource": "Pull Request",
}
)
if not StartPR:
df.append(
dict(
BEP=BEP,
Start=StartDoc,
Finish=Finish,
Resource="Google Doc",
)
{
"BEP": BEP,
"Start": StartDoc,
"Finish": Finish,
"Resource": "Google Doc",
}
)

df = pd.DataFrame(df)
Expand All @@ -81,18 +81,22 @@ def main():
"""

for bep in df.BEP.unique():
bep_df = df[df.BEP == bep]
google_start = bep_df[bep_df.Resource == "Google Doc"].Start.values[0]
google_end = bep_df[bep_df.Resource == "Google Doc"].Finish.values[0]
bep_df = df[bep == df.BEP]
google_start = bep_df[
bep_df.Resource == "Google Doc"
].Start.to_numpy()[0]
google_end = bep_df[bep_df.Resource == "Google Doc"].Finish.to_numpy()[
0
]

text += f""" section BEP{bep[:3]}
Google doc :{google_start}, {google_end}
"""

pr_df = bep_df[bep_df.Resource == "Pull Request"]
if len(pr_df) > 0:
pr_start = pr_df.Start.values[0]
pr_end = pr_df.Finish.values[0]
pr_start = pr_df.Start.to_numpy()[0]
pr_end = pr_df.Finish.to_numpy()[0]

text += f""" Pull request :{pr_start}, {pr_end}
"""
Expand All @@ -102,11 +106,11 @@ def main():
print(text)

# insert into target file
with open(target_file(), "r") as f:
with Path(target_file()).open() as f:
lines = f.readlines()

inser_mermaid_here = False
with open(target_file(), "w") as f:
with Path(target_file()).open("w") as f:
for line in lines:
if line.startswith("<!-- MERMAID GANTT CHART STARTS -->"):
inser_mermaid_here = True
Expand Down
Loading
Loading