Last active
August 5, 2019 05:15
-
-
Save epassaro/66a510b36d64e8809bf1abc253350bf1 to your computer and use it in GitHub Desktop.
GFALL Lines
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"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=\"C\")\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 C 1\n", | |
"Ingesting levels for C 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 C 1\n", | |
"Ingesting lines for C 2\n" | |
] | |
} | |
], | |
"source": [ | |
"gfall_ingester = GFALLIngester(session, fname=\"../gfall.dat\", ions=\"C 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=\"C\")" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"# Now we try to replicate the same DataFrame with our new class" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 6, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"from carsus.io.kurucz.gfall import GFALL" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 7, | |
"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', 'C 1-2')" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 8, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"[\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", | |
"[\u001b[1mpy.warnings \u001b[0m][\u001b[1;33mWARNING\u001b[0m] /home/epassaro/Desktop/gsoc/notebooks/carsus/io/kurucz/gfall.py:530: PerformanceWarning: indexing past lexsort depth may impact performance.\n", | |
" df = gf.lines.loc[ion]\n", | |
" (\u001b[1mwarnings.py\u001b[0m:99)\n", | |
"[\u001b[1mpy.warnings \u001b[0m][\u001b[1;33mWARNING\u001b[0m] /home/epassaro/Desktop/gsoc/notebooks/carsus/io/kurucz/gfall.py:530: PerformanceWarning: indexing past lexsort depth may impact performance.\n", | |
" df = gf.lines.loc[ion]\n", | |
" (\u001b[1mwarnings.py\u001b[0m:99)\n", | |
"[\u001b[1mpy.warnings \u001b[0m][\u001b[1;33mWARNING\u001b[0m] /home/epassaro/Desktop/gsoc/notebooks/carsus/io/kurucz/gfall.py:533: PerformanceWarning: indexing past lexsort depth may impact performance.\n", | |
" lvl_index2id = self._levels_all.set_index(['atomic_number', 'ion_number']).loc[ion]\n", | |
" (\u001b[1mwarnings.py\u001b[0m:99)\n", | |
"[\u001b[1mpy.warnings \u001b[0m][\u001b[1;33mWARNING\u001b[0m] /home/epassaro/Desktop/gsoc/notebooks/carsus/io/kurucz/gfall.py:533: PerformanceWarning: indexing past lexsort depth may impact performance.\n", | |
" lvl_index2id = self._levels_all.set_index(['atomic_number', 'ion_number']).loc[ion]\n", | |
" (\u001b[1mwarnings.py\u001b[0m:99)\n" | |
] | |
} | |
], | |
"source": [ | |
"x.lines_all = x._get_all_lines_data()" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"# Compare the two DataFrames" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 9, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"lower_level_id 1472\n", | |
"upper_level_id 1472\n", | |
"wavelength 1472\n", | |
"gf 1472\n", | |
"loggf 1472\n", | |
"dtype: int64" | |
] | |
}, | |
"execution_count": 9, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"atom_data._get_all_lines_data().eq(x.lines_all).sum()" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 10, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"True" | |
] | |
}, | |
"execution_count": 10, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"atom_data._get_all_lines_data().equals(x.lines_all)" | |
] | |
} | |
], | |
"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" | |
}, | |
"widgets": { | |
"application/vnd.jupyter.widget-state+json": { | |
"state": {}, | |
"version_major": 2, | |
"version_minor": 0 | |
} | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 4 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment