<!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>Constants (astropy.constants) — Astropy v0.2.4</title> <link rel="stylesheet" href="../_static/bootstrap-astropy.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.2.4', COLLAPSE_INDEX: false, FILE_SUFFIX: '.html', HAS_SOURCE: true }; </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> <script type="text/javascript" src="../_static/sidebar.js"></script> <link rel="shortcut icon" href="../_static/astropy_logo.ico"/> <link rel="top" title="Astropy v0.2.4" href="../index.html" /> <link rel="next" title="Constant" href="../_generated/astropy.constants.constant.Constant.html" /> <link rel="prev" title="What’s New in Astropy 0.2" href="../whatsnew/0.2.html" /> </head> <body> <div class="topbar"> <a class="brand" title="Documentation Home" href="../index.html"></a> <ul> <li><a class="homelink" title="AstroPy Homepage" href="http://www.astropy.org"></a></li> <li><a title="General Index" href="../genindex.html">Index</a></li> <li><a title="Python Module Index" href="../py-modindex.html">Modules</a></li> <li> <form action="../search.html" method="get"> <input type="text" name="q" placeholder="Search" /> <input type="hidden" name="check_keywords" value="yes" /> <input type="hidden" name="area" value="default" /> </form> </li> </ul> </div> <div class="related"> <h3>Navigation</h3> <ul> <li class="right"> <a href="../_generated/astropy.constants.constant.Constant.html" title="Constant"> next » </a> </li> <li class="right"> <a href="../whatsnew/0.2.html" title="What’s New in Astropy 0.2"> « previous </a> | </li> <li> <a href="../index.html">Astropy v0.2.4</a> » </li> <li>Constants (<tt class="docutils literal"><span class="pre">astropy.constants</span></tt>)</li> </ul> </div> <div class="document"> <div class="documentwrapper"> <div class="bodywrapper"> <div class="body"> <div class="section" id="constants-astropy-constants"> <h1>Constants (<a class="reference internal" href="#module-astropy.constants" title="astropy.constants"><tt class="xref py py-obj docutils literal"><span class="pre">astropy.constants</span></tt></a>)<a class="headerlink" href="#constants-astropy-constants" title="Permalink to this headline">¶</a></h1> <div class="section" id="introduction"> <h2>Introduction<a class="headerlink" href="#introduction" title="Permalink to this headline">¶</a></h2> <p><a class="reference internal" href="#module-astropy.constants" title="astropy.constants"><tt class="xref py py-obj docutils literal"><span class="pre">astropy.constants</span></tt></a> contains a number of physical constants useful in Astronomy. Constants are <a class="reference internal" href="../_generated/astropy.units.quantity.Quantity.html#astropy.units.quantity.Quantity" title="astropy.units.quantity.Quantity"><tt class="xref py py-obj docutils literal"><span class="pre">Quantity</span></tt></a> objects with additional meta-data describing their provenance and uncertainties.</p> </div> <div class="section" id="getting-started"> <h2>Getting Started<a class="headerlink" href="#getting-started" title="Permalink to this headline">¶</a></h2> <p>To use the constants in S.I. units, you can import the constants directly from the <a class="reference internal" href="#module-astropy.constants" title="astropy.constants"><tt class="xref py py-obj docutils literal"><span class="pre">astropy.constants</span></tt></a> sub-package:</p> <div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="kn">from</span> <span class="nn">astropy.constants</span> <span class="kn">import</span> <span class="n">G</span> </pre></div> </div> <p>or, if you want to avoid having to explicitly import all the constants you need, you can simply do:</p> <div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="kn">from</span> <span class="nn">astropy</span> <span class="kn">import</span> <span class="n">constants</span> <span class="k">as</span> <span class="n">const</span> </pre></div> </div> <p>and then subsequently use for example <tt class="docutils literal"><span class="pre">const.G</span></tt>. Constants are fully-fleged <a class="reference internal" href="../_generated/astropy.units.quantity.Quantity.html#astropy.units.quantity.Quantity" title="astropy.units.quantity.Quantity"><tt class="xref py py-obj docutils literal"><span class="pre">Quantity</span></tt></a> objects, so you can easily convert them to different units for example:</p> <div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="k">print</span> <span class="n">const</span><span class="o">.</span><span class="n">c</span> <span class="go"> Name = Speed of light in vacuum</span> <span class="go"> Value = 299792458.0</span> <span class="go"> Error = 0.0</span> <span class="go"> Units = m / (s)</span> <span class="go"> Reference = CODATA 2010</span> <span class="gp">>>> </span><span class="k">print</span> <span class="n">const</span><span class="o">.</span><span class="n">c</span><span class="o">.</span><span class="n">to</span><span class="p">(</span><span class="s">'km/s'</span><span class="p">)</span> <span class="go">299792.458 km / (s)</span> <span class="gp">>>> </span><span class="k">print</span> <span class="n">const</span><span class="o">.</span><span class="n">c</span><span class="o">.</span><span class="n">to</span><span class="p">(</span><span class="s">'pc/yr'</span><span class="p">)</span> <span class="go">0.306594845466 pc / (yr)</span> </pre></div> </div> <p>and you can use them in conjunction with unit and other non-constant <a class="reference internal" href="../_generated/astropy.units.quantity.Quantity.html#astropy.units.quantity.Quantity" title="astropy.units.quantity.Quantity"><tt class="xref py py-obj docutils literal"><span class="pre">Quantity</span></tt></a> objects:</p> <div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">F</span> <span class="o">=</span> <span class="p">(</span><span class="n">const</span><span class="o">.</span><span class="n">G</span> <span class="o">*</span> <span class="mf">3.</span> <span class="o">*</span> <span class="n">const</span><span class="o">.</span><span class="n">M_sun</span> <span class="o">*</span> <span class="mi">100</span> <span class="o">*</span> <span class="n">u</span><span class="o">.</span><span class="n">kg</span><span class="p">)</span> <span class="o">/</span> <span class="p">(</span><span class="mf">2.2</span> <span class="o">*</span> <span class="n">u</span><span class="o">.</span><span class="n">au</span><span class="p">)</span> <span class="o">**</span> <span class="mi">2</span> <span class="gp">>>> </span><span class="k">print</span> <span class="n">F</span><span class="o">.</span><span class="n">to</span><span class="p">(</span><span class="n">u</span><span class="o">.</span><span class="n">N</span><span class="p">)</span> <span class="go">0.367669392028 N</span> </pre></div> </div> <p>It is possible to convert most constants to cgs using e.g.:</p> <div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">const</span><span class="o">.</span><span class="n">c</span><span class="o">.</span><span class="n">cgs</span> <span class="go"><Quantity 29979245800.0 cm / (s)></span> </pre></div> </div> <p>However, some constants are defined with different physical dimensions in cgs and cannot be directly converted. Because of this ambiguity, such constants cannot be used in expressions without specifying a system:</p> <div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="mi">100</span> <span class="o">*</span> <span class="n">const</span><span class="o">.</span><span class="n">e</span> <span class="go">ERROR: TypeError: Constant 'e' does not have physically compatible units</span> <span class="go">across all systems of units and cannot be combined with other values without</span> <span class="go">specifying a system (eg. e.esu) [astropy.constants.constant]</span> <span class="gp">...</span> <span class="gp">>>> </span><span class="mi">100</span> <span class="o">*</span> <span class="n">const</span><span class="o">.</span><span class="n">e</span><span class="o">.</span><span class="n">esu</span> <span class="go"><Quantity 4.80320450571e-08 Fr></span> </pre></div> </div> </div> <div class="section" id="reference-api"> <h2>Reference/API<a class="headerlink" href="#reference-api" title="Permalink to this headline">¶</a></h2> <div class="section" id="module-astropy.constants"> <span id="astropy-constants-module"></span><h3>astropy.constants Module<a class="headerlink" href="#module-astropy.constants" title="Permalink to this headline">¶</a></h3> <p>Contains astronomical and physical constants for use in Astropy or other places.</p> <p>A typical use case might be:</p> <div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="kn">from</span> <span class="nn">astropy.constants</span> <span class="kn">import</span> <span class="n">c</span><span class="p">,</span> <span class="n">m_e</span> <span class="gp">>>> </span><span class="c"># ... define the mass of something you want the rest energy of as m ...</span> <span class="gp">>>> </span><span class="n">m</span> <span class="o">=</span> <span class="n">m_e</span> <span class="gp">>>> </span><span class="n">E</span> <span class="o">=</span> <span class="n">m</span> <span class="o">*</span> <span class="n">c</span><span class="o">**</span><span class="mi">2</span> <span class="gp">>>> </span><span class="n">E</span><span class="o">.</span><span class="n">to</span><span class="p">(</span><span class="s">'MeV'</span><span class="p">)</span> <span class="go"><Quantity 0.510998927603 MeV></span> </pre></div> </div> <p>The following constants are available:</p> <table border="1" class="docutils"> <colgroup> <col width="15%" /> <col width="22%" /> <col width="25%" /> <col width="38%" /> </colgroup> <thead valign="bottom"> <tr class="row-odd"><th class="head">Name</th> <th class="head">Value</th> <th class="head">Unit</th> <th class="head">Description</th> </tr> </thead> <tbody valign="top"> <tr class="row-even"><td>G</td> <td>6.67384e-11</td> <td>m3 / (kg s2)</td> <td>Gravitational constant</td> </tr> <tr class="row-odd"><td>L_sun</td> <td>3.846e+26</td> <td>W</td> <td>Solar luminosity</td> </tr> <tr class="row-even"><td>M_earth</td> <td>5.9742e+24</td> <td>kg</td> <td>Earth mass</td> </tr> <tr class="row-odd"><td>M_jup</td> <td>1.8987e+27</td> <td>kg</td> <td>Jupiter mass</td> </tr> <tr class="row-even"><td>M_sun</td> <td>1.9891e+30</td> <td>kg</td> <td>Solar mass</td> </tr> <tr class="row-odd"><td>N_A</td> <td>6.02214129e+23</td> <td>1 / (mol)</td> <td>Avogadro’s number</td> </tr> <tr class="row-even"><td>R</td> <td>8.3144621</td> <td>J / (K mol)</td> <td>Gas constant</td> </tr> <tr class="row-odd"><td>R_earth</td> <td>6378136</td> <td>m</td> <td>Earth equatorial radius</td> </tr> <tr class="row-even"><td>R_jup</td> <td>71492000</td> <td>m</td> <td>Jupiter equatorial radius</td> </tr> <tr class="row-odd"><td>R_sun</td> <td>695508000</td> <td>m</td> <td>Solar radius</td> </tr> <tr class="row-even"><td>Ryd</td> <td>10973731.6</td> <td>1 / (m)</td> <td>Rydberg constant</td> </tr> <tr class="row-odd"><td>au</td> <td>1.49597871e+11</td> <td>m</td> <td>Astronomical Unit</td> </tr> <tr class="row-even"><td>c</td> <td>299792458</td> <td>m / (s)</td> <td>Speed of light in vacuum</td> </tr> <tr class="row-odd"><td>e</td> <td>1.60217657e-19</td> <td>C</td> <td>Electron charge</td> </tr> <tr class="row-even"><td>h</td> <td>6.62606957e-34</td> <td>J s</td> <td>Planck constant</td> </tr> <tr class="row-odd"><td>hbar</td> <td>1.05457173e-34</td> <td>J s</td> <td>Reduced Planck constant</td> </tr> <tr class="row-even"><td>k_B</td> <td>1.3806488e-23</td> <td>J / (K)</td> <td>Boltzmann constant</td> </tr> <tr class="row-odd"><td>kpc</td> <td>3.08567758e+19</td> <td>m</td> <td>Kiloparsec</td> </tr> <tr class="row-even"><td>m_e</td> <td>9.10938291e-31</td> <td>kg</td> <td>Electron mass</td> </tr> <tr class="row-odd"><td>m_n</td> <td>1.67492735e-27</td> <td>kg</td> <td>Neutron mass</td> </tr> <tr class="row-even"><td>m_p</td> <td>1.67262178e-27</td> <td>kg</td> <td>Proton mass</td> </tr> <tr class="row-odd"><td>pc</td> <td>3.08567758e+16</td> <td>m</td> <td>Parsec</td> </tr> <tr class="row-even"><td>sigma_sb</td> <td>5.670373e-08</td> <td>W / (K4 m2)</td> <td>Stefan-Boltzmann constant</td> </tr> </tbody> </table> <div class="section" id="classes"> <h4>Classes<a class="headerlink" href="#classes" title="Permalink to this headline">¶</a></h4> <table border="1" class="longtable docutils"> <colgroup> <col width="10%" /> <col width="90%" /> </colgroup> <tbody valign="top"> <tr class="row-odd"><td><a class="reference internal" href="../_generated/astropy.constants.constant.Constant.html#astropy.constants.constant.Constant" title="astropy.constants.constant.Constant"><tt class="xref py py-obj docutils literal"><span class="pre">Constant</span></tt></a>(abbrev, name, value, unit, ...[, ...])</td> <td>A physical or astronomical constant.</td> </tr> <tr class="row-even"><td><a class="reference internal" href="../_generated/astropy.constants.constant.EMConstant.html#astropy.constants.constant.EMConstant" title="astropy.constants.constant.EMConstant"><tt class="xref py py-obj docutils literal"><span class="pre">EMConstant</span></tt></a>(abbrev, name, value, unit, ...[, ...])</td> <td>An electromagnetic constant.</td> </tr> </tbody> </table> </div> <div class="section" id="class-inheritance-diagram"> <h4>Class Inheritance Diagram<a class="headerlink" href="#class-inheritance-diagram" title="Permalink to this headline">¶</a></h4> <p class="graphviz"> digraph inheritance9ab5a854db { rankdir=LR; size="8.0, 12.0"; "astropy.constants.constant.EMConstant" [style="setlinewidth(0.5)",URL="../_generated/astropy.constants.constant.EMConstant.html#astropy.constants.constant.EMConstant",fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",height=0.25,shape=box,fontsize=10]; "astropy.constants.constant.Constant" -> "astropy.constants.constant.EMConstant" [arrowsize=0.5,style="setlinewidth(0.5)"]; "astropy.units.quantity.Quantity" [style="setlinewidth(0.5)",URL="../_generated/astropy.units.quantity.Quantity.html#astropy.units.quantity.Quantity",fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",height=0.25,shape=box,fontsize=10]; "astropy.constants.constant.Constant" [style="setlinewidth(0.5)",URL="../_generated/astropy.constants.constant.Constant.html#astropy.constants.constant.Constant",fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",height=0.25,shape=box,fontsize=10]; "astropy.units.quantity.Quantity" -> "astropy.constants.constant.Constant" [arrowsize=0.5,style="setlinewidth(0.5)"]; } </p> </div> </div> </div> </div> </div> </div> </div> <div class="sphinxsidebar"> <div class="sphinxsidebarwrapper"><h3>Page Contents</h3> <ul> <li><a class="reference internal" href="#">Constants (<tt class="docutils literal"><span class="pre">astropy.constants</span></tt>)</a><ul> <li><a class="reference internal" href="#introduction">Introduction</a></li> <li><a class="reference internal" href="#getting-started">Getting Started</a></li> <li><a class="reference internal" href="#reference-api">Reference/API</a><ul> <li><a class="reference internal" href="#module-astropy.constants">astropy.constants Module</a><ul> <li><a class="reference internal" href="#classes">Classes</a><ul> </ul> </li> <li><a class="reference internal" href="#class-inheritance-diagram">Class Inheritance Diagram</a></li> </ul> </li> </ul> </li> </ul> </li> </ul> </div> </div> <div class="clearer"></div> </div> <footer class="footer"> <p class="pull-right"> <a href="http://github.com/astropy/astropy/tree/v0.2.4/docs/constants/index.rst">Edit This Page on Github</a> <a href="../_sources/constants/index.txt" rel="nofollow">Page Source</a> <a href="#">Back to Top</a></p> <p> © Copyright 2011-2013, The Astropy Developers.<br/> Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.1.3. Last built 22 Oct 2013. <br/> </p> </footer> </body> </html>