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

Repair 3dQwarp workflow #454

Draft
wants to merge 15 commits into
base: master
Choose a base branch
from
2 changes: 1 addition & 1 deletion .github/workflows/unittests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ jobs:
pip install datalad datalad-osf
- name: Install fsl
run: |
conda install fsl-fugue fsl-topup
conda install fsl-fugue fsl-topup fsl-bet2
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you using BET anywhere?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

- uses: actions/checkout@v4
- name: Install dependencies
timeout-minutes: 5
Expand Down
3 changes: 2 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ RUN mkdir -p /opt/afni-latest \
-name "3dTshift" -or \
-name "3dUnifize" -or \
-name "3dAutomask" -or \
-name "3dvolreg" \) -delete
-name "3dvolreg" -or \
-name "3dQwarp" \) -delete

# Convert3d 1.4.0
FROM downloader as c3d
Expand Down
1 change: 1 addition & 0 deletions env.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@ dependencies:
# Workflow dependencies: FSL (versions pinned in 6.0.6.2)
- fsl-fugue=2201.2
- fsl-topup=2203.1
- fsl-bet2=2111.8
14 changes: 11 additions & 3 deletions sdcflows/utils/epimanip.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,10 +188,14 @@ def get_trt(in_meta, in_file=None):
raise ValueError(f"'{trt}'")

return trt
elif in_file is None:
msg = "Unable to find TotalReadoutTime in metadata and in_file \
not defined."
raise AssertionError(msg)
psadil marked this conversation as resolved.
Show resolved Hide resolved

# npe = N voxels PE direction
pe_index = "ijk".index(in_meta["PhaseEncodingDirection"][0])
npe = nb.load(in_file).shape[pe_index]
npe = nb.loadsave.load(in_file).shape[pe_index]

# Use case 2: EES is defined
ees = in_meta.get("EffectiveEchoSpacing")
Expand Down Expand Up @@ -252,7 +256,9 @@ def epi_mask(in_file, out_file=None):
maxnorm = np.percentile(closed[closed > 0], 90)
closed = np.clip(closed, a_min=0.0, a_max=maxnorm)
# Calculate index of center of masses
cm = tuple(np.round(ndimage.measurements.center_of_mass(closed)).astype(int))
cm = tuple(
np.round(ndimage.measurements.center_of_mass(closed)).astype(int)
)
# Erode the picture of the brain by a lot
eroded = ndimage.grey_erosion(closed, structure=ball(5))
# Calculate the residual
Expand All @@ -268,6 +274,8 @@ def epi_mask(in_file, out_file=None):
hdr = img.header.copy()
hdr.set_data_dtype("uint8")
nb.Nifti1Image(
ndimage.binary_dilation(labels == 2, ball(2)).astype("uint8"), img.affine, hdr
ndimage.binary_dilation(labels == 2, ball(2)).astype("uint8"),
img.affine,
hdr,
).to_filename(out_file)
return out_file
33 changes: 33 additions & 0 deletions sdcflows/utils/tests/test_epimanip.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: nil -*-
# vi: set ft=python sts=4 ts=4 sw=4 et:
#
# Copyright 2021 The NiPreps Developers <[email protected]>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# We support and encourage derived works from this project, please read
# about our expectations at
#
# https://www.nipreps.org/community/licensing/
#
"""Test EPI manipulation routines."""
import pytest
from sdcflows.utils.epimanip import get_trt


def test_get_trt_err_wo_trt_and_in_file():
"""Test that calling get_trt with dict that does not have TotalReadoutTime \
and no in_file raises AssertionError.
"""
with pytest.raises(AssertionError):
psadil marked this conversation as resolved.
Show resolved Hide resolved
get_trt(in_meta={})
Loading
Loading