Enable user-selectable cosmology and update default to Planck18#391
Enable user-selectable cosmology and update default to Planck18#391elijahmathews wants to merge 3 commits into
Planck18#391Conversation
… rules This commit replaces the ad-hoc .gitignore with the standard GitHub Python template to better handle common artifacts like __pycache__, build directories, and coverage reports. It retains project-specific exclusions, including: - Scientific data formats (*.fits, *.h5) - Manuscript and LaTeX files - Custom demo and misc directories - The generated _version.py file
This commit updates the default cosmology used in Prospector to the `astropy.cosmology.Planck18` cosmology (Planck Collaboration 2020, Table 2), in place of the previous default of `WMAP9` (Hinshaw et al. 2013).
Refactors the codebase to treat cosmology as a model parameter (`model.params['cosmology']`) rather than a hard-coded global constant. This allows users to specify custom `astropy` cosmology objects in their parameter files. Key Changes: - **Model Parameters:** Added `cosmology` to the default parameter templates in `prospect.models.templates`. - **Prospector-Beta:** Explicitly pinned the `beta` template to `WMAP9` to ensure consistency with `prospect/models/prior_data/wmap9_z_age.txt`. - **SpecModel:** Added a `cosmology` property to `SpecModel` that handles retrieval and unwrapping of the cosmology object from the parameters dictionary. - **Transforms:** Updated helper functions in `prospect.models.transforms` (e.g., `zred_to_agebins`, `tage_from_tuniv`) to accept an optional `cosmology` argument, resolving the correct object via a new `_get_cosmology` helper. - **Backward Compatibility:** Retained `cosmo` alias in `constants.py` and implemented fallbacks in transform functions to prevent breaking changes for scripts relying on the global default. Resolves bd-j#171
|
@bd-j Do you have a preference about allowing the Prospector-β priors to be used with cosmologies other than |
|
Hi @elijahmathews I do not have a strong preference about the cosmology for prospector-beta, as long as it's noted in the documentation. That said, I'd be in favor of removing the data file and instead computing during initialization. |
|
Regarding having a cosmology object instance as a parameter, I wonder if this will cause any issues with writing outputs. |
Description
Fixes #171
This PR refactors the codebase to treat cosmology as a configurable model parameter (
model.params['cosmology']) rather than a hard-coded global constant.Previously, Prospector was hard-coded to use
WMAP9(Hinshaw et al. 2013) viaastropy. This PR updates the default cosmology toPlanck18(Planck Collaboration 2018) to match modern simulations and survey parameters, while allowing users to inject customastropy.cosmologyobjects (e.g.,FlatLambdaCDM,Planck15) via the parameter file.Changes Implemented
1. Cosmology Parameterization
cosmologyto the default parameter templates inprospect/models/templates.py. It is now stored inmodel.paramsalongside physics parameters.SpecModelLogic: Added a@propertytoSpecModelinprospect/models/sedmodel.pythat retrieves the cosmology object. This property handles the necessary "unwrapping" of the object (asProspectorParamswraps all inputs in NumPy arrays).prospect/models/transforms.py(e.g.,zred_to_agebins,tage_from_tuniv) to accept an optionalcosmologyargument.2. Physics & Defaults
prospect/sources/constants.pyfromWMAP9toPlanck18.betaandbeta_phisfhtemplates inprospect/models/templates.pyto useWMAP9. This is mathematically required because the Prospector-β prior data (specifically the redshift-age relationship tables inprospect/models/prior_data/wmap9_z_age.txt) was generated using WMAP9.3. Maintenance & Compatibility
cosmoalias inprospect/sources/constants.pyand implemented fallback logic in transform functions. Existing scripts that do not specify a cosmology parameter will default gracefully toPlanck18without raising errors..gitignoreto use the standard Python GitHub template while preserving project-specific rules (e.g.,*.h5,manual*,demo/*/).Verification
I have added a new test module
tests/test_cosmology.pythat verifies:Planck18.WMAP9object inmodel_paramsalters derived properties (e.g., luminosity distance, age of universe) compared to the default.SpecModeland transforms, preventingAttributeErrorwhen accessing cosmology methods.Checklist
SpecModelandtransformsto accept cosmology objects.TemplateLibrarydefaults.WMAP9to ensure consistency with prior data.constants.py.WMAP9(maybe?)..gitignore.