def _initialize_hessio(filename, tel_id, item):
        """
        reads the Camera data out of the open hessio file
        
        Parameters
        ----------
        filename: string
            name of the hessio file (must be a hessio file!)
        tel_id: int
            ID of the telescope whose optics information should be loaded
        """
        cam_fov = -1 * u.degree
        pix_posX = h.get_pixel_position(tel_id)[0] * u.m
        pix_posY = h.get_pixel_position(tel_id)[1] * u.m
        pix_posZ = [-1] * u.m
        pix_id = np.arange(len(pix_posX))

        cam_class, pix_area, pix_type, dx = _guess_camera_geometry(
            pix_posX, pix_posY)

        try:
            cam_class = h.get_camera_class(tel_id)
        except:
            pass

        try:
            pix_area = h.get_pixel_area(tel_id)
        except:
            pass

        try:
            pix_type = h.get_pixel_type(tel_id)
        except:
            pass

        try:
            pix_neighbors = h.get_pix_neighbors(tel_id)
        except:
            pix_neighbors = _find_neighbor_pixels(pix_posX.value,
                                                  pix_posY.value,
                                                  dx.value + 0.01)
        fadc_pulsshape = [[-1], [-1]]
        #to use this, one has to go through every event of the run...
        #n_channel = h.get_num_channel(tel_id)
        #ld.channel_num = n_channel
        #for chan in range(n_channel):
        #    ld.adc_samples.append(h.get_adc_sample(tel_id,chan).tolist())

        return (cam_class, cam_fov, pix_id, pix_posX, pix_posY, pix_posZ,
                pix_area, pix_type, pix_neighbors, fadc_pulsshape)
def from_file_hessio(filename,tel_id,item):
    """
    reads the Camera data out of the open hessio file
    
    Parameters
    ----------
    filename: string
        name of the hessio file (must be a hessio file!)
    tel_id: int
        ID of the telescope whose optics information should be loaded
    """
    cam_fov = -1*u.degree
    pix_posX = h.get_pixel_position(tel_id)[0]*u.m
    pix_posY = h.get_pixel_position(tel_id)[1]*u.m
    pix_posZ = [-1]*u.m
    pix_id = np.arange(len(pix_posX))
    
    cam_class,pix_area,pix_type,dx = _guess_camera_geometry(pix_posX,
                                                            pix_posY)
    
    try: cam_class = h.get_camera_class(tel_id)
    except: pass
    
    try: pix_area = h.get_pixel_area(tel_id)
    except: pass
    
    try: pix_type = h.get_pixel_type(tel_id)
    except: pass
    
    try: pix_neighbors = h.get_pix_neighbors(tel_id)
    except:
        pix_neighbors = _find_neighbor_pixels(pix_posX.value,
                                              pix_posY.value,
                                              dx.value + 0.01)
    fadc_pulsshape = [[-1],[-1]]
    #to use this, one has to go through every event of the run...
    #n_channel = h.get_num_channel(tel_id)
    #ld.channel_num = n_channel
    #for chan in range(n_channel):
    #    ld.adc_samples.append(h.get_adc_sample(tel_id,chan).tolist())

    return (cam_class,cam_fov,pix_id,pix_posX,pix_posY,pix_posZ,pix_area,
            pix_type,pix_neighbors,fadc_pulsshape)
def load_hessio(filename):
    """
    Function to open and load a hessio file
    
    Parameters
    ----------
    filename: string
        name of the file
    """
    print("Hessio file will be opened.")    
    h.file_open(filename)
    next(h.move_to_next_event())
    #version = h.get...
    version = 'Feb2016'
    
    #Creating 3 dictionaries where the instrument configuration will be stored
    #The dictionaries themselves contain astropy.table.Table objects
    telescope = {}
    camera = {}
    optics = {}  
    
    #--------------------------------------------------------------------------
    #Telescope configuration
    tel_table_prime = Table()
    tel_table_prime.meta = {'VERSION': version}    
    
    try: 
        tel_id = h.get_telescope_ids()
        tel_table_prime['TelID']= tel_id
    except: pass    
    try:
        tel_posX = [h.get_telescope_position(i)[0] for i in tel_id]
        tel_table_prime['TelX'] = tel_posX
        tel_table_prime['TelX'].unit = u.m
        tel_table_prime.meta['TelX_description'] =\
        'x-position of the telescope measured by...'
    except: pass
    try:
        tel_posY = [h.get_telescope_position(i)[1] for i in tel_id]
        tel_table_prime['TelY'] = tel_posY
        tel_table_prime['TelY'].unit = u.m
    except: pass
    try:
        tel_posZ = [h.get_telescope_position(i)[2] for i in tel_id]
        tel_table_prime['TelZ'] = tel_posZ
        tel_table_prime['TelZ'].unit = u.m
    except: pass
    try: tel_table['CameraClass'] = [h.get_camera_class(i) for i in tel_id]
    except: pass
    try:
        tel_table_prime['MirA'] = [h.get_mirror_area(i) for i in tel_id]
        tel_table_prime['MirA'].unit = u.m**2
    except: pass
    try:  tel_table_prime['MirN'] = [h.get_mirror_number(i) for i in tel_id]
    except: pass    
    try: 
        tel_table_prime['FL'] = [h.get_optical_foclen(i) for i in tel_id]
        tel_table_prime['FL'].unit = u.m
    except: pass
    try: tel_table_prime.meta['TelNum'] =  len(tel_posX)
    except: pass
    
    #Beside other tables containimng telescope configuration data, the main
    #telescope table is written into the telescope dictionary.
    telescope['TelescopeTable_Version%s' % version] = tel_table_prime
    
    #--------------------------------------------------------------------------
    #Camera and Optics configuration
    try:    
        for t in range(len(tel_id)):       
            
            cam_table_prime = Table()
            cam_table_prime.meta = {'TELID': tel_id[t], 'VERSION': version}
            opt_table_prime = Table()
            opt_table_prime.meta = {'TELID': tel_id[t], 'VERSION': version}
            
            try:
                pix_posX = h.get_pixel_position(tel_id[t])[0]
                pix_id = np.arange(len(pix_posX))
                cam_table_prime['PixID'] = pix_id                
                cam_table_prime['PixX'] = pix_posX
                cam_table_prime['PixX'].unit = u.m
                cam_table_prime.meta['PixXDescription'] =\
                'x-position of the pixel measured by...'
            except: pass
            try:
                pix_posY = h.get_pixel_position(tel_id[t])[1]
                cam_table_prime['PixY'] = pix_posY
                cam_table_prime['PixY'].unit = u.m
            except: pass
            try:
                camera_class = CD.guess_camera_geometry(pix_posX*u.m,pix_posY*u.m)
                pix_area_prime = camera_class.pix_area
                pix_type_prime = camera_class.pix_type
                pix_neighbors_prime = camera_class.pix_neighbors
            except: pass        
    
            try:
                pix_area = h.get_pixel_area(tel_id[t])
                cam_table_prime['PixA'] = pix_area
                cam_table_prime['PixA'].unit = u.mm**2
            except:
                try:
                    cam_table_prime['PixA'] = pix_area_prime
                    cam_table_prime['PixA'].unit = u.mm**2
                except: pass
            try: pix_type = h.get_pixel_type(tel_id[t])
            except:
                try: pix_type = pix_type_prime
                except: pix_type = 'unknown'
            cam_table_prime.meta['PixType'] = pix_type
            try:
                pix_neighbors = h.get_pixel_neighbor(tel_id[t])
                cam_table_prime['PixNeig'] = pix_neighbors
            except:
                try: cam_table_prime['PixNeig'] = pix_neighbors_prime
                except: pass       
            
            #as long as no mirror IDs are given, use the following:
            opt_table_prime['MirrID'] = [1,2]
            try:
                opt_table_prime.meta['MirNum'] = h.get_mirror_number(tel_id[t])
            except: pass
            try:
                opt_table_prime['MirArea'] = h.get_mirror_area(tel_id[t])
                opt_table_prime['MirArea'].unit = u.m**2
                opt_table_prime.meta['MirAreaDescription'] =\
                'Area of all mirrors'
            except: pass
            try:
                opt_table_prime['OptFocLen'] = h.get_optical_foclen(tel_id[t])
                opt_table_prime['OptFocLen'].unit = u.m
            except: pass
            
            #Beside other tables containing camera and optics configuration
            #data, the main  tables are written into the camera and optics
            #dictionary.
            camera['CameraTable_Version%s_TelID%i' % (version,tel_id[t])] \
            = cam_table_prime
            optics['OpticsTable_Version%s_TelID%i' % (version,tel_id[t])] \
            = opt_table_prime
    except: pass
        
    print('Astropy tables have been created.')
    h.close_file()
    print("Hessio file has been closed.")
    return(telescope,camera,optics)
