# Path: pyneb/utils/physics.py
# IP = {}
# 
# 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 pyneb as pn
from pyneb.utils.physics import IP
from pyneb.utils.misc import parseAtom
    
    # define a dictionnary for the ionic abundances
    ab_dic = {}
    # we  use the following lines to determine the ionic abundances
    ab_labels = ['C3_1907A', 'C3_1909A',
                 'N2_6583A', 'N3_57.4m', 'N4_1487A', 
                 'O2_3726A', 'O2_3729A', 'O3_5007A', 'O4_25.9m',
                 'S2_6731A', 'S3_9069A', 'S4_10.5m',
                 'Ar3_7136A', 'Ar4_4740A', 'Ar5_7006A', 'Ar6_4.5m', 
                 'Ne2_12.8m', 'Ne3_3869A', 'Ne5_3426A', 'Ne6_7.6m', 
                 'Cl3_5518A', 'Cl3_5538A', 'Cl4_5323A', 
                 'Mg4_4.5m', 'Mg5_5.6m']
    # loop on the observed lines to determine the corresponding ionic abundances
    for line in obs.getSortedLines():
        # this is one way to define temp and dens in each zone
        # must be adapted to each case
        if (line.atom in all_atoms) and (line.label in ab_labels):
            IP_cut = 30. #
            if IP[line.atom] > IP_cut:
                temp = T_O3
                dens = Ne_Ar4
                IP_used = 'H'
            else:
                temp = T_N2
                dens = Ne_O2
                IP_used = 'L'                 
            ab = all_atoms[line.atom].getIonAbundance(line.corrIntens, temp, dens, to_eval=line.to_eval, Hbeta=100)
            if printIonAb:
                print('{0:13s} {1} '.format(line.label, IP_used) + ' '.join(['{0:>8.4f}'.format(t) for t in ab * 1e6]))
            if line.atom not in ab_dic:

# Path: pyneb/utils/physics.py
# IP = {}
# 
# 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/ex3_1.py
import numpy as np
import pyneb as pn
from pyneb.utils.physics import IP
from pyneb.utils.misc import parseAtom

    
    # define a dictionnary for the ionic abundances
    ab_dic = {}
    # we  use the following lines to determine the ionic abundances
    ab_labels = ['C3_1907A', 'C3_1909A',
                 'N2_6583A', 'N3_57.4m', 'N4_1487A', 
                 'O2_3726A', 'O2_3729A', 'O3_5007A', 'O4_25.9m',
                 'S2_6731A', 'S3_9069A', 'S4_10.5m',
                 'Ar3_7136A', 'Ar4_4740A', 'Ar5_7006A', 'Ar6_4.5m', 
                 'Ne2_12.8m', 'Ne3_3869A', 'Ne5_3426A', 'Ne6_7.6m', 
                 'Cl3_5518A', 'Cl3_5538A', 'Cl4_5323A', 
                 'Mg4_4.5m', 'Mg5_5.6m']
    # loop on the observed lines to determine the corresponding ionic abundances
    for line in obs.getSortedLines():
        # this is one way to define temp and dens in each zone
        # must be adapted to each case
        if (line.atom in all_atoms) and (line.label in ab_labels):
            IP_cut = 30. #
            if IP[line.atom] > IP_cut:
                temp = T_O3
                dens = Ne_Ar4
                IP_used = 'H'
            else:
                temp = T_N2
                dens = Ne_O2
                IP_used = 'L'                 
            ab = all_atoms[line.atom].getIonAbundance(line.corrIntens, temp, dens, to_eval=line.to_eval, Hbeta=100)
            if printIonAb:
                print('{0:13s} {1} '.format(line.label, IP_used) + ' '.join(['{0:>8.4f}'.format(t) for t in ab * 1e6]))
            if line.atom not in ab_dic:

                ab_dic[line.atom] = []