# XXIOP: Cosmological 21cm Signal Toolkit
[](https://badge.fury.io/py/xxiop)
[](https://opensource.org/licenses/MIT)
`xxiop` is a Python package designed for researchers in cosmology to perform calculations related to the 21cm signal from the Epoch of Reionization. It provides tools to compute the Thomson scattering optical depth and to calculate, analyze, and visualize the 21cm brightness temperature power spectrum from given cosmological fields.
## Features
- **Thomson Optical Depth**: Calculate the optical depth from a given reionization history (ionization fraction vs. redshift).
- **21cm Brightness Temperature**: Compute the 21cm brightness temperature ($\delta T_b$) field from matter density and ionization fraction fields.
- **Power Spectrum Analysis**: Calculate the dimensionless power spectrum $\Delta^2(k)$ of the 21cm signal or any other 3D field.
- **Visualization**: Integrated plotting functions to visualize 2D slices of ionization and 21cm fields, and to plot the resulting power spectrum with error bars.
- **Customizable Cosmology**: Easily set custom cosmological parameters (`h`, `omegam`, `ns`, `sigma8`) for all calculations.
## Installation
You can install `xxiop` directly from PyPI:
```bash
pip install xxiop
```
## Core Dependencies
The package relies on the following scientific libraries:
- `numpy`
- `scipy`
- `astropy`
- `matplotlib`
- `massfunc`
All dependencies will be automatically installed via pip.
## Usage Examples
Here are some basic examples of how to use the core functionalities of the `xxiop` package.
### 1. Calculate Thomson Optical Depth
You can calculate the integrated optical depth up to a certain redshift given a reionization history.
```python
import numpy as np
from xxiop.op import OpticalDepth
# 1. Define a sample reionization history (ionization fraction vs. redshift)
z_history = np.linspace(5, 15, 100)
# Mock ionization fraction: starts near 0, ends near 1
ionf_history = 1.0 / (1.0 + np.exp((z_history - 10) / 1.0))
# 2. Initialize the calculator with this history
# You can also provide custom cosmological parameters, e.g., h=0.67, omegam=0.32
tau_calculator = OpticalDepth(z=z_history, ionf=ionf_history)
# 3. Calculate the optical depth up to z=7.5
z_target = 7.5
tau = tau_calculator.OpticalDepth(z=z_target)
print(f"Thomson Optical Depth (τ) at z={z_target}: {tau:.4f}")
```
### 2. Calculate 21cm Power Spectrum
Given 3D cubes of the matter density field and ionization fraction, you can compute and plot the 21cm power spectrum.
```python
import numpy as np
from xxiop.op import XXIPowerSpectrum
# 1. Generate mock 3D cosmological fields
box_dim = 128 # Grid dimension
box_length_mpc = 200.0 # Box size in Mpc/h
# Mock matter density contrast field: delta_R = (rho / rho_bar) - 1
delta_r_field = np.random.randn(box_dim, box_dim, box_dim)
# Mock ionization fraction field (0=neutral, 1=ionized)
# Create a simple ionized bubble in the center
ion_fraction_field = np.zeros((box_dim, box_dim, box_dim))
center, radius = box_dim // 2, 30
x, y, z = np.ogrid[:box_dim, :box_dim, :box_dim]
mask = (x - center)**2 + (y - center)**2 + (z - center)**2 < radius**2
ion_fraction_field[mask] = 1.0
# 2. Initialize the power spectrum calculator
ps_calculator = XXIPowerSpectrum(h=0.674, omegam=0.315)
# 3. Calculate the 21cm brightness temperature field
# This is an intermediate step, but useful for visualization
z_snapshot = 8.0
delta_tb_field = ps_calculator.XXI_Field(
z=z_snapshot,
deltaR=delta_r_field,
ionf=ion_fraction_field
)
# 4. Calculate the power spectrum from the 21cm field
# The PowerSpectrum method takes the 3D field and box length as input
k, delta_sq, error = ps_calculator.PowerSpectrum(
field=delta_tb_field,
box_length=box_length_mpc,
num_bins=30 # Optional: number of bins for k
)
print("Power spectrum calculation complete.")
print(f"k (h/Mpc):\n{k[:5]}")
print(f"Δ^2(k) (mK^2):\n{delta_sq[:5]}")
# 5. Use the built-in plotting function to visualize the result
# This will also save a plot to the 'figure_deltaTb/' directory
ps_calculator.PowerSpectrumPlot(
field=delta_tb_field,
box_length=box_length_mpc,
label=f'Power Spectrum at z={z_snapshot}'
)
print("Plot saved to figure_deltaTb/PowerSpectrum_...png")
```
## License
This project is licensed under the MIT License. See the `LICENSE` file for details.
Raw data
{
"_id": null,
"home_page": null,
"name": "xxiop",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.7",
"maintainer_email": null,
"keywords": "cosmology, power spectrum, 21cm, optical depth, astrophysics",
"author": null,
"author_email": "Hajime Hinata <onmyojiflow@gmail.com>",
"download_url": "https://files.pythonhosted.org/packages/d5/b4/08b767a03c600ea9b530871577069db403a0dd8d981212d9f5af562a433e/xxiop-1.0.1.tar.gz",
"platform": null,
"description": "# XXIOP: Cosmological 21cm Signal Toolkit\n\n[](https://badge.fury.io/py/xxiop)\n[](https://opensource.org/licenses/MIT)\n\n`xxiop` is a Python package designed for researchers in cosmology to perform calculations related to the 21cm signal from the Epoch of Reionization. It provides tools to compute the Thomson scattering optical depth and to calculate, analyze, and visualize the 21cm brightness temperature power spectrum from given cosmological fields.\n\n## Features\n\n- **Thomson Optical Depth**: Calculate the optical depth from a given reionization history (ionization fraction vs. redshift).\n- **21cm Brightness Temperature**: Compute the 21cm brightness temperature ($\\delta T_b$) field from matter density and ionization fraction fields.\n- **Power Spectrum Analysis**: Calculate the dimensionless power spectrum $\\Delta^2(k)$ of the 21cm signal or any other 3D field.\n- **Visualization**: Integrated plotting functions to visualize 2D slices of ionization and 21cm fields, and to plot the resulting power spectrum with error bars.\n- **Customizable Cosmology**: Easily set custom cosmological parameters (`h`, `omegam`, `ns`, `sigma8`) for all calculations.\n\n## Installation\n\nYou can install `xxiop` directly from PyPI:\n\n```bash\npip install xxiop\n```\n\n## Core Dependencies\n\nThe package relies on the following scientific libraries:\n- `numpy`\n- `scipy`\n- `astropy`\n- `matplotlib`\n- `massfunc`\n\nAll dependencies will be automatically installed via pip.\n\n## Usage Examples\n\nHere are some basic examples of how to use the core functionalities of the `xxiop` package.\n\n### 1. Calculate Thomson Optical Depth\n\nYou can calculate the integrated optical depth up to a certain redshift given a reionization history.\n\n```python\nimport numpy as np\nfrom xxiop.op import OpticalDepth\n\n# 1. Define a sample reionization history (ionization fraction vs. redshift)\nz_history = np.linspace(5, 15, 100)\n# Mock ionization fraction: starts near 0, ends near 1\nionf_history = 1.0 / (1.0 + np.exp((z_history - 10) / 1.0))\n\n# 2. Initialize the calculator with this history\n# You can also provide custom cosmological parameters, e.g., h=0.67, omegam=0.32\ntau_calculator = OpticalDepth(z=z_history, ionf=ionf_history)\n\n# 3. Calculate the optical depth up to z=7.5\nz_target = 7.5\ntau = tau_calculator.OpticalDepth(z=z_target)\n\nprint(f\"Thomson Optical Depth (\u03c4) at z={z_target}: {tau:.4f}\")\n```\n\n### 2. Calculate 21cm Power Spectrum\n\nGiven 3D cubes of the matter density field and ionization fraction, you can compute and plot the 21cm power spectrum.\n\n```python\nimport numpy as np\nfrom xxiop.op import XXIPowerSpectrum\n\n# 1. Generate mock 3D cosmological fields\nbox_dim = 128 # Grid dimension\nbox_length_mpc = 200.0 # Box size in Mpc/h\n\n# Mock matter density contrast field: delta_R = (rho / rho_bar) - 1\ndelta_r_field = np.random.randn(box_dim, box_dim, box_dim)\n\n# Mock ionization fraction field (0=neutral, 1=ionized)\n# Create a simple ionized bubble in the center\nion_fraction_field = np.zeros((box_dim, box_dim, box_dim))\ncenter, radius = box_dim // 2, 30\nx, y, z = np.ogrid[:box_dim, :box_dim, :box_dim]\nmask = (x - center)**2 + (y - center)**2 + (z - center)**2 < radius**2\nion_fraction_field[mask] = 1.0\n\n# 2. Initialize the power spectrum calculator\nps_calculator = XXIPowerSpectrum(h=0.674, omegam=0.315)\n\n# 3. Calculate the 21cm brightness temperature field\n# This is an intermediate step, but useful for visualization\nz_snapshot = 8.0\ndelta_tb_field = ps_calculator.XXI_Field(\n z=z_snapshot,\n deltaR=delta_r_field,\n ionf=ion_fraction_field\n)\n\n# 4. Calculate the power spectrum from the 21cm field\n# The PowerSpectrum method takes the 3D field and box length as input\nk, delta_sq, error = ps_calculator.PowerSpectrum(\n field=delta_tb_field,\n box_length=box_length_mpc,\n num_bins=30 # Optional: number of bins for k\n)\n\nprint(\"Power spectrum calculation complete.\")\nprint(f\"k (h/Mpc):\\n{k[:5]}\")\nprint(f\"\u0394^2(k) (mK^2):\\n{delta_sq[:5]}\")\n\n# 5. Use the built-in plotting function to visualize the result\n# This will also save a plot to the 'figure_deltaTb/' directory\nps_calculator.PowerSpectrumPlot(\n field=delta_tb_field,\n box_length=box_length_mpc,\n label=f'Power Spectrum at z={z_snapshot}'\n)\n\nprint(\"Plot saved to figure_deltaTb/PowerSpectrum_...png\")\n```\n## License\n\nThis project is licensed under the MIT License. See the `LICENSE` file for details.\n",
"bugtrack_url": null,
"license": null,
"summary": "Python package for cosmological power spectrum, 21cm signal, and optical depth calculations.",
"version": "1.0.1",
"project_urls": {
"Bug Reports": "https://github.com/SOYONAOC/xxiop/issues",
"Documentation": "https://github.com/SOYONAOC/xxiop#readme",
"Homepage": "https://github.com/SOYONAOC/xxiop",
"Repository": "https://github.com/SOYONAOC/xxiop"
},
"split_keywords": [
"cosmology",
" power spectrum",
" 21cm",
" optical depth",
" astrophysics"
],
"urls": [
{
"comment_text": null,
"digests": {
"blake2b_256": "a42d7e4ee1eaf3bafb8d52b37cce11a836efa02178b7988f7069119a8bfc6858",
"md5": "0f39f42b1930d76ee007d9fa72fcbc8e",
"sha256": "778b02bdff954ebe10c17940ddffd96053fc2e95e940144d5420b4d3650608d2"
},
"downloads": -1,
"filename": "xxiop-1.0.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "0f39f42b1930d76ee007d9fa72fcbc8e",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.7",
"size": 7520,
"upload_time": "2025-08-17T01:34:01",
"upload_time_iso_8601": "2025-08-17T01:34:01.948380Z",
"url": "https://files.pythonhosted.org/packages/a4/2d/7e4ee1eaf3bafb8d52b37cce11a836efa02178b7988f7069119a8bfc6858/xxiop-1.0.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "d5b408b767a03c600ea9b530871577069db403a0dd8d981212d9f5af562a433e",
"md5": "c6dbfe8eb0f9b74c2d51215d34c86a9d",
"sha256": "bf39b373f587abe3e87010a1a19993dc7c1194c52b5ebb9127b469b29f132f38"
},
"downloads": -1,
"filename": "xxiop-1.0.1.tar.gz",
"has_sig": false,
"md5_digest": "c6dbfe8eb0f9b74c2d51215d34c86a9d",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.7",
"size": 10267,
"upload_time": "2025-08-17T01:34:03",
"upload_time_iso_8601": "2025-08-17T01:34:03.008699Z",
"url": "https://files.pythonhosted.org/packages/d5/b4/08b767a03c600ea9b530871577069db403a0dd8d981212d9f5af562a433e/xxiop-1.0.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-08-17 01:34:03",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "SOYONAOC",
"github_project": "xxiop",
"github_not_found": true,
"lcname": "xxiop"
}