Skip to content

Filter anat suffix during load#255

Closed
kaitj wants to merge 3 commits into
mainfrom
maint/anat-suffix
Closed

Filter anat suffix during load#255
kaitj wants to merge 3 commits into
mainfrom
maint/anat-suffix

Conversation

@kaitj
Copy link
Copy Markdown
Contributor

@kaitj kaitj commented Apr 2, 2026

The filtering for T1w images was a patch fix to get the workflow working, but was repeated across all workflows.

This replaces the 3 separate calls into the initial loading of the session once (where the filter can be updated later on if we want to support anatomical contrasts). Also makes use of the schema generated suffix instead of matching a string.

@kaitj kaitj requested review from jpillai00 and nx10 April 2, 2026 17:58
@kaitj kaitj linked an issue Apr 2, 2026 that may be closed by this pull request
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 2, 2026

Coverage

Tests Skipped Failures Errors Time
781 0 💤 0 ❌ 0 🔥 11.416s ⏱️

@nx10
Copy link
Copy Markdown
Contributor

nx10 commented Apr 3, 2026

You could also use Datatype.ANAT

@nx10
Copy link
Copy Markdown
Contributor

nx10 commented Apr 3, 2026

also does this close #250 ?

@kaitj kaitj force-pushed the maint/anat-suffix branch from 59c544a to 799b63a Compare April 6, 2026 19:19
Comment thread src/rbc/bids/session.py Outdated
Comment thread src/rbc/bids/session.py
Comment on lines 39 to 61
def load_session(df: pl.DataFrame, subject: str, session: str | None) -> SessionTables:
"""Filter for anatomical and functional data for a single subject/session.

Args:
df: Full bids2table dataframe.
subject: Subject label without 'sub-' prefix (e.g. ``'01'``)
session: Session label without 'ses-' prefix (e.g. ``'02'``)

Returns:
A :class:`SessionTables` containing separate anatomical and functional
dataframes.
"""
base: list[pl.Expr] = [pl.col("sub") == subject]
if session is not None:
base.append(pl.col("ses") == session)
anat_df = df.filter(pl.all_horizontal([*base, pl.col("datatype") == "anat"]))
func_df = df.filter(pl.all_horizontal([*base, pl.col("datatype") == "func"]))
anat_df = df.filter(
pl.all_horizontal(
[*base, pl.col("datatype") == Datatype.ANAT, pl.col("suffix") == Suffix.T1W]
)
)
func_df = df.filter(pl.all_horizontal([*base, pl.col("datatype") == Datatype.FUNC]))

return SessionTables(anat=anat_df, func=func_df if not func_df.is_empty() else None)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

downstream we have a bunch of redundant filters after this already filters for t1w

  • src/rbc/bids/anatomical.py:44
  • src/rbc/orchestration/longitudinal.py:160

I wonder if this is sound...

Also closes off everything to T1w - should suffix be a param so t2w + flair is possible in the future?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I would probably remove the downstream filters. If we decide to support other contrasts in the future then yeah i would make it a parameter.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Removed the redundant filters downstream (waiting for e2e tests). I've left out adding suffix as a param for now. Probably want to consider how we want to include this since we may want diff params for anat vs func.

@kaitj kaitj requested a review from nx10 April 7, 2026 15:51
@kaitj kaitj force-pushed the maint/anat-suffix branch from 43c0795 to 2eac273 Compare April 27, 2026 15:37
This is causing the non T1w suffix rows to be filtered out, which is needed downstream.
@kaitj
Copy link
Copy Markdown
Contributor Author

kaitj commented Apr 29, 2026

PR is no longer relevant...can reopen if we need to revisit

@kaitj kaitj closed this Apr 29, 2026
@kaitj kaitj deleted the maint/anat-suffix branch May 20, 2026 23:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Revisit anatomical suffix filtering

2 participants