CosmoPH is a full-stack web application for applying Topological Data Analysis (TDA) to Cosmic Microwave Background (CMB) maps. It helps users upload or select CMB data, preprocess maps, compute persistent homology, visualize topological signatures, compare results with Gaussian null models, and classify inflation-model patterns using machine learning.
The project is designed for students, researchers, and educators who want an accessible browser-based workflow for exploring primordial non-Gaussianity without manually running a complex Python/TDA pipeline.
- FITS file upload and dataset selection for CMB analysis.
- Interactive preprocessing for CMB patches.
- Robust FITS loading with support for both 2D image HDUs and HEALPix-style table HDUs.
- Persistent homology computation for H0 and H1 features.
- Persistence diagram, Betti curve, persistence image, ECC curve, and lifespan histogram visualizations.
- Gaussian null-hypothesis comparison using calibrated TDA thresholds.
- Defect and anomaly detection overlays.
- Hybrid ML classifier using raw CMB map information and extracted TDA features.
- Demo workflow for quick testing without custom data.
- Export-ready result views and report page.
- Full frontend included in the main repository.
| Page / View | Screenshot Path |
|---|---|
| Home | ![]() |
| Upload Dataset | ![]() |
| Results Dashboard | ![]() |
| Defect Detection | ![]() |
| Anomaly Classification | ![]() |
| Graphs & Analytics | ![]() |
| Overall Gaussianity / Workflow | ![]() |
| Layer | Technologies |
|---|---|
| Frontend | Next.js, React, TypeScript, Tailwind CSS |
| Visualization | Plotly.js, react-plotly.js |
| UI Icons | lucide-react |
| Backend | FastAPI, Pydantic, Uvicorn |
| Astronomy / FITS | Astropy, Healpy |
| TDA | Ripser, Persim |
| Machine Learning | PyTorch, scikit-learn, joblib |
| Data Processing | NumPy, SciPy |
| Testing | Pytest, ESLint |
Code1/
|-- backend/
| |-- app/
| | |-- main.py
| | |-- routes/
| | |-- schemas/
| | |-- services/
| | |-- models/
| | `-- utils/
| |-- tests/
| |-- requirements.txt
| `-- Dockerfile
|-- frontend/
| |-- app/
| | |-- dashboard/
| | |-- demo/
| | |-- docs/
| | |-- report/
| | |-- results/
| | `-- upload/
| |-- components/
| |-- lib/
| |-- public/
| |-- types/
| |-- package.json
| `-- Dockerfile
|-- dataset/
|-- scripts/
|-- uploads/
|-- docker-compose.yml
|-- PRD.txt
|-- UPDATES.md
`-- README.md
- Python 3.10 or newer
- Node.js 18 or newer
- npm
- Git
git clone https://github.com/Yog964/CosmoPH.git
cd CosmoPHcd backend
python -m venv venv
venv\Scripts\activate
pip install -r requirements.txt
uvicorn app.main:app --reload --port 8000Backend URLs:
- API:
http://localhost:8000 - Swagger docs:
http://localhost:8000/docs
Open a new terminal:
cd frontend
npm install
npm run devFrontend URL:
- App:
http://localhost:3000
From the project root:
docker-compose up --build- Open the frontend in the browser.
- Upload a FITS file or select a sample dataset.(https://irsa.ipac.caltech.edu/data/Planck/release_3/)
- Configure preprocessing options.
- Generate a clean CMB patch.
- Run TDA computation.
- View persistence diagrams, Betti curves, persistence images, and related plots.
- Compare the sample against Gaussian null models.
- Inspect detected defects or anomalies.
- Run the ML classifier.
- Export or review the generated report.
| Method | Endpoint | Purpose |
|---|---|---|
| GET | /health |
Check backend health |
| GET | /api/datasets |
List available datasets |
| POST | /api/upload |
Upload a FITS file |
| POST | /api/preprocess |
Run preprocessing |
| POST | /api/compute-tda |
Start TDA computation |
| GET | /api/compute-tda/{job_id} |
Check TDA job status |
| GET | /api/results/{job_id} |
Fetch result data |
| GET | /api/export/{job_id} |
Export result files |
| POST | /api/demo |
Run demo analysis |
Generate or prepare sample datasets:
python scripts/download_datasets.pyGenerate Gaussian and non-Gaussian FITS samples:
python scripts/generate_fits.pyTrain or refresh the classifier:
python scripts/train_classifier.pyBackend tests:
cd backend
pytest tests/ -vFrontend lint:
cd frontend
npm run lint- Large generated files such as
.zip,.fits,.npy, and.npzare ignored. - Uploaded files and generated outputs are stored locally during development.
- The frontend is tracked as normal source code inside this repository.
MIT License.






