Repository navigation
Open
Labels
Description
Currently Astropy provides the very broad FLRW subclasses which have the full gamut of density components. With these classes we can achieve any of the standard pedagogical classes, e.g. matter-only, M+Lambda, etc.
However, this generality ends up obscuring in the code the beautiful and simple analytic expressions to which many computed quantities reduce.
I want to provide pedagogical models like a MatterOnly, MatterAndDarkEnergy (names not final).
Doing this will take 3 steps:
- Splitting out of FLRW private ABCs for the components, e.g. a DarkMatterComponent class. FLRW will subclass these orthogonal ABCs, implement the necessary concrete methods.
- Move these component classes into a new module and make them public (preferably private, but importing them to the top-level namespace)
- Make new pedagogically-focused cosmology classes. Interested users (e.g. students) can see the analytic expressions in the code and explained in the docstrings.
For details of what this will look like, see https://cosmology.readthedocs.io/projects/api/en/latest/
Component PRs:
- Separate out NeutrinoComponent (Neutrino component #18809)
- Separate out BaryonComponent (refactor(cosmo): refactor separate baryon component #17522)
- Separate out PhotonComponent
- Separate out DarkMatterComponent (Updating to add a trait class for darkmatter in cosmology. #18760)
- Separate out MatterComponent (all matter) (Matter density as a trait #18307)
- Separate out DarkEnergyComponent (Dark Energy Component Trait Class #18447)
- Separate out CurvatureComponent (feat(cosmo): curvature component #18232)
- Separate out TotalComponent (Total Component Trait #18794)
- Separate out CriticalDensity (cosmo: refactor separate rhocrit mixin #17500)
- Separate out HubbleParameter (cosmo: Hubble parameter trait #18271)
- Separate out ScaleFactor (feat: scale factor #17151)
- Separate out TemperatureCMB (cosmo: separate out tcmb #17153)
- Separate out DistanceMeasures (feat(cosmo):
DistanceMeasurestrait class #18808) - Move components out of FLRW folder
Pedagogical Classes:
- Matter only (feat(cosmo): matter-only pedagogical cosmology #18876)
- Curvature only
- Photon only
- Lambda only
- Matter + Photons
- Matter + Lambda
- Photons + Lamda
- New documentation
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsIn Progress
Activity
pllim commentedon Oct 9, 2024
Will these classes actually be useful outside of teaching? If not, maybe better as example over at Learn Astropy?
nstarman commentedon Oct 9, 2024
They are good approximations during periods of 1 or 2 component domination, so are still useful in research contexts. The simplified analytic expressions should also be faster.
nstarman commentedon Oct 10, 2024
mhvk commentedon Oct 10, 2024
This is starting to look like
cosmologycould be a set ofModelinstances! That might actually be interesting - would enable fitting a cosmology to a set of data points...Like @pllim, I'm not quite clear whether astropy itself should contain the pedagogical implementations, but I think it will become clearer whether that makes sense or not once some of the modular pieces are in place. It will also be good to see to what extent these make the code simpler - the temperature and scale factor seem good cases, but a bit less obvious to me that others will be.
nstarman commentedon Dec 13, 2024
Preferably not! But better I/O between them would be nice. The current interface is limited.
https://github.com/astropy/astropy/blob/main/astropy/cosmology/_io/model.py
spranav1205 commentedon Dec 17, 2024
Hi @nstarman ,
I’m a beginner looking to contribute to this project. If I understand correctly, you're restructuring the FLRW class by creating new classes for various methods, as mentioned in the list.
While going through the codebase, I found it challenging to fully understand the testing code. There are a few nested test classes, and I couldn't locate the instance for cosmo_cls.
Could you please help me understand the test code, particularly where cosmo_cls is instantiated? With your guidance, I hope to separate a few classes as part of the restructuring.
Thanks!
nstarman commentedon Dec 18, 2024
Thanks @spranav1205 for the interest! I'd be happy to look at PRs that separate the cosmology class into its component classes, according to the schema outlined in https://cosmology.readthedocs.io/projects/api/en/latest/.
This task is currently waiting on #17543 before it can be worked on again.
In the meantime, Astropy uses
pytestas its testing framework. up-to-datepytesttests use fixtures as inputs to the test functions. Here's a refined search for thecosmo_clsfixture — https://github.com/search?q=repo%3Aastropy%2Fastropy+%22def+cosmo_cls%22&type=code — the use of which depends on a per-test basis. Hope that helps!spranav1205 commentedon Dec 20, 2024
Thanks for your guidance! I'll look into it.
preshanth commentedon Jun 4, 2025
@nstarman you planning to keep pushing this list forward. I would like to try and help if thats the case.
6 remaining items
nstarman commentedon Oct 20, 2025
Thanks @preshanth. That sounds great. Do you want to take a look at
DarkMatterComponent?preshanth commentedon Oct 22, 2025
@nstarman Any other trait you want me to take a stab at ?
nstarman commentedon Oct 23, 2025
TotalComponentshould be a simple one. It has to abstract since it can't know what are the set of implemented components.Then
DistanceMeasures, which should just be the public API methods, not the private implementations. I'm interested in discussing what are the minimum set of abstract methods required to get the distance measures working!preshanth commentedon Oct 23, 2025
I will start with
TotalComponentmaybe thePhotonComponentafter that ? Let me ponder theDistanceMeasurestoo in the meantime.preshanth commentedon Oct 30, 2025
Can I present an issue with my fix for neutrino component and distance measure in a separate ticket? We can hash it out and then I can submit a PR for them one at a time. I also want to make another ticket for unit tests for the traits themselves.
nstarman commentedon Oct 30, 2025
That'd be great. I pushed a couple PR drafts, one of which will impact a distance measures PR significantly. There's a couple other related issues with setting up the distance measures (two-argument forms, default implementations, etc), so maybe I'll take that one.
preshanth commentedon Nov 18, 2025
Do you want to leave the doc tests in place ? They also make good unit tests. I was going to do some check for known failures and put in a trait unit test PR that sound alright ? Don't want to increase your reviewing workload so let me know if that's okay
nstarman commentedon Nov 18, 2025
Yes, agreed.
Great!
pllim commentedon May 1, 2026
This is not a release blocker, so I am removing milestone for this issue. FYI.
preshanth commentedon May 4, 2026
@nstarman Would you like me to look at anything remaining here. There are two open Drafts I am not sure what else to touch. Happy to help if you point me towards something useful.
nstarman commentedon May 14, 2026
@preshanth Oh, sorry for the delayed response.
The DistanceMeasures PR is slowly going, but it's going.
A PhotonComponent PR would be amazing!
preshanth commentedon May 15, 2026
I will take a stab at that and put in a PR over the weekend.