Created
March 22, 2017 23:11
-
-
Save jdriordan/7209af6160bfe345eff66b996ffb2be9 to your computer and use it in GitHub Desktop.
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
| import pint | |
| units = pint.UnitRegistry() | |
| def make_constant(name): | |
| '''Make a dimensional quanitity from a CODATA value using pint and scipy''' | |
| from warnings import warn | |
| from scipy.constants import physical_constants | |
| if not (name in physical_constants): | |
| matches = scipy.constants.find(name) | |
| if matches==[] : | |
| raise LookupError("Constant not found, use scipy.constant.find(name) \n or see https://docs.scipy.org/doc/scipy/reference/constants.html") | |
| else: | |
| warn("Assuming \"{}\" means \"{}\".".format(name,matches[0])) | |
| name = matches[0] | |
| value, unit, error = physical_constants[name] | |
| return value*units[unit] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment