# 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 pyneb as pn
import matplotlib.pyplot as plt
from pyneb.utils.misc import parseAtom
    # Define all the ions that are involved in the diagnostics
    all_atoms = diags.atomDict
    
    pn.log_.message('Atoms built')
    
    obs = pn.Observation(corrected = True)
    for atom in all_atoms:
        # Computes all the intensities of all the lines of all the ions considered
        for wavelength in all_atoms[atom].lineList:
            elem, spec = parseAtom(atom)
            intens1 = all_atoms[atom].getEmissivity(tem1, dens1, wave = wavelength) * dens1 * mass1
            intens2 = all_atoms[atom].getEmissivity(tem2, dens2, wave = wavelength) * dens2 * mass2
            obs.addLine(pn.EmissionLine(elem, spec, wavelength,
                                         obsIntens=[intens1, intens2, intens1+intens2], 
                                         obsError=[0.0, 0.0, 0.0]))
    
    pn.log_.message('Virtual observations computed')
    
    emisgrids = pn.getEmisGridDict(atomDict = all_atoms)
    
    pn.log_.message('EmisGrids available')
    
    # Produce a diagnostic plot for each of the two regions and another one for the (misanalyzed) overall region
    
    plt.subplot(2,2,1)
    diags.plot(emisgrids, obs, i_obs=0)

    plt.subplot(2,2,2)
    diags.plot(emisgrids, obs, i_obs=1)
    

# 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/ex7_3.py
import pyneb as pn
import matplotlib.pyplot as plt
from pyneb.utils.misc import parseAtom

    # Define all the ions that are involved in the diagnostics
    all_atoms = diags.atomDict
    
    pn.log_.message('Atoms built')
    
    obs = pn.Observation(corrected = True)
    for atom in all_atoms:
        # Computes all the intensities of all the lines of all the ions considered
        for wavelength in all_atoms[atom].lineList:
            elem, spec = parseAtom(atom)
            intens1 = all_atoms[atom].getEmissivity(tem1, dens1, wave = wavelength) * dens1 * mass1
            intens2 = all_atoms[atom].getEmissivity(tem2, dens2, wave = wavelength) * dens2 * mass2
            obs.addLine(pn.EmissionLine(elem, spec, wavelength,
                                         obsIntens=[intens1, intens2, intens1+intens2], 
                                         obsError=[0.0, 0.0, 0.0]))
    
    pn.log_.message('Virtual observations computed')
    
    emisgrids = pn.getEmisGridDict(atomDict = all_atoms)
    
    pn.log_.message('EmisGrids available')
    
    # Produce a diagnostic plot for each of the two regions and another one for the (misanalyzed) overall region
    
    plt.subplot(2,2,1)
    diags.plot(emisgrids, obs, i_obs=0)

    plt.subplot(2,2,2)
    diags.plot(emisgrids, obs, i_obs=1)
    

    plt.subplot(2,1,2)