# Path: pyneb/utils/misc.py
# def parseAtom(atom):
#     '''
#     Parses an atom label into the element and spectrum parts
#     '''
# 
#     iso = ''
#     elem = ''
#     spec = ''
#     cont = True
#     firstdigit = True
#     for l in atom:
#         if l.isalpha() and cont:
#             elem += l
#             firstdigit = False
#         elif l.isdigit():
#             if firstdigit:
#                 iso += l
#             else:
#                 spec += l
#                 cont = False
#     return iso+str.capitalize(elem), spec


import numpy as np
import matplotlib.pyplot as plt
import pyneb as pn
from pyneb.utils.misc import parseAtom
import a few libraries as listed at the beginning of the file run_ex.py
as well as this file.
the functions can then be called  as explained in the file run_ex.py

the functions defined here can be modified. 
In that case, is is necessary, before using the modified version, 
to do "reload(ex1_1)" from the terminal
sometimes this does not work well. 
it is then recommended to quit python (ctrl D) and enter again (ipython --pylab)
"""

#pn.atomicData.setDataFile('cl_iii_atom_M83-KS86.fits')

def p1(ion):
        # split ion into elem and spec, e.g 'O3' into 'O' and 3
        elem, spec = parseAtom(ion)
        # instanciate the corresponding Atom object
        atom = pn.Atom(elem, spec)
        # print information including transition probabilities
        #atom.printIonic(printA = True)
        # prepare a new figure
        plt.figure()
        # plot energy levels
        atom.plotGrotrian()


def p2(diag):
    # get the ion, and diagnostic description from the dictionary:
    ion, diag_eval, err = pn.diags_dict[diag]
    # split ion into elem and spec, e.g 'O3' into 'O' and 3

# Path: pyneb/utils/misc.py
# def parseAtom(atom):
#     '''
#     Parses an atom label into the element and spectrum parts
#     '''
# 
#     iso = ''
#     elem = ''
#     spec = ''
#     cont = True
#     firstdigit = True
#     for l in atom:
#         if l.isalpha() and cont:
#             elem += l
#             firstdigit = False
#         elif l.isdigit():
#             if firstdigit:
#                 iso += l
#             else:
#                 spec += l
#                 cont = False
#     return iso+str.capitalize(elem), spec


# Path: pyneb/sample_scripts/Choroni_School/ex2_1.py
import numpy as np
import matplotlib.pyplot as plt
import pyneb as pn
from pyneb.utils.misc import parseAtom

import a few libraries as listed at the beginning of the file run_ex.py
as well as this file.
the functions can then be called  as explained in the file run_ex.py

the functions defined here can be modified. 
In that case, is is necessary, before using the modified version, 
to do "reload(ex1_1)" from the terminal
sometimes this does not work well. 
it is then recommended to quit python (ctrl D) and enter again (ipython --pylab)
"""

#pn.atomicData.setDataFile('cl_iii_atom_M83-KS86.fits')

def p1(ion):
        # split ion into elem and spec, e.g 'O3' into 'O' and 3
        elem, spec = parseAtom(ion)
        # instanciate the corresponding Atom object
        atom = pn.Atom(elem, spec)
        # print information including transition probabilities
        #atom.printIonic(printA = True)
        # prepare a new figure
        plt.figure()
        # plot energy levels
        atom.plotGrotrian()


def p2(diag):
    # get the ion, and diagnostic description from the dictionary:
    ion, diag_eval, err = pn.diags_dict[diag]
    # split ion into elem and spec, e.g 'O3' into 'O' and 3

    elem, spec = parseAtom(ion)