# Path: pyneb/utils/misc.py
# def int_to_roman(input_):
#     """
#     Convert an integer to Roman numerals.
#     
#     Examples:
#     >>> int_to_roman(0)
#     Traceback (most recent call last):
#     ValueError: Argument must be between 1 and 3999
#     
#     >>> int_to_roman(-1)
#     Traceback (most recent call last):
#     ValueError: Argument must be between 1 and 3999
#     
#     >>> int_to_roman(1.5)
#     Traceback (most recent call last):
#     TypeError: expected integer, got <type 'float'>
#     
#     >>> print int_to_roman(2000)
#     MM
# 
#     >>> print int_to_roman(1999)
#     MCMXCIX
# 
#     """
#     if type(input_) != type(1):
#         #raise TypeError, "expected integer, got %s" % type(input_)
#         return None
#     if not 0 < input_ < 4000:
#         #raise ValueError, "Argument must be between 1 and 3999"
#         return None
#     ints = (1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1)
#     nums = ('M', 'CM', 'D', 'CD', 'C', 'XC', 'L', 'XL', 'X', 'IX', 'V', 'IV', 'I')
#     result = ""
#     for i in range(len(ints)):
#         count = int(input_ / ints[i])
#         result += nums[i] * count
#         input_ -= ints[i] * count
#     return result
# 
# 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
# 
# def parseAtom2(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
#     if atom[-1] == 'r':
#         rec = 'r'
#     else:
#         rec = ''
#     return iso+str.capitalize(elem), spec, rec
# 
# Path: pyneb/utils/init.py
# BLEND_LIST = {}


import numpy as np
import pyneb as pn
            import matplotlib.pyplot as plt
from pyneb.utils.misc import int_to_roman, parseAtom, parseAtom2
from pyneb.utils.init import BLEND_LIST
                from ai4neb import manage_RM
        - guess_tem  temperature assumed in the first iteration, in K
        - tol_tem    tolerance of the temperature result, in %
        - tol_den    tolerance of the density result, in %
        - max_iter   maximum number of iterations to be performed, after which the function will throw a result
        - maxError   maximum error in the calls to getTemDen, in %
        - start_tem, end_tem  lower and upper limit of the explored temperature range 
        - start_den, end_den  lower and upper limit of the explored density range 
        - use_ANN    if True, an Analogic Neural Network will be used for the determination of Te and Ne.
                        manage_RM from mwinai library is used.
                        the hyper_parameters can be set-up with the self.ANN_inst_kwargs and
                        self.ANN_init_kwargs dictionnaries.
                        self.ANN_n_tem=30 and self.ANN_n_den=30 are the number of Te and Ne
                        used to train. May also be changed before calling getCrossTemDen
        - limit_res  in case of using ANN, if limit_res, the tem and den values out of the start_tem, end_tem,
                     start_den, end_den are set to np.nan. Otherwise, extrapolation is allowed.
        - ANN        if string, filename where to read AI4neb ANN. Otherwise, ANN is a manage_RM object.
                     In both casesm the ANN needs to already be trained

    
        Example:
            tem, den = diags.getCrossTemDen('[OIII] 4363/5007', '[SII] 6731/6716', 0.0050, 1.0, 
                        guess_tem=10000, tol_tem = 1., tol_den = 1., max_iter = 5)

        """
        # TODO:
        # Define a lower/upper density and temperature 
        # to be used in case the diag is pointing to values out of the boundaires
        if diag_tem not in self.diags:
            self.addDiag(diag_tem)
        atom_tem = self.diags[diag_tem][0]

# Path: pyneb/utils/misc.py
# def int_to_roman(input_):
#     """
#     Convert an integer to Roman numerals.
#     
#     Examples:
#     >>> int_to_roman(0)
#     Traceback (most recent call last):
#     ValueError: Argument must be between 1 and 3999
#     
#     >>> int_to_roman(-1)
#     Traceback (most recent call last):
#     ValueError: Argument must be between 1 and 3999
#     
#     >>> int_to_roman(1.5)
#     Traceback (most recent call last):
#     TypeError: expected integer, got <type 'float'>
#     
#     >>> print int_to_roman(2000)
#     MM
# 
#     >>> print int_to_roman(1999)
#     MCMXCIX
# 
#     """
#     if type(input_) != type(1):
#         #raise TypeError, "expected integer, got %s" % type(input_)
#         return None
#     if not 0 < input_ < 4000:
#         #raise ValueError, "Argument must be between 1 and 3999"
#         return None
#     ints = (1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1)
#     nums = ('M', 'CM', 'D', 'CD', 'C', 'XC', 'L', 'XL', 'X', 'IX', 'V', 'IV', 'I')
#     result = ""
#     for i in range(len(ints)):
#         count = int(input_ / ints[i])
#         result += nums[i] * count
#         input_ -= ints[i] * count
#     return result
# 
# 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
# 
# def parseAtom2(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
#     if atom[-1] == 'r':
#         rec = 'r'
#     else:
#         rec = ''
#     return iso+str.capitalize(elem), spec, rec
# 
# Path: pyneb/utils/init.py
# BLEND_LIST = {}


# Path: pyneb/core/diags.py
import numpy as np
import pyneb as pn
            import matplotlib.pyplot as plt
from pyneb.utils.misc import int_to_roman, parseAtom, parseAtom2
from pyneb.utils.init import BLEND_LIST
                from ai4neb import manage_RM

        - guess_tem  temperature assumed in the first iteration, in K
        - tol_tem    tolerance of the temperature result, in %
        - tol_den    tolerance of the density result, in %
        - max_iter   maximum number of iterations to be performed, after which the function will throw a result
        - maxError   maximum error in the calls to getTemDen, in %
        - start_tem, end_tem  lower and upper limit of the explored temperature range 
        - start_den, end_den  lower and upper limit of the explored density range 
        - use_ANN    if True, an Analogic Neural Network will be used for the determination of Te and Ne.
                        manage_RM from mwinai library is used.
                        the hyper_parameters can be set-up with the self.ANN_inst_kwargs and
                        self.ANN_init_kwargs dictionnaries.
                        self.ANN_n_tem=30 and self.ANN_n_den=30 are the number of Te and Ne
                        used to train. May also be changed before calling getCrossTemDen
        - limit_res  in case of using ANN, if limit_res, the tem and den values out of the start_tem, end_tem,
                     start_den, end_den are set to np.nan. Otherwise, extrapolation is allowed.
        - ANN        if string, filename where to read AI4neb ANN. Otherwise, ANN is a manage_RM object.
                     In both casesm the ANN needs to already be trained

    
        Example:
            tem, den = diags.getCrossTemDen('[OIII] 4363/5007', '[SII] 6731/6716', 0.0050, 1.0, 
                        guess_tem=10000, tol_tem = 1., tol_den = 1., max_iter = 5)

        """
        # TODO:
        # Define a lower/upper density and temperature 
        # to be used in case the diag is pointing to values out of the boundaires
        if diag_tem not in self.diags:
            self.addDiag(diag_tem)
        atom_tem = self.diags[diag_tem][0]

        elem_tem, spec_tem = parseAtom(atom_tem)