from __future__ import print_function
import numpy as np


def variable_list_to_save_in_header(flag_output="flux"):
    header_param_list_flux = [\
    "m_source","wave_band_source","source_type","instrument",\
    "resolution_mode","spectra_type","dia_telescope","ccd_pix_size_micron",\
    "dia_fibre_arcsec","CRVAL1","CDELT1","N_pixel_obs","lambda_scale",\
    "flag_cont_method","lsf_type","flag_noise","m_sky",\
    "wave_band_sky","t_exp","fwhm_seeing","beamsize","dark_current",\
    "seeing_profile","r_offset","read_noise","airmass","beta_moffat","fcol",\
    "fFP","fcam","PRI_fwhm","throughput_type","flux_norm_(erg/s/cm^2/A)",\
    ]

    header_param_list_tau = [\
    "z_em","sim_name","L_box","N_Grid","spec_id","HI_trans_list","flag_tau",\
    "flag_tau_each_trans","flag_absorber","z_DLA","log_N_HI_DLA","b_DLA",\
    "flag_metal_method","metal_trans_list","log_Z_val_const","uvb_model_metal",\
    ]

    header_param_list = header_param_list_tau # By default only initialize Header with basic parameters

    if flag_output == "flux":
        header_param_list.extend(header_param_list_flux)

    return header_param_list


def generate_standard_fits_file_compact_header():
    std_fit_header_dict = {\
    "m_source"        :["OBJMAG","Source magnitude"],\
    "wave_band_source":["OBJWBAND","Wavelength filter of source magnitude"],\
    "source_type":["OBJTYPE","Type of source (Point or Extended)"],\
    "instrument":["INSTR","Instrument Name"],\
    "resolution_mode":["RESMODE","Resolution mode for WEAVE survey"],\
    "spectra_type":["SPECTYPE","Type of Spectra"],\
    "dia_telescope":["DIATEL","Diameter of telescope in meters"],\
    "ccd_pix_size_micron":["PIXSIZE","Size of CCD pixel in microns"],\
    "dia_fibre_arcsec":["FIBREDIA","Diameter of fibre in arcsec"],\
    "CRVAL1":["CRVAL1","Start of wavelength array in angstroms"],\
    "CDELT1":["CDELT1","Wavelength spacing in angstroms"],\
    "N_pixel_obs":["NPIXEL","Number of pixels in wavelength/flux array"],\
    "lambda_scale":["WSCALE","Wavelength spacing scale (LIN or LOG)"],\
    "flag_cont_method":["CONTINUM","Continuum generation method"],\
    "lsf_type":["LSFTYPE","Functional form of Line Spread Function"],\
    "flag_noise":["NOISTYPE","Type of noise added to spectra"],\
    "m_sky":["SKYMAG","Sky magnitude"],\
    "wave_band_sky":["SKYWBAND","Wavelength Filter of sky magnitude"],\
    "t_exp":["EXPTIME","Exposure time in seconds"],\
    "fwhm_seeing":["SEEING","Atmospheric Seeing"],\
    "beamsize":["BEAMSIZE","Beam size"],\
    "dark_current":["DARKCURR","Amount of Dark current"],\
    "seeing_profile":["SEEPRFLE","Functional form of Seeing Profile"],\
    "r_offset":["ROFFSET","Offset of source from center of fibre in arcsec"],\
    "read_noise":["READNOIS","Amount of read noise "],\
    "airmass":["AIRMASS","Atmospheric airmass"],\
    "beta_moffat":["BETAMOFT","Power law index of MOFFAT Seeing profile"],\
    "fcol":["FCOL",""],\
    "fFP":["FFP",""],\
    "fcam":["FCAM",""],\
    "PRI_fwhm":["PRIFWHM",""],\
    "throughput_type":["THRTYPE","Type of throughput"],\
    "flux_norm_(erg/s/cm^2/A)":["FLUXNORM","Normalization factor for flux"],\
    "z_em":["ZEM","Emission redshift of QSO"],\
    "sim_name":["SIMNAME","Name of the simulation"],\
    "L_box":["BOXSIZE","Size of simulation box in cMpc / h"],\
    "N_Grid":["NGRIDSIM","Number of grids in simulation sightline"],\
    "spec_id":["SPECID","Spectrum Identification number or String"],\
    "HI_trans_list":["HILIST","HI transition list to calculate OD and Flux"],\
    "flag_tau":["TAUFIELD","Optical Depth to be calculated for specie"],\
    "flag_tau_each_trans":["TAUSCALE","If y, scaling relations are used to calculate OD"],\
    "flag_absorber":["ABSTYPE","Flux to be calculated for specie"],\
    "z_DLA":["ZDLA","Redshift list of DLA"],\
    "log_N_HI_DLA":["LNHIDLA","Column Denstion (Log N_HI) list of DLA"],\
    "b_DLA":["BDLA","Line width parameter (b) list of DLA"],\
    "flag_metal_method":["METLTYPE","Method of adding method to spectrum"],\
    "metal_trans_list":["METLLIST","Metal transition list for OD and flux calculation"],\
    "log_Z_val_const":["LZMETAL","Factor if metallicity is constant expressed in log Z_sun"],\
    "uvb_model_metal":["METALUVB","UVB used to calculate metal specie abundances"]
    }
    return std_fit_header_dict

def old_variable_list_to_save_in_header():
    source_text      = "COMMENT ---------- Properties of the source ---------"
    source_prop_list = ["z_em","m_source","wave_band_source","source_type"]


    instr_text       = "COMMENT -------- Properties of the Instrument ---------"
    instr_prop_list  = ["instrument","resolution_mode","spectra_type",\
                        "dia_telescope","ccd_pix_size_micron","dia_fibre_arcsec"]

    lambda_samp_text = "COMMENT -------- Wavelength Sampling Parameters ---------"
    lambda_samp_list = ["CRVAL1","CDELT1","N_pixel_obs","lambda_scale"]


    sim_text         = "COMMENT -------- Simulation Box Parameters ---------"
    sim_prop_list    = ["sim_name","L_box","N_Grid","spec_id","HI_trans_list"]

    dla_metal_text      = "COMMENT ------- Metal and DLA Absorbers Parameters ---------"
    dla_metal_prop_list = ["flag_tau","flag_tau_each_trans","flag_absorber",\
                          "z_DLA","log_N_HI_DLA","b_DLA","flag_metal_method",\
                          "metal_trans_list","log_Z_val_const","uvb_model_metal"]


    cont_text        = "COMMENT ------- Continuum Placement Parameters ---------"
    cont_prop_list   = ["cont_template_num","flag_cont_template","lsf_type"]

    noise_text       = "COMMENT ------- Noise Parameters ---------"
    noise_prop_list  = ["flag_noise","m_sky","wave_band_sky","t_exp","fwhm_seeing",\
                        "beamsize","dark_current","seeing_profile","r_offset",\
                        "read_noise","airmass","beta_moffat","fcol","fFP","fcam",\
                        "PRI_fwhm","throughput_type"]

    var_dict = {\
    0:{"text":source_text,      "var_list":source_prop_list},\
    1:{"text":instr_text,       "var_list":instr_prop_list},\
    2:{"text":lambda_samp_text, "var_list":lambda_samp_list},\
    3:{"text":sim_text,         "var_list":sim_prop_list},\
    4:{"text":dla_metal_text,   "var_list":dla_metal_prop_list},\
    5:{"text":cont_text,        "var_list":cont_prop_list},\
    6:{"text":noise_text,       "var_list":noise_prop_list},\
    }

    return var_dict




def backup_generate_standard_fits_file_compact_header():
    std_fit_header_dict = {\
    "m_source":"OBJMAG",\
    "wave_band_source":"OBJWBAND",\
    "source_type":"OBJTYPE",\
    "instrument":"INSTR",\
    "resolution_mode":"RESMODE",\
    "spectra_type":"SPECTYPE",\
    "dia_telescope":"DIATEL",\
    "ccd_pix_size_micron":"PIXSIZE",\
    "dia_fibre_arcsec":"FIBREDIA",\
    "CRVAL1":"CRVAL1",\
    "CDELT1":"CDELT1",\
    "N_pixel_obs":"NPIXEL",\
    "lambda_scale":"WSCALE",\
    "flag_cont_method":"CONTINUM",\
    "lsf_type":"LSFTYPE",\
    "flag_noise":"NOISTYPE",\
    "m_sky":"SKYMAG",\
    "wave_band_sky":"SKYWBAND",\
    "t_exp":"EXPTIME",\
    "fwhm_seeing":"SEEING",\
    "beamsize":"BEAMSIZE",\
    "dark_current":"DARKCURR",\
    "seeing_profile":"SEEPRFLE",\
    "r_offset":"ROFFSET",\
    "read_noise":"READNOIS",\
    "airmass":"AIRMASS",\
    "beta_moffat":"BETAMOFT",\
    "fcol":"FCOL",\
    "fFP":"FFP",\
    "fcam":"FCAM",\
    "PRI_fwhm":"PRIFWHM",\
    "throughput_type":"THRTYPE",\
    "flux_norm_(erg/s/cm^2/A)":"FLUXNORM",\
    "z_em":"ZEM",\
    "sim_name":"SIMNAME",\
    "L_box":"BOXSIZE",\
    "N_Grid":"NGRIDSIM",\
    "spec_id":"SPECID",\
    "HI_trans_list":"HILIST",\
    "flag_tau":"TAUFIELD",\
    "flag_tau_each_trans":"TAUSCALE",\
    "flag_absorber":"ABSTYPE",\
    "z_DLA":"ZDLA",\
    "log_N_HI_DLA":"LNHIDLA",\
    "b_DLA":"BDLA",\
    "flag_metal_method":"METLTYPE",\
    "metal_trans_list":"METLLIST",\
    "log_Z_val_const":"LZMETAL",\
    "uvb_model_metal":"METALUVB"
    }
    return std_fit_header_dict
