import numpy as np
import os,sys,re

from WEAVEify_routines.step_02_common_routines.dictionary_functions import \
CONVERT_DTYPE_OBJECT_TO_DICTIONARY

from WEAVEify_routines.step_02_common_routines.python_2_3_compatibility_routines \
import genfromtxt_compatible

def generate_XI_forest_line_dict(inp_path_aux_files):
    """
    --------------------- Dictionary for Line Transition  -------------------------

     Method to calculate i_alpha
     i_alpha   = (pi * e^2 * f_12) / (m_2 * c * nu_12)
     i_alpha_X = 8.83788e-21 * (f_12_X * lambda_rest_X) 

     HI   -->> Neutral Hydrogen
     HeI  -->> Neutral Helium
     HeII -->> Single ionized Helium
     1215 -->> Transition Wavelength (first 4 digits)
    """
    inp_path_param  = inp_path_aux_files + "/ABSOPRTION_TRANSITION_LIST/"
    inp_file_specie = "specie_transition_properties.txt"
    specie_filename = inp_path_param + inp_file_specie
    data_arr        = genfromtxt_compatible(inp_path_param,inp_file_specie,None)
    N_data          = data_arr.shape[0]
    key_name_arr    = ["n_proton","n_neutron","lambda_rest","f_lu","damp_gamma"]
    line_dict       = CONVERT_DTYPE_OBJECT_TO_DICTIONARY(data_arr,key_name_arr)
    specie_list     = list(line_dict.keys())

    for line_indx in range(len(line_dict)):
        specie        = specie_list[line_indx]
        line_sub_dict = line_dict[specie]
        lambda_rest   = line_sub_dict["lambda_rest"]
        f_lu          = line_sub_dict["f_lu"]
        i_alpha       = 8.83788e-21 * (f_lu * lambda_rest)
        line_sub_dict.update({"i_alpha":i_alpha})
        line_dict.update({specie:line_sub_dict})
    return line_dict


