Repository navigation
feat: uni-modal cosmology wrt Ob0 - #16847
Conversation
|
Thank you for your contribution to Astropy! 🌌 This checklist is meant to remind the package maintainers who will review this pull request of some common things to look for.
|
6c8c678 to
9b48ed7
Compare
b61406f to
8111cfb
Compare
mhvk
left a comment
There was a problem hiding this comment.
I don't feel completely competent to judge the impact, but it certainly seems to make more sense to keep the class consistent like this, rather than sometimes getting errors. My comments are mostly about making clearer what is changed.
| if value is None: | ||
| return value | ||
| warnings.warn( | ||
| "Ob0=None is deprecated, use Ob0=0 instead.", |
There was a problem hiding this comment.
Also mention that there will no failures!
| tba.arguments.pop("Ob0", None) | ||
| cosmo = cosmo_cls(*tba.args, **tba.kwargs) | ||
| with pytest.raises(ValueError): | ||
| cosmo.Ob(1) |
There was a problem hiding this comment.
Proabbly makes sense to check that cosmo.Ob(1) == 0
| In this case the dark matter-only density at redshift 0 is available as class | ||
| attribute ``Odm0`` and the redshift evolution of dark and baryonic matter | ||
| densities can be computed using the methods ``Odm`` and ``Ob``, respectively. | ||
| If ``Ob0`` is not specified at class instantiation, it defaults to ``None`` and |
There was a problem hiding this comment.
Should state that if Ob0 is not specified, it will be set to 0 and thus ignored in further calculations. Only then does the next example make sense (though I'd add cosmo.Ob(1) as well, to show it stays zero).
| Setting ``Ob0 = None`` in FLRW cosmologies has been deprecated in favor of ``Ob0 = | ||
| 0.0``. Conceptually this is a change in that baryons are now always a component of the | ||
| cosmology. Practically, the only change (besides that ``Ob0`` is never ``None``) is that | ||
| methods relying on ``Ob0`` always work, rather than sometimes raising an exception. |
There was a problem hiding this comment.
Add ", instead by default taking the contribution of the baryons to be negligible."
e09f90f to
2e1320e
Compare
mhvk
left a comment
There was a problem hiding this comment.
The other PRs brought this up again. Still seems reasonable, and I now have only a most minimal comment left. Approving, since either I'm right and this is a trivial change, or I'm not, and then what you have is OK.
| # validation | ||
| assert Ob0.validate(cosmo, None) is None | ||
| with pytest.warns( | ||
| DeprecationWarning, match=re.escape("Ob0=None is deprecated") |
There was a problem hiding this comment.
Why the re.escape - this string should work fine directly, no?
There was a problem hiding this comment.
Good Q. Not sure if I added this because of a test failure or as a matter of habit.
There was a problem hiding this comment.
Hopefully habits will be auto-fixed astral-sh/ruff#13705
There was a problem hiding this comment.
Indeed, this seems auto-detectable (it already detects f-strings without actual {...}).
| cosmo.Ob(1) | ||
| tba.arguments["Ob0"] = None | ||
| with pytest.warns( | ||
| DeprecationWarning, match=re.escape("Ob0=None is deprecated") |
There was a problem hiding this comment.
I now quickly checked, and it does just work without re.escape.
Deprecate Ob0=None, changing to Ob0=0 Signed-off-by: nstarman <[email protected]>
2e1320e to
2e41761
Compare
Deprecates
Ob0=None, changing it toOb0=0.Currently FLRW is multi-modal in that it supports both a cosmology with no baryon component and also one with a baryon component. Except that the no-baryon cosmology is implemented as an attribute that always raises an exception. This is not an ideal code pattern. From a code perspective the best is to have two different classes, each representing one of these modalities. Pragmatically, at least for now, just having
Ob0 = 0fulfills the same requirements without adding a new class nor all the child classes for the dark energy EoS. Longer term, one of thegoals of the cosmology API project and its application to Astropy is to make defining new cosmology classes significantly easier through more modular components. Then we can have true no-baryon cosmologies, not just baryons=0.
This is a breaking change since
Ob0 = Noneis nowOb0 = 0and no longer ever errors.