Ejemplo n.º 4
0
def load_hessio(filename):
    """
    Function to open and load a hessio file
    
    Parameters
    ----------
    filename: string
        name of the file
    """
    print("Hessio file will be opened.")
    h.file_open(filename)
    next(h.move_to_next_event())
    #version = h.get...
    version = 'Feb2016'

    #Creating 3 dictionaries where the instrument configuration will be stored
    #The dictionaries themselves contain astropy.table.Table objects
    telescope = {}
    camera = {}
    optics = {}

    #--------------------------------------------------------------------------
    #Telescope configuration
    tel_table_prime = Table()
    tel_table_prime.meta = {'VERSION': version}

    try:
        tel_id = h.get_telescope_ids()
        tel_table_prime['TelID'] = tel_id
    except:
        pass
    try:
        tel_posX = [h.get_telescope_position(i)[0] for i in tel_id]
        tel_table_prime['TelX'] = tel_posX
        tel_table_prime['TelX'].unit = u.m
        tel_table_prime.meta['TelX_description'] =\
        'x-position of the telescope measured by...'
    except:
        pass
    try:
        tel_posY = [h.get_telescope_position(i)[1] for i in tel_id]
        tel_table_prime['TelY'] = tel_posY
        tel_table_prime['TelY'].unit = u.m
    except:
        pass
    try:
        tel_posZ = [h.get_telescope_position(i)[2] for i in tel_id]
        tel_table_prime['TelZ'] = tel_posZ
        tel_table_prime['TelZ'].unit = u.m
    except:
        pass
    try:
        tel_table['CameraClass'] = [h.get_camera_class(i) for i in tel_id]
    except:
        pass
    try:
        tel_table_prime['MirA'] = [h.get_mirror_area(i) for i in tel_id]
        tel_table_prime['MirA'].unit = u.m**2
    except:
        pass
    try:
        tel_table_prime['MirN'] = [h.get_mirror_number(i) for i in tel_id]
    except:
        pass
    try:
        tel_table_prime['FL'] = [h.get_optical_foclen(i) for i in tel_id]
        tel_table_prime['FL'].unit = u.m
    except:
        pass
    try:
        tel_table_prime.meta['TelNum'] = len(tel_posX)
    except:
        pass

    #Beside other tables containimng telescope configuration data, the main
    #telescope table is written into the telescope dictionary.
    telescope['TelescopeTable_Version%s' % version] = tel_table_prime

    #--------------------------------------------------------------------------
    #Camera and Optics configuration
    try:
        for t in range(len(tel_id)):

            cam_table_prime = Table()
            cam_table_prime.meta = {'TELID': tel_id[t], 'VERSION': version}
            opt_table_prime = Table()
            opt_table_prime.meta = {'TELID': tel_id[t], 'VERSION': version}

            try:
                pix_posX = h.get_pixel_position(tel_id[t])[0]
                pix_id = np.arange(len(pix_posX))
                cam_table_prime['PixID'] = pix_id
                cam_table_prime['PixX'] = pix_posX
                cam_table_prime['PixX'].unit = u.m
                cam_table_prime.meta['PixXDescription'] =\
                'x-position of the pixel measured by...'
            except:
                pass
            try:
                pix_posY = h.get_pixel_position(tel_id[t])[1]
                cam_table_prime['PixY'] = pix_posY
                cam_table_prime['PixY'].unit = u.m
            except:
                pass
            try:
                camera_class = CD.guess_camera_geometry(
                    pix_posX * u.m, pix_posY * u.m)
                pix_area_prime = camera_class.pix_area
                pix_type_prime = camera_class.pix_type
                pix_neighbors_prime = camera_class.pix_neighbors
            except:
                pass

            try:
                pix_area = h.get_pixel_area(tel_id[t])
                cam_table_prime['PixA'] = pix_area
                cam_table_prime['PixA'].unit = u.mm**2
            except:
                try:
                    cam_table_prime['PixA'] = pix_area_prime
                    cam_table_prime['PixA'].unit = u.mm**2
                except:
                    pass
            try:
                pix_type = h.get_pixel_type(tel_id[t])
            except:
                try:
                    pix_type = pix_type_prime
                except:
                    pix_type = 'unknown'
            cam_table_prime.meta['PixType'] = pix_type
            try:
                pix_neighbors = h.get_pixel_neighbor(tel_id[t])
                cam_table_prime['PixNeig'] = pix_neighbors
            except:
                try:
                    cam_table_prime['PixNeig'] = pix_neighbors_prime
                except:
                    pass

            #as long as no mirror IDs are given, use the following:
            opt_table_prime['MirrID'] = [1, 2]
            try:
                opt_table_prime.meta['MirNum'] = h.get_mirror_number(tel_id[t])
            except:
                pass
            try:
                opt_table_prime['MirArea'] = h.get_mirror_area(tel_id[t])
                opt_table_prime['MirArea'].unit = u.m**2
                opt_table_prime.meta['MirAreaDescription'] =\
                'Area of all mirrors'
            except:
                pass
            try:
                opt_table_prime['OptFocLen'] = h.get_optical_foclen(tel_id[t])
                opt_table_prime['OptFocLen'].unit = u.m
            except:
                pass

            #Beside other tables containing camera and optics configuration
            #data, the main  tables are written into the camera and optics
            #dictionary.
            camera['CameraTable_Version%s_TelID%i' % (version,tel_id[t])] \
            = cam_table_prime
            optics['OpticsTable_Version%s_TelID%i' % (version,tel_id[t])] \
            = opt_table_prime
    except:
        pass

    print('Astropy tables have been created.')
    h.close_file()
    print("Hessio file has been closed.")
    return (telescope, camera, optics)