I’m a contributor of the astropy-affiliated package
gammapy, an analysis package for gamma-ray astronomy.
The gamma-ray energy range is open-ended and we use energy units ranging from MeV to PeV energies spanning 9 decades !
In gammapy we use astropy units but can sometime end up with values as E=1.5e6 MeV which is hard to understand from a user point of view. E=1.5 TeV is more readable.
In this gammapy PR, I proposed a helper function to transform :
E = [1.54e2 *u.GeV, 4300 u.keV, 300.6e12 u.eV] (astropy unit list)
=> [‘154 GeV’, ‘4.30 MeV’, ‘301 TeV’] (string representation for label, legends, titles, etc)
Right now, I’m just doing an if/elif test to find the most appropriate unit.
See the full code description here.
Is there already way to do this with astropy ?
Same issue exists with distance units (nm,cm,m, lyr, Mpc, etc) or time.
Would you see a more astropy/pythonic way to do this ?
Thanks for any suggestions you might have,