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

Test collect_derivatives function #29

Merged
merged 31 commits into from
May 16, 2024
Merged
Changes from 1 commit
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
622bc78
Work on collect_derivatives.
tsalo May 16, 2024
9703bef
Work on queries.
tsalo May 16, 2024
85bec3a
Work on collect_derivatives.
tsalo May 16, 2024
0da1278
Tests look good now. Will still fail.
tsalo May 16, 2024
48360bd
Update conftest.py
tsalo May 16, 2024
b7729d5
Work on raw vs. derivative collection.
tsalo May 16, 2024
c2a5269
Update test_utils_bids.py
tsalo May 16, 2024
3efa4f2
Update bids.py
tsalo May 16, 2024
9991d18
Merge remote-tracking branch 'upstream/main' into testing
tsalo May 16, 2024
35f7f69
Try this.
tsalo May 16, 2024
3a7889b
Fix style issues.
tsalo May 16, 2024
88edabf
Update utils.py
tsalo May 16, 2024
ea500e9
Update conftest.py
tsalo May 16, 2024
93fb0d3
Update test_utils_bids.py
tsalo May 16, 2024
ca329af
Update test_utils_bids.py
tsalo May 16, 2024
1a02037
Don't index metadata.
tsalo May 16, 2024
85c3a1b
Update test_utils_bids.py
tsalo May 16, 2024
1d42fc1
Update test_utils_bids.py
tsalo May 16, 2024
68ea226
Fix up entrypoint and imports.
tsalo May 16, 2024
dbe3a25
Keep fixing.
tsalo May 16, 2024
867ff8c
Update.
tsalo May 16, 2024
6d5babe
Fix some stuff.
tsalo May 16, 2024
9f3f8e6
Keep trying to fix.
tsalo May 16, 2024
9d75012
Update base.py
tsalo May 16, 2024
f217d16
Get it building at least.
tsalo May 16, 2024
11bb3d9
Remove reporting nodes.
tsalo May 16, 2024
98ffee2
Whoops!
tsalo May 16, 2024
b4dd02d
Fix more stuff.
tsalo May 16, 2024
d6f3e36
Get the workflow to run all the way through.
tsalo May 16, 2024
f6b8ef3
Fix style issues.
tsalo May 16, 2024
33b624a
Update confounds.py
tsalo May 16, 2024
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
Prev Previous commit
Next Next commit
Fix style issues.
  • Loading branch information
tsalo committed May 16, 2024
commit f6b8ef33516dc74758d68611e611ca97008434a6
3 changes: 1 addition & 2 deletions src/fmripost_aroma/reports/core.py
Original file line number Diff line number Diff line change
@@ -22,9 +22,8 @@
#
from pathlib import Path

from nireports.assembler.report import Report

from fmripost_aroma import config, data
from nireports.assembler.report import Report


def run_reports(
2 changes: 0 additions & 2 deletions src/fmripost_aroma/workflows/base.py
Original file line number Diff line number Diff line change
@@ -138,7 +138,7 @@
8. Warp BOLD to requested output spaces and denoise with ICA-AROMA.

"""
from bids.utils import listify

Check warning on line 141 in src/fmripost_aroma/workflows/base.py

Codecov / codecov/patch

src/fmripost_aroma/workflows/base.py#L141

Added line #L141 was not covered by tests
from niworkflows.engine.workflows import LiterateWorkflow as Workflow
from niworkflows.interfaces.nilearn import NILEARN_VERSION
from niworkflows.utils.spaces import Reference
@@ -146,8 +146,6 @@
from fmripost_aroma.utils.bids import collect_derivatives, extract_entities
from fmripost_aroma.workflows.aroma import init_denoise_wf, init_ica_aroma_wf

spaces = config.workflow.spaces

workflow = Workflow(name=f'sub_{subject_id}_wf')
workflow.__desc__ = f"""
Results included in this manuscript come from postprocessing
@@ -180,19 +178,19 @@

if config.execution.derivatives:
# Raw dataset + derivatives dataset
config.loggers.workflow.info('Raw+derivatives workflow mode enabled')
subject_data = collect_derivatives(

Check warning on line 182 in src/fmripost_aroma/workflows/base.py

Codecov / codecov/patch

src/fmripost_aroma/workflows/base.py#L181-L182

Added lines #L181 - L182 were not covered by tests
raw_dataset=config.execution.layout,
derivatives_dataset=None,
entities=config.execution.bids_filters,
fieldmap_id=None,
allow_multiple=True,
)
subject_data['bold'] = listify(subject_data['bold_raw'])

Check warning on line 189 in src/fmripost_aroma/workflows/base.py

Codecov / codecov/patch

src/fmripost_aroma/workflows/base.py#L189

Added line #L189 was not covered by tests
else:
# Derivatives dataset only
config.loggers.workflow.info('Derivatives-only workflow mode enabled')
subject_data = collect_derivatives(

Check warning on line 193 in src/fmripost_aroma/workflows/base.py

Codecov / codecov/patch

src/fmripost_aroma/workflows/base.py#L192-L193

Added lines #L192 - L193 were not covered by tests
raw_dataset=None,
derivatives_dataset=config.execution.layout,
entities=config.execution.bids_filters,
@@ -200,7 +198,7 @@
allow_multiple=True,
)
# Patch standard-space BOLD files into 'bold' key
subject_data['bold'] = listify(subject_data['bold_std'])

Check warning on line 201 in src/fmripost_aroma/workflows/base.py

Codecov / codecov/patch

src/fmripost_aroma/workflows/base.py#L201

Added line #L201 was not covered by tests

# Make sure we always go through these two checks
if not subject_data['bold']:
@@ -222,8 +220,8 @@
"""

for bold_file in subject_data['bold']:
bold_metadata = config.execution.layout.get_metadata(bold_file)
ica_aroma_wf = init_ica_aroma_wf(bold_file=bold_file, metadata=bold_metadata)

Check warning on line 224 in src/fmripost_aroma/workflows/base.py

Codecov / codecov/patch

src/fmripost_aroma/workflows/base.py#L223-L224

Added lines #L223 - L224 were not covered by tests
ica_aroma_wf.__desc__ = func_pre_desc + (ica_aroma_wf.__desc__ or '')

entities = extract_entities(bold_file)
@@ -232,7 +230,7 @@
if config.execution.derivatives:
# Collect native-space derivatives and transforms
for deriv_dir in config.execution.derivatives.values():
functional_cache = update_dict(

Check warning on line 233 in src/fmripost_aroma/workflows/base.py

Codecov / codecov/patch

src/fmripost_aroma/workflows/base.py#L233

Added line #L233 was not covered by tests
functional_cache,
collect_derivatives(
raw_dataset=None,
@@ -245,14 +243,14 @@

if not functional_cache['confounds']:
if config.workflow.dummy_scans is None:
raise ValueError(

Check warning on line 246 in src/fmripost_aroma/workflows/base.py

Codecov / codecov/patch

src/fmripost_aroma/workflows/base.py#L246

Added line #L246 was not covered by tests
'No confounds detected. '
'Automatical dummy scan detection cannot be performed. '
'Please set the `--dummy-scans` flag explicitly.'
)

# TODO: Calculate motion parameters from motion correction transform
raise ValueError('Motion parameters cannot be extracted from transforms yet.')

Check warning on line 253 in src/fmripost_aroma/workflows/base.py

Codecov / codecov/patch

src/fmripost_aroma/workflows/base.py#L253

Added line #L253 was not covered by tests

# Resample to MNI152NLin6Asym:res-2, for ICA-AROMA classification
resample_raw_wf = init_resample_volumetric_wf(
@@ -284,7 +282,7 @@
ica_aroma_wf.inputs.inputnode.bold_mask_std = functional_cache['bold_mask_std']
workflow.add_nodes([ica_aroma_wf])

config.loggers.workflow.info(

Check warning on line 285 in src/fmripost_aroma/workflows/base.py

Codecov / codecov/patch

src/fmripost_aroma/workflows/base.py#L285

Added line #L285 was not covered by tests
(
f'Collected run data for {os.path.basename(bold_file)}:\n'
f'{yaml.dump(functional_cache, default_flow_style=False, indent=4)}'
@@ -292,18 +290,18 @@
)

if config.workflow.dummy_scans is not None:
skip_vols = config.workflow.dummy_scans

Check warning on line 293 in src/fmripost_aroma/workflows/base.py

Codecov / codecov/patch

src/fmripost_aroma/workflows/base.py#L293

Added line #L293 was not covered by tests
else:
if not functional_cache['confounds']:
raise ValueError(

Check warning on line 296 in src/fmripost_aroma/workflows/base.py

Codecov / codecov/patch

src/fmripost_aroma/workflows/base.py#L296

Added line #L296 was not covered by tests
'No confounds detected. '
'Automatical dummy scan detection cannot be performed. '
'Please set the `--dummy-scans` flag explicitly.'
)
skip_vols = get_nss(functional_cache['confounds'])

Check warning on line 301 in src/fmripost_aroma/workflows/base.py

Codecov / codecov/patch

src/fmripost_aroma/workflows/base.py#L301

Added line #L301 was not covered by tests

ica_aroma_wf.inputs.inputnode.confounds = functional_cache['confounds']
ica_aroma_wf.inputs.inputnode.skip_vols = skip_vols

Check warning on line 304 in src/fmripost_aroma/workflows/base.py

Codecov / codecov/patch

src/fmripost_aroma/workflows/base.py#L303-L304

Added lines #L303 - L304 were not covered by tests

if config.workflow.denoise_method:
# for space in spaces:
@@ -316,12 +314,12 @@
# )

# Now denoise the output-space BOLD data using ICA-AROMA
denoise_wf = init_denoise_wf(bold_file=bold_file)
denoise_wf.inputs.inputnode.skip_vols = skip_vols
denoise_wf.inputs.inputnode.bold_file = functional_cache['bold_std']
denoise_wf.inputs.inputnode.bold_mask = functional_cache['bold_mask_std']
denoise_wf.inputs.inputnode.spatial_reference = 'MNI152NLin6Asym'
workflow.connect([

Check warning on line 322 in src/fmripost_aroma/workflows/base.py

Codecov / codecov/patch

src/fmripost_aroma/workflows/base.py#L317-L322

Added lines #L317 - L322 were not covered by tests
# (resample_to_space_wf, denoise_wf, [
# ('bold_std', 'inputnode.bold_file'),
# ('bold_mask_std', 'inputnode.bold_mask'),
@@ -350,20 +348,20 @@

def get_nss(confounds_file):
"""Get number of non-steady state volumes."""
import numpy as np
import pandas as pd

Check warning on line 352 in src/fmripost_aroma/workflows/base.py

Codecov / codecov/patch

src/fmripost_aroma/workflows/base.py#L351-L352

Added lines #L351 - L352 were not covered by tests

df = pd.read_table(confounds_file)

Check warning on line 354 in src/fmripost_aroma/workflows/base.py

Codecov / codecov/patch

src/fmripost_aroma/workflows/base.py#L354

Added line #L354 was not covered by tests

nss_cols = [c for c in df.columns if c.startswith('non_steady_state_outlier')]

dummy_scans = 0

Check warning on line 358 in src/fmripost_aroma/workflows/base.py

Codecov / codecov/patch

src/fmripost_aroma/workflows/base.py#L358

Added line #L358 was not covered by tests
if nss_cols:
initial_volumes_df = df[nss_cols]
dummy_scans = np.any(initial_volumes_df.to_numpy(), axis=1)
dummy_scans = np.where(dummy_scans)[0]

Check warning on line 362 in src/fmripost_aroma/workflows/base.py

Codecov / codecov/patch

src/fmripost_aroma/workflows/base.py#L360-L362

Added lines #L360 - L362 were not covered by tests

# reasonably assumes all NSS volumes are contiguous
dummy_scans = int(dummy_scans[-1] + 1)

Check warning on line 365 in src/fmripost_aroma/workflows/base.py

Codecov / codecov/patch

src/fmripost_aroma/workflows/base.py#L365

Added line #L365 was not covered by tests

return dummy_scans

Check warning on line 367 in src/fmripost_aroma/workflows/base.py

Codecov / codecov/patch

src/fmripost_aroma/workflows/base.py#L367

Added line #L367 was not covered by tests
Loading