Skip to content

Cosmo read/write ECSV - #12321

Merged
nstarman merged 3 commits into
astropy:mainfrom
nstarman:cosmo_readwrite_ecsv
Oct 30, 2021
Merged

nstarman merged 3 commits into
astropy:mainfrom
nstarman:cosmo_readwrite_ecsv

Conversation

@nstarman

@nstarman nstarman commented Oct 28, 2021 •

Copy link
Copy Markdown
Member

Description

A Cosmology can be read from / written to an ECSV file. This keeps all units and metadata and will work when Cosmology is enhanced to be able to be array-valued.

Requires #12213 . Will be rebased when that it is merged. Test failing because there is more than 1 changelog fragment.
Merged.

Checklist for package maintainer(s)

This checklist is meant to remind the package maintainer(s) who will review this pull request of some common things to look for. This list is not exhaustive.

  • Do the proposed changes actually accomplish desired goals?
  • Do the proposed changes follow the Astropy coding guidelines?
  • Are tests added/updated as required? If so, do they follow the Astropy testing guidelines?
  • Are docs added/updated as required? If so, do they follow the Astropy documentation guidelines?
  • Is rebase and/or squash necessary? If so, please provide the author with appropriate instructions. Also see "When to rebase and squash commits".
  • Did the CI pass? If no, are the failures related? If you need to run daily and weekly cron jobs as part of the PR, please apply the Extra CI label.
  • Is a change log needed? If yes, did the change log check pass? If no, add the no-changelog-entry-needed label. If this is a manual backport, use the skip-changelog-checks label unless special changelog handling is necessary.
  • Is a milestone set? Milestone must be set but astropy-bot check might be missing; do not let the green checkmark fool you.
  • At the time of adding the milestone, if the milestone set requires a backport to release branch(es), apply the appropriate backport-X.Y.x label(s) before merge.

@nstarman nstarman added this to the v5.0 milestone Oct 28, 2021
@nstarman
nstarman requested a review from taldcroft October 28, 2021 17:30
@pep8speaks

pep8speaks commented Oct 28, 2021 •

Copy link
Copy Markdown

Hello @nstarman 👋! It looks like you've made some changes in your pull request, so I've checked the code again for style.

There are no PEP8 style issues with this pull request - thanks! 🎉

Comment last updated at 2021-10-30 16:38:46 UTC

@nstarman
nstarman force-pushed the cosmo_readwrite_ecsv branch from 16ada4e to 89c75f5 Compare October 28, 2021 17:31
@nstarman
nstarman force-pushed the cosmo_readwrite_ecsv branch 3 times, most recently from e6b160c to f3c6299 Compare October 28, 2021 18:14
@nstarman nstarman mentioned this pull request Oct 28, 2021
9 tasks done
@nstarman
nstarman requested a review from mhvk October 29, 2021 00:05
@nstarman
nstarman force-pushed the cosmo_readwrite_ecsv branch 4 times, most recently from 464c4a0 to c843604 Compare October 29, 2021 13:24
@nstarman

Copy link
Copy Markdown
Member Author

@nstarman @taldcroft
If the mypackage move is too large to review, I can split it off of this PR.

@nstarman
nstarman force-pushed the cosmo_readwrite_ecsv branch 2 times, most recently from 5788a76 to cdcdf5d Compare October 29, 2021 23:37
@nstarman
nstarman force-pushed the cosmo_readwrite_ecsv branch from cdcdf5d to 4854646 Compare October 30, 2021 01:51
Signed-off-by: Nathaniel Starkman (@nstarman) <[email protected]>
@nstarman
nstarman force-pushed the cosmo_readwrite_ecsv branch from 4854646 to 85dc20d Compare October 30, 2021 01:55

@taldcroft taldcroft left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a few docs comments for now, will try to get to the rest soon.

Comment thread docs/whatsnew/5.0.rst Resolved
Comment thread docs/whatsnew/5.0.rst Outdated
registered. Details are discussed in an addition to the docs.

Currently no file formats are registered, but the syntax is as follows:
Currently the only registered read/write format is "ascii.ecsv", like for Table.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to sound apologetic, the one format is great and this can be where we try to define the new standard. 😄

Suggested change
Currently the only registered read/write format is "ascii.ecsv", like for Table.
For writing the representation of a ``Cosmology`` to a file, the ECSV [link to APE-6] table format
is available. Astropy is encouraging the use of this format as a standard interoperable
way of storing and communicating cosmology parameters.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!
Implemented.

Comment thread docs/whatsnew/5.0.rst Resolved
Comment thread docs/whatsnew/5.0.rst Outdated
>>>
>>> from astropy.cosmology import Cosmology
>>> cosmo = Cosmology.read('<file name>.<format>')
>>> cosmo = Cosmology.read('<file name>.ecsv')

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
>>> cosmo = Cosmology.read('<file name>.ecsv')
>>> cosmo = Cosmology.read('plank18.ecsv')

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't think whatsnew was skipped in tests. This makes examples much better.

Comment thread docs/whatsnew/5.0.rst
>>> cosmo = Cosmology.read('<file name>.ecsv')
>>> cosmo == Planck18
True

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the examples below are a bit long for the What's New. The idea is not to comprehensively show the capabilities but just highlight things enough for interested people to click through to the docs link. I think each What's New entry should fit comfortably on one laptop screen (and maybe half the people are reading on mobile?). So maybe just:

Transformations between ``Cosmology`` and `dict`, ``QTable``,  and``Model`` are
pre-registered, enabling for example::

    >>> from astropy.cosmology import Cosmology, Planck18
    >>> cm = Planck18.to_format("mapping")
    >>> cm
    {'cosmology': <class 'astropy.cosmology.flrw.FlatLambdaCDM'>,
     'name': 'Planck18',
     'H0': <Quantity 67.66 km / (Mpc s)>,
     'Om0': 0.30966,
     ...

For details see :ref:`whatever`.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SGTM. I would like to show Table and Model. I think those are the compelling examples.

@nstarman
nstarman force-pushed the cosmo_readwrite_ecsv branch 2 times, most recently from 023ab91 to 9a52d7a Compare October 30, 2021 16:37
Co-authored-by: Tom Aldcroft <[email protected]>
Signed-off-by: Nathaniel Starkman (@nstarman) <[email protected]>
@nstarman
nstarman force-pushed the cosmo_readwrite_ecsv branch from 9a52d7a to 2a4e468 Compare October 30, 2021 16:38
@nstarman
nstarman requested a review from taldcroft October 30, 2021 16:39

@taldcroft taldcroft left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

@nstarman
nstarman merged commit 12d5892 into astropy:main Oct 30, 2021
@nstarman
nstarman deleted the cosmo_readwrite_ecsv branch October 30, 2021 19:55
@nstarman

Copy link
Copy Markdown
Member Author

Thanks @taldcroft for pushing to get this in for v5.0!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants