How sidd0529/cosmos_lens works
Project type and purpose
• This is a scientific data‐processing pipeline (not a web or full‐stack app) that generates convergence and lensing maps from the COSMOS2015 galaxy catalog.
• It combines Python for orchestration, Cython as a bridge, and C for the high‐performance core routines.
File structure
Top‐level files and directories:
• setup.py – build script (cythonize + compile C)
• cosmos_cy.pyx – Cython wrapper module
• potential.c / .h – C implementation of the Poisson solver
• galaxy_bias.py – Python routine for calculating galaxy bias
• gauss_smooth.py – Python routine for Gaussian smoothing
• hole_fill.py – Python routine to fill masked regions
• cosmos_runme.py – main Python driver orchestrating the pipeline
• README.md, LICENSE, .gitignore
README for additional insights
• Input: COSMOS2015_FITS data (download externally).
• Build: “python setup.py build_ext --inplace” compiles C/Cython.
• Run: “python cosmos_runme.py” invokes end‐to‐end map generation.
• Outputs: convergence map, potential map (image files).
Main components
a. Input Data
• COSMOS2015 FITS catalog files
b. Build System
• setup.py → invokes Cython + C compiler → produces extension module “cosmos_cy.so” (or .pyd)
c. Orchestration Layer (Python)
• cosmos_runme.py – top‐level script
• galaxy_bias.py, gauss_smooth.py, hole_fill.py – pre‐ and post‐processing Python modules
d. Compute Core (C via Cython)
• cosmos_cy.pyx → wraps potential.c functions and exposes them as Python‐callable APIs
• potential.c / .h – high-performance numerical routines
e. External Libraries
• NumPy (arrays, FFTs, etc.)
• Cython (build and wrapping)
• astropy.io or fits I/O libraries (if used for FITS read/write)
f. Outputs
• Convergence map (image)
• Potential map (image)
Relationships and interactions
1. User invokes cosmos_runme.py
2. Python code loads FITS data → NumPy arrays
3. Preprocessing steps in Python modules (gauss_smooth, hole_fill, galaxy_bias)
4. cosmos_runme calls Cython‐wrapped functions in cosmos_cy
5. Inside cosmos_cy: data marshaled to C arrays → potential.c solver runs → results returned
6. Python receives results → further processing/normalization → write output images
Architectural patterns and principles
• Layered architecture:
– Top: Python orchestration & I/O
– Middle: Cython interface (glue)
– Bottom: Native C compute engine
• Separation of concerns:
– Python handles I/O, control flow, plotting;
– C handles CPU‐intensive numerical kernels
• Build pipeline: Cython compilation orchestrated by setup.py