Skip to content

Conversation

@E-W-Jones
Copy link

After the yt workshop in Edinburgh I looked this issue in yt which stems from yt sometimes using its internal, and old, units, and sometimes unyt.

In doing so I discovered that a couple of unyt's constants could be updated to the CODATA 2022 values. I am getting confused by the conversion between SI and CGS units for electromagnetism, and so would appreciate someone else's eyes to tell me if Im missing something.

The issue stems from the fact that the SI had a shift in how they define/measure units, including the permeability of free space, $\mu_0$. It used to be defined as exactly $4\pi \times 10^7~\mathrm{NA}^{-2}$. Now it has to be measured as $1.25663706127(20)\times10^{-6}~\mathrm{NA}^{-2}$. This new value is within an error bar of the old one, and they differ at the 10th decimal place. This is useful because it means you can get away with just not changing it.

When we update this value of $\mu_0$ it raises an error in testing our conversion between SI (metre, kilogram, second, coulomb) and CGS (centimetre, gram, second, statcoulomb) units. Specifically converting the B-field from tesla to gauss. To convert B field you introduce factors of $\sqrt{\frac{4\pi}{\mu_0}}$. This is how you get the equation of energy density used to test the conversion:

B = 1.0 * u.T
B_cgs = B.in_base("cgs")
u_mks = B * B / (2 * u.mu_0)
assert_equal(u_mks.units.dimensions, dimensions.pressure)
u_cgs = B_cgs * B_cgs / (8 * np.pi)

However, this doesn't happen when we convert from tesla to gauss. And it is only sometimes mentioned (for example not on the Gauss (unit) wikipedia page, but is on the Gaussian units but in a way that is unclear to me if it part of the definition of the units. What I do know is that the ratio of u_mks to u_cgs when you convert them between unit systems is the same as the ratio of $\mu_0$ to $4\pi\times10^{-7}~\mathrm{NA}^{-2}$.

Was failing a pytest --doctest-modules test, and unphysical to say the index of an array has the same units as the array, I think.
See [https://pml.nist.gov/cuu/Constants/](https://pml.nist.gov/cuu/Constants/) for CODATA 2022 values.

Link at the top was broken so added what I think is the same information. There are probably a lot of other units that could do with checking.

Each constant I have updated I have included a comment following it with the fact it's from CODATA 2022, and any other information. I think any future updates should also include a comment immediately with the value, as opposed to all sources at the top of the file.

The big change in constants is where some are no longer experimentally determined, but rather have been exactly defined, and vice versa. For example, Avogadro's constant is no longer defined by the mass of a kilogram and determined experimentally, but is exactly defined as 6.02214076e23 1/mol. Inversely, the permeability of free space is no longer exactly defined at 4pi x 10^-7 N A^-2, but is experimentally determined (to within 1 part per billion of the previous value). [https://www.npl.co.uk/resources/the-si-units/the-redefinition-of-the-si-units](https://www.npl.co.uk/resources/the-si-units/the-redefinition-of-the-si-units) has some more general information about the redefinitions.

Changed:
 - electron mass
 - amu
 - proton mass
 - gravitational constant (G)
 - planck constant (h)
 - elementary charge (e)
 - permeability of free space (mu_0)
 - Avogadro's number
 - bolztmann constant
 - erg_per_eV

Changing both G and h mean that the planck units (length, mass, etc.) have also all changed.

speed of light and acceleration due to gravity (g) I haven't changed but I have added the note that these values are the same as CODATA 2022
This function is for testing if the two inputs are both lists of the same length, and that the elements are all close (using the unyt array isclose method)
Changing the number of decimal places in kB (to the CODATA value) meant that assert_equals wasn't working. So I have changed it to assert_allclose, which is consistent with every other comparison in the same block. This meant writing and using the `assert_lists_allclose` function from 87fe8f1.

This commit fails because of electromagnetic units. This is something I'm working on.
@neutrinoceros neutrinoceros marked this pull request as ready for review October 3, 2025 07:50
@neutrinoceros neutrinoceros marked this pull request as draft October 3, 2025 07:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant