def initialize_optics(tel_id, filename, file_closed = 1):
    if 'simtel.gz' in filename:
        if file_closed:
            ld.clear_lists_optics()
            load_hessio(filename)
            nextevent_hessio()
        else:
            pass
    
        ld.mirror_area.append(h.get_mirror_area(tel_id))
        ld.mirror_number.append(h.get_mirror_number(tel_id))

        if file_closed:
            close_hessio()        

    elif 'fits' in filename:
        hdulist = file_closed
        if file_closed == 1:
            ld.clear_lists_optics()
            ld.clear_lists_telescope()
            hdulist = load_fits(filename)
            teles = hdulist[1].data
            ld.telescope = teles["TelID"].tolist()  
        else:
            pass
        index = ld.telescope_id.index(tel_id)
        ld.mirror_area.append(hdulist[1].data[index]["MirrorArea"])

        if file_closed == 1:
            close_fits(hdulist)
def initialize_optics(tel_id, filename, file_closed=1):
    if 'simtel.gz' in filename:
        if file_closed:
            ld.clear_lists_optics()
            load_hessio(filename)
            nextevent_hessio()
        else:
            pass

        ld.mirror_area.append(h.get_mirror_area(tel_id))
        ld.mirror_number.append(h.get_mirror_number(tel_id))

        if file_closed:
            close_hessio()

    elif 'fits' in filename:
        hdulist = file_closed
        if file_closed == 1:
            ld.clear_lists_optics()
            ld.clear_lists_telescope()
            hdulist = load_fits(filename)
            teles = hdulist[1].data
            ld.telescope = teles["TelID"].tolist()
        else:
            pass
        index = ld.telescope_id.index(tel_id)
        ld.mirror_area.append(hdulist[1].data[index]["MirrorArea"])

        if file_closed == 1:
            close_fits(hdulist)
def initialize_optics(filename, tel_id,file_closed = True):
    if file_closed:
        ld.clear_lists_optics()
        ld.clear_lists_telescope()
    else:
        pass

    if 'simtel.gz' in filename:
        OD.initialize_hessio(filename,tel_id,file_closed)
    elif 'fits' in filename:
        OD.initialize_fits(filename,tel_id,file_closed)
def initialize_optics(filename, tel_id, file_closed=True):
    if file_closed:
        ld.clear_lists_optics()
        ld.clear_lists_telescope()
    else:
        pass

    if 'simtel.gz' in filename:
        OD.initialize_hessio(filename, tel_id, file_closed)
    elif 'fits' in filename:
        OD.initialize_fits(filename, tel_id, file_closed)
def initialize_telescope(filename, file_closed = True):
    ld.clear_lists_telescope()
    ld.clear_lists_camera()
    ld.clear_lists_optics()

    if 'simtel.gz' in filename:
        file_closed = TD.initialize_hessio(filename,file_closed)
        for tel in ld.telescope_id:
            CD.initialize_hessio(filename,tel,file_closed)
            OD.initialize_hessio(filename,tel,file_closed)
        util_functions.close_hessio()

    elif 'fits' in filename:
        file_closed = TD.initialize_fits(filename,file_closed)
        for tel in ld.telescope_id:
            CD.initialize_fits(filename,tel,file_closed)
            OD.initialize_fits(filename,tel,file_closed)
        util_functions.close_fits(file_closed)
def initialize_telescope(filename, file_closed=True):
    ld.clear_lists_telescope()
    ld.clear_lists_camera()
    ld.clear_lists_optics()

    if 'simtel.gz' in filename:
        file_closed = TD.initialize_hessio(filename, file_closed)
        for tel in ld.telescope_id:
            CD.initialize_hessio(filename, tel, file_closed)
            OD.initialize_hessio(filename, tel, file_closed)
        util_functions.close_hessio()

    elif 'fits' in filename:
        file_closed = TD.initialize_fits(filename, file_closed)
        for tel in ld.telescope_id:
            CD.initialize_fits(filename, tel, file_closed)
            OD.initialize_fits(filename, tel, file_closed)
        util_functions.close_fits(file_closed)