Skip to content

Commit

Permalink
Update base.py
Browse files Browse the repository at this point in the history
  • Loading branch information
tsalo committed May 16, 2024
1 parent 9f3f8e6 commit 9d75012
Showing 1 changed file with 27 additions and 4 deletions.
31 changes: 27 additions & 4 deletions src/fmripost_aroma/workflows/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -349,11 +349,13 @@ def init_single_subject_wf(subject_id: str):
ica_aroma_wf.inputs.inputnode.bold_mask_std = functional_cache['bold_mask_std']
workflow.add_nodes([ica_aroma_wf])

functional_cache['skip_vols'] = (
config.workflow.dummy_scans or functional_cache['skip_vols']
)
if config.workflow.dummy_scans is not None:
skip_vols = config.workflow.dummy_scans

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

View check run for this annotation

Codecov / codecov/patch

src/fmripost_aroma/workflows/base.py#L353

Added line #L353 was not covered by tests
else:
skip_vols = get_nss(functional_cache['confounds'])

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

View check run for this annotation

Codecov / codecov/patch

src/fmripost_aroma/workflows/base.py#L355

Added line #L355 was not covered by tests

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

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

View check run for this annotation

Codecov / codecov/patch

src/fmripost_aroma/workflows/base.py#L358

Added line #L358 was not covered by tests

if config.workflow.denoise_method:
for space in spaces:
Expand Down Expand Up @@ -393,3 +395,24 @@ def clean_datasinks(workflow: pe.Workflow) -> pe.Workflow:
if node.split('.')[-1].startswith('ds_'):
workflow.get_node(node).interface.out_path_base = ''
return workflow


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

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

View check run for this annotation

Codecov / codecov/patch

src/fmripost_aroma/workflows/base.py#L402-L403

Added lines #L402 - L403 were not covered by tests

df = pd.read_table(confounds_file)

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

View check run for this annotation

Codecov / codecov/patch

src/fmripost_aroma/workflows/base.py#L405

Added line #L405 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 409 in src/fmripost_aroma/workflows/base.py

View check run for this annotation

Codecov / codecov/patch

src/fmripost_aroma/workflows/base.py#L409

Added line #L409 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 413 in src/fmripost_aroma/workflows/base.py

View check run for this annotation

Codecov / codecov/patch

src/fmripost_aroma/workflows/base.py#L411-L413

Added lines #L411 - L413 were not covered by tests

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

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

View check run for this annotation

Codecov / codecov/patch

src/fmripost_aroma/workflows/base.py#L416

Added line #L416 was not covered by tests

return dummy_scans

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

View check run for this annotation

Codecov / codecov/patch

src/fmripost_aroma/workflows/base.py#L418

Added line #L418 was not covered by tests

0 comments on commit 9d75012

Please sign in to comment.