-
craftutils.wrap.psfex.Fittable2DModel.coerce_units(input_units=
None, return_units=None, input_units_equivalencies=None, input_units_allow_dimensionless=False) Attach units to this (unitless) model.
Parameters¶
- input_unitsdict or tuple, optional
Input units to attach. If dict, each key is the name of a model input, and the value is the unit to attach. If tuple, the elements are units to attach in order corresponding to Model.inputs.
- return_unitsdict or tuple, optional
Output units to attach. If dict, each key is the name of a model output, and the value is the unit to attach. If tuple, the elements are units to attach in order corresponding to Model.outputs.
- input_units_equivalenciesdict, optional
Default equivalencies to apply to input values. If set, this should be a dictionary where each key is a string that corresponds to one of the model inputs.
- input_units_allow_dimensionlessbool or dict, optional
Allow dimensionless input. If this is True, input values to evaluate will gain the units specified in input_units. If this is a dictionary then it should map input name to a bool to allow dimensionless numbers for that input.
Returns¶
- CompoundModel
A CompoundModel composed of the current model plus ~astropy.modeling.mappings.UnitsMapping model(s) that attach the units.
Raises¶
- ValueError
If the current model already has units.
Examples¶
Wrapping a unitless model to require and convert units:
>>> from astropy.modeling.models import Polynomial1D >>> from astropy import units as u >>> poly = Polynomial1D(1, c0=1, c1=2) >>> model = poly.coerce_units((u.m,), (u.s,)) >>> model(u.Quantity(10, u.m)) <Quantity 21. s> >>> model(u.Quantity(1000, u.cm)) <Quantity 21. s> >>> model(u.Quantity(10, u.cm)) <Quantity 1.2 s>Wrapping a unitless model but still permitting unitless input:
>>> from astropy.modeling.models import Polynomial1D >>> from astropy import units as u >>> poly = Polynomial1D(1, c0=1, c1=2) >>> model = poly.coerce_units((u.m,), (u.s,), input_units_allow_dimensionless=True) >>> model(u.Quantity(10, u.m)) <Quantity 21. s> >>> model(10) <Quantity 21. s>