Skip to content

Commit

Permalink
Move gauss equivalency to pint __init__ file.
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthew Kerr committed Nov 14, 2024
1 parent 53ae031 commit 3ad5f9b
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
3 changes: 3 additions & 0 deletions src/pint/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@
"hourangle_second": hourangle_second,
}

# define a units equivalency for gauss in cgs
gauss_equiv = [u.Gauss, u.Hz * (u.g / u.cm) ** (1 / 2), lambda x: x, lambda x: x]

import astropy.version

if astropy.version.major < 4:
Expand Down
3 changes: 1 addition & 2 deletions src/pint/derived_quantities.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,7 @@ def _to_gauss(B: u.Quantity) -> u.G:
In cgs units, magnetic field is has units (mass/length)^(1/2) / time.
"""
eq = [u.Gauss, u.Hz * (u.g / u.cm) ** (1 / 2), lambda x: x, lambda x: x]
return B.to(u.Gauss, equivalencies=[eq])
return B.to(u.Gauss, equivalencies=[pint.gauss_equiv])


@u.quantity_input(f=u.Hz, fdot=u.Hz / u.s, fo=u.Hz)
Expand Down

0 comments on commit 3ad5f9b

Please sign in to comment.