/usr/share/doc/python-pint-doc/html/nonmult.html is in python-pint-doc 0.8.1-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Temperature conversion — pint 0.8.1 documentation</title>
<link rel="stylesheet" href="_static/flasky.css" type="text/css" />
<link rel="stylesheet" href="_static/pygments.css" type="text/css" />
<script type="text/javascript">
var DOCUMENTATION_OPTIONS = {
URL_ROOT: './',
VERSION: '0.8.1',
COLLAPSE_INDEX: false,
FILE_SUFFIX: '.html',
HAS_SOURCE: true,
SOURCELINK_SUFFIX: '.txt'
};
</script>
<script type="text/javascript" src="_static/jquery.js"></script>
<script type="text/javascript" src="_static/underscore.js"></script>
<script type="text/javascript" src="_static/doctools.js"></script>
<link rel="index" title="Index" href="genindex.html" />
<link rel="search" title="Search" href="search.html" />
<link rel="next" title="Wrapping and checking functions" href="wrapping.html" />
<link rel="prev" title="NumPy support" href="numpy.html" />
<link media="only screen and (max-device-width: 480px)" href="_static/small_flask.css" type= "text/css" rel="stylesheet" />
</head>
<body>
<div class="related" role="navigation" aria-label="related navigation">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="genindex.html" title="General Index"
accesskey="I">index</a></li>
<li class="right" >
<a href="wrapping.html" title="Wrapping and checking functions"
accesskey="N">next</a> |</li>
<li class="right" >
<a href="numpy.html" title="NumPy support"
accesskey="P">previous</a> |</li>
<li class="nav-item nav-item-0"><a href="index.html">pint 0.8.1 documentation</a> »</li>
</ul>
</div>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body" role="main">
<div class="section" id="temperature-conversion">
<span id="nonmult"></span><h1>Temperature conversion<a class="headerlink" href="#temperature-conversion" title="Permalink to this headline">¶</a></h1>
<p>Unlike meters and seconds, the temperature units fahrenheits and
celsius are non-multiplicative units. These temperature units are
expressed in a system with a reference point, and relations between
temperature units include not only a scaling factor but also an offset.
Pint supports these type of units and conversions between them.
The default definition file includes fahrenheits, celsius,
kelvin and rankine abbreviated as degF, degC, degK, and degR.</p>
<p>For example, to convert from celsius to fahrenheit:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="kn">from</span> <span class="nn">pint</span> <span class="k">import</span> <span class="n">UnitRegistry</span>
<span class="gp">>>> </span><span class="n">ureg</span> <span class="o">=</span> <span class="n">UnitRegistry</span><span class="p">()</span>
<span class="gp">>>> </span><span class="n">Q_</span> <span class="o">=</span> <span class="n">ureg</span><span class="o">.</span><span class="n">Quantity</span>
<span class="gp">>>> </span><span class="n">home</span> <span class="o">=</span> <span class="n">Q_</span><span class="p">(</span><span class="mf">25.4</span><span class="p">,</span> <span class="n">ureg</span><span class="o">.</span><span class="n">degC</span><span class="p">)</span>
<span class="gp">>>> </span><span class="nb">print</span><span class="p">(</span><span class="n">home</span><span class="o">.</span><span class="n">to</span><span class="p">(</span><span class="s1">'degF'</span><span class="p">))</span>
<span class="go">77.7200004 degF</span>
</pre></div>
</div>
<p>or to other kelvin or rankine:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="nb">print</span><span class="p">(</span><span class="n">home</span><span class="o">.</span><span class="n">to</span><span class="p">(</span><span class="s1">'kelvin'</span><span class="p">))</span>
<span class="go">298.55 kelvin</span>
<span class="gp">>>> </span><span class="nb">print</span><span class="p">(</span><span class="n">home</span><span class="o">.</span><span class="n">to</span><span class="p">(</span><span class="s1">'degR'</span><span class="p">))</span>
<span class="go">537.39 degR</span>
</pre></div>
</div>
<p>Additionally, for every non-multiplicative temperature unit
in the registry, there is also a <em>delta</em> counterpart to specify
differences. Absolute units have no <em>delta</em> counterpart.
For example, the change in celsius is equal to the change
in kelvin, but not in fahrenheit (as the scaling factor
is different).</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">increase</span> <span class="o">=</span> <span class="mf">12.3</span> <span class="o">*</span> <span class="n">ureg</span><span class="o">.</span><span class="n">delta_degC</span>
<span class="gp">>>> </span><span class="nb">print</span><span class="p">(</span><span class="n">increase</span><span class="o">.</span><span class="n">to</span><span class="p">(</span><span class="n">ureg</span><span class="o">.</span><span class="n">kelvin</span><span class="p">))</span>
<span class="go">12.3 kelvin</span>
<span class="gp">>>> </span><span class="nb">print</span><span class="p">(</span><span class="n">increase</span><span class="o">.</span><span class="n">to</span><span class="p">(</span><span class="n">ureg</span><span class="o">.</span><span class="n">delta_degF</span><span class="p">))</span>
<span class="go">22.14 delta_degF</span>
</pre></div>
</div>
<p>Subtraction of two temperatures given in offset units yields a <em>delta</em> unit:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">Q_</span><span class="p">(</span><span class="mf">25.4</span><span class="p">,</span> <span class="n">ureg</span><span class="o">.</span><span class="n">degC</span><span class="p">)</span> <span class="o">-</span> <span class="n">Q_</span><span class="p">(</span><span class="mf">10.</span><span class="p">,</span> <span class="n">ureg</span><span class="o">.</span><span class="n">degC</span><span class="p">)</span>
<span class="go"><Quantity(15.4, 'delta_degC')></span>
</pre></div>
</div>
<p>You can add or subtract a quantity with <em>delta</em> unit and a quantity with
offset unit:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">Q_</span><span class="p">(</span><span class="mf">25.4</span><span class="p">,</span> <span class="n">ureg</span><span class="o">.</span><span class="n">degC</span><span class="p">)</span> <span class="o">+</span> <span class="n">Q_</span><span class="p">(</span><span class="mf">10.</span><span class="p">,</span> <span class="n">ureg</span><span class="o">.</span><span class="n">delta_degC</span><span class="p">)</span>
<span class="go"><Quantity(35.4, 'degC')></span>
<span class="gp">>>> </span><span class="n">Q_</span><span class="p">(</span><span class="mf">25.4</span><span class="p">,</span> <span class="n">ureg</span><span class="o">.</span><span class="n">degC</span><span class="p">)</span> <span class="o">-</span> <span class="n">Q_</span><span class="p">(</span><span class="mf">10.</span><span class="p">,</span> <span class="n">ureg</span><span class="o">.</span><span class="n">delta_degC</span><span class="p">)</span>
<span class="go"><Quantity(15.4, 'degC')></span>
</pre></div>
</div>
<p>If you want to add a quantity with absolute unit to one with offset unit, like here</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">heating_rate</span> <span class="o">=</span> <span class="mf">0.5</span> <span class="o">*</span> <span class="n">ureg</span><span class="o">.</span><span class="n">kelvin</span><span class="o">/</span><span class="n">ureg</span><span class="o">.</span><span class="n">min</span>
<span class="gp">>>> </span><span class="n">Q_</span><span class="p">(</span><span class="mf">10.</span><span class="p">,</span> <span class="n">ureg</span><span class="o">.</span><span class="n">degC</span><span class="p">)</span> <span class="o">+</span> <span class="n">heating_rate</span> <span class="o">*</span> <span class="n">Q_</span><span class="p">(</span><span class="mi">30</span><span class="p">,</span> <span class="n">ureg</span><span class="o">.</span><span class="n">min</span><span class="p">)</span>
<span class="gt">Traceback (most recent call last):</span>
<span class="o">...</span>
<span class="gr">pint.errors.OffsetUnitCalculusError</span>: <span class="n">Ambiguous operation with offset unit (degC, kelvin).</span>
</pre></div>
</div>
<p>you have to avoid the ambiguity by either converting the offset unit to the
absolute unit before addition</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">Q_</span><span class="p">(</span><span class="mf">10.</span><span class="p">,</span> <span class="n">ureg</span><span class="o">.</span><span class="n">degC</span><span class="p">)</span><span class="o">.</span><span class="n">to</span><span class="p">(</span><span class="n">ureg</span><span class="o">.</span><span class="n">kelvin</span><span class="p">)</span> <span class="o">+</span> <span class="n">heating_rate</span> <span class="o">*</span> <span class="n">Q_</span><span class="p">(</span><span class="mi">30</span><span class="p">,</span> <span class="n">ureg</span><span class="o">.</span><span class="n">min</span><span class="p">)</span>
<span class="go"><Quantity(298.15, 'kelvin')></span>
</pre></div>
</div>
<p>or convert the absolute unit to a <em>delta</em> unit:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">Q_</span><span class="p">(</span><span class="mf">10.</span><span class="p">,</span> <span class="n">ureg</span><span class="o">.</span><span class="n">degC</span><span class="p">)</span> <span class="o">+</span> <span class="n">heating_rate</span><span class="o">.</span><span class="n">to</span><span class="p">(</span><span class="s1">'delta_degC/min'</span><span class="p">)</span> <span class="o">*</span> <span class="n">Q_</span><span class="p">(</span><span class="mi">30</span><span class="p">,</span> <span class="n">ureg</span><span class="o">.</span><span class="n">min</span><span class="p">)</span>
<span class="go"><Quantity(25.0, 'degC')></span>
</pre></div>
</div>
<p>In contrast to subtraction, the addition of quantities with offset units
is ambiguous, e.g. for <em>10 degC + 100 degC</em> two different result are reasonable
depending on the context, <em>110 degC</em> or <em>383.15 °C (= 283.15 K + 373.15 K)</em>.
Because of this ambiguity pint raises an error for the addition of two
quantities with offset units (since pint-0.6).</p>
<p>Quantities with <em>delta</em> units are multiplicative:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">speed</span> <span class="o">=</span> <span class="mf">60.</span> <span class="o">*</span> <span class="n">ureg</span><span class="o">.</span><span class="n">delta_degC</span> <span class="o">/</span> <span class="n">ureg</span><span class="o">.</span><span class="n">min</span>
<span class="gp">>>> </span><span class="nb">print</span><span class="p">(</span><span class="n">speed</span><span class="o">.</span><span class="n">to</span><span class="p">(</span><span class="s1">'delta_degC/second'</span><span class="p">))</span>
<span class="go">1.0 delta_degC / second</span>
</pre></div>
</div>
<p>However, multiplication, division and exponentiation of quantities with
offset units is problematic just like addition. Pint (since version 0.6)
will by default raise an error when a quantity with offset unit is used in
these operations. Due to this quantities with offset units cannot be created
like other quantities by multiplication of magnitude and unit but have
to be explicitly created:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">ureg</span> <span class="o">=</span> <span class="n">UnitRegistry</span><span class="p">()</span>
<span class="gp">>>> </span><span class="n">home</span> <span class="o">=</span> <span class="mf">25.4</span> <span class="o">*</span> <span class="n">ureg</span><span class="o">.</span><span class="n">degC</span>
<span class="gt">Traceback (most recent call last):</span>
<span class="o">...</span>
<span class="gr">pint.errors.OffsetUnitCalculusError</span>: <span class="n">Ambiguous operation with offset unit (degC).</span>
<span class="gp">>>> </span><span class="n">Q_</span><span class="p">(</span><span class="mf">25.4</span><span class="p">,</span> <span class="n">ureg</span><span class="o">.</span><span class="n">degC</span><span class="p">)</span>
<span class="go"><Quantity(25.4, 'degC')></span>
</pre></div>
</div>
<p>As an alternative to raising an error, pint can be configured to work more
relaxed via setting the UnitRegistry parameter <em>autoconvert_offset_to_baseunit</em>
to true. In this mode, pint behaves differently:</p>
<ul class="simple">
<li>Multiplication of a quantity with a single offset unit with order +1 by
a number or ndarray yields the quantity in the given unit.</li>
</ul>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">ureg</span> <span class="o">=</span> <span class="n">UnitRegistry</span><span class="p">(</span><span class="n">autoconvert_offset_to_baseunit</span> <span class="o">=</span> <span class="kc">True</span><span class="p">)</span>
<span class="gp">>>> </span><span class="n">T</span> <span class="o">=</span> <span class="mf">25.4</span> <span class="o">*</span> <span class="n">ureg</span><span class="o">.</span><span class="n">degC</span>
<span class="gp">>>> </span><span class="n">T</span>
<span class="go"><Quantity(25.4, 'degC')></span>
</pre></div>
</div>
<ul>
<li><p class="first">Before all other multiplications, all divisions and in case of
exponentiation <a class="footnote-reference" href="#f1" id="id1">[1]</a> involving quantities with offset-units, pint
will convert the quantities with offset units automatically to the
corresponding base unit before performing the operation.</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="mi">1</span><span class="o">/</span><span class="n">T</span>
<span class="go"><Quantity(0.00334952269302, '1 / kelvin')></span>
<span class="gp">>>> </span><span class="n">T</span> <span class="o">*</span> <span class="mi">10</span> <span class="o">*</span> <span class="n">ureg</span><span class="o">.</span><span class="n">meter</span>
<span class="go"><Quantity(527.15, 'kelvin * meter')></span>
</pre></div>
</div>
</li>
</ul>
<p>You can change the behaviour at any time:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">ureg</span><span class="o">.</span><span class="n">autoconvert_offset_to_baseunit</span> <span class="o">=</span> <span class="kc">False</span>
<span class="gp">>>> </span><span class="mi">1</span><span class="o">/</span><span class="n">T</span>
<span class="gt">Traceback (most recent call last):</span>
<span class="o">...</span>
<span class="gr">pint.errors.OffsetUnitCalculusError</span>: <span class="n">Ambiguous operation with offset unit (degC).</span>
</pre></div>
</div>
<p>The parser knows about <em>delta</em> units and uses them when a temperature unit
is found in a multiplicative context. For example, here:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="nb">print</span><span class="p">(</span><span class="n">ureg</span><span class="o">.</span><span class="n">parse_units</span><span class="p">(</span><span class="s1">'degC/meter'</span><span class="p">))</span>
<span class="go">delta_degC / meter</span>
</pre></div>
</div>
<p>but not here:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="nb">print</span><span class="p">(</span><span class="n">ureg</span><span class="o">.</span><span class="n">parse_units</span><span class="p">(</span><span class="s1">'degC'</span><span class="p">))</span>
<span class="go">degC</span>
</pre></div>
</div>
<p>You can override this behaviour:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="nb">print</span><span class="p">(</span><span class="n">ureg</span><span class="o">.</span><span class="n">parse_units</span><span class="p">(</span><span class="s1">'degC/meter'</span><span class="p">,</span> <span class="n">as_delta</span><span class="o">=</span><span class="kc">False</span><span class="p">))</span>
<span class="go">degC / meter</span>
</pre></div>
</div>
<p>Note that the magnitude is left unchanged:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">Q_</span><span class="p">(</span><span class="mi">10</span><span class="p">,</span> <span class="s1">'degC/meter'</span><span class="p">)</span>
<span class="go"><Quantity(10, 'delta_degC / meter')></span>
</pre></div>
</div>
<p>To define a new temperature, you need to specify the offset. For example,
this is the definition of the celsius and fahrenheit:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">degC</span> <span class="o">=</span> <span class="n">degK</span><span class="p">;</span> <span class="n">offset</span><span class="p">:</span> <span class="mf">273.15</span> <span class="o">=</span> <span class="n">celsius</span>
<span class="n">degF</span> <span class="o">=</span> <span class="mi">5</span> <span class="o">/</span> <span class="mi">9</span> <span class="o">*</span> <span class="n">degK</span><span class="p">;</span> <span class="n">offset</span><span class="p">:</span> <span class="mf">255.372222</span> <span class="o">=</span> <span class="n">fahrenheit</span>
</pre></div>
</div>
<p>You do not need to define <em>delta</em> units, as they are defined automatically.</p>
<table class="docutils footnote" frame="void" id="f1" rules="none">
<colgroup><col class="label" /><col /></colgroup>
<tbody valign="top">
<tr><td class="label"><a class="fn-backref" href="#id1">[1]</a></td><td>If the exponent is +1, the quantity will not be converted to base
unit but remains unchanged.</td></tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
<div class="sphinxsidebar" role="navigation" aria-label="main navigation">
<div class="sphinxsidebarwrapper"><p><a href="index.html">
<img src="_images/logo-full.jpg" alt="Logo" style="width:80%;height:80%"/>
</a></p>
<h3>About Pint</h3>
Units in Python.
You are currently looking at the documentation of version 0.8.1.
<h3>Other Formats</h3>
<p>
You can download the documentation in other formats as well:
</p>
<ul>
<li><a href="https://media.readthedocs.org/pdf/pint/latest/pint.pdf">as PDF</a>
<li><a href="https://media.readthedocs.org/htmlzip/pint/latest/pint.zip">as zipped HTML</a>
<li><a href="https://media.readthedocs.org/epub/pint/latest/pint.epub">as ePub</a>
</ul>
<h3>Useful Links</h3>
<ul>
<li><a href="https://pypi.python.org/pypi/Pint/">Pint @ PyPI</a></li>
<li><a href="https://github.com/hgrecco/pint">Code in GitHub</a></li>
<li><a href="https://github.com/hgrecco/pint/issues">Issue Tracker</a></li>
</ul>
<h3>Related Topics</h3>
<ul>
<li><a href="index.html">Documentation overview</a></li>
<p>
<b>Previous</b><br/>
<a href="numpy.html" title="previous chapter">NumPy support</a>
</p>
<p>
<b>Next</b><br/>
<a href="wrapping.html" title="next chapter">Wrapping and checking functions</a>
</p>
<div role="note" aria-label="source link">
<h3>This Page</h3>
<ul class="this-page-menu">
<li><a href="_sources/nonmult.rst.txt"
rel="nofollow">Show Source</a></li>
</ul>
</div>
<div id="searchbox" style="display: none" role="search">
<h3>Quick search</h3>
<form class="search" action="search.html" method="get">
<div><input type="text" name="q" /></div>
<div><input type="submit" value="Go" /></div>
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
</div>
</div>
<div class="clearer"></div>
</div>
<a href="http://github.com/hgrecco/pint"><img style="position: fixed; top: 0; right: 0; border: 0;"
src="" alt="Fork me on GitHub" /></a>
<div class="footer">
© Copyright 2018, Hernan E. Grecco. Pint 0.8.1.
Created using <a href="http://sphinx.pocoo.org/">Sphinx</a>.
</div>
</body>
</html>
|