Last active
February 19, 2018 22:03
-
-
Save nden/40247cb41318902adf91a89de3b516b7 to your computer and use it in GitHub Desktop.
Rules for units in modeling
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Current definitions: | |
input_units_strict | |
# If set to True, values that are passed in compatible units will be converted to | |
# the exact units specified in input_units. | |
input_units_equivalencies | |
# This can be set to a dictionary that maps the input names to a list of equivalencies, for example: | |
input_units_allow_dimensionless | |
# If set to True, values that are plain scalars or Numpy arrays can be passed | |
# to evaluate even if input_units specifies that the input should have units. | |
# It is up to the evaluate() to then decide how to handle these dimensionless values. | |
========== | |
Rules for single models | |
============ | |
- If one parameter is a Quantity (Q), then all should be | |
g = Gaussian1D(10 * u.Jy, 2 * u.m, 1 ) | |
In [41]: g | |
Out[41]: <Gaussian1D(amplitude=10.0 Jy, mean=2.0 m, stddev=1.0)> | |
In [42]: g= Gaussian1D(10, 2 * u.m, 1 * u.m) | |
In [43]: g(2*u.m) | |
Out[43]: <Quantity 10.0> | |
=========================== | |
- If models are defined with Q, inputs also must be Q | |
for Scale: | |
scl = Scale(2*u.one) | |
10*u.m *5*u.one | |
Out[44]: <Quantity 50.0 m> | |
======================= | |
input_units_allow_dimensionless should not be settable | |
================== | |
input_units_strict should not be settable | |
==================== | |
Should input_units and return_units be settable? | |
input_units can be settable | |
return_units should not be settable. | |
================ | |
when creating a model from a function with @custom_model decorator, input_units are not | |
defined. Function annotations should be used | |
=========== | |
Rules for Compound models | |
==================== | |
If one of the submodels is instantiated with units then all submodels should be initialized with Q | |
========================== | |
- If initialized with Q, inputs shuld be Q. | |
============== | |
The rest of the rules are the same as for single models. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The rest of the rules sounds reasonable. If for whatever reason, I don't want one of my parameters to have units, I will simply use the model as unitless and then re-apply units outside of models, like the old days.