Skip to content

Cosmology base class - #11518

Closed
nstarman wants to merge 2 commits into
astropy:mainfrom
nstarman:cosmo_perturb
Closed

nstarman wants to merge 2 commits into
astropy:mainfrom
nstarman:cosmo_perturb

Conversation

@nstarman

@nstarman nstarman commented Apr 11, 2021 •

Copy link
Copy Markdown
Member

Description

Directly instantiating the Cosmology base class now clones the current
default cosmology (controlled by default_cosmology), updating parameters
as specified. This allows for:

>>> from astropy.cosmology import Cosmology, default_cosmology
>>> print(Cosmology())  # the default cosmology
FlatLambdaCDM(name="Planck18", H0=67.7 km / (Mpc s), ...)

>>> with default_cosmology.set("WMAP5"):
>>>      print(Cosmology())  # gets the new default
FlatLambdaCDM(name="WMAP5", H0=70.2 km / (Mpc s), ...)

>>> Cosmology(name="modified", H0=70)  # perturb around the default
FlatLambdaCDM(name="modified", H0=70 km / (Mpc s), ...)

Some things this does:

  • Make instantiating non built-in cosmos slightly easier.
  • Simplifies programmatic creation of cosmology classes, perturbing some values, e.g.
for name in cosmology.parameters.available:
    with default_cosmology.set(name):
        Cosmology(H0=77)

While this is convenient, I think this is the least consequential / necessary change outlined in #10673. I'm totally fine if we don't merge this in, I just thought I should suggest it.

Requires #11515
Part of #10673

nstarman and others added 2 commits April 11, 2021 14:31
Store initialization signature and arguments
changelog fragment
deprecation warning for AttributeError over TypeError

Co-authored-by: Adrian Price-Whelan <[email protected]>
Signed-off-by: Nathaniel Starkman (@nstarman) <[email protected]>
@pep8speaks

Copy link
Copy Markdown

Hello @nstarman 👋! Thanks for opening this pull request, we are very grateful for your contribution! I'm a friendly 🤖 that checks for style issues in this pull request, since this project follows the PEP8 style guidelines. I've listed some small issues I found below, but please don't hesitate to ask if any of them are unclear!

Line 86:1: E302 expected 2 blank lines, found 1

@github-actions

Copy link
Copy Markdown
Contributor

👋 Thank you for your draft pull request! Do you know that you can use [ci skip] or [skip ci] in your commit messages to skip running continuous integration tests until you are ready?

@nstarman nstarman mentioned this pull request Apr 18, 2021
2 of 7 tasks
@nstarman nstarman closed this May 21, 2021
@nstarman nstarman mentioned this pull request May 23, 2021
2 of 7 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants