Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update workflows #62

Merged
merged 5 commits into from
Sep 6, 2024
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
7 changes: 3 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,19 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu, macos, windows]
python-version: [3.8, 3.9, "3.10", "3.11"]
python-version: ["3.9", "3.10", "3.11", "3.12"]
name: ${{ matrix.os }} - py${{ matrix.python-version }}
runs-on: ${{ matrix.os }}-latest
defaults:
run:
shell: bash
steps:
- name: Checkout repository
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Setup Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
#architecture: 'x64'
- name: Install dependencies
run: |
python -m pip install --progress-bar off --upgrade pip setuptools wheel
Expand Down
15 changes: 4 additions & 11 deletions .github/workflows/code-style.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,18 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Setup Python 3.9
uses: actions/setup-python@v4
uses: actions/checkout@v4
- name: Setup Python 3.10
uses: actions/setup-python@v5
with:
python-version: '3.9'
python-version: '3.10'
architecture: 'x64'
- name: Install dependencies
run: |
python -m pip install --progress-bar off --upgrade pip setuptools wheel
python -m pip install --progress-bar off .[style]
- name: Run Ruff
run: ruff check .
- name: Run isort
uses: isort/isort-action@master
- name: Run black
uses: psf/black@stable
with:
options: "--check --verbose"
version: "23.10.1"
- name: Run codespell
uses: codespell-project/actions-codespell@master
with:
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/doc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ jobs:
uses: actions/checkout@v4
with:
path: ./main
- name: Setup Python 3.9
uses: actions/setup-python@v4
- name: Setup Python 3.10
uses: actions/setup-python@v5
with:
python-version: 3.9
python-version: '3.10'
architecture: 'x64'
- name: Install package
run: |
Expand Down Expand Up @@ -56,7 +56,7 @@ jobs:
name: doc-dev
path: ./doc-dev
- name: Deploy dev documentation
uses: peaceiris/actions-gh-pages@v3
uses: peaceiris/actions-gh-pages@v4
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./doc-dev
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Setup Python 3.9
uses: actions/setup-python@v4
uses: actions/checkout@v4
- name: Setup Python 3.10
uses: actions/setup-python@v5
with:
python-version: '3.9'
python-version: '3.10'
architecture: 'x64'
- name: Install dependencies
run: |
Expand Down
2 changes: 1 addition & 1 deletion fsqc/checkCCSize.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def checkCCSize(subjects_dir, subject):
relative_cc = sum_cc / intracranial_volume

logging.info(
"Relative size of the corpus callosum is " + "{:.4}".format(relative_cc)
"Relative size of the corpus callosum is " + f"{relative_cc:.4}"
)

# Return
Expand Down
16 changes: 10 additions & 6 deletions fsqc/checkContrast.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,20 +49,23 @@ def checkContrast(subjects_dir, subject):
# Check if files exist
path_pct_lh = os.path.join(subjects_dir, subject, "surf", "lh.w-g.pct.mgh")
if not os.path.exists(path_pct_lh):
warnings.warn("WARNING: could not find " + path_pct_lh + ", returning NaNs")
warnings.warn("WARNING: could not find " + path_pct_lh + ", returning NaNs",
stacklevel = 2)
return numpy.nan

path_pct_rh = os.path.join(subjects_dir, subject, "surf", "rh.w-g.pct.mgh")
if not os.path.exists(path_pct_rh):
warnings.warn("WARNING: could not find " + path_pct_rh + ", returning NaNs")
warnings.warn("WARNING: could not find " + path_pct_rh + ", returning NaNs",
stacklevel = 2)
return numpy.nan

path_label_cortex_lh = os.path.join(
subjects_dir, subject, "label", "lh.cortex.label"
)
if not os.path.exists(path_label_cortex_lh):
warnings.warn(
"WARNING: could not find " + path_label_cortex_lh + ", returning NaNs"
"WARNING: could not find " + path_label_cortex_lh + ", returning NaNs",
stacklevel = 2
)
return numpy.nan

Expand All @@ -71,7 +74,8 @@ def checkContrast(subjects_dir, subject):
)
if not os.path.exists(path_label_cortex_rh):
warnings.warn(
"WARNING: could not find " + path_label_cortex_rh + ", returning NaNs"
"WARNING: could not find " + path_label_cortex_rh + ", returning NaNs",
stacklevel = 2
)
return numpy.nan

Expand All @@ -91,14 +95,14 @@ def checkContrast(subjects_dir, subject):
con_lh_std = numpy.std(con_lh)
con_lh_snr = con_lh_mean / con_lh_std
logging.info(
"WM/GM contrast SNR for the left hemisphere: " + "{:.4}".format(con_lh_snr)
"WM/GM contrast SNR for the left hemisphere: " + f"{con_lh_snr:.4}"
)

con_rh_mean = numpy.mean(con_rh)
con_rh_std = numpy.std(con_rh)
con_rh_snr = con_rh_mean / con_rh_std
logging.info(
"WM/GM contrast SNR for the right hemisphere: " + "{:.4}".format(con_rh_snr)
"WM/GM contrast SNR for the right hemisphere: " + f"{con_rh_snr:.4}"
)

# Return
Expand Down
14 changes: 8 additions & 6 deletions fsqc/checkRotation.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ def checkRotation(subjects_dir, subject):

if importlib.util.find_spec("transforms3d") is None:
warnings.warn(
"WARNING: 'transforms3d' package required for running this script, returning NaNs."
"WARNING: 'transforms3d' package required for running this script, returning NaNs.",
stacklevel = 2
)
return np.nan, np.nan, np.nan
else:
Expand All @@ -64,12 +65,13 @@ def checkRotation(subjects_dir, subject):
warnings.warn(
"WARNING: could not open "
+ os.path.join(subjects_dir, subject, "mri", "transforms", "talairach.lta")
+ ", returning NaNs."
+ ", returning NaNs.",
stacklevel = 2
)
return np.nan, np.nan, np.nan

with open(
os.path.join(subjects_dir, subject, "mri", "transforms", "talairach.lta"), "r"
os.path.join(subjects_dir, subject, "mri", "transforms", "talairach.lta")
) as datafile:
lines = datafile.readlines()

Expand Down Expand Up @@ -102,11 +104,11 @@ def checkRotation(subjects_dir, subject):

logging.info(
"Found Talairach rotation angles: x = "
+ "{:.3}".format(rot_x)
+ f"{rot_x:.3}"
+ ", y = "
+ "{:.3}".format(rot_y)
+ f"{rot_y:.3}"
+ ", z = "
+ "{:.3}".format(rot_z)
+ f"{rot_z:.3}"
+ " radians.",
)

