{"id":38685897,"url":"https://github.com/cosmostatgw/mgcosmopop","last_synced_at":"2026-01-17T10:23:31.804Z","repository":{"id":156336929,"uuid":"425232654","full_name":"CosmoStatGW/MGCosmoPop","owner":"CosmoStatGW","description":"Modified Gravity and Cosmology with Binary Black Holes' Population models : hierarchical bayesian inference package for constraining the Hubble constant, modified GW propagation and BBH population models with GWs.","archived":false,"fork":false,"pushed_at":"2025-10-07T16:12:30.000Z","size":2850,"stargazers_count":16,"open_issues_count":0,"forks_count":6,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-10-07T18:25:26.125Z","etag":null,"topics":["cosmology","gravitational-waves","hierarchical-bayesian-analysis"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/CosmoStatGW.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2021-11-06T11:59:51.000Z","updated_at":"2025-10-07T16:12:36.000Z","dependencies_parsed_at":null,"dependency_job_id":"41f39a56-a9bc-4bc3-9922-8cd3c8a8142a","html_url":"https://github.com/CosmoStatGW/MGCosmoPop","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/CosmoStatGW/MGCosmoPop","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CosmoStatGW%2FMGCosmoPop","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CosmoStatGW%2FMGCosmoPop/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CosmoStatGW%2FMGCosmoPop/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CosmoStatGW%2FMGCosmoPop/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/CosmoStatGW","download_url":"https://codeload.github.com/CosmoStatGW/MGCosmoPop/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CosmoStatGW%2FMGCosmoPop/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28506379,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-17T06:57:29.758Z","status":"ssl_error","status_checked_at":"2026-01-17T06:56:03.931Z","response_time":85,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cosmology","gravitational-waves","hierarchical-bayesian-analysis"],"created_at":"2026-01-17T10:23:31.200Z","updated_at":"2026-01-17T10:23:31.794Z","avatar_url":"https://github.com/CosmoStatGW.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# MGCosmoPop\nThis package implements a hierarchical bayesian framework for constraining the standard cosmological parameters (Hubble constant and Dark Matter density) and modified Gravitational Wave propagation parameters together with the Binary Black Hole (BBH) population parameters (mass function, merger rate density, spin distribution)\n\n\nDeveloped by [Michele Mancarella](\u003chttps://github.com/Mik3M4n\u003e).\n\nIf using this code, please cite this repository: [![DOI](https://zenodo.org/badge/425232654.svg)](https://zenodo.org/badge/latestdoi/425232654) , \nand the paper [Cosmology and modified gravitational wave propagation from binary black hole population models](\u003chttps://arxiv.org/abs/2112.05728\u003e). Bibtex:\n\n```\n@article{Mancarella:2021ecn,\n    author = \"Mancarella, Michele and Genoud-Prachex, Edwin and Maggiore, Michele\",\n    title = \"{Cosmology and modified gravitational wave propagation from binary black hole population models}\",\n    eprint = \"2112.05728\",\n    archivePrefix = \"arXiv\",\n    primaryClass = \"gr-qc\",\n    month = \"12\",\n    year = \"2021\"\n}\n```\n\nThe data products associated to the paper (injections used for computation of the selection effects in GWTC-3, mock datasets and injections) are avaliable at [![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.6461447.svg)](https://doi.org/10.5281/zenodo.6461447)\n\n\n\n## Summary\n\n\n* [Overview and code organisation](https://github.com/CosmoStatGW/MGCosmoPop#Overview-and-code-organisation)\n* [Installation](https://github.com/CosmoStatGW/MGCosmoPop#Installation)\n* [Data](https://github.com/CosmoStatGW/MGCosmoPop#Data)\n* [Usage](https://github.com/CosmoStatGW/MGCosmoPop#Usage)\n* [Example](https://github.com/CosmoStatGW/MGCosmoPop#Example)\n\n## Installation\n\n \n### Using conda\n \n Create the dedicated environment:\n ```\n conda create -y --name gwstat python=3.7\n conda activate gwstat\n ```\n \n Clone the repo:\n \n ```\n git clone https://github.com/CosmoStatGW/MGCosmoPop.git\n cd MGCosmoPop\n ```\n \n Install dependencies and package\n \n```\nconda install -y -c conda-forge --file requirements_conda.txt  \npip install .\n```\n\n\n### Manually, without cloning\nInstall manually the dependencies in requirements.txt\n\nThen\n\n ```\npip install git+https://github.com/CosmoStatGW/MGCosmoPop\n ```\n\n## Overview and code organisation\n\n### General structure\nThe code implements the hierarchical framework in an object-oriented way. \nFor the moment, a single population of astrophysical BBHs is present. The code is however ready to support multiple populations, which should be implemented inheriting from the Abstract Base Class ```ABSpopulation```\n\n\nThe organisation of the code is the following:\n\n```bash\nMGCosmoPop/MGCosmoPop/\n\t\t\t\t\t├── cosmology/ \n\t\t\t\t\t\t\t a class Cosmo implementing cosmology-related functions\n\t\t\t\t\t├── dataStructures/\n\t\t\t\t\t\t\t One abstract base class for data and classes for reading and using mock data and data from the O1-O2 and O3a observing runs. Classes for reading and using injections to compute selection effects are also there\n\t\t\t\t\t├── mock/\n\t\t\t\t\t\t\t Tools to generate mock datasets and injections\n\t\t\t\t\t├── population/\n\t\t\t\t\t\t\t Classes for implementing the population function. Described below separately\n\t\t\t\t\t├── posteriors/\n\t\t\t\t\t\t\t Classes implementing likelihood, posterior and selection effects\n\t\t\t\t\t├── sample/\n\t\t\t\t\t\t\t MCMC tools\n\t\t\t\t\t\t\n```\t\t\n\n### The population model\n\nThe key module for the population function(s) is ```population```, organised as follows:\n\n```bash\npopulation/\n\t\t├── ABSpopulation.py\n\t\t\t\t Abstract Base Classes for describing a population. Contains three ABCs: \n\t\t\t\t\ti) Population, that requires to implement a (log) differential rate log(dR/dm1 dm2 )  \n\t\t\t\t\tii) RateEvolution requiring to implement the (log) differential log ( dN/dV dt )  = log ( R(z) ) \n\t\t\t\t\tiii) BBHdistfunction, used to implement the mass and spin distribution. \n\t\t\t\t\t\tThis requires to implement a (log) probability distribution log p(m1, m2) or log p(chi1, chi2)\n\t\t├── allPopulations.py\n\t\t\t\tcollects the differential rates from all populations, adds the volume element jacobian, \n\t\t\t\tthe jacobian between source and detector frame variables, observation time, \n\t\t\t\tand yields the full population function dN/dtheta (theta = {m1_det, m2_det , dL, chi_1, chi_2...})\n\t\t├── astro/ \n\t\t\t population of astrophysical black holes. \n\t\t\t \t├── astroPopulation.py\n\t\t\t \t\t\tpopulation function dR/dm1dm2\n\t\t\t \t├── astroMassDistribution.py \n\t\t\t \t\t\tmass function p(m1, m2)\n\t\t\t\t├── astroSpinDistribution.py \n\t\t\t \t\t\tspin distribution\n\t\t\t \t├── rateEvolution.py\n\t\t\t \t\t\tmerger rate density \n\t\t\t\t\t\n```\t\t\n\nAn explanatory notebook on how to set up a model is provided in the notebook folder.\n\n## Supported models\n\nThe following models are implemented: \n\n### Astrophysical black holes\n\nThe astrophysical BH population is defined by three base ingredients: mass distribution, spin distribution, and merger rate evolution. Each one is implemented in a specific object.\n\n#### Mass functions (primary mass)\n* Truncated power law\n* Truncated power law with smoothed edges\n* Broken power law\n* (From v1.1) Power law + peak model \n* (From v1.1) Neutron stars: uncorrelated gaussian\n* (From v1.1) Neutron stars: uncorrelated flat\n\n#### Rate evolution\n* Power law : R(z) = R_0 * (1+z)^\\lambda\n* Madau-Dickinson rate\n\n#### Spin distributions\n* (Uncorrelated) Gaussian model for chi\\_1, chi\\_2\n* (From v1.1) \"Default\" spin model\n\n\n### Extensions\n\nTo add models, one should inherit from the corresponding ABC and implement the required functions. \nTo add populations, one should implement a new module (e.g. : PBHs )\n\n\n## Data\n\nData for O1-O2, O3a, and O3b can be downloaded from the LVK data releases. The data products associated to the paper (injections used for computation of the selection effects in GWTC-3, mock adasets and injections) are avaliable at [![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.6461447.svg)](https://doi.org/10.5281/zenodo.6461447).\n\nAll data can be downloaded running the script ```getData.sh```:\n\n```\nchmod +x getData\n./getData.sh\n```\n\n\n\n### GWTC-3\n\nO1-O2 O3a, and O3b are supported. The corresponding posterior samples should be placed under data/O1O2, data/O3a, data/O3b respectively.\n\n### Injections\nTools for generating injections are in mock/ . Examples of configuration files to generate injections for O3a/O3b are provided. After editing the config file, run:\n\n```\npython generateInjections.py --config=configInjections_O3b.py --fout=\u003cname_of_output_folder\u003e \n```\n\nThe corresponding file is saved in the output folder as ```selected.h5 ```. It can be loaded using the object ```GWMockInjectionsData ``` in ```dataStructures ```:\n\n```\nfile_name  = os.path.join(\u003cname_of_output_folder\u003e ,'selected.h5' )\nmyInjections = GWMockInjectionsData(file_name ,  Tobs=Tobs )\n```\n\nwhere ```Tobs ``` is the duration in years of the observing run.\n\n## Usage\n\nAn introductory notebook is available in notebooks/\n\nA module to run a MCMC analysis is available in ```sample/``` . To run on a cluster, edit the configuration file as in the template ```config_template.py``` (explanations in the file) with the option ```parallelization='mpi'```. Then:\n\n```\nfout = myMCMC\nmkdir $fout\n\nsrun  python runMCMC.py --config=config_template --fout=$fout\n```\n\n## Example\n\nHere we show the analysis of the GWTC-2 catalog  with a BBH population model given by a broken power law mass distribution using MGCosmoPop, and compare to the result of the LVC. See [the LVC paper](https://arxiv.org/abs/2010.14533) for details. We compare the LVC result (blue) to the result obtained with this code using the LVC injections for computing selection effects (green) and using this code and our own injections (red).\n\n![alt text](https://github.com/CosmoStatGW/MGCosmoPop/blob/master/R0_lambda_alpha1_alpha2_beta_deltam_ml_mh_b_corner_local_LVC.png?raw=true)\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcosmostatgw%2Fmgcosmopop","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcosmostatgw%2Fmgcosmopop","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcosmostatgw%2Fmgcosmopop/lists"}