Skip to content

Commit

Permalink
sty: run ruff
Browse files Browse the repository at this point in the history
  • Loading branch information
oesteban committed Aug 16, 2024
1 parent d8b55da commit cf1ea8f
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 44 deletions.
6 changes: 2 additions & 4 deletions mriqc/cli/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,6 @@ def _bids_filter(value):

def parse_args(args=None, namespace=None):
"""Parse args and run further checks on the command line."""
from contextlib import suppress
from json import loads
from logging import DEBUG, FileHandler
from pathlib import Path
Expand Down Expand Up @@ -555,10 +554,9 @@ def parse_args(args=None, namespace=None):
if output_dir == bids_dir:
parser.error(
'The selected output folder is the same as the input BIDS folder. '
'Please modify the output path (suggestion: %s).'
% bids_dir
f'Please modify the output path (suggestion: {bids_dir}).'
/ 'derivatives'
/ ('mriqc-%s' % version.split('+')[0])
/ ('mriqc-{}'.format(version.split('+')[0]))
)

if bids_dir in work_dir.parents:
Expand Down
30 changes: 13 additions & 17 deletions mriqc/interfaces/webapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,15 +169,17 @@ def _run_interface(self, runtime):
config.loggers.interface.info(messages.QC_UPLOAD_COMPLETE)
return runtime

errmsg = '\n'.join([
'Unsuccessful upload.',
f'Server response status {response.status_code}:',
response.text,
'',
'',
'Payload:',
json.dumps(payload, indent=2),
])
errmsg = '\n'.join(
[
'Unsuccessful upload.',
f'Server response status {response.status_code}:',
response.text,
'',
'',
'Payload:',
json.dumps(payload, indent=2),
]
)
config.loggers.interface.warning(errmsg)
if self.inputs.strict:
raise RuntimeError(errmsg)
Expand Down Expand Up @@ -227,11 +229,7 @@ def upload_qc_metrics(
data = deepcopy(in_data)

# Check modality
modality = (
meta.get('modality', None)
or meta.get('suffix', None)
or modality
)
modality = meta.get('modality', None) or meta.get('suffix', None) or modality
if modality not in ('T1w', 'bold', 'T2w'):
errmsg = (
'Submitting to MRIQCWebAPI: image modality should be "bold", "T1w", or "T2w", '
Expand All @@ -244,9 +242,7 @@ def upload_qc_metrics(

# Check for fields with appended _id
bids_meta_names = {k: k.replace('_id', '') for k in META_WHITELIST if k.endswith('_id')}
data['bids_meta'].update({
k: meta[v] for k, v in bids_meta_names.items() if v in meta
})
data['bids_meta'].update({k: meta[v] for k, v in bids_meta_names.items() if v in meta})

# For compatibility with WebAPI. Should be rolled back to int
if (run_id := data['bids_meta'].get('run_id', None)) is not None:
Expand Down
40 changes: 25 additions & 15 deletions mriqc/workflows/anatomical/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
"""

from itertools import chain

from nipype.interfaces import utility as niu
from nipype.pipeline import engine as pe
from niworkflows.interfaces.fixes import FixHeaderApplyTransforms as ApplyTransforms
Expand Down Expand Up @@ -94,18 +95,24 @@ def anat_qc_workflow(name='anatMRIQC'):
# config.workflow.biggest_file_gb['t1w'],
# config.workflow.biggest_file_gb['t2w'],
# )
dataset = list(chain(
config.workflow.inputs.get('t1w', []),
config.workflow.inputs.get('t2w', []),
))
metadata = list(chain(
config.workflow.inputs_metadata.get('t1w', []),
config.workflow.inputs_metadata.get('t2w', []),
))
entities = list(chain(
config.workflow.inputs_entities.get('t1w', []),
config.workflow.inputs_entities.get('t2w', []),
))
dataset = list(
chain(
config.workflow.inputs.get('t1w', []),
config.workflow.inputs.get('t2w', []),
)
)
metadata = list(
chain(
config.workflow.inputs_metadata.get('t1w', []),
config.workflow.inputs_metadata.get('t2w', []),
)
)
entities = list(
chain(
config.workflow.inputs_entities.get('t1w', []),
config.workflow.inputs_entities.get('t2w', []),
)
)
message = BUILDING_WORKFLOW.format(
modality='anatomical',
detail=f'for {len(dataset)} NIfTI files.',
Expand All @@ -117,9 +124,12 @@ def anat_qc_workflow(name='anatMRIQC'):

# Define workflow, inputs and outputs
# 0. Get data
inputnode = pe.Node(niu.IdentityInterface(
fields=['in_file', 'metadata', 'entities'],
), name='inputnode')
inputnode = pe.Node(
niu.IdentityInterface(
fields=['in_file', 'metadata', 'entities'],
),
name='inputnode',
)
inputnode.synchronize = True # Do not test combinations of iterables
inputnode.iterables = [
('in_file', dataset),
Expand Down
9 changes: 6 additions & 3 deletions mriqc/workflows/diffusion/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,12 @@ def dmri_qc_workflow(name='dwiMRIQC'):
# Define workflow, inputs and outputs
# 0. Get data, put it in RAS orientation
workflow = pe.Workflow(name=name)
inputnode = pe.Node(niu.IdentityInterface(
fields=['in_file', 'metadata', 'entities'],
), name='inputnode')
inputnode = pe.Node(
niu.IdentityInterface(
fields=['in_file', 'metadata', 'entities'],
),
name='inputnode',
)
inputnode.synchronize = True # Do not test combinations of iterables
inputnode.iterables = [
('in_file', dataset),
Expand Down
10 changes: 6 additions & 4 deletions mriqc/workflows/functional/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
This workflow is orchestrated by :py:func:`fmri_qc_workflow`.
"""


from nipype.interfaces import utility as niu
from nipype.pipeline import engine as pe
from niworkflows.utils.connections import pop_file as _pop
Expand Down Expand Up @@ -86,9 +85,12 @@ def fmri_qc_workflow(name='funcMRIQC'):
# Define workflow, inputs and outputs
# 0. Get data, put it in RAS orientation
workflow = pe.Workflow(name=name)
inputnode = pe.Node(niu.IdentityInterface(
fields=['in_file', 'metadata', 'entities'],
), name='inputnode')
inputnode = pe.Node(
niu.IdentityInterface(
fields=['in_file', 'metadata', 'entities'],
),
name='inputnode',
)
inputnode.synchronize = True # Do not test combinations of iterables
inputnode.iterables = [
('in_file', dataset),
Expand Down
2 changes: 1 addition & 1 deletion mriqc/workflows/functional/output.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def init_func_report_wf(name='func_report_wf'):
# from mriqc.interfaces.reports import IndividualReport

verbose = config.execution.verbose_reports
mem_gb = config.workflow.biggest_file_gb["bold"]
mem_gb = config.workflow.biggest_file_gb['bold']
reportlets_dir = config.execution.work_dir / 'reportlets'

workflow = pe.Workflow(name=name)
Expand Down

0 comments on commit cf1ea8f

Please sign in to comment.