ENH: Modularize tedana.py workflow into pipeline stages #1280
+1,565
−660
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This PR refactors the monolithic
tedana_workflow()function (~800 lines) into a modular pipeline architecture with distinct stages, improving maintainability, testability, and memory efficiency.Changes
PipelineContextdataclass (pipeline_context.py): Centralizes all workflow state (configuration, data arrays, masks, decomposition results) in a single container, reducing parameter passing between functionspipeline_stages.py): Organizes the workflow into 9 logical stages with 20+ self-contained functionstedana_workflow(): Now creates aPipelineContextand delegates torun_tedana_pipeline(), reducing the function from ~800 to ~30 linesclear_intermediate_data(),get_memory_usage()) with garbage collectionPipeline Stages
setup_output_directory,validate_inputs,initialize_component_selector,setup_io_generatorload_data,validate_tr,load_external_regressors,handle_precomputed_filescreate_masksfit_decay_modelcompute_optimal_combinationperform_pca_decomposition,perform_ica_decomposition,compute_component_metrics,perform_component_selection,run_decomposition_with_restartssave_component_outputs,apply_tedort,write_denoised_data,save_registry_and_metadata,finalize_report_textgenerate_reportscleanupBenefits
tedana_workflow()now returnsPipelineContextfor programmatic access to results (component table, mixing matrix, selector, etc.)File Changes
pipeline_context.pypipeline_stages.pytedana.py__init__.pyTest Plan
🤖 Generated with Claude Code