Created
June 2, 2019 20:38
-
-
Save epassaro/5ba3fabe81827ad04d8362783a655cbd to your computer and use it in GitHub Desktop.
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": [], | |
"source": [ | |
"import numpy as np\n", | |
"import pandas as pd\n", | |
"import warnings" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 2, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"def find_row(fname, string1, string2='', num_row=False):\n", | |
" \"\"\" Description \"\"\"\n", | |
" with open(fname, encoding='ISO-8859-1') as f:\n", | |
" n = 0\n", | |
" for line in f: \n", | |
" n += 1\n", | |
" if string1 in line and string2 in line:\n", | |
" break\n", | |
" \n", | |
" if num_row:\n", | |
" return n-1\n", | |
" \n", | |
" else: \n", | |
" return line" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 3, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"def oscillator_strengths(fname):\n", | |
" \"\"\" Description \"\"\"\n", | |
" args = {}\n", | |
" args['header'] = None\n", | |
" args['index_col'] = False\n", | |
" args['sep'] = '\\s*\\|\\s*|-?\\s+-?|(?<=[^ED\\s])-(?=[^\\s])'\n", | |
" args['skiprows'] = find_row(fname, \"Transition\", \"Lam\", num_row=True) +1\n", | |
" \n", | |
" n = find_row(fname, \"Number of transitions\").split()[0]\n", | |
" args['nrows'] = int(n)\n", | |
"\n", | |
" columns = ['State A', 'State B', 'f', 'A', 'Lam(A)', 'i', 'j', 'Lam(obs)', '% Acc']\n", | |
" \n", | |
" \n", | |
" try:\n", | |
" data = pd.read_csv(fname, **args)\n", | |
" \n", | |
" except pd.errors.EmptyDataError:\n", | |
" data = pd.DataFrame(columns=columns)\n", | |
" warnings.warn('Empty table')\n", | |
" \n", | |
" \n", | |
" # Assign column names by file content\n", | |
" if data.shape[1] == 9:\n", | |
" data.columns = columns\n", | |
" \n", | |
" elif data.shape[1] == 10: # This shouldn't happen (e.g. si2_osc_kurucz)\n", | |
" data.columns = columns + ['?']\n", | |
" data = data.drop(columns=['?'])\n", | |
" \n", | |
" elif data.shape[1] == 8:\n", | |
" data.columns = columns[:-2] + ['#']\n", | |
" data = data.drop(columns=['#'])\n", | |
" data['Lam(obs)'] = np.nan\n", | |
" data['% Acc'] = np.nan\n", | |
" \n", | |
" else:\n", | |
" warnings.warn('Inconsistent number of columns')\n", | |
" \n", | |
" \n", | |
" # Fix for Fortran float type 'D'\n", | |
" if data.shape[0] > 0 and 'D' in str(data['f'][0]):\n", | |
" data['f'] = data['f'].str.replace('D', 'E').map(np.float)\n", | |
" data['A'] = data['A'].str.replace('D', 'E').map(np.float)\n", | |
" \n", | |
" \n", | |
" return data" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 4, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stderr", | |
"output_type": "stream", | |
"text": [ | |
"/home/epassaro/miniconda3/envs/carsus/lib/python3.6/site-packages/ipykernel_launcher.py:16: ParserWarning: Falling back to the 'python' engine because the 'c' engine does not support regex separators (separators > 1 char and different from '\\s+' are interpreted as regex); you can avoid this warning by specifying engine='python'.\n", | |
" app.launch_new_instance()\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>State A</th>\n", | |
" <th>State B</th>\n", | |
" <th>f</th>\n", | |
" <th>A</th>\n", | |
" <th>Lam(A)</th>\n", | |
" <th>i</th>\n", | |
" <th>j</th>\n", | |
" <th>Lam(obs)</th>\n", | |
" <th>% Acc</th>\n", | |
" </tr>\n", | |
" </thead>\n", | |
" <tbody>\n", | |
" <tr>\n", | |
" <th>0</th>\n", | |
" <td>3d3(3)4Fe[3/2]</td>\n", | |
" <td>3d2(3F)4p4Go[5/2]</td>\n", | |
" <td>1.940000e-02</td>\n", | |
" <td>9.870800e+08</td>\n", | |
" <td>295.634</td>\n", | |
" <td>1</td>\n", | |
" <td>36</td>\n", | |
" <td>NaN</td>\n", | |
" <td>NaN</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>1</th>\n", | |
" <td>3d3(3)4Fe[3/2]</td>\n", | |
" <td>3d2(3F)4p4Fo[3/2]</td>\n", | |
" <td>9.065000e-02</td>\n", | |
" <td>6.971100e+09</td>\n", | |
" <td>294.516</td>\n", | |
" <td>1</td>\n", | |
" <td>38</td>\n", | |
" <td>NaN</td>\n", | |
" <td>NaN</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>2</th>\n", | |
" <td>3d3(3)4Fe[3/2]</td>\n", | |
" <td>3d2(3F)4p4Fo[5/2]</td>\n", | |
" <td>1.765000e-02</td>\n", | |
" <td>9.091600e+08</td>\n", | |
" <td>293.820</td>\n", | |
" <td>1</td>\n", | |
" <td>39</td>\n", | |
" <td>NaN</td>\n", | |
" <td>NaN</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>3</th>\n", | |
" <td>3d3(3)4Fe[3/2]</td>\n", | |
" <td>3d2(3F)4p2Fo[5/2]</td>\n", | |
" <td>8.831000e-04</td>\n", | |
" <td>4.608600e+07</td>\n", | |
" <td>291.910</td>\n", | |
" <td>1</td>\n", | |
" <td>43</td>\n", | |
" <td>NaN</td>\n", | |
" <td>NaN</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>4</th>\n", | |
" <td>3d3(3)4Fe[3/2]</td>\n", | |
" <td>3d2(3F)4p4Do[3/2]</td>\n", | |
" <td>4.965000e-03</td>\n", | |
" <td>3.901100e+08</td>\n", | |
" <td>291.366</td>\n", | |
" <td>1</td>\n", | |
" <td>45</td>\n", | |
" <td>NaN</td>\n", | |
" <td>NaN</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>5</th>\n", | |
" <td>3d3(3)4Fe[3/2]</td>\n", | |
" <td>3d2(3F)4p4Do[1/2]</td>\n", | |
" <td>4.875000e-02</td>\n", | |
" <td>7.679100e+09</td>\n", | |
" <td>291.020</td>\n", | |
" <td>1</td>\n", | |
" <td>47</td>\n", | |
" <td>NaN</td>\n", | |
" <td>NaN</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>6</th>\n", | |
" <td>3d3(3)4Fe[3/2]</td>\n", | |
" <td>3d2(3F)4p4Do[5/2]</td>\n", | |
" <td>1.425000e-04</td>\n", | |
" <td>7.510700e+06</td>\n", | |
" <td>290.467</td>\n", | |
" <td>1</td>\n", | |
" <td>48</td>\n", | |
" <td>NaN</td>\n", | |
" <td>NaN</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>7</th>\n", | |
" <td>3d3(3)4Fe[3/2]</td>\n", | |
" <td>3d2(3F)4p2Do[3/2]</td>\n", | |
" <td>1.100000e-02</td>\n", | |
" <td>8.715800e+08</td>\n", | |
" <td>290.147</td>\n", | |
" <td>1</td>\n", | |
" <td>49</td>\n", | |
" <td>NaN</td>\n", | |
" <td>NaN</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>8</th>\n", | |
" <td>3d3(3)4Fe[3/2]</td>\n", | |
" <td>3d2(3F)4p2Do[5/2]</td>\n", | |
" <td>6.520000e-04</td>\n", | |
" <td>3.469200e+07</td>\n", | |
" <td>289.095</td>\n", | |
" <td>1</td>\n", | |
" <td>51</td>\n", | |
" <td>NaN</td>\n", | |
" <td>NaN</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>9</th>\n", | |
" <td>3d3(3)4Fe[3/2]</td>\n", | |
" <td>3d2(3P)4p2So[1/2]</td>\n", | |
" <td>9.018000e-07</td>\n", | |
" <td>1.489000e+05</td>\n", | |
" <td>284.248</td>\n", | |
" <td>1</td>\n", | |
" <td>54</td>\n", | |
" <td>NaN</td>\n", | |
" <td>NaN</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>10</th>\n", | |
" <td>3d3(3)4Fe[3/2]</td>\n", | |
" <td>3d2(3P)4p4So[3/2]</td>\n", | |
" <td>5.648000e-07</td>\n", | |
" <td>4.765500e+04</td>\n", | |
" <td>281.170</td>\n", | |
" <td>1</td>\n", | |
" <td>55</td>\n", | |
" <td>NaN</td>\n", | |
" <td>NaN</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>11</th>\n", | |
" <td>3d3(3)4Fe[3/2]</td>\n", | |
" <td>3d2(1D)4p2Po[3/2]</td>\n", | |
" <td>3.171000e-06</td>\n", | |
" <td>2.707200e+05</td>\n", | |
" <td>279.521</td>\n", | |
" <td>1</td>\n", | |
" <td>56</td>\n", | |
" <td>NaN</td>\n", | |
" <td>NaN</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>12</th>\n", | |
" <td>3d3(3)4Fe[3/2]</td>\n", | |
" <td>3d2(1D)4p2Fo[5/2]</td>\n", | |
" <td>3.056000e-06</td>\n", | |
" <td>1.745000e+05</td>\n", | |
" <td>279.069</td>\n", | |
" <td>1</td>\n", | |
" <td>57</td>\n", | |
" <td>NaN</td>\n", | |
" <td>NaN</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>13</th>\n", | |
" <td>3d3(3)4Fe[3/2]</td>\n", | |
" <td>3d2(1D)4p2Po[1/2]</td>\n", | |
" <td>1.381000e-02</td>\n", | |
" <td>2.375800e+09</td>\n", | |
" <td>278.475</td>\n", | |
" <td>1</td>\n", | |
" <td>58</td>\n", | |
" <td>NaN</td>\n", | |
" <td>NaN</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>14</th>\n", | |
" <td>3d3(3)4Fe[3/2]</td>\n", | |
" <td>3d2(3P)4p4Do[1/2]</td>\n", | |
" <td>2.123000e-03</td>\n", | |
" <td>3.658300e+08</td>\n", | |
" <td>278.245</td>\n", | |
" <td>1</td>\n", | |
" <td>59</td>\n", | |
" <td>NaN</td>\n", | |
" <td>NaN</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>15</th>\n", | |
" <td>3d3(3)4Fe[3/2]</td>\n", | |
" <td>3d2(3P)4p4Do[3/2]</td>\n", | |
" <td>6.141000e-03</td>\n", | |
" <td>5.302300e+08</td>\n", | |
" <td>277.947</td>\n", | |
" <td>1</td>\n", | |
" <td>60</td>\n", | |
" <td>NaN</td>\n", | |
" <td>NaN</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>16</th>\n", | |
" <td>3d3(3)4Fe[3/2]</td>\n", | |
" <td>3d2(3P)4p4Do[5/2]</td>\n", | |
" <td>4.470000e-04</td>\n", | |
" <td>2.586300e+07</td>\n", | |
" <td>277.233</td>\n", | |
" <td>1</td>\n", | |
" <td>62</td>\n", | |
" <td>NaN</td>\n", | |
" <td>NaN</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>17</th>\n", | |
" <td>3d3(3)4Fe[3/2]</td>\n", | |
" <td>3d2(1D)4p2Do[3/2]</td>\n", | |
" <td>3.288000e-04</td>\n", | |
" <td>2.871800e+07</td>\n", | |
" <td>276.351</td>\n", | |
" <td>1</td>\n", | |
" <td>63</td>\n", | |
" <td>NaN</td>\n", | |
" <td>NaN</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>18</th>\n", | |
" <td>3d3(3)4Fe[3/2]</td>\n", | |
" <td>3d2(1D)4p2Do[5/2]</td>\n", | |
" <td>4.944000e-05</td>\n", | |
" <td>2.890700e+06</td>\n", | |
" <td>275.784</td>\n", | |
" <td>1</td>\n", | |
" <td>65</td>\n", | |
" <td>NaN</td>\n", | |
" <td>NaN</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>19</th>\n", | |
" <td>3d3(3)4Fe[3/2]</td>\n", | |
" <td>3d2(3P)4p4Po[1/2]</td>\n", | |
" <td>3.412000e-06</td>\n", | |
" <td>6.029200e+05</td>\n", | |
" <td>274.766</td>\n", | |
" <td>1</td>\n", | |
" <td>66</td>\n", | |
" <td>NaN</td>\n", | |
" <td>NaN</td>\n", | |
" </tr>\n", | |
" </tbody>\n", | |
"</table>\n", | |
"</div>" | |
], | |
"text/plain": [ | |
" State A State B f A Lam(A) i \\\n", | |
"0 3d3(3)4Fe[3/2] 3d2(3F)4p4Go[5/2] 1.940000e-02 9.870800e+08 295.634 1 \n", | |
"1 3d3(3)4Fe[3/2] 3d2(3F)4p4Fo[3/2] 9.065000e-02 6.971100e+09 294.516 1 \n", | |
"2 3d3(3)4Fe[3/2] 3d2(3F)4p4Fo[5/2] 1.765000e-02 9.091600e+08 293.820 1 \n", | |
"3 3d3(3)4Fe[3/2] 3d2(3F)4p2Fo[5/2] 8.831000e-04 4.608600e+07 291.910 1 \n", | |
"4 3d3(3)4Fe[3/2] 3d2(3F)4p4Do[3/2] 4.965000e-03 3.901100e+08 291.366 1 \n", | |
"5 3d3(3)4Fe[3/2] 3d2(3F)4p4Do[1/2] 4.875000e-02 7.679100e+09 291.020 1 \n", | |
"6 3d3(3)4Fe[3/2] 3d2(3F)4p4Do[5/2] 1.425000e-04 7.510700e+06 290.467 1 \n", | |
"7 3d3(3)4Fe[3/2] 3d2(3F)4p2Do[3/2] 1.100000e-02 8.715800e+08 290.147 1 \n", | |
"8 3d3(3)4Fe[3/2] 3d2(3F)4p2Do[5/2] 6.520000e-04 3.469200e+07 289.095 1 \n", | |
"9 3d3(3)4Fe[3/2] 3d2(3P)4p2So[1/2] 9.018000e-07 1.489000e+05 284.248 1 \n", | |
"10 3d3(3)4Fe[3/2] 3d2(3P)4p4So[3/2] 5.648000e-07 4.765500e+04 281.170 1 \n", | |
"11 3d3(3)4Fe[3/2] 3d2(1D)4p2Po[3/2] 3.171000e-06 2.707200e+05 279.521 1 \n", | |
"12 3d3(3)4Fe[3/2] 3d2(1D)4p2Fo[5/2] 3.056000e-06 1.745000e+05 279.069 1 \n", | |
"13 3d3(3)4Fe[3/2] 3d2(1D)4p2Po[1/2] 1.381000e-02 2.375800e+09 278.475 1 \n", | |
"14 3d3(3)4Fe[3/2] 3d2(3P)4p4Do[1/2] 2.123000e-03 3.658300e+08 278.245 1 \n", | |
"15 3d3(3)4Fe[3/2] 3d2(3P)4p4Do[3/2] 6.141000e-03 5.302300e+08 277.947 1 \n", | |
"16 3d3(3)4Fe[3/2] 3d2(3P)4p4Do[5/2] 4.470000e-04 2.586300e+07 277.233 1 \n", | |
"17 3d3(3)4Fe[3/2] 3d2(1D)4p2Do[3/2] 3.288000e-04 2.871800e+07 276.351 1 \n", | |
"18 3d3(3)4Fe[3/2] 3d2(1D)4p2Do[5/2] 4.944000e-05 2.890700e+06 275.784 1 \n", | |
"19 3d3(3)4Fe[3/2] 3d2(3P)4p4Po[1/2] 3.412000e-06 6.029200e+05 274.766 1 \n", | |
"\n", | |
" j Lam(obs) % Acc \n", | |
"0 36 NaN NaN \n", | |
"1 38 NaN NaN \n", | |
"2 39 NaN NaN \n", | |
"3 43 NaN NaN \n", | |
"4 45 NaN NaN \n", | |
"5 47 NaN NaN \n", | |
"6 48 NaN NaN \n", | |
"7 49 NaN NaN \n", | |
"8 51 NaN NaN \n", | |
"9 54 NaN NaN \n", | |
"10 55 NaN NaN \n", | |
"11 56 NaN NaN \n", | |
"12 57 NaN NaN \n", | |
"13 58 NaN NaN \n", | |
"14 59 NaN NaN \n", | |
"15 60 NaN NaN \n", | |
"16 62 NaN NaN \n", | |
"17 63 NaN NaN \n", | |
"18 65 NaN NaN \n", | |
"19 66 NaN NaN " | |
] | |
}, | |
"execution_count": 4, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"oscillator_strengths('../CMFGEN/atomic/FE/VI/8may97/fevi_osc_kb_rk.dat').head(20)" | |
] | |
} | |
], | |
"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": 2 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment