Skip to content

Commit

Permalink
Merge pull request #8 from mishinma/nist-atomic-weights-notebook
Browse files Browse the repository at this point in the history
Notebook for the NIST Atomic Weights and Isotopic Compositions
  • Loading branch information
wkerzendorf committed May 12, 2016
2 parents a0e5156 + 493bd42 commit fc324b2
Show file tree
Hide file tree
Showing 2 changed files with 209 additions and 6 deletions.
13 changes: 7 additions & 6 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ Carsus is a TARDIS support package for creating and working with atomic datasets

See the :ref:`notebooks/quickstart.ipynb` for a short introduction.

Supported data sources:
-----------------------

- :ref:`notebooks/nist_weights_comp.ipynb`

For more information about how to use this package, see the :ref:`api`.


Expand All @@ -13,10 +18,6 @@ Contents:
:maxdepth: 1

notebooks/quickstart.ipynb
notebooks/nist_weights_comp.ipynb
api







202 changes: 202 additions & 0 deletions docs/notebooks/nist_weights_comp.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,202 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# NIST Atomic Weights and Isotopic Compositions\n",
"\n",
"This [database](http://www.nist.gov/pml/data/comp.cfm) provides atomic weights for elements 1 through 118 and isotopic compositions (abundances). Look [here](http://nist.gov/pml/data/comp-notes.cfm#comp) for the detailed description."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Initialize a database. In this document we'll be using a memory database as an example."
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Initializing the database\n",
"Ingesting basic atomic data\n"
]
}
],
"source": [
"from carsus import init_db\n",
"session = init_db(\"sqlite://\")\n",
"session.commit()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
" Create an ingester"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"from carsus.io.nist import NISTWeightsCompIngester\n",
"ingester = NISTWeightsCompIngester()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Use `download()` to download the data from the source. With the default arguments, only the data for the most common isotopes will be downloaded."
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Downloading the data from http://physics.nist.gov/cgi-bin/Compositions/stand_alone.pl\n"
]
}
],
"source": [
"ingester.download()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Use `ingest()` to persist the data into the database. Don't forget to commit the session!"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Ingesting atomic weights\n"
]
}
],
"source": [
"ingester.ingest(session)\n",
"session.commit()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Now you have the data in your database. Currently only atomic weights are supported in `carsus`. To get them you can use this query:"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"symbol: H, atomic number: 1, weight: 1.007975 u\n",
"symbol: He, atomic number: 2, weight: 4.002602 u\n",
"symbol: Li, atomic number: 3, weight: 6.9675 u\n",
"symbol: Be, atomic number: 4, weight: 9.0121831 u\n",
"symbol: B, atomic number: 5, weight: 10.8135 u\n"
]
}
],
"source": [
"from carsus.model import Atom, AtomicWeight\n",
"q = session.query(Atom, AtomicWeight).join(Atom.quantities.of_type(AtomicWeight))\n",
"for atom, weight in q[:5]:\n",
" print \"symbol: {}, atomic number: {}, weight: {}\".format(atom.symbol, atom.atomic_number, weight.quantity)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"You can also convert quanities to different units in queries:"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"symbol: H, atomic number: 1, weight: 1.67378149613e-27 kg\n",
"symbol: He, atomic number: 2, weight: 6.6464755217e-27 kg\n",
"symbol: Li, atomic number: 3, weight: 1.15698033922e-26 kg\n",
"symbol: Be, atomic number: 4, weight: 1.4965078809e-26 kg\n",
"symbol: B, atomic number: 5, weight: 1.79562352324e-26 kg\n"
]
}
],
"source": [
"from astropy import units as u\n",
"q = session.query(Atom, AtomicWeight.quantity.to(u.kg).value).\\\n",
" join(Atom.quantities.of_type(AtomicWeight))\n",
"for atom, weight_value in q[:5]:\n",
" print \"symbol: {}, atomic number: {}, weight: {}\".format(atom.symbol, atom.atomic_number, weight_value*u.kg)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 2",
"language": "python",
"name": "python2"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 2.0
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2",
"version": "2.7.10"
}
},
"nbformat": 4,
"nbformat_minor": 0
}

0 comments on commit fc324b2

Please sign in to comment.