Skip to content

Conversation

@eurunuela
Copy link
Collaborator

@eurunuela eurunuela commented Dec 18, 2025

Summary

This PR refactors the tedana workflow files to use a new shared module architecture (tedana/workflows/shared/). The goal is to improve code organization, reduce duplication, and make the codebase more maintainable.

Key Changes

  • New workflows/shared/ submodule with focused, reusable components:

    • containers.py - Typed dataclasses (MultiEchoData, MaskData, DecayMaps, OptcomData)
    • setup.py - Workflow setup/teardown utilities (logging, output directory, command saving)
    • data_loading.py - Multi-echo data loading and TR validation
    • masking.py - Adaptive mask creation for denoising and classification
    • fitting.py - T2*/S0 decay model fitting
    • combination.py - Optimal echo combination
    • output.py - Result writing, tedort, MIR, metadata generation
    • reporting.py - Static figures and dynamic report generation
  • Refactored all three workflows to use the shared modules:

    • tedana.py - Now uses shared functions and returns a results dictionary
    • t2smap.py - Simplified using shared data loading, masking, and fitting
    • ica_reclassify.py - Simplified using shared output and reporting functions

Benefits

  • Separation of concerns: Each shared module handles a specific aspect of the workflow
  • Type safety: Dataclasses provide clear interfaces between workflow stages
  • Reduced duplication: Common operations are now shared across all workflows
  • Easier testing: Individual modules can be tested in isolation
  • Better maintainability: Changes to shared functionality only need to be made once

Changes Summary

File Change
workflows/shared/*.py New shared modules (8 files)
workflows/tedana.py Refactored to use shared modules, added type hints, returns results dict
workflows/t2smap.py Simplified using shared modules
workflows/ica_reclassify.py Simplified using shared modules

Test plan

  • Run existing test suite to ensure no regressions
  • Verify t2smap workflow produces identical outputs
  • Verify tedana workflow produces identical outputs
  • Verify ica_reclassify workflow produces identical outputs
  • Test with different parameter combinations

🤖 Generated with Claude Code

Moved reusable workflow logic into tedana.workflows.shared, including data containers, setup, output, reporting, masking, combination, and fitting utilities. Updated ica_reclassify.py to use shared functions for report handling, logging, result writing, and metadata. This improves code organization and maintainability by centralizing common workflow operations.
@eurunuela eurunuela force-pushed the modularrize_tedana_main branch from 5e02b59 to d35d9ad Compare December 18, 2025 17:39
@eurunuela
Copy link
Collaborator Author

This is an alternative to #1280.

@eurunuela eurunuela added the refactoring issues proposing/requesting changes to the code which do not impact behavior label Dec 18, 2025
@codecov
Copy link

codecov bot commented Dec 18, 2025

Codecov Report

❌ Patch coverage is 90.26316% with 37 lines in your changes missing coverage. Please review.
✅ Project coverage is 89.97%. Comparing base (e093290) to head (d35d9ad).

Files with missing lines Patch % Lines
tedana/workflows/shared/masking.py 75.60% 8 Missing and 2 partials ⚠️
tedana/workflows/shared/containers.py 89.18% 8 Missing ⚠️
tedana/workflows/tedana.py 89.39% 5 Missing and 2 partials ⚠️
tedana/workflows/shared/data_loading.py 80.95% 2 Missing and 2 partials ⚠️
tedana/workflows/shared/setup.py 89.74% 4 Missing ⚠️
tedana/workflows/ica_reclassify.py 86.66% 2 Missing ⚠️
tedana/workflows/shared/combination.py 89.47% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1281      +/-   ##
==========================================
+ Coverage   89.73%   89.97%   +0.24%     
==========================================
  Files          29       37       +8     
  Lines        4403     4560     +157     
  Branches      730      735       +5     
==========================================
+ Hits         3951     4103     +152     
- Misses        299      302       +3     
- Partials      153      155       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

refactoring issues proposing/requesting changes to the code which do not impact behavior

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant