cmbstack 0.0.3__tar.gz → 0.0.4__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,63 @@
1
+ Metadata-Version: 2.4
2
+ Name: cmbstack
3
+ Version: 0.0.4
4
+ Summary: Stack patches of the CMB temperature sky around local maxima
5
+ Author-email: Isaac Alexis López Paredes <isaacalexis.lopezparedes@students.uniroma2.eu>, Anushka Sanjay Tilekar <anushka.tilekar.23@alumni.ucl.ac.uk>
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://github.com/IsaacLP/cmbstack
8
+ Project-URL: Repository, https://github.com/IsaacLP/cmbstack.git
9
+ Classifier: Programming Language :: Python :: 3
10
+ Classifier: Operating System :: OS Independent
11
+ Requires-Python: >=3.8
12
+ Description-Content-Type: text/markdown
13
+ Requires-Dist: numpy
14
+ Requires-Dist: healpy
15
+ Requires-Dist: matplotlib
16
+
17
+ [![Made at Code/Astro](https://img.shields.io/badge/Made%20at-Code/Astro-blueviolet.svg)](https://semaphorep.github.io/codeastro/)
18
+ [![PyPI version](https://img.shields.io/pypi/v/cmbstack.svg)](https://pypi.org/project/cmbstack/)
19
+ [![Python version](https://img.shields.io/pypi/pyversions/cmbstack.svg)](https://pypi.org/project/cmbstack/)
20
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
21
+ ![Development Status](https://img.shields.io/badge/Status-In_Development-brightgreen.svg)
22
+
23
+ # cmbstack
24
+
25
+ Stack patches of the Cosmic Microwave Background (CMB) temperature sky. Go [here](https://cmbstack-docs.readthedocs.io/en/latest/index.html) to see the full documentation and a worked example.
26
+
27
+ ## Installation
28
+
29
+ Install the latest release from PyPI:
30
+
31
+ ```bash
32
+ pip install cmbstack
33
+ ```
34
+
35
+ Or install the development version from GitHub:
36
+
37
+ ```bash
38
+ git clone https://github.com/IsaacLP/cmbstack.git
39
+ cd cmbstack
40
+ pip install -e .
41
+ ```
42
+
43
+ ## Quick Start
44
+
45
+ **From a power spectrum file:**
46
+ ```python
47
+ from cmbstack.main import StackingPipeline
48
+
49
+ pipeline = StackingPipeline.from_cl("path/to/spectrum.cl", nside=1024, seed=42)
50
+ StackedResult = pipeline.run()
51
+ ```
52
+
53
+ **From an existing FITS map:**
54
+ ```python
55
+ pipeline = StackingPipeline.from_fits("path/to/map.fits", field=0)
56
+ StackedResult = pipeline.run()
57
+ ```
58
+
59
+ **From a map array already in memory:**
60
+ ```python
61
+ pipeline = StackingPipeline.from_map(sky_map)
62
+ StackedResult = pipeline.run()
63
+ ```
@@ -0,0 +1,47 @@
1
+ [![Made at Code/Astro](https://img.shields.io/badge/Made%20at-Code/Astro-blueviolet.svg)](https://semaphorep.github.io/codeastro/)
2
+ [![PyPI version](https://img.shields.io/pypi/v/cmbstack.svg)](https://pypi.org/project/cmbstack/)
3
+ [![Python version](https://img.shields.io/pypi/pyversions/cmbstack.svg)](https://pypi.org/project/cmbstack/)
4
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
5
+ ![Development Status](https://img.shields.io/badge/Status-In_Development-brightgreen.svg)
6
+
7
+ # cmbstack
8
+
9
+ Stack patches of the Cosmic Microwave Background (CMB) temperature sky. Go [here](https://cmbstack-docs.readthedocs.io/en/latest/index.html) to see the full documentation and a worked example.
10
+
11
+ ## Installation
12
+
13
+ Install the latest release from PyPI:
14
+
15
+ ```bash
16
+ pip install cmbstack
17
+ ```
18
+
19
+ Or install the development version from GitHub:
20
+
21
+ ```bash
22
+ git clone https://github.com/IsaacLP/cmbstack.git
23
+ cd cmbstack
24
+ pip install -e .
25
+ ```
26
+
27
+ ## Quick Start
28
+
29
+ **From a power spectrum file:**
30
+ ```python
31
+ from cmbstack.main import StackingPipeline
32
+
33
+ pipeline = StackingPipeline.from_cl("path/to/spectrum.cl", nside=1024, seed=42)
34
+ StackedResult = pipeline.run()
35
+ ```
36
+
37
+ **From an existing FITS map:**
38
+ ```python
39
+ pipeline = StackingPipeline.from_fits("path/to/map.fits", field=0)
40
+ StackedResult = pipeline.run()
41
+ ```
42
+
43
+ **From a map array already in memory:**
44
+ ```python
45
+ pipeline = StackingPipeline.from_map(sky_map)
46
+ StackedResult = pipeline.run()
47
+ ```
@@ -0,0 +1,63 @@
1
+ Metadata-Version: 2.4
2
+ Name: cmbstack
3
+ Version: 0.0.4
4
+ Summary: Stack patches of the CMB temperature sky around local maxima
5
+ Author-email: Isaac Alexis López Paredes <isaacalexis.lopezparedes@students.uniroma2.eu>, Anushka Sanjay Tilekar <anushka.tilekar.23@alumni.ucl.ac.uk>
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://github.com/IsaacLP/cmbstack
8
+ Project-URL: Repository, https://github.com/IsaacLP/cmbstack.git
9
+ Classifier: Programming Language :: Python :: 3
10
+ Classifier: Operating System :: OS Independent
11
+ Requires-Python: >=3.8
12
+ Description-Content-Type: text/markdown
13
+ Requires-Dist: numpy
14
+ Requires-Dist: healpy
15
+ Requires-Dist: matplotlib
16
+
17
+ [![Made at Code/Astro](https://img.shields.io/badge/Made%20at-Code/Astro-blueviolet.svg)](https://semaphorep.github.io/codeastro/)
18
+ [![PyPI version](https://img.shields.io/pypi/v/cmbstack.svg)](https://pypi.org/project/cmbstack/)
19
+ [![Python version](https://img.shields.io/pypi/pyversions/cmbstack.svg)](https://pypi.org/project/cmbstack/)
20
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
21
+ ![Development Status](https://img.shields.io/badge/Status-In_Development-brightgreen.svg)
22
+
23
+ # cmbstack
24
+
25
+ Stack patches of the Cosmic Microwave Background (CMB) temperature sky. Go [here](https://cmbstack-docs.readthedocs.io/en/latest/index.html) to see the full documentation and a worked example.
26
+
27
+ ## Installation
28
+
29
+ Install the latest release from PyPI:
30
+
31
+ ```bash
32
+ pip install cmbstack
33
+ ```
34
+
35
+ Or install the development version from GitHub:
36
+
37
+ ```bash
38
+ git clone https://github.com/IsaacLP/cmbstack.git
39
+ cd cmbstack
40
+ pip install -e .
41
+ ```
42
+
43
+ ## Quick Start
44
+
45
+ **From a power spectrum file:**
46
+ ```python
47
+ from cmbstack.main import StackingPipeline
48
+
49
+ pipeline = StackingPipeline.from_cl("path/to/spectrum.cl", nside=1024, seed=42)
50
+ StackedResult = pipeline.run()
51
+ ```
52
+
53
+ **From an existing FITS map:**
54
+ ```python
55
+ pipeline = StackingPipeline.from_fits("path/to/map.fits", field=0)
56
+ StackedResult = pipeline.run()
57
+ ```
58
+
59
+ **From a map array already in memory:**
60
+ ```python
61
+ pipeline = StackingPipeline.from_map(sky_map)
62
+ StackedResult = pipeline.run()
63
+ ```
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "cmbstack"
7
- version = "0.0.3"
7
+ version = "0.0.4"
8
8
  description = "Stack patches of the CMB temperature sky around local maxima"
9
9
  readme = "README.md"
10
10
  authors = [
cmbstack-0.0.3/PKG-INFO DELETED
@@ -1,173 +0,0 @@
1
- Metadata-Version: 2.4
2
- Name: cmbstack
3
- Version: 0.0.3
4
- Summary: Stack patches of the CMB temperature sky around local maxima
5
- Author-email: Isaac Alexis López Paredes <isaacalexis.lopezparedes@students.uniroma2.eu>, Anushka Sanjay Tilekar <anushka.tilekar.23@alumni.ucl.ac.uk>
6
- License-Expression: MIT
7
- Project-URL: Homepage, https://github.com/IsaacLP/cmbstack
8
- Project-URL: Repository, https://github.com/IsaacLP/cmbstack.git
9
- Classifier: Programming Language :: Python :: 3
10
- Classifier: Operating System :: OS Independent
11
- Requires-Python: >=3.8
12
- Description-Content-Type: text/markdown
13
- Requires-Dist: numpy
14
- Requires-Dist: healpy
15
- Requires-Dist: matplotlib
16
-
17
- [![Made at Code/Astro](https://img.shields.io/badge/Made%20at-Code/Astro-blueviolet.svg)](https://semaphorep.github.io/codeastro/)
18
- [![PyPI version](https://img.shields.io/pypi/v/cmbstack.svg)](https://pypi.org/project/cmbstack/)
19
- [![Python version](https://img.shields.io/pypi/pyversions/cmbstack.svg)](https://pypi.org/project/cmbstack/)
20
- [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
21
- ![Development Status](https://img.shields.io/badge/Status-In_Development-brightgreen.svg)
22
-
23
- # cmbstack
24
-
25
- `cmbstack` is a Python package for stacking patches of the Cosmic Microwave Background (CMB) temperature sky. It accepts input as a theoretical power spectrum, a [HEALPix](https://healpy.readthedocs.io/en/latest/index.html) FITS file, or a map array already in memory. From there it detects local maxima, extracts gnomonic (flat-sky) patches around each peak, and averages them. This stacking procedure enhances the coherent peak profile while suppressing uncorrelated noise.
26
-
27
- ## Installation
28
-
29
- ```bash
30
- pip install cmbstack
31
- ```
32
-
33
- ## Quick Start
34
-
35
- **From a power spectrum file:**
36
- ```python
37
- from cmbstack.main import StackingPipeline
38
-
39
- pipeline = StackingPipeline.from_cl("path/to/spectrum.dat", nside=1024, seed=42)
40
- pipeline.run()
41
- ```
42
-
43
- **From an existing FITS map:**
44
- ```python
45
- pipeline = StackingPipeline.from_fits("path/to/map.fits", field=0)
46
- pipeline.run()
47
- ```
48
-
49
- **From a map array already in memory:**
50
- ```python
51
- pipeline = StackingPipeline.from_map(sky_map)
52
- pipeline.run()
53
- ```
54
-
55
- See `examples/from_theoretical_cl.ipynb` for a full worked example.
56
-
57
- ## Package Structure
58
-
59
- ```
60
- cmbstack/
61
- ├── maps.py — power-spectrum loading, map simulation, normalisation
62
- ├── stacking.py — peak finding, patch extraction, stacking, radial profile
63
- └── main.py — StackingPipeline high-level class
64
- ```
65
-
66
- ## Workflow
67
-
68
- > **Note:** Steps 1–2 apply when starting from a power spectrum. Use `StackingPipeline.from_fits` or `from_map` to skip them when working with a real or pre-simulated map.
69
-
70
- ### 1. Load the Power Spectrum — `maps.load_cl`
71
-
72
- The input file contains the power spectrum as $D_\ell^{TT}$:
73
-
74
- $$D_\ell \equiv \frac{\ell(\ell+1)}{2\pi} C_\ell$$
75
-
76
- `load_cl` reads columns $(\ell, D_\ell)$ and converts to $C_\ell$:
77
-
78
- $$C_\ell = \frac{2\pi}{\ell(\ell+1)} D_\ell, \qquad C_0 = C_1 = 0$$
79
-
80
- ---
81
-
82
- ### 2. Simulate a Sky Map — `maps.simulate_map`
83
-
84
- A Gaussian random realization is drawn by sampling spherical harmonic coefficients $a_{\ell m}$ with variance $C_\ell$:
85
-
86
- $$T(\hat{n}) = \sum_{\ell,m} a_{\ell m} \, Y_{\ell m}(\hat{n}), \qquad \langle |a_{\ell m}|^2 \rangle = C_\ell$$
87
-
88
- This calls `healpy.synfast` internally. An optional `seed` makes runs reproducible.
89
-
90
- ---
91
-
92
- ### 3. Normalise the Map — `maps.normalize_map`
93
-
94
- Before peak detection, the map is standardised so that thresholds have a clear statistical meaning:
95
-
96
- $$T_{\text{norm}}(\hat{n}) = \frac{T(\hat{n}) - \langle T \rangle}{\sigma}$$
97
-
98
- After this step the map has mean $\approx 0$ and standard deviation $= 1$, so peaks are measured in units of $\sigma$.
99
-
100
- ---
101
-
102
- ### 4. Detect Peaks — `stacking.find_peaks`
103
-
104
- Local maxima are identified with `healpy.hotspots`: a pixel is a maximum if its value exceeds every immediate HEALPix neighbour. Peaks are filtered by a significance threshold $\nu$ (default $\nu = 3\sigma$) and optionally capped at the $N$ highest:
105
-
106
- $$\text{Peaks} = \{\hat{n}_p \in \text{Maxima} \mid T_{\text{norm}}(\hat{n}_p) > \nu\}$$
107
-
108
- Returns sky positions as $(θ, φ)$ pairs in radians.
109
-
110
- ---
111
-
112
- ### 5. Extract Patches — `stacking.extract_patches`
113
-
114
- For each peak a square patch is cut using a gnomonic (tangent-plane) projection centred on $\hat{n}_p$. Every patch shares the same fixed pixel grid (side length `size_deg`, pixel scale `reso_arcmin`), so the centre pixel always corresponds to the peak itself and patches can be co-added directly.
115
-
116
- ---
117
-
118
- ### 6. Stack — `stacking.stack_patches`
119
-
120
- Patches are averaged pixel-by-pixel:
121
-
122
- $$S = \frac{1}{N} \sum_{i=1}^{N} P_i$$
123
-
124
- Incoherent noise averages towards zero; the coherent central profile survives.
125
-
126
- ---
127
-
128
- ### 7. Radial Profile — `stacking.radial_profile`
129
-
130
- The 2D stacked image is collapsed to a 1D profile by azimuthal averaging in concentric annuli about the centre. Returns bin-centre radii in arcminutes and the mean temperature in each annulus.
131
-
132
- ---
133
-
134
- ## Pipeline Constructors
135
-
136
- `StackingPipeline` provides three entry points depending on where your data comes from:
137
-
138
- | Constructor | Input | Notes |
139
- |---|---|---|
140
- | `from_cl(path, nside, seed)` | Power-spectrum file | Simulates a Gaussian random map via `healpy.synfast` |
141
- | `from_fits(path, field=0)` | HEALPix FITS file | Loads the map with `maps.load_map`; `nside` is inferred automatically |
142
- | `from_map(sky_map)` | NumPy array | Accepts any in-memory HEALPix map; `nside` is inferred automatically |
143
-
144
- All three store the map in `pipeline.map` and share the same `run()` interface.
145
-
146
- ---
147
-
148
- ## Map I/O Utilities
149
-
150
- `maps.load_map` and `maps.save_map` wrap the healpy FITS readers for convenience:
151
-
152
- ```python
153
- from cmbstack import maps
154
-
155
- m = maps.load_map("map.fits", field=0) # wraps hp.read_map
156
- maps.save_map("out.fits", m) # wraps hp.write_map (overwrite=True by default)
157
- ```
158
-
159
- ---
160
-
161
- ## Pipeline Object
162
-
163
- `StackingPipeline` stores every intermediate product as an attribute:
164
-
165
- | Attribute | Content |
166
- |---|---|
167
- | `pipeline.map` | Raw simulated map |
168
- | `pipeline.normalized` | Normalised map (units of $\sigma$) |
169
- | `pipeline.positions` | Peak positions $(θ, φ)$ in radians |
170
- | `pipeline.patches` | List of 2D gnomonic patches |
171
- | `pipeline.stacked` | Mean stacked 2D image |
172
- | `pipeline.radius` | Radial bin centres (arcmin) |
173
- | `pipeline.profile` | Mean temperature per radial bin |
cmbstack-0.0.3/README.md DELETED
@@ -1,157 +0,0 @@
1
- [![Made at Code/Astro](https://img.shields.io/badge/Made%20at-Code/Astro-blueviolet.svg)](https://semaphorep.github.io/codeastro/)
2
- [![PyPI version](https://img.shields.io/pypi/v/cmbstack.svg)](https://pypi.org/project/cmbstack/)
3
- [![Python version](https://img.shields.io/pypi/pyversions/cmbstack.svg)](https://pypi.org/project/cmbstack/)
4
- [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
5
- ![Development Status](https://img.shields.io/badge/Status-In_Development-brightgreen.svg)
6
-
7
- # cmbstack
8
-
9
- `cmbstack` is a Python package for stacking patches of the Cosmic Microwave Background (CMB) temperature sky. It accepts input as a theoretical power spectrum, a [HEALPix](https://healpy.readthedocs.io/en/latest/index.html) FITS file, or a map array already in memory. From there it detects local maxima, extracts gnomonic (flat-sky) patches around each peak, and averages them. This stacking procedure enhances the coherent peak profile while suppressing uncorrelated noise.
10
-
11
- ## Installation
12
-
13
- ```bash
14
- pip install cmbstack
15
- ```
16
-
17
- ## Quick Start
18
-
19
- **From a power spectrum file:**
20
- ```python
21
- from cmbstack.main import StackingPipeline
22
-
23
- pipeline = StackingPipeline.from_cl("path/to/spectrum.dat", nside=1024, seed=42)
24
- pipeline.run()
25
- ```
26
-
27
- **From an existing FITS map:**
28
- ```python
29
- pipeline = StackingPipeline.from_fits("path/to/map.fits", field=0)
30
- pipeline.run()
31
- ```
32
-
33
- **From a map array already in memory:**
34
- ```python
35
- pipeline = StackingPipeline.from_map(sky_map)
36
- pipeline.run()
37
- ```
38
-
39
- See `examples/from_theoretical_cl.ipynb` for a full worked example.
40
-
41
- ## Package Structure
42
-
43
- ```
44
- cmbstack/
45
- ├── maps.py — power-spectrum loading, map simulation, normalisation
46
- ├── stacking.py — peak finding, patch extraction, stacking, radial profile
47
- └── main.py — StackingPipeline high-level class
48
- ```
49
-
50
- ## Workflow
51
-
52
- > **Note:** Steps 1–2 apply when starting from a power spectrum. Use `StackingPipeline.from_fits` or `from_map` to skip them when working with a real or pre-simulated map.
53
-
54
- ### 1. Load the Power Spectrum — `maps.load_cl`
55
-
56
- The input file contains the power spectrum as $D_\ell^{TT}$:
57
-
58
- $$D_\ell \equiv \frac{\ell(\ell+1)}{2\pi} C_\ell$$
59
-
60
- `load_cl` reads columns $(\ell, D_\ell)$ and converts to $C_\ell$:
61
-
62
- $$C_\ell = \frac{2\pi}{\ell(\ell+1)} D_\ell, \qquad C_0 = C_1 = 0$$
63
-
64
- ---
65
-
66
- ### 2. Simulate a Sky Map — `maps.simulate_map`
67
-
68
- A Gaussian random realization is drawn by sampling spherical harmonic coefficients $a_{\ell m}$ with variance $C_\ell$:
69
-
70
- $$T(\hat{n}) = \sum_{\ell,m} a_{\ell m} \, Y_{\ell m}(\hat{n}), \qquad \langle |a_{\ell m}|^2 \rangle = C_\ell$$
71
-
72
- This calls `healpy.synfast` internally. An optional `seed` makes runs reproducible.
73
-
74
- ---
75
-
76
- ### 3. Normalise the Map — `maps.normalize_map`
77
-
78
- Before peak detection, the map is standardised so that thresholds have a clear statistical meaning:
79
-
80
- $$T_{\text{norm}}(\hat{n}) = \frac{T(\hat{n}) - \langle T \rangle}{\sigma}$$
81
-
82
- After this step the map has mean $\approx 0$ and standard deviation $= 1$, so peaks are measured in units of $\sigma$.
83
-
84
- ---
85
-
86
- ### 4. Detect Peaks — `stacking.find_peaks`
87
-
88
- Local maxima are identified with `healpy.hotspots`: a pixel is a maximum if its value exceeds every immediate HEALPix neighbour. Peaks are filtered by a significance threshold $\nu$ (default $\nu = 3\sigma$) and optionally capped at the $N$ highest:
89
-
90
- $$\text{Peaks} = \{\hat{n}_p \in \text{Maxima} \mid T_{\text{norm}}(\hat{n}_p) > \nu\}$$
91
-
92
- Returns sky positions as $(θ, φ)$ pairs in radians.
93
-
94
- ---
95
-
96
- ### 5. Extract Patches — `stacking.extract_patches`
97
-
98
- For each peak a square patch is cut using a gnomonic (tangent-plane) projection centred on $\hat{n}_p$. Every patch shares the same fixed pixel grid (side length `size_deg`, pixel scale `reso_arcmin`), so the centre pixel always corresponds to the peak itself and patches can be co-added directly.
99
-
100
- ---
101
-
102
- ### 6. Stack — `stacking.stack_patches`
103
-
104
- Patches are averaged pixel-by-pixel:
105
-
106
- $$S = \frac{1}{N} \sum_{i=1}^{N} P_i$$
107
-
108
- Incoherent noise averages towards zero; the coherent central profile survives.
109
-
110
- ---
111
-
112
- ### 7. Radial Profile — `stacking.radial_profile`
113
-
114
- The 2D stacked image is collapsed to a 1D profile by azimuthal averaging in concentric annuli about the centre. Returns bin-centre radii in arcminutes and the mean temperature in each annulus.
115
-
116
- ---
117
-
118
- ## Pipeline Constructors
119
-
120
- `StackingPipeline` provides three entry points depending on where your data comes from:
121
-
122
- | Constructor | Input | Notes |
123
- |---|---|---|
124
- | `from_cl(path, nside, seed)` | Power-spectrum file | Simulates a Gaussian random map via `healpy.synfast` |
125
- | `from_fits(path, field=0)` | HEALPix FITS file | Loads the map with `maps.load_map`; `nside` is inferred automatically |
126
- | `from_map(sky_map)` | NumPy array | Accepts any in-memory HEALPix map; `nside` is inferred automatically |
127
-
128
- All three store the map in `pipeline.map` and share the same `run()` interface.
129
-
130
- ---
131
-
132
- ## Map I/O Utilities
133
-
134
- `maps.load_map` and `maps.save_map` wrap the healpy FITS readers for convenience:
135
-
136
- ```python
137
- from cmbstack import maps
138
-
139
- m = maps.load_map("map.fits", field=0) # wraps hp.read_map
140
- maps.save_map("out.fits", m) # wraps hp.write_map (overwrite=True by default)
141
- ```
142
-
143
- ---
144
-
145
- ## Pipeline Object
146
-
147
- `StackingPipeline` stores every intermediate product as an attribute:
148
-
149
- | Attribute | Content |
150
- |---|---|
151
- | `pipeline.map` | Raw simulated map |
152
- | `pipeline.normalized` | Normalised map (units of $\sigma$) |
153
- | `pipeline.positions` | Peak positions $(θ, φ)$ in radians |
154
- | `pipeline.patches` | List of 2D gnomonic patches |
155
- | `pipeline.stacked` | Mean stacked 2D image |
156
- | `pipeline.radius` | Radial bin centres (arcmin) |
157
- | `pipeline.profile` | Mean temperature per radial bin |
@@ -1,173 +0,0 @@
1
- Metadata-Version: 2.4
2
- Name: cmbstack
3
- Version: 0.0.3
4
- Summary: Stack patches of the CMB temperature sky around local maxima
5
- Author-email: Isaac Alexis López Paredes <isaacalexis.lopezparedes@students.uniroma2.eu>, Anushka Sanjay Tilekar <anushka.tilekar.23@alumni.ucl.ac.uk>
6
- License-Expression: MIT
7
- Project-URL: Homepage, https://github.com/IsaacLP/cmbstack
8
- Project-URL: Repository, https://github.com/IsaacLP/cmbstack.git
9
- Classifier: Programming Language :: Python :: 3
10
- Classifier: Operating System :: OS Independent
11
- Requires-Python: >=3.8
12
- Description-Content-Type: text/markdown
13
- Requires-Dist: numpy
14
- Requires-Dist: healpy
15
- Requires-Dist: matplotlib
16
-
17
- [![Made at Code/Astro](https://img.shields.io/badge/Made%20at-Code/Astro-blueviolet.svg)](https://semaphorep.github.io/codeastro/)
18
- [![PyPI version](https://img.shields.io/pypi/v/cmbstack.svg)](https://pypi.org/project/cmbstack/)
19
- [![Python version](https://img.shields.io/pypi/pyversions/cmbstack.svg)](https://pypi.org/project/cmbstack/)
20
- [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
21
- ![Development Status](https://img.shields.io/badge/Status-In_Development-brightgreen.svg)
22
-
23
- # cmbstack
24
-
25
- `cmbstack` is a Python package for stacking patches of the Cosmic Microwave Background (CMB) temperature sky. It accepts input as a theoretical power spectrum, a [HEALPix](https://healpy.readthedocs.io/en/latest/index.html) FITS file, or a map array already in memory. From there it detects local maxima, extracts gnomonic (flat-sky) patches around each peak, and averages them. This stacking procedure enhances the coherent peak profile while suppressing uncorrelated noise.
26
-
27
- ## Installation
28
-
29
- ```bash
30
- pip install cmbstack
31
- ```
32
-
33
- ## Quick Start
34
-
35
- **From a power spectrum file:**
36
- ```python
37
- from cmbstack.main import StackingPipeline
38
-
39
- pipeline = StackingPipeline.from_cl("path/to/spectrum.dat", nside=1024, seed=42)
40
- pipeline.run()
41
- ```
42
-
43
- **From an existing FITS map:**
44
- ```python
45
- pipeline = StackingPipeline.from_fits("path/to/map.fits", field=0)
46
- pipeline.run()
47
- ```
48
-
49
- **From a map array already in memory:**
50
- ```python
51
- pipeline = StackingPipeline.from_map(sky_map)
52
- pipeline.run()
53
- ```
54
-
55
- See `examples/from_theoretical_cl.ipynb` for a full worked example.
56
-
57
- ## Package Structure
58
-
59
- ```
60
- cmbstack/
61
- ├── maps.py — power-spectrum loading, map simulation, normalisation
62
- ├── stacking.py — peak finding, patch extraction, stacking, radial profile
63
- └── main.py — StackingPipeline high-level class
64
- ```
65
-
66
- ## Workflow
67
-
68
- > **Note:** Steps 1–2 apply when starting from a power spectrum. Use `StackingPipeline.from_fits` or `from_map` to skip them when working with a real or pre-simulated map.
69
-
70
- ### 1. Load the Power Spectrum — `maps.load_cl`
71
-
72
- The input file contains the power spectrum as $D_\ell^{TT}$:
73
-
74
- $$D_\ell \equiv \frac{\ell(\ell+1)}{2\pi} C_\ell$$
75
-
76
- `load_cl` reads columns $(\ell, D_\ell)$ and converts to $C_\ell$:
77
-
78
- $$C_\ell = \frac{2\pi}{\ell(\ell+1)} D_\ell, \qquad C_0 = C_1 = 0$$
79
-
80
- ---
81
-
82
- ### 2. Simulate a Sky Map — `maps.simulate_map`
83
-
84
- A Gaussian random realization is drawn by sampling spherical harmonic coefficients $a_{\ell m}$ with variance $C_\ell$:
85
-
86
- $$T(\hat{n}) = \sum_{\ell,m} a_{\ell m} \, Y_{\ell m}(\hat{n}), \qquad \langle |a_{\ell m}|^2 \rangle = C_\ell$$
87
-
88
- This calls `healpy.synfast` internally. An optional `seed` makes runs reproducible.
89
-
90
- ---
91
-
92
- ### 3. Normalise the Map — `maps.normalize_map`
93
-
94
- Before peak detection, the map is standardised so that thresholds have a clear statistical meaning:
95
-
96
- $$T_{\text{norm}}(\hat{n}) = \frac{T(\hat{n}) - \langle T \rangle}{\sigma}$$
97
-
98
- After this step the map has mean $\approx 0$ and standard deviation $= 1$, so peaks are measured in units of $\sigma$.
99
-
100
- ---
101
-
102
- ### 4. Detect Peaks — `stacking.find_peaks`
103
-
104
- Local maxima are identified with `healpy.hotspots`: a pixel is a maximum if its value exceeds every immediate HEALPix neighbour. Peaks are filtered by a significance threshold $\nu$ (default $\nu = 3\sigma$) and optionally capped at the $N$ highest:
105
-
106
- $$\text{Peaks} = \{\hat{n}_p \in \text{Maxima} \mid T_{\text{norm}}(\hat{n}_p) > \nu\}$$
107
-
108
- Returns sky positions as $(θ, φ)$ pairs in radians.
109
-
110
- ---
111
-
112
- ### 5. Extract Patches — `stacking.extract_patches`
113
-
114
- For each peak a square patch is cut using a gnomonic (tangent-plane) projection centred on $\hat{n}_p$. Every patch shares the same fixed pixel grid (side length `size_deg`, pixel scale `reso_arcmin`), so the centre pixel always corresponds to the peak itself and patches can be co-added directly.
115
-
116
- ---
117
-
118
- ### 6. Stack — `stacking.stack_patches`
119
-
120
- Patches are averaged pixel-by-pixel:
121
-
122
- $$S = \frac{1}{N} \sum_{i=1}^{N} P_i$$
123
-
124
- Incoherent noise averages towards zero; the coherent central profile survives.
125
-
126
- ---
127
-
128
- ### 7. Radial Profile — `stacking.radial_profile`
129
-
130
- The 2D stacked image is collapsed to a 1D profile by azimuthal averaging in concentric annuli about the centre. Returns bin-centre radii in arcminutes and the mean temperature in each annulus.
131
-
132
- ---
133
-
134
- ## Pipeline Constructors
135
-
136
- `StackingPipeline` provides three entry points depending on where your data comes from:
137
-
138
- | Constructor | Input | Notes |
139
- |---|---|---|
140
- | `from_cl(path, nside, seed)` | Power-spectrum file | Simulates a Gaussian random map via `healpy.synfast` |
141
- | `from_fits(path, field=0)` | HEALPix FITS file | Loads the map with `maps.load_map`; `nside` is inferred automatically |
142
- | `from_map(sky_map)` | NumPy array | Accepts any in-memory HEALPix map; `nside` is inferred automatically |
143
-
144
- All three store the map in `pipeline.map` and share the same `run()` interface.
145
-
146
- ---
147
-
148
- ## Map I/O Utilities
149
-
150
- `maps.load_map` and `maps.save_map` wrap the healpy FITS readers for convenience:
151
-
152
- ```python
153
- from cmbstack import maps
154
-
155
- m = maps.load_map("map.fits", field=0) # wraps hp.read_map
156
- maps.save_map("out.fits", m) # wraps hp.write_map (overwrite=True by default)
157
- ```
158
-
159
- ---
160
-
161
- ## Pipeline Object
162
-
163
- `StackingPipeline` stores every intermediate product as an attribute:
164
-
165
- | Attribute | Content |
166
- |---|---|
167
- | `pipeline.map` | Raw simulated map |
168
- | `pipeline.normalized` | Normalised map (units of $\sigma$) |
169
- | `pipeline.positions` | Peak positions $(θ, φ)$ in radians |
170
- | `pipeline.patches` | List of 2D gnomonic patches |
171
- | `pipeline.stacked` | Mean stacked 2D image |
172
- | `pipeline.radius` | Radial bin centres (arcmin) |
173
- | `pipeline.profile` | Mean temperature per radial bin |
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes