hope you're all doing well.

I'm not very familiarized with AstroPy and I'm having a problem computing the conversion between angular momentum units.

If I define the abs. value angular momentum

$$ \|\vec{J_2}\| \propto \|\vec{r}\times \vec{p}\| \overset{!}{\propto} a_2 m_2 \left(\frac{G M_s}{a_2}\right)^{1/2} = m_2 (G M_s a_2)^{1/2}$$

from the movement of a body $m_2$ interacting with $M_s$, assuming a Keplerian motion, I'll write:

then, a generic abs. ang. mom. $\|J_1\|$, let's say $$\|J_1\| \equiv \mathrm{\|((1m) \times (1 \frac{kg \, m}{s}))\| = 1 \frac{kg\, m}{s}}$$ J1 = u.m * u.kg * u.m * (1/u.s) should have equivalent dimensions compared to $J_2$. So I should be able to verify using

J2.decompose() or J2.to(J1), but all I get is UnitConversionError: 'AU(1/2) earthMass G(1/2) solMass(1/2)' and 'kg m2 / s' (angular momentum) are not convertible

J1 = angular_momentum(1* u.Msun, 3*u.Mearth, 0.1*u.au)

J2 = u.m * u.kg * u.m * (1/u.s)

---> UnitConversionError


angular_momentum(1*u.Msun, 3*u.Mearth, 0.1*u.au).decompose() #why?

$$3.0900743 \times 10^{43} \mathrm{\frac{kg^2 \,m^{1/2}}{A^{1/2}\,s}} \qquad \mathrm{(output)}$$

this looks like * u.au is not working as expected. Anyways, passing units, e.g., in u.m does not fix the issue.

Question: anyone knows what is happening here?

Edit: this is the function I'm using to compute $J_2$ def angular_momentum(ms, mp, a):

    #from Lp = r x p ~~ a * (mp (G ms / a)^1/2) keplerian rot ~~ mp (g ms a)^1/2
    Lp = mp * (u.G  *  ms  *  a)**(1./2.)   #This MUST! have L units
    return Lp 
  • 5
    $\begingroup$ Screenshots of text are discouraged in Stack Exchange for several reasons, including that they can not be searched and that users using screen readers (e.g. text to speech) can't read them. The standard way is to copy paste the text from your computer output to your post, then for code/script add four spaces in front of each line to display as a code block. I've done that for you here (by just retyping it) and it should probably be done here as well. Thanks! $\endgroup$
    – uhoh
    Oct 12, 2021 at 22:25

1 Answer 1


In Astropy, u.G represents a Gauss, not the gravitational constant. That's why you get the "A" in one of the error messages; it represents an ampere. To use the gravitational constant in your code, you need to use astropy.constants and replace u.G in your code with constants.G (or just add import astropy.constants as c and use c.G, if you prefer).


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .