from __future__ import print_function
import numpy as np
import sys,os
import matplotlib.pyplot as plt

sys.path.append(sys.path[0])

from WEAVEify_routines.step_02_common_routines.dictionary_functions import  CHECK_AND_INITIALIZE_KEY_VALUE



def test_1_step_b_read_input(inp_dict={}):
    from WEAVEify_routines.step_02_common_routines.dictionary_functions import  READ_DICTIONARY_FROM_FILE

    CHECK_AND_INITIALIZE_KEY_VALUE(inp_dict,"spec_indx",0)
    inp_path_aux_files = inp_dict["inp_path_aux_files"]
    flag_test          = inp_dict["flag_test"]
    spec_indx          = inp_dict["spec_indx"]
    instrument         = flag_test.upper()
    inp_path           = inp_path_aux_files + "/CODE_TEST_EXAMPLES/" + instrument + "/INPUT/"
    out_path           = inp_path_aux_files + "/CODE_TEST_EXAMPLES/" + instrument + "/OUTPUT/SERIAL_SINGLE_SPECTRUM/"
    inp_file           = "Cosmological_Mock_Fields.npy"
    npy_filename       = inp_path + inp_file
    data_dict          = READ_DICTIONARY_FROM_FILE(npy_filename,flag_delete_file = "n",rank = None,comm = None)
    z_arr              = data_dict["z_arr"]
    Delta_arr          = data_dict["Delta_arr"][:,spec_indx]
    T_gas_arr          = data_dict["T_gas_arr"][:,spec_indx]
    v_gas_arr          = data_dict["v_gas_arr"][:,spec_indx]
    f_HI_arr           = data_dict["f_HI_arr"][:,spec_indx]
    N_pixel            = z_arr.shape[0]

    #inp_dict_user  = inp_dict["inp_dict_user"]
    #CHECK_AND_INITIALIZE_KEY_VALUE(inp_dict_user,"log_Z_val_const",-1.5)
    #log_Z_val_const = float(inp_dict_user["log_Z_val_const"])

    #log_Z_arr       = np.ones(N_pixel,dtype=np.float32) * log_Z_val_const

    # You do not need to change following lines in function
    inp_dict_field = vars()
    inp_dict.update({"out_path":out_path})
    return inp_dict_field
