I have a units.py module in my project where I define a few custom units. How can i add these units so they are accessible like any of the other built-in units, like u.meter?
For example, if I have my units defined like this:
myproj/units.py
import astropy.units as u
foobar = def_unit('foobar')
...
I want to be able to access built-in units like this:
from myproj.units import u
x = np.array((1, 2, 3)) * u.meter
y = np.array((1, 2, 3)) * u.foobar
The pint library does this automatically with it’s u.define function. I would like to replicate this with astropy.
In my package with custom unit, I basically have user import from the units module in my package. So, not completely transparent, but once the quantity is defined, it works just like any other quantity. Perhaps not the answer you are looking for but I am not aware of a better way (would be interested if there is one).
But are they all available under your units this way? Wouldn’t they need to be added to __all__ similar to synphot.units — synphot v1.2.1.dev3+g11db7cf ?
Wondering if something like