Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I've found <a href="https://github.com/astropy/astropy/blob/master/astropy/units/tests/test_units.py" rel="nofollow">astropy</a> to have a good units module. After some preparation you can do</p> <pre><code>import astropy.units as u from functools import reduce u.Unit('MeV/fm').si #160.218 N eval('1*MeV/fm+3*N',u.__dict__).si #163.21765649999998 N from astropy.units import imperial u.__dict__.update(imperial.__dict__) u.sqmiles = u.mile**2 eval('3*cm/Ys**2 + 4e-4*sqmiles/km/h**2',u.__dict__).si #7.993790464000001e-08 m / s2 </code></pre> <p>The following function adds <code>scipy</code> CODATA constants as quantities to <code>astropy</code> units</p> <pre><code>def units_and_constants(): """ &gt;&gt;&gt; u = units_and_constants() &gt;&gt;&gt; u.hartree_joule_relationship &lt;Quantity 4.35974434e-18 J&gt; &gt;&gt;&gt; eval('1*MeV/fm+3*N',u.__dict__).si &lt;Quantity 163.21765649999998 N&gt; """ import astropy.units as u from astropy.units import imperial u.__dict__.update(imperial.__dict__) from scipy.constants import physical_constants, value, unit import string def qntty(x): un = unit(x) va = value(x) if un: return va*eval(un.strip().replace(' ','*').replace('^','**'),u.__dict__) else: return va u.sr = u.radian**2 u.E_h = qntty('hartree-joule relationship') u.c = qntty('speed of light in vacuum') u.C_90 = (1+4.6e-8)*u.C codata = {} for n, t in physical_constants.items(): v = qntty(n) for x in string.punctuation+' ': n = n.replace(x,'_') codata[n] = v u.__dict__.update(codata) return u </code></pre> <p><a href="http://yt-project.org/" rel="nofollow">yt</a> also <a href="http://ytep.readthedocs.org/en/latest/YTEPs/YTEP-0011.html" rel="nofollow">tackles a problem similar to yours</a>. Have a look at the <a href="https://bitbucket.org/MatthewTurk/yt/src/f157266200b526c63adde4e67971c932a169c4bb/yt/utilities/tests/test_units.py?at=yt-3.0" rel="nofollow">Test file</a> to see how it is used.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload