dataclass_input¶
- sbpy.data.dataclass_input(func=None, **kwargs)¶
Decorator that converts parameters to
DataClass
.sbpy methods use
DataClass
objects whenever possible. But for convenience, we may let users pass other objects that are internally converted:dictionary,
file name,
Examples
>>> import astropy.units as u >>> import sbpy.data as sbd >>> >>> @sbd.dataclass_input(eph=sbd.Ephem) ... def myfunction(eph): ... return eph['rh']**2 * eph['delta']**2 >>> >>> dictionary = {'rh': 2 * u.au, 'delta': 1 * u.au} >>> print(myfunction(dictionary)) [4.0] AU4 >>> >>> from astropy.table import QTable >>> qtable = QTable([[2] * u.au, [1] * u.au], names=('rh', 'delta')) >>> print(myfunction(qtable)) [4.0] AU4
Data classes may also be specified with function annotations: >>> import sbpy.data as sbd >>> >>> @sbd.dataclass_input … def myfunction(eph: sbd.Ephem): … return eph[‘rh’]**2 * eph[‘delta’]**2