Skip to content

Instantly share code, notes, and snippets.

@epassaro
Last active August 1, 2019 21:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save epassaro/1d1a26f1d9d643e6c94005c1e7774eb0 to your computer and use it in GitHub Desktop.
Save epassaro/1d1a26f1d9d643e6c94005c1e7774eb0 to your computer and use it in GitHub Desktop.
GFALL levels
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"/home/epassaro/miniconda3/envs/carsus/lib/python3.6/site-packages/tqdm/autonotebook/__init__.py:18: TqdmExperimentalWarning: Using `tqdm.autonotebook.tqdm` in notebook mode. Use `tqdm.tqdm` instead to force console mode (e.g. in jupyter console)\n",
" \" (e.g. in jupyter console)\", TqdmExperimentalWarning)\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Initializing the database at sqlite://\n",
"Ingesting basic atomic data\n"
]
}
],
"source": [
"import numpy as np\n",
"import pandas as pd\n",
"from carsus import init_db\n",
"from carsus.model import Atom, Ion, Level, Line\n",
"from carsus.io.output import AtomData\n",
"from carsus.io.nist import NISTIonizationEnergiesIngester, NISTWeightsCompIngester\n",
"from carsus.io.kurucz import GFALLIngester\n",
"session = init_db()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# This is the usual SQL stuff"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Downloading data from the NIST Atomic Weights and Isotopic Compositions database.\n",
"Ingesting atomic weights from nist\n"
]
}
],
"source": [
"weightscomp_ingester = NISTWeightsCompIngester(session)\n",
"weightscomp_ingester.ingest()\n",
"session.commit()"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Downloading ionization energies from the NIST Atomic Spectra Database\n",
"Ingesting ionization energies from nist-asd\n",
"Ingesting ground levels from nist-asd\n"
]
}
],
"source": [
"ioniz_energies_ingester = NISTIonizationEnergiesIngester(session, spectra=\"Si\")\n",
"ioniz_energies_ingester.ingest(ionization_energies=True, ground_levels=True)\n",
"session.commit()"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[\u001b[1mcarsus.io.kurucz.gfall\u001b[0m][\u001b[1;33mWARNING\u001b[0m] A specific combination to identify unique levels from the gfall data has not been given. Defaulting to [\"energy\", \"j\"]. (\u001b[1mgfall.py\u001b[0m:71)\n",
"[\u001b[1mcarsus.io.kurucz.gfall\u001b[0m][\u001b[1;37mINFO\u001b[0m ] Parsing GFALL ../gfall.dat (\u001b[1mgfall.py\u001b[0m:119)\n",
"Ingesting levels from ku_latest\n",
"Ingesting levels for Si 1\n",
"Ingesting levels for Si 2\n",
"[\u001b[1mcarsus.io.kurucz.gfall\u001b[0m][\u001b[1;37mINFO\u001b[0m ] Extracting line data: atomic_number, ion_charge, energy_lower, j_lower, energy_upper, j_upper, wavelength, loggf (\u001b[1mgfall.py\u001b[0m:295)\n",
"Ingesting lines from ku_latest\n",
"Ingesting lines for Si 1\n",
"Ingesting lines for Si 2\n"
]
}
],
"source": [
"gfall_ingester = GFALLIngester(session, fname=\"../gfall.dat\", ions=\"Si 1-2\")\n",
"gfall_ingester.ingest(levels=True, lines=True)\n",
"session.commit()"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
"atom_data = AtomData(session, selected_atoms='Si')"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[\u001b[1mpy.warnings \u001b[0m][\u001b[1;33mWARNING\u001b[0m] /home/epassaro/miniconda3/envs/carsus/lib/python3.6/site-packages/pandas/core/frame.py:6692: FutureWarning: Sorting because non-concatenation axis is not aligned. A future version\n",
"of pandas will change to not sort by default.\n",
"\n",
"To accept the future behavior, pass 'sort=False'.\n",
"\n",
"To retain the current behavior and silence the warning, pass 'sort=True'.\n",
"\n",
" sort=sort)\n",
" (\u001b[1mwarnings.py\u001b[0m:99)\n",
"[\u001b[1mpy.warnings \u001b[0m][\u001b[1;33mWARNING\u001b[0m] /home/epassaro/miniconda3/envs/carsus/lib/python3.6/site-packages/pandas/core/frame.py:6692: FutureWarning: Sorting because non-concatenation axis is not aligned. A future version\n",
"of pandas will change to not sort by default.\n",
"\n",
"To accept the future behavior, pass 'sort=False'.\n",
"\n",
"To retain the current behavior and silence the warning, pass 'sort=True'.\n",
"\n",
" sort=sort)\n",
" (\u001b[1mwarnings.py\u001b[0m:99)\n"
]
},
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>atomic_number</th>\n",
" <th>energy</th>\n",
" <th>g</th>\n",
" <th>ion_number</th>\n",
" <th>level_id</th>\n",
" <th>level_number</th>\n",
" <th>metastable</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>14</td>\n",
" <td>0.000000</td>\n",
" <td>1</td>\n",
" <td>0</td>\n",
" <td>1</td>\n",
" <td>0</td>\n",
" <td>True</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>14</td>\n",
" <td>0.000000</td>\n",
" <td>2</td>\n",
" <td>1</td>\n",
" <td>15</td>\n",
" <td>0</td>\n",
" <td>True</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>14</td>\n",
" <td>0.035613</td>\n",
" <td>4</td>\n",
" <td>1</td>\n",
" <td>16</td>\n",
" <td>1</td>\n",
" <td>True</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>14</td>\n",
" <td>5.309535</td>\n",
" <td>2</td>\n",
" <td>1</td>\n",
" <td>17</td>\n",
" <td>2</td>\n",
" <td>True</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>14</td>\n",
" <td>5.322966</td>\n",
" <td>4</td>\n",
" <td>1</td>\n",
" <td>18</td>\n",
" <td>3</td>\n",
" <td>True</td>\n",
" </tr>\n",
" <tr>\n",
" <th>5</th>\n",
" <td>14</td>\n",
" <td>5.344700</td>\n",
" <td>6</td>\n",
" <td>1</td>\n",
" <td>19</td>\n",
" <td>4</td>\n",
" <td>True</td>\n",
" </tr>\n",
" <tr>\n",
" <th>6</th>\n",
" <td>14</td>\n",
" <td>6.857485</td>\n",
" <td>4</td>\n",
" <td>1</td>\n",
" <td>20</td>\n",
" <td>5</td>\n",
" <td>False</td>\n",
" </tr>\n",
" <tr>\n",
" <th>7</th>\n",
" <td>14</td>\n",
" <td>6.859448</td>\n",
" <td>6</td>\n",
" <td>1</td>\n",
" <td>21</td>\n",
" <td>6</td>\n",
" <td>False</td>\n",
" </tr>\n",
" <tr>\n",
" <th>8</th>\n",
" <td>14</td>\n",
" <td>8.121023</td>\n",
" <td>2</td>\n",
" <td>1</td>\n",
" <td>22</td>\n",
" <td>7</td>\n",
" <td>False</td>\n",
" </tr>\n",
" <tr>\n",
" <th>9</th>\n",
" <td>14</td>\n",
" <td>9.505292</td>\n",
" <td>2</td>\n",
" <td>1</td>\n",
" <td>23</td>\n",
" <td>8</td>\n",
" <td>False</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" atomic_number energy g ion_number level_id level_number metastable\n",
"0 14 0.000000 1 0 1 0 True\n",
"1 14 0.000000 2 1 15 0 True\n",
"2 14 0.035613 4 1 16 1 True\n",
"3 14 5.309535 2 1 17 2 True\n",
"4 14 5.322966 4 1 18 3 True\n",
"5 14 5.344700 6 1 19 4 True\n",
"6 14 6.857485 4 1 20 5 False\n",
"7 14 6.859448 6 1 21 6 False\n",
"8 14 8.121023 2 1 22 7 False\n",
"9 14 9.505292 2 1 23 8 False"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"atom_data.levels.head(10)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Now we try to replicate the same DataFrame with our new class"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [],
"source": [
"from carsus.io.kurucz.gfall import GFALL"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[\u001b[1mcarsus.io.kurucz.gfall\u001b[0m][\u001b[1;33mWARNING\u001b[0m] A specific combination to identify unique levels from the gfall data has not been given. Defaulting to [\"energy\", \"j\"]. (\u001b[1mgfall.py\u001b[0m:71)\n",
"Downloading ionization energies from the NIST Atomic Spectra Database\n",
"[\u001b[1mcarsus.io.kurucz.gfall\u001b[0m][\u001b[1;37mINFO\u001b[0m ] Parsing GFALL ./gfall.dat (\u001b[1mgfall.py\u001b[0m:119)\n",
"[\u001b[1mpy.warnings \u001b[0m][\u001b[1;33mWARNING\u001b[0m] /home/epassaro/miniconda3/envs/carsus/lib/python3.6/site-packages/pandas/core/frame.py:6692: FutureWarning: Sorting because non-concatenation axis is not aligned. A future version\n",
"of pandas will change to not sort by default.\n",
"\n",
"To accept the future behavior, pass 'sort=False'.\n",
"\n",
"To retain the current behavior and silence the warning, pass 'sort=True'.\n",
"\n",
" sort=sort)\n",
" (\u001b[1mwarnings.py\u001b[0m:99)\n",
"[\u001b[1mpy.warnings \u001b[0m][\u001b[1;33mWARNING\u001b[0m] /home/epassaro/miniconda3/envs/carsus/lib/python3.6/site-packages/pandas/core/frame.py:6692: FutureWarning: Sorting because non-concatenation axis is not aligned. A future version\n",
"of pandas will change to not sort by default.\n",
"\n",
"To accept the future behavior, pass 'sort=False'.\n",
"\n",
"To retain the current behavior and silence the warning, pass 'sort=True'.\n",
"\n",
" sort=sort)\n",
" (\u001b[1mwarnings.py\u001b[0m:99)\n"
]
}
],
"source": [
"x = GFALL('./gfall.dat', ions='Si 1-2')"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>atomic_number</th>\n",
" <th>energy</th>\n",
" <th>g</th>\n",
" <th>ion_number</th>\n",
" <th>level_id</th>\n",
" <th>level_number</th>\n",
" <th>metastable</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>14</td>\n",
" <td>0.000000</td>\n",
" <td>1</td>\n",
" <td>0</td>\n",
" <td>1</td>\n",
" <td>0</td>\n",
" <td>False</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>14</td>\n",
" <td>0.000000</td>\n",
" <td>2</td>\n",
" <td>1</td>\n",
" <td>15</td>\n",
" <td>0</td>\n",
" <td>False</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>14</td>\n",
" <td>0.035613</td>\n",
" <td>4</td>\n",
" <td>1</td>\n",
" <td>16</td>\n",
" <td>1</td>\n",
" <td>False</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>14</td>\n",
" <td>5.309535</td>\n",
" <td>2</td>\n",
" <td>1</td>\n",
" <td>17</td>\n",
" <td>2</td>\n",
" <td>False</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>14</td>\n",
" <td>5.322966</td>\n",
" <td>4</td>\n",
" <td>1</td>\n",
" <td>18</td>\n",
" <td>3</td>\n",
" <td>False</td>\n",
" </tr>\n",
" <tr>\n",
" <th>5</th>\n",
" <td>14</td>\n",
" <td>5.344700</td>\n",
" <td>6</td>\n",
" <td>1</td>\n",
" <td>19</td>\n",
" <td>4</td>\n",
" <td>False</td>\n",
" </tr>\n",
" <tr>\n",
" <th>6</th>\n",
" <td>14</td>\n",
" <td>6.857485</td>\n",
" <td>4</td>\n",
" <td>1</td>\n",
" <td>20</td>\n",
" <td>5</td>\n",
" <td>False</td>\n",
" </tr>\n",
" <tr>\n",
" <th>7</th>\n",
" <td>14</td>\n",
" <td>6.859448</td>\n",
" <td>6</td>\n",
" <td>1</td>\n",
" <td>21</td>\n",
" <td>6</td>\n",
" <td>False</td>\n",
" </tr>\n",
" <tr>\n",
" <th>8</th>\n",
" <td>14</td>\n",
" <td>8.121023</td>\n",
" <td>2</td>\n",
" <td>1</td>\n",
" <td>22</td>\n",
" <td>7</td>\n",
" <td>False</td>\n",
" </tr>\n",
" <tr>\n",
" <th>9</th>\n",
" <td>14</td>\n",
" <td>9.505292</td>\n",
" <td>2</td>\n",
" <td>1</td>\n",
" <td>23</td>\n",
" <td>8</td>\n",
" <td>False</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" atomic_number energy g ion_number level_id level_number metastable\n",
"0 14 0.000000 1 0 1 0 False\n",
"1 14 0.000000 2 1 15 0 False\n",
"2 14 0.035613 4 1 16 1 False\n",
"3 14 5.309535 2 1 17 2 False\n",
"4 14 5.322966 4 1 18 3 False\n",
"5 14 5.344700 6 1 19 4 False\n",
"6 14 6.857485 4 1 20 5 False\n",
"7 14 6.859448 6 1 21 6 False\n",
"8 14 8.121023 2 1 22 7 False\n",
"9 14 9.505292 2 1 23 8 False"
]
},
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"x.levels.head(10)"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"atomic_number 272\n",
"energy 272\n",
"g 272\n",
"ion_number 272\n",
"level_id 272\n",
"level_number 272\n",
"metastable 247\n",
"dtype: int64"
]
},
"execution_count": 10,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"atom_data.levels.eq(x.levels).sum()"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.7"
}
},
"nbformat": 4,
"nbformat_minor": 4
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment