Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cosmological units module #12092

Merged
merged 5 commits into from Aug 24, 2021
Merged

Cosmological units module #12092

merged 5 commits into from Aug 24, 2021

Conversation

nstarman
Copy link
Member

@nstarman nstarman commented Aug 20, 2021

Adds a new module to Cosmology — units — for defining and collecting cosmological units and
equivalencies.
@eteq, though I advocated for it, I'm holding off from actually moving littleh and with_H0 for now. The latter will be easy to move, but moving littleh and having it be imported into units/astrophys is a nightmare of circular imports.
It would be much easier to just deprecate it from units/astrophys, but I'd want some discussion on that, and since it's a low priority, I'll save it for a followup. Thanks!

Necessary For : #11784
Fixes: #12093

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.
  • 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 Aug 20, 2021
@nstarman nstarman requested a review from eteq August 20, 2021 01:50
@nstarman nstarman added this to In progress in Cosmology, the Expansion via automation Aug 20, 2021
@pep8speaks
Copy link

pep8speaks commented Aug 20, 2021

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-08-24 19:33:17 UTC

Copy link
Contributor

@mhvk mhvk left a comment

Choose a reason for hiding this comment

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

This looks good. A question is whether the documentation of with_H0 in units.equivalencies should not just point here. But perhaps that becomes more logical if the equivalency and unit definitions are moved here as well - which is perhaps requires more logic than is worth it...

Anyway, more important is to move forward and define new stuff here!

docs/cosmology/index.rst Outdated Show resolved Hide resolved
@@ -557,3 +566,4 @@ Reference/API
=============

.. automodapi:: astropy.cosmology

Copy link
Contributor

Choose a reason for hiding this comment

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

Extraneous empty line? (Emacs would auto-remove it with my no-end-of-line space setting...)

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah. My editor has an end-of-line space setting! 😆.
I think it's PEP8 W292 (https://www.flake8rules.com/rules/W292.html)

# This generates a docstring for this module that describes all of the
# standard units defined here.
if __doc__ is not None:
__doc__ += _generate_unit_summary(globals())
Copy link
Contributor

Choose a reason for hiding this comment

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

Would it be an idea to define enable() (as in imperial.py, etc.)?

Copy link
Member Author

Choose a reason for hiding this comment

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

Let me take a look! that seems a good idea.

Copy link
Contributor

Choose a reason for hiding this comment

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

My second thought was perhaps not (see below), but do have your own look, since clearly I am wavering!

docs/cosmology/units.rst Show resolved Hide resolved
docs/cosmology/units.rst Outdated Show resolved Hide resolved
@nstarman nstarman force-pushed the cosmo_units branch 6 times, most recently from bf9af7a to 3a44376 Compare August 24, 2021 06:23
@nstarman
Copy link
Member Author

@mhvk, I'm not sure if we want to deprecate littleh and with_H0 from astropy.units, so I've collapsed that into one commit. Can roll back...

"hours."

If no argument is given (or the argument is `None`), this equivalency assumes
the ``H0`` from the current default :ref:`cosmology <astropy-cosmology>`:
Copy link
Member

Choose a reason for hiding this comment

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

When this text was in the units documentation it made sense to have a link to the cosmology subpackage, but if you are moving the text then it might be better to use

Suggested change
the ``H0`` from the current default :ref:`cosmology <astropy-cosmology>`:
the ``H0`` from the current default :class:`~astropy.cosmology.Cosmology`:

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks! applied in 958aa5c

Copy link
Contributor

@mhvk mhvk left a comment

Choose a reason for hiding this comment

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

I was unsure, but now seeing it, I think a real move to cosmology.units and deprecating in units is the right way to go! Also, LTS versions are the best place to do these types of things, as then they have more minimal impact for packages that try to support LTS+current.

astropy/cosmology/units.py Outdated Show resolved Hide resolved
astropy/cosmology/units.py Outdated Show resolved Hide resolved
astropy/cosmology/units.py Outdated Show resolved Hide resolved
astropy/units/__init__.py Outdated Show resolved Hide resolved
astropy/units/__init__.py Outdated Show resolved Hide resolved
@@ -0,0 +1,3 @@
Added units module for defining and collecting cosmological units and
equivalencies. The units can be added to the main Astropy units namespace using
Copy link
Contributor

Choose a reason for hiding this comment

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

As you noted, this is not quite true.

Copy link
Member Author

Choose a reason for hiding this comment

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

I've removed that portion.

For some future date: with a module-level__getattr__ and the units registry it should be possible for add_enabled_units to also put the units on the top-level namespace in a way that's compatible with _UnitsContext (context manager returned by add_enabled_units).

Copy link
Contributor

Choose a reason for hiding this comment

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

True, though perhaps too much magic? And perhaps worries for thread safety? I guess the idea of enabling units was mostly that they can be used in strings, and thus in storing them inside files, etc.

docs/cosmology/units.rst Show resolved Hide resolved
docs/cosmology/units.rst Show resolved Hide resolved
docs/units/index.rst Outdated Show resolved Hide resolved
astropy/units/astrophys.py Outdated Show resolved Hide resolved
nstarman and others added 2 commits August 24, 2021 14:43
Signed-off-by: Nathaniel Starkman (@nstarman) <nstarkman@protonmail.com>
Co-authored-by: Erik Tollerud <erik.tollerud@gmail.com>
Signed-off-by: Nathaniel Starkman (@nstarman) <nstarkman@protonmail.com>
@nstarman nstarman force-pushed the cosmo_units branch 2 times, most recently from 588c0bf to f3f3c00 Compare August 24, 2021 19:14
Copy link
Contributor

@mhvk mhvk left a comment

Choose a reason for hiding this comment

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

Looks all great now, except still to revert the added lines in docs/units/index.rst (I think).

docs/units/index.rst Outdated Show resolved Hide resolved
@@ -252,6 +253,7 @@ Reference/API
.. automodapi:: astropy.units.physical

.. automodapi:: astropy.units.equivalencies
:skip: with_H0
Copy link
Contributor

Choose a reason for hiding this comment

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

And this one too?

Copy link
Member Author

Choose a reason for hiding this comment

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

How did those sneak in there?!? I used a fixup! commit to prune them from the whole history

Copy link
Member Author

Choose a reason for hiding this comment

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

Gone now.

Signed-off-by: Nathaniel Starkman (@nstarman) <nstarkman@protonmail.com>
nstarman and others added 2 commits August 24, 2021 15:32
Signed-off-by: Nathaniel Starkman (@nstarman) <nstarkman@protonmail.com>
Co-authored-by: Eero Vaher <eero.vaher@astro.lu.se>
Signed-off-by: Nathaniel Starkman (@nstarman) <nstarkman@protonmail.com>
@nstarman
Copy link
Member Author

Thanks @mhvk and @eerovaher for the reviews!

Copy link
Contributor

@mhvk mhvk left a comment

Choose a reason for hiding this comment

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

Looks all OK now! (Weird about the git thingy not working)

Cosmology, the Expansion automation moved this from In progress to Reviewer approved Aug 24, 2021
@mhvk
Copy link
Contributor

mhvk commented Aug 24, 2021

The code coverage is clearly a red herring, so merging. Thanks, @nstarman!

@mhvk mhvk merged commit 2631ed5 into astropy:main Aug 24, 2021
Cosmology, the Expansion automation moved this from Reviewer approved to Done Aug 24, 2021
@nstarman nstarman deleted the cosmo_units branch August 24, 2021 20:04
@nstarman
Copy link
Member Author

@mhvk. I'm thinking this might have merited a whatsnew... here or in the followup adding cosmological redshift units

@mhvk
Copy link
Contributor

mhvk commented Aug 24, 2021

Yes, with the redshift unit - so that it makes sense that there is a new cosmology.units module.

eerovaher added a commit to eerovaher/astropy that referenced this pull request Oct 20, 2023
In astropy#12092 `littleh` and `with_H0` were moved from `units` to
`cosmology.units`, but importing them from `units` was still possible,
albeit deprecated. Removing them from `units` entirely finalizes the
moving process.
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.

Add a cosmology.units module
4 participants