SNEWS2 / snewpy

A Python package for working with supernova neutrinos
https://snewpy.readthedocs.io
BSD 3-Clause "New" or "Revised" License
26 stars 19 forks source link

Fixes #267: explicitly call the units decomposition on Container creation #268

Closed Sheshuk closed 1 year ago

Sheshuk commented 1 year ago

Call "decompose" each time a new Container is created - this should prevent situations like "cm2/cm2" or "h/min" units.

Note: this reduces the units to SI bases. If we want, we can list standard SNEWPY units here, so everything will be converted to them instead.

JostMigenda commented 1 year ago

Thanks for investigating this further. As I already said on the AstroPy issue: Very nice detective work!

Regarding this PR, one quick example:

>>> data = [1, 2, 3] << 1/u.MeV/u.s
>>> data.decompose()
<Quantity [6.24150907e+12, 1.24830181e+13, 1.87245272e+13] s / (kg m2)>

So, yes, I think we would need to provide a custom unit list for decomposition; otherwise this will be unintuitive.

Also, have you had a chance to look at the test failures?

Sheshuk commented 1 year ago

Thanks! You're right, I didn't think about MeVs. Now using [MeV, m, s, kg] as the bases. Will this be enough for general use cases? Also it fixes these obscure test failures.