Skip to content

Commit

Permalink
Merge pull request #434 from mgxd/sty/fix [skip ci]
Browse files Browse the repository at this point in the history
FIX: Tests
  • Loading branch information
mgxd authored Jan 22, 2025
2 parents bfa91a1 + 398c882 commit d2436b7
Show file tree
Hide file tree
Showing 19 changed files with 81 additions and 68 deletions.
2 changes: 2 additions & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
# isort addition
6f809fa9950654cbb7f755922c45dffbc88dc45d
# Ruff 0.9.2
03e848c6f7c102cc9e0907a38c311afe5c357e77
18 changes: 10 additions & 8 deletions .readthedocs.yml
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
version: 2

sphinx:
configuration: docs/conf.py
build:
os: ubuntu-22.04
tools:
python: "3.11"
jobs:
post_checkout:
- git fetch --unshallow
- git fetch --unshallow

python:
install:
- requirements: docs/requirements.txt
- method: pip
path: .
extra_requirements:
- doc
- method: pip
path: wrapper/
- requirements: docs/requirements.txt
- method: pip
path: .
extra_requirements:
- doc
- method: pip
path: wrapper/
19 changes: 0 additions & 19 deletions nibabies/__about__.py

This file was deleted.

29 changes: 28 additions & 1 deletion nibabies/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,28 @@
from .__about__ import __version__ # noqa: F401
# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: nil -*-
# vi: set ft=python sts=4 ts=4 sw=4 et:
#
# Copyright 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/
#
"""Top-module metadata."""

try:
from ._version import __version__
except ImportError:
__version__ = '0+unknown'
File renamed without changes.
24 changes: 11 additions & 13 deletions nibabies/cli/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ class DeprecatedAction(Action):
def __call__(self, parser, namespace, values, option_string=None):
new_opt, rem_vers = deprecations.get(self.dest, (None, None))
msg = (
f"{self.option_strings} has been deprecated and will be removed in "
f"{rem_vers or 'a later version'}."
f'{self.option_strings} has been deprecated and will be removed in '
f'{rem_vers or "a later version"}.'
)
if new_opt:
msg += f' Please use `{new_opt}` instead.'
Expand Down Expand Up @@ -140,7 +140,7 @@ def _slice_time_ref(value, parser):
value = float(value)
except ValueError as e:
raise parser.error(
"Slice time reference must be number, 'start', or 'middle'. " f'Received {value}.'
f"Slice time reference must be number, 'start', or 'middle'. Received {value}."
) from e
if not 0 <= value <= 1:
raise parser.error(f'Slice time reference must be in range 0-1. Received {value}.')
Expand Down Expand Up @@ -182,7 +182,7 @@ def _str_none(val):
'output_dir',
action='store',
type=Path,
help='the output path for the outcomes of preprocessing and visual ' 'reports',
help='the output path for the outcomes of preprocessing and visual reports',
)
parser.add_argument(
'analysis_level',
Expand Down Expand Up @@ -297,7 +297,7 @@ def _str_none(val):
g_perfm.add_argument(
'--low-mem',
action='store_true',
help='attempt to reduce memory usage (will increase disk usage ' 'in working directory)',
help='attempt to reduce memory usage (will increase disk usage in working directory)',
)
g_perfm.add_argument(
'--use-plugin',
Expand Down Expand Up @@ -497,8 +497,7 @@ def _str_none(val):
action='store',
default=0.5,
type=float,
help='Threshold for flagging a frame as an outlier on the basis of framewise '
'displacement',
help='Threshold for flagging a frame as an outlier on the basis of framewise displacement',
)
g_confounds.add_argument(
'--dvars-spike-threshold',
Expand All @@ -507,7 +506,7 @@ def _str_none(val):
action='store',
default=1.5,
type=float,
help='Threshold for flagging a frame as an outlier on the basis of standardised ' 'DVARS',
help='Threshold for flagging a frame as an outlier on the basis of standardised DVARS',
)

# ANTs options
Expand Down Expand Up @@ -657,7 +656,7 @@ def _str_none(val):
'--stop-on-first-crash',
action='store_true',
default=False,
help='Force stopping on first crash, even if a work directory' ' was specified.',
help='Force stopping on first crash, even if a work directory was specified.',
)
g_other.add_argument(
'--notrack',
Expand Down Expand Up @@ -875,8 +874,7 @@ def parse_args(args=None, namespace=None):
from ..utils.bids import validate_input_dir

build_log.info(
'Making sure the input data is BIDS compliant (warnings can be ignored in most '
'cases).'
'Making sure the input data is BIDS compliant (warnings can be ignored in most cases).'
)
validate_input_dir(config.environment.exec_env, opts.bids_dir, opts.participant_label)

Expand All @@ -896,8 +894,8 @@ def parse_args(args=None, namespace=None):
missing_subjects = participant_label - set(all_subjects)
if missing_subjects:
parser.error(
"One or more participant labels were not found in the BIDS directory: "
f"{', '.join(missing_subjects)}."
'One or more participant labels were not found in the BIDS directory: '
f'{", ".join(missing_subjects)}.'
)

config.execution.participant_label = sorted(participant_label)
Expand Down
4 changes: 2 additions & 2 deletions nibabies/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ class execution(_Config):
"""Force usage of this anatomical scan as the structural reference."""
reports_only = False
"""Only build the reports, based on the reportlets found in a cached working directory."""
run_uuid = f"{strftime('%Y%m%d-%H%M%S')}_{uuid4()}"
run_uuid = f'{strftime("%Y%m%d-%H%M%S")}_{uuid4()}'
"""Unique identifier of this particular run."""
segmentation_atlases_dir = None
"""Directory with atlases to use for JLF segmentations"""
Expand Down Expand Up @@ -622,7 +622,7 @@ class workflow(_Config):
class loggers:
"""Keep loggers easily accessible (see :py:func:`init`)."""

_fmt = '%(asctime)s,%(msecs)d %(name)-2s ' '%(levelname)-2s:\n\t %(message)s'
_fmt = '%(asctime)s,%(msecs)d %(name)-2s %(levelname)-2s:\n\t %(message)s'
_datefmt = '%y%m%d-%H:%M:%S'

default = logging.getLogger()
Expand Down
9 changes: 3 additions & 6 deletions nibabies/interfaces/metric.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,7 @@ class MetricDilateInputSpec(CommandLineInputSpec):
argstr='-exponent %f ',
position=9,
default=6.0,
desc='exponent n to use in (area / (distance ^ n)) as the '
'weighting function (default 6)',
desc='exponent n to use in (area / (distance ^ n)) as the weighting function (default 6)',
)

corrected_areas = File(
Expand Down Expand Up @@ -246,16 +245,14 @@ class MetricResample(WBCommand):
def _format_arg(self, opt, spec, val):
if opt in ['current_area', 'new_area']:
if not self.inputs.area_surfs and not self.inputs.area_metrics:
raise ValueError(
f'{opt} was set but neither area_surfs or' ' area_metrics were set'
)
raise ValueError(f'{opt} was set but neither area_surfs or area_metrics were set')
if opt == 'method':
if (
val == 'ADAP_BARY_AREA'
and not self.inputs.area_surfs
and not self.inputs.area_metrics
):
raise ValueError('Exactly one of area_surfs or area_metrics' ' must be specified')
raise ValueError('Exactly one of area_surfs or area_metrics must be specified')
if opt == 'valid_roi_out' and val:
# generate a filename and add it to argstr
roi_out = self._gen_filename(self.inputs.in_file, suffix='_roi')
Expand Down
8 changes: 5 additions & 3 deletions nibabies/utils/bids.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ def write_bidsignore(deriv_dir):


def write_derivative_description(bids_dir, deriv_dir, dataset_links=None):
from ..__about__ import DOWNLOAD_URL, __packagename__, __version__
from nibabies import __version__

DOWNLOAD_URL = f'https://github.com/nipreps/nibabies/archive/{__version__}.tar.gz'

bids_dir = Path(bids_dir)
deriv_dir = Path(deriv_dir)
Expand All @@ -51,7 +53,7 @@ def write_derivative_description(bids_dir, deriv_dir, dataset_links=None):
'DatasetType': 'derivative',
'GeneratedBy': [
{
'Name': __packagename__,
'Name': 'NiBabies',
'Version': __version__,
'CodeURL': DOWNLOAD_URL,
}
Expand All @@ -63,7 +65,7 @@ def write_derivative_description(bids_dir, deriv_dir, dataset_links=None):
if 'NIBABIES_DOCKER_TAG' in os.environ:
desc['GeneratedBy'][0]['Container'] = {
'Type': 'docker',
'Tag': f"nipreps/nibabies:{os.environ['NIBABIES_DOCKER_TAG']}",
'Tag': f'nipreps/nibabies:{os.environ["NIBABIES_DOCKER_TAG"]}',
}
if 'NIBABIES_SINGULARITY_URL' in os.environ:
desc['GeneratedBy'][0]['Container'] = {
Expand Down
6 changes: 3 additions & 3 deletions nibabies/workflows/anatomical/fit.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,11 +170,11 @@ def init_infant_anat_fit_wf(

# Stage 2 - Anatomicals
t1w_buffer = pe.Node(
niu.IdentityInterface(fields=['t1w_preproc', 't1w_mask' 't1w_brain']),
niu.IdentityInterface(fields=['t1w_preproc', 't1w_maskt1w_brain']),
name='t1w_buffer',
)
t2w_buffer = pe.Node(
niu.IdentityInterface(fields=['t2w_preproc', 't2w_mask' 't2w_brain', 't2w_probmap']),
niu.IdentityInterface(fields=['t2w_preproc', 't2w_maskt2w_brain', 't2w_probmap']),
name='t2w_buffer',
)
anat_buffer = pe.Node(
Expand Down Expand Up @@ -453,7 +453,7 @@ def init_infant_anat_fit_wf(
t2w_mask = precomputed.get('t2w_mask')
anat_mask = precomputed.get(f'{anat}_mask')
refine_mask = False
# T1w masking - define pre-emptively
# T1w masking - define preemptively
apply_t1w_mask = pe.Node(ApplyMask(), name='apply_t1w_mask')
apply_t2w_mask = apply_t1w_mask.clone(name='apply_t2w_mask')

Expand Down
6 changes: 5 additions & 1 deletion nibabies/workflows/anatomical/registration.py
Original file line number Diff line number Diff line change
Expand Up @@ -537,9 +537,11 @@ def _load_intermediate_xfms(intermediate, std):


def _create_inverse_composite(in_file, out_file='inverse_composite.h5'):
"""Build a composite transform with SimpleITK.
"""
Build a composite transform with SimpleITK.
This serves as a workaround for a bug in ANTs's CompositeTransformUtil
https://github.com/ANTsX/ANTs/issues/1827
where composite transforms cannot be created with a displacement field placed first.
Parameters
Expand All @@ -553,6 +555,8 @@ def _create_inverse_composite(in_file, out_file='inverse_composite.h5'):
-------
out_file : str
Absolute path to the composite transform.
"""

from pathlib import Path

import SimpleITK as sitk
Expand Down
2 changes: 1 addition & 1 deletion nibabies/workflows/anatomical/segmentation.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ def _to_dtype(in_file, dtype='uint8'):
import numpy as np

img = nb.load(in_file)
out_file = Path(f"labels{''.join(Path(in_file).suffixes)}").absolute()
out_file = Path(f'labels{"".join(Path(in_file).suffixes)}').absolute()

new_data = np.asanyarray(img.get_fdata(), dtype=dtype)
img.set_data_dtype(dtype)
Expand Down
10 changes: 5 additions & 5 deletions nibabies/workflows/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ def init_nibabies_wf(subworkflows_list: list[SubjectSession]):
freesurfer_home=os.getenv('FREESURFER_HOME'),
spaces=execution_spaces.get_fs_spaces(),
),
name=f"fsdir_run_{config.execution.run_uuid.replace('-', '_')}",
name=f'fsdir_run_{config.execution.run_uuid.replace("-", "_")}',
run_without_submitting=True,
)
if config.execution.fs_subjects_dir is not None:
Expand Down Expand Up @@ -291,9 +291,9 @@ def init_single_subject_wf(

if subject_data['roi']:
warnings.warn(
f"Lesion mask {subject_data['roi']} found. "
"Future versions of NiBabies will use alternative conventions. "
"Please refer to the documentation before upgrading.",
f'Lesion mask {subject_data["roi"]} found. '
'Future versions of NiBabies will use alternative conventions. '
'Please refer to the documentation before upgrading.',
FutureWarning,
stacklevel=1,
)
Expand Down Expand Up @@ -939,7 +939,7 @@ def map_fieldmap_estimation(
for bold_file, estimator_key in all_estimators.items():
if len(estimator_key) > 1:
config.loggers.workflow.warning(
f"Several fieldmaps <{', '.join(estimator_key)}> are "
f'Several fieldmaps <{", ".join(estimator_key)}> are '
f"'IntendedFor' <{bold_file}>, using {estimator_key[0]}"
)
estimator_key[1:] = []
Expand Down
2 changes: 1 addition & 1 deletion nibabies/workflows/bold/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@
from niworkflows.utils.connections import listify

from nibabies import config
from nibabies._types import Anatomical
from nibabies.interfaces import DerivativesDataSink
from nibabies.types import Anatomical
from nibabies.utils.misc import estimate_bold_mem_usage

# BOLD workflows
Expand Down
2 changes: 1 addition & 1 deletion nibabies/workflows/bold/fit.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@
from sdcflows.workflows.apply.registration import init_coeff2epi_wf

from nibabies import config
from nibabies._types import Anatomical
from nibabies.interfaces.reports import FunctionalSummary
from nibabies.interfaces.resampling import (
DistortionParameters,
ReconstructFieldmap,
ResampleSeries,
)
from nibabies.types import Anatomical
from nibabies.utils.bids import extract_entities
from nibabies.utils.misc import estimate_bold_mem_usage

Expand Down
2 changes: 1 addition & 1 deletion nibabies/workflows/bold/outputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@
from niworkflows.utils.images import dseg_label

from nibabies import config
from nibabies._types import Anatomical
from nibabies.config import DEFAULT_DISMISS_ENTITIES, DEFAULT_MEMORY_MIN_GB, dismiss_echo
from nibabies.interfaces import DerivativesDataSink
from nibabies.interfaces.bids import BIDSURI
from nibabies.types import Anatomical


def prepare_timing_parameters(metadata: dict):
Expand Down
2 changes: 1 addition & 1 deletion nibabies/workflows/bold/registration.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from nipype.pipeline import engine as pe

from nibabies import config, data
from nibabies.types import AffineDOF, RegistrationInit
from nibabies._types import AffineDOF, RegistrationInit

DEFAULT_MEMORY_MIN_GB = config.DEFAULT_MEMORY_MIN_GB
LOGGER = logging.getLogger('nipype.workflow')
Expand Down
2 changes: 1 addition & 1 deletion nibabies/workflows/bold/stc.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ def init_bold_stc_wf(metadata, name='bold_stc_wf'):
slice_timing_correction = pe.Node(
TShift(
outputtype='NIFTI_GZ',
tr=f"{metadata['RepetitionTime']}s",
tr=f'{metadata["RepetitionTime"]}s',
slice_timing=metadata['SliceTiming'],
slice_encoding_direction=metadata.get('SliceEncodingDirection', 'k'),
tzero=tzero,
Expand Down
2 changes: 1 addition & 1 deletion scripts/fetch_templates.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python

'Pre-emptive caching of commonly used TemplateFlow templates'
'Preemptive caching of commonly used TemplateFlow templates'
import templateflow.api as tf


Expand Down

0 comments on commit d2436b7

Please sign in to comment.