Expand Down
13 changes: 8 additions & 5 deletions fsqc/checkSNR.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ def checkSNR(
norm_data = norm.get_fdata()
else:
warnings.warn(
"WARNING: could not open " + path_reference_image + ", returning NaNs."
"WARNING: could not open " + path_reference_image + ", returning NaNs.",
stacklevel = 2
)
return np.nan, np.nan

Expand All @@ -86,7 +87,8 @@ def checkSNR(
aseg = nib.load(path_aseg)
data_aseg = aseg.get_fdata()
else:
warnings.warn("WARNING: could not open " + path_aseg + ", returning NaNs.")
warnings.warn("WARNING: could not open " + path_aseg + ", returning NaNs.",
stacklevel = 2)
return np.nan, np.nan

path_aparc_aseg = os.path.join(subjects_dir, subject, "mri", aparc_image)
Expand All @@ -95,7 +97,8 @@ def checkSNR(
data_aparc_aseg = inseg.get_fdata()
else:
warnings.warn(
"WARNING: could not open " + path_aparc_aseg + ", returning NaNs."
"WARNING: could not open " + path_aparc_aseg + ", returning NaNs.",
stacklevel = 2
)
return np.nan, np.nan

Expand All @@ -122,7 +125,7 @@ def checkSNR(
signal_wm_mean = np.mean(signal_wm)
signal_wm_std = np.std(signal_wm)
wm_snr = signal_wm_mean / signal_wm_std
logging.info("White matter signal to noise ratio: " + "{:.4}".format(wm_snr))
logging.info("White matter signal to noise ratio: " + f"{wm_snr:.4}")

# Process gray matter image

Expand All @@ -143,7 +146,7 @@ def checkSNR(
signal_gm_mean = np.mean(signal_gm)
signal_gm_std = np.std(signal_gm)
gm_snr = signal_gm_mean / signal_gm_std
logging.info("Gray matter signal to noise ratio: " + "{:.4}".format(gm_snr))
logging.info("Gray matter signal to noise ratio: " + f"{gm_snr:.4}")

# Return
return wm_snr, gm_snr
5 changes: 3 additions & 2 deletions fsqc/checkTopology.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,11 @@ def checkTopology(subjects_dir, subject):
path_log_file = os.path.join(subjects_dir, subject, "scripts", "recon-all.log")

if os.path.exists(path_log_file):
with open(path_log_file, "r") as logfile:
with open(path_log_file) as logfile:
lines_log_file = logfile.read().splitlines()
else:
warnings.warn("WARNING: could not find " + path_log_file + ", returning NaNs.")
warnings.warn("WARNING: could not find " + path_log_file + ", returning NaNs.",
stacklevel = 2)
return np.nan, np.nan, np.nan, np.nan, np.nan, np.nan

# Initialize
Expand Down
49 changes: 28 additions & 21 deletions fsqc/createScreenshots.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@ def createScreenshots(
OUTFILE,
INTERACTIVE=True,
LAYOUT=None,
BASE=["default"],
OVERLAY=["default"],
BASE="default",
OVERLAY="default",
LABELS=None,
SURF=["default"],
SURFCOLOR=["default"],
VIEWS=["default"],
SURF="default",
SURFCOLOR="default",
VIEWS="default",
XLIM=None,
YLIM=None,
BINARIZE=False,
ORIENTATION=["radiological"],
ORIENTATION=None,
):
"""
Function to create screenshots.
Expand All @@ -39,31 +39,34 @@ def createScreenshots(
LAYOUT : str, optional
The layout, default is None.
BASE : list, optional
The base, default is ["default"].
The base, default is "default".
Load norm.mgz as default.
OVERLAY : list, optional
The overlay, default is ["default"].
The overlay, default is "default".
Load aseg.mgz as default.
LABELS : None or str, optional
The labels, default is None.
SURF : list, optional
The surface, default is ["default"].
The surface, default is "default".
SURFCOLOR : list, optional
The surface color, default is ["default"].
The surface color, default is "default".
VIEWS : list, optional
The views, default is ["default"].
The views, default is "default".
XLIM : None or list, optional
The x limits, default is None.
YLIM : None or list, optional
The y limits, default is None.
BINARIZE : bool, optional
Flag for binarization, default is False.
ORIENTATION : list, optional
The orientation, default is ["radiological"].
The orientation, default is None.
Will use ["radiological"] per default.

Notes
-----
BASE, VIEWS must be lists, can be ["default"].
BASE, VIEWS must be lists, can be "default".

OVERLAY, SURF, SURFCOLOR can be lists or None, can be ["default"].
OVERLAY, SURF, SURFCOLOR can be lists, None, or "default".

XLIM, YLIM can be lists of list two-element numeric lists or None; if given,
length must match length of VIEWS. x and y refer to final image dimensions,
Expand Down Expand Up @@ -92,6 +95,9 @@ def computeLayout(n):
import nibabel as nb
import numpy as np

if ORIENTATION is None:
ORIENTATION = ["radiological"]

if not INTERACTIVE:
matplotlib.use("Agg")

Expand All @@ -115,22 +121,22 @@ def computeLayout(n):
# -----------------------------------------------------------------------------
# import image data

if BASE == ["default"]:
if BASE == "default":
norm = nb.load(os.path.join(SUBJECTS_DIR, SUBJECT, "mri", "norm.mgz"))
else:
norm = nb.load(BASE[0])

if OVERLAY is None:
aseg = None
elif OVERLAY == ["default"]:
elif OVERLAY == "default":
aseg = nb.load(os.path.join(SUBJECTS_DIR, SUBJECT, "mri", "aseg.mgz"))
else:
aseg = nb.load(OVERLAY[0])

# -----------------------------------------------------------------------------
# import surface data

if SURF == ["default"]:
if SURF == "default":
surflist = [
os.path.join(SUBJECTS_DIR, SUBJECT, "surf", "lh.white"),
os.path.join(SUBJECTS_DIR, SUBJECT, "surf", "rh.white"),
Expand All @@ -146,9 +152,9 @@ def computeLayout(n):
for i in range(len(surflist)):
surf.append(nb.freesurfer.io.read_geometry(surflist[i], read_metadata=True))

if SURFCOLOR == ["default"] and SURF == ["default"]:
if SURFCOLOR == "default" and SURF == "default":
surfcolor = ["yellow", "yellow", "red", "red"]
elif SURFCOLOR == ["default"] and SURF != ["default"]:
elif SURFCOLOR == "default" and SURF != "default":
surfcolor = ["yellow"] * len(surf)
else:
surfcolor = SURFCOLOR
Expand Down Expand Up @@ -211,7 +217,7 @@ def computeLayout(n):
# -----------------------------------------------------------------------------
# determine VIEWS

if VIEWS == ["default"]:
if VIEWS == "default":
CutsRRAS = [("x", -10), ("x", 10), ("y", 0), ("z", 0)]
else:
CutsRRAS = VIEWS
Expand Down Expand Up @@ -678,7 +684,8 @@ def computeLayout(n):
sortIdx = np.delete(sortIdx, findIdx[0, 0])
elif findIdx.shape[0] > 1:
warnings.warn(
"WARNING: a problem occurred with the surface overlays"
"WARNING: a problem occurred with the surface overlays",
stacklevel = 2
)
# now final plot
axs[axsx, axsy].plot(
Expand Down
Loading