# cmbscipol/megatop architecture

> Architecture diagram of the GitHub repository cmbscipol/megatop, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-09-26). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/cmbscipol/megatop
- Repository: https://github.com/cmbscipol/megatop

## Overview

Megatop is a configurable, map-based CMB polarization analysis pipeline. Users run distinct command-line stages: prepare masks and simulated or observed maps, preprocess maps and estimate noise, separate astrophysical components, compute angular power spectra, then infer cosmological parameters such as the tensor-to-scalar ratio. Separate plotting commands inspect stage outputs. The graph preserves these documented capabilities, but source excerpts are partial, so links between most stages are not asserted as direct calls; each stage is independently exposed as a command.

Main entry points: [`src/megatop/pipeline/mocker.py`](https://github.com/cmbscipol/megatop/blob/master/src/megatop/pipeline/mocker.py) (Map simulations), [`src/megatop/pipeline/preprocesser.py`](https://github.com/cmbscipol/megatop/blob/master/src/megatop/pipeline/preprocesser.py) (Map preprocessing), [`src/megatop/config.py`](https://github.com/cmbscipol/megatop/blob/master/src/megatop/config.py) (Configuration), [`src/megatop/data_manager.py`](https://github.com/cmbscipol/megatop/blob/master/src/megatop/data_manager.py) (Data manager)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_setup["Inputs and masks"]
  node_config["Configuration<br/>[config.py]"]
  node_manager["Data manager<br/>[data_manager.py]"]
  node_mask["Mask handling<br/>[mask_handler.py]"]
end

subgraph group_maps["Map products"]
  node_mock["Map simulations<br/>[mocker.py]"]
  node_landscape["Map geometry<br/>[landscapes.py]"]
  node_preprocess["Map preprocessing<br/>[preprocesser.py]"]
  node_noise_pre["Noise preprocessing"]
  node_noise_cov["Pixel noise covariance"]
end

subgraph group_inference["Spectra and inference"]
  node_noise_spectra["Noise spectra"]
  node_binning["Spectral binning<br/>[binner_maker.py]"]
  node_compsep["Component separation"]
  node_map2cl["Map to spectra<br/>[map_to_cler.py]"]
  node_transfer["Transfer functions"]
  node_cl2r["Tensor ratio inference<br/>[cl2r_estimater.py]"]
end

subgraph group_inspection["Plots and reports"]
  node_mock_plot["Simulation plots<br/>[mock_plotter.py]"]
  node_preproc_plot["Preprocessing plots<br/>[preproc_plotter.py]"]
  node_noise_plot["Noise spectra plots"]
  node_compsep_plot["Separation plots"]
  node_spectra_plot["Map spectra plots<br/>[map2cl_plotter.py]"]
  node_r_plot["Inference plots<br/>[r_stats_plotter.py]"]
  node_mcmc_plot["MCMC plots<br/>[mcmc_plotter.py]"]
end

node_user(("Pipeline user"))
node_external_maps["Frequency maps"]
node_outputs[("Pipeline data products")]

node_user -->|"provides settings"| node_config
node_user -->|"runs stage"| node_mask
node_user -->|"runs stage"| node_mock
node_user -->|"runs stage"| node_preprocess
node_user -->|"runs stage"| node_noise_pre
node_user -->|"runs stage"| node_noise_cov
node_user -->|"runs stage"| node_noise_spectra
node_user -->|"runs stage"| node_binning
node_user -->|"runs stage"| node_compsep
node_user -->|"runs stage"| node_map2cl
node_user -->|"runs stage"| node_transfer
node_user -->|"runs stage"| node_cl2r
node_config -->|"configures paths"| node_manager
node_manager -->|"creates directories"| node_outputs
node_external_maps -->|"map input"| node_preprocess
node_mask -->|"writes products"| node_outputs
node_mock -->|"uses geometry"| node_landscape
node_mock -->|"writes maps"| node_outputs
node_preprocess -->|"writes maps"| node_outputs
node_noise_pre -->|"writes products"| node_outputs
node_noise_cov -->|"writes covariance"| node_outputs
node_noise_spectra -->|"writes spectra"| node_outputs
node_binning -->|"writes bins"| node_outputs
node_compsep -->|"writes results"| node_outputs
node_map2cl -->|"writes spectra"| node_outputs
node_transfer -->|"writes functions"| node_outputs
node_cl2r -->|"writes chains"| node_outputs
node_mock_plot -->|"reads products"| node_outputs
node_preproc_plot -->|"reads products"| node_outputs
node_noise_plot -->|"reads spectra"| node_outputs
node_compsep_plot -->|"reads results"| node_outputs
node_spectra_plot -->|"reads spectra"| node_outputs
node_r_plot -->|"reads statistics"| node_outputs
node_mcmc_plot -->|"reads chains"| node_outputs

click node_config "https://github.com/cmbscipol/megatop/blob/master/src/megatop/config.py"
click node_manager "https://github.com/cmbscipol/megatop/blob/master/src/megatop/data_manager.py"
click node_mask "https://github.com/cmbscipol/megatop/blob/master/src/megatop/pipeline/mask_handler.py"
click node_mock "https://github.com/cmbscipol/megatop/blob/master/src/megatop/pipeline/mocker.py"
click node_landscape "https://github.com/cmbscipol/megatop/blob/master/src/megatop/landscapes.py"
click node_preprocess "https://github.com/cmbscipol/megatop/blob/master/src/megatop/pipeline/preprocesser.py"
click node_noise_pre "https://github.com/cmbscipol/megatop/blob/master/src/megatop/pipeline/noise_preprocesser.py"
click node_noise_cov "https://github.com/cmbscipol/megatop/blob/master/src/megatop/pipeline/pixel_noisecov_estimater.py"
click node_noise_spectra "https://github.com/cmbscipol/megatop/blob/master/src/megatop/pipeline/noise_spectra_estimater.py"
click node_binning "https://github.com/cmbscipol/megatop/blob/master/src/megatop/pipeline/binner_maker.py"
click node_compsep "https://github.com/cmbscipol/megatop/blob/master/src/megatop/pipeline/parametric_separater.py"
click node_map2cl "https://github.com/cmbscipol/megatop/blob/master/src/megatop/pipeline/map_to_cler.py"
click node_transfer "https://github.com/cmbscipol/megatop/blob/master/src/megatop/pipeline/TF_computation_interface.py"
click node_cl2r "https://github.com/cmbscipol/megatop/blob/master/src/megatop/pipeline/cl2r_estimater.py"
click node_mock_plot "https://github.com/cmbscipol/megatop/blob/master/src/megatop/plot/mock_plotter.py"
click node_preproc_plot "https://github.com/cmbscipol/megatop/blob/master/src/megatop/plot/preproc_plotter.py"
click node_noise_plot "https://github.com/cmbscipol/megatop/blob/master/src/megatop/plot/noise_spectra_plotter.py"
click node_compsep_plot "https://github.com/cmbscipol/megatop/blob/master/src/megatop/plot/comp_sep_plotter.py"
click node_spectra_plot "https://github.com/cmbscipol/megatop/blob/master/src/megatop/plot/map2cl_plotter.py"
click node_r_plot "https://github.com/cmbscipol/megatop/blob/master/src/megatop/plot/r_stats_plotter.py"
click node_mcmc_plot "https://github.com/cmbscipol/megatop/blob/master/src/megatop/plot/mcmc_plotter.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_config,node_manager,node_mask,node_user toneBlue
class node_mock,node_landscape,node_preprocess,node_noise_pre,node_noise_cov,node_outputs toneAmber
class node_noise_spectra,node_binning,node_compsep,node_map2cl,node_transfer,node_cl2r toneMint
class node_mock_plot,node_preproc_plot,node_noise_plot,node_compsep_plot,node_spectra_plot,node_r_plot,node_mcmc_plot toneRose
class node_external_maps toneIndigo
```

## Components

### Inputs and masks

- [Configuration](https://github.com/cmbscipol/megatop/blob/master/src/megatop/config.py): `src/megatop/config.py`
- [Data manager](https://github.com/cmbscipol/megatop/blob/master/src/megatop/data_manager.py): `src/megatop/data_manager.py`
- [Mask handling](https://github.com/cmbscipol/megatop/blob/master/src/megatop/pipeline/mask_handler.py): `src/megatop/pipeline/mask_handler.py`

### Map products

- [Map simulations](https://github.com/cmbscipol/megatop/blob/master/src/megatop/pipeline/mocker.py): `src/megatop/pipeline/mocker.py`
- [Map geometry](https://github.com/cmbscipol/megatop/blob/master/src/megatop/landscapes.py): `src/megatop/landscapes.py`
- [Map preprocessing](https://github.com/cmbscipol/megatop/blob/master/src/megatop/pipeline/preprocesser.py): `src/megatop/pipeline/preprocesser.py`
- [Noise preprocessing](https://github.com/cmbscipol/megatop/blob/master/src/megatop/pipeline/noise_preprocesser.py): `src/megatop/pipeline/noise_preprocesser.py`
- [Pixel noise covariance](https://github.com/cmbscipol/megatop/blob/master/src/megatop/pipeline/pixel_noisecov_estimater.py): `src/megatop/pipeline/pixel_noisecov_estimater.py`

### Spectra and inference

- [Noise spectra](https://github.com/cmbscipol/megatop/blob/master/src/megatop/pipeline/noise_spectra_estimater.py): `src/megatop/pipeline/noise_spectra_estimater.py`
- [Spectral binning](https://github.com/cmbscipol/megatop/blob/master/src/megatop/pipeline/binner_maker.py): `src/megatop/pipeline/binner_maker.py`
- [Component separation](https://github.com/cmbscipol/megatop/blob/master/src/megatop/pipeline/parametric_separater.py): `src/megatop/pipeline/parametric_separater.py`
- [Map to spectra](https://github.com/cmbscipol/megatop/blob/master/src/megatop/pipeline/map_to_cler.py): `src/megatop/pipeline/map_to_cler.py`
- [Transfer functions](https://github.com/cmbscipol/megatop/blob/master/src/megatop/pipeline/TF_computation_interface.py): `src/megatop/pipeline/TF_computation_interface.py`
- [Tensor ratio inference](https://github.com/cmbscipol/megatop/blob/master/src/megatop/pipeline/cl2r_estimater.py): `src/megatop/pipeline/cl2r_estimater.py`

### Plots and reports

- [Simulation plots](https://github.com/cmbscipol/megatop/blob/master/src/megatop/plot/mock_plotter.py): `src/megatop/plot/mock_plotter.py`
- [Preprocessing plots](https://github.com/cmbscipol/megatop/blob/master/src/megatop/plot/preproc_plotter.py): `src/megatop/plot/preproc_plotter.py`
- [Noise spectra plots](https://github.com/cmbscipol/megatop/blob/master/src/megatop/plot/noise_spectra_plotter.py): `src/megatop/plot/noise_spectra_plotter.py`
- [Separation plots](https://github.com/cmbscipol/megatop/blob/master/src/megatop/plot/comp_sep_plotter.py): `src/megatop/plot/comp_sep_plotter.py`
- [Map spectra plots](https://github.com/cmbscipol/megatop/blob/master/src/megatop/plot/map2cl_plotter.py): `src/megatop/plot/map2cl_plotter.py`
- [Inference plots](https://github.com/cmbscipol/megatop/blob/master/src/megatop/plot/r_stats_plotter.py): `src/megatop/plot/r_stats_plotter.py`
- [MCMC plots](https://github.com/cmbscipol/megatop/blob/master/src/megatop/plot/mcmc_plotter.py): `src/megatop/plot/mcmc_plotter.py`

### Other components

- **Pipeline user**
- **Frequency maps**
- **Pipeline data products**

## Connections

- Pipeline user → Configuration: provides settings
- Pipeline user → Mask handling: runs stage
- Pipeline user → Map simulations: runs stage
- Pipeline user → Map preprocessing: runs stage
- Pipeline user → Noise preprocessing: runs stage
- Pipeline user → Pixel noise covariance: runs stage
- Pipeline user → Noise spectra: runs stage
- Pipeline user → Spectral binning: runs stage
- Pipeline user → Component separation: runs stage
- Pipeline user → Map to spectra: runs stage
- Pipeline user → Transfer functions: runs stage
- Pipeline user → Tensor ratio inference: runs stage
- Configuration → Data manager: configures paths
- Data manager → Pipeline data products: creates directories
- Frequency maps → Map preprocessing: map input
- Mask handling → Pipeline data products: writes products
- Map simulations → Map geometry: uses geometry
- Map simulations → Pipeline data products: writes maps
- Map preprocessing → Pipeline data products: writes maps
- Noise preprocessing → Pipeline data products: writes products
- Pixel noise covariance → Pipeline data products: writes covariance
- Noise spectra → Pipeline data products: writes spectra
- Spectral binning → Pipeline data products: writes bins
- Component separation → Pipeline data products: writes results
- Map to spectra → Pipeline data products: writes spectra
- Transfer functions → Pipeline data products: writes functions
- Tensor ratio inference → Pipeline data products: writes chains
- Simulation plots → Pipeline data products: reads products
- Preprocessing plots → Pipeline data products: reads products
- Noise spectra plots → Pipeline data products: reads spectra
- Separation plots → Pipeline data products: reads results
- Map spectra plots → Pipeline data products: reads spectra
- Inference plots → Pipeline data products: reads statistics
- MCMC plots → Pipeline data products: reads chains
