예제 #1
0
def test_load_and_write_telescope_data():
    tel1, cam1, opt1 = ID.load(filename1)
    tel2, cam2, opt2 = ID.load(filename2)
    tel3, cam3, opt3 = ID.load(filename3)
    tel4, cam4, opt4 = ID.load()
    assert (len(tel1) > 0)
    assert (len(tel2) > 0)
    assert (len(opt3) > 0)
    assert (len(tel4) > 0)

    ID.write_fits(instr_dict=tel4, filename='test.fits', overwrite=True)
    tel41, cam41, opt41 = ID.load('test.fits')
    assert (len(tel41) > 0)
    os.remove('test.fits')
예제 #2
0
def test_load_and_write_telescope_data():
    tel1,cam1,opt1 = ID.load(filename1)
    tel2,cam2,opt2 = ID.load(filename2)
    tel3,cam3,opt3 = ID.load(filename3)
    tel4,cam4,opt4 = ID.load()
    assert(len(tel1)>0)
    assert(len(tel2)>0)
    assert(len(opt3)>0)
    assert(len(tel4)>0)
    
    ID.write_fits(instr_dict=tel4,filename='test.fits',overwrite=True)
    tel41,cam41,opt41 = ID.load('test.fits')
    assert(len(tel41)>0)
    os.remove('test.fits')
예제 #3
0
Example of using the instrument module and reading data from a hessio, a
fits, and a sim_telarray-config file.
"""

from ctapipe.instrument import InstrumentDescription as ID
from ctapipe.utils.datasets import get_path
import matplotlib.pyplot as plt
import os

if __name__ == '__main__':
    
    filename1 = get_path('PROD2_telconfig.fits.gz')
    filename2 = get_path('gamma_test.simtel.gz')
    filename3 = get_path('CTA-ULTRA6-SCT.cfg')
    
    tel1,cam1,opt1 = ID.load(filename1)
    tel2,cam2,opt2 = ID.load(filename2)
    tel3,cam3,opt3 = ID.load(filename3)
    tel4,cam4,opt4 = ID.load()
    
    #To check which tables are in the dictionaries, do:
    print('Print the name of the tables present in the dictionaries taken',\
    'from the fits file:')
    print(tel1.keys(),cam1.keys(),opt1.keys())
    print('As you can see, in the fits file, only the first dictionary is',\
    'filled with tables.')
    print('------------------------------------------------------------------')
    print('Print the name of the tables present in the dictionaries taken',\
    'from the hessio file:')
    print(tel2.keys(),cam2.keys(),opt2.keys())
    print('------------------------------------------------------------------')
예제 #4
0
    parser.add_argument('-c', '--channel', type=int, default=0)
    parser.add_argument('-w', '--write', action='store_true',
                        help='write images to files')
    parser.add_argument('-s', '--show-samples', action='store_true',
                        help='show time-variablity, one frame at a time')
    parser.add_argument('--calibrate', action='store_true',
                        help='apply calibration coeffs from MC')
    parser.add_argument('--hillas', action='store_true',
                        help='apply hillas parameterization and cleaning')
    args = parser.parse_args()

    source = hessio_event_source(args.filename,
                                 allowed_tels=[args.tel, ],
                                 max_events=args.max_events)
    disp = None
    tel,cam,opt = ID.load(args.filename)
    print(tel['TelescopeTable_VersionFeb2016'][tel['TelescopeTable_VersionFeb2016']['TelID']==args.tel])

    print('SELECTING EVENTS FROM TELESCOPE {}'.format(args.tel))
    print('=' * 70)

    for event in source:

        print('Scanning input file... count = {}'.format(event.count))
        print(event.trig)
        print(event.mc)
        print(event.dl0)

        if disp is None:
            x, y = event.meta.pixel_pos[args.tel]
            geom = io.CameraGeometry.guess(x, y,
예제 #5
0
def camera_calibration(filename, parameters, disp_args, level):
    """
    Parameters
    ----------
    filename   MC filename with raw data (in ADC samples)
    parameters Parameters to be passed to the different calibration functions
               (described in each function separately inside mc.py)
    disp_args  Either: per telescope per event or
               all telescopes of the event (currently dissabled)
    level      Output information of the calibration level results
    Returns
    -------
    A display (see function display_telescope)

    """
    # Number of llops for each calibration function (in debug mode
    # will measure the calibration time)
    nlooptime = 1
    if __debug__:
        nlooptime = 10

    # Load dl1 container
    # container = Container("calibrated_hessio_container")
    # container.add_item("dl1", RawData())
    # container.meta.add_item('pixel_pos', dict())

    tel, cam, opt = ID.load(filename)
    # loop over all events, all telescopes and all channels and call
    # the calc_peds function defined above to do some work:
    nt = 0
    for event in hessio_event_source(filename):
        if nt == 0:
            container = init_dl1(event)

        nt = nt+1
        # Fill DL1 container headers information. Clear also telescope info.
        load_dl1_eventheader(event.dl0, container.dl1)
        if __debug__:
            logger.debug("%s> %d #%d %d %s %.3e TeV @ (%.0f,%.0f)deg @ %.3f m"
                         % (sys._getframe().f_code.co_name,
                            container.dl1.run_id, nt,
                            container.dl1.event_id,
                            str(container.dl1.tels_with_data),
                            get_mc_shower_energy(), get_mc_shower_altitude(),
                            get_mc_shower_azimuth(),
                            np.sqrt(pow(get_mc_event_xcore(), 2) +
                                    pow(get_mc_event_ycore(), 2)))
                         )

        for telid in event.dl0.tels_with_data:
            logger.info("%s> Calibrating.. CT%d\n"
                        % (sys._getframe().f_code.co_name,  telid))

            # Get per telescope the camera geometry
            x, y = event.meta.pixel_pos[telid]
            foclen = event.meta.optical_foclen[telid]
            container.meta.pixel_pos[telid] = x, y
            container.meta.optical_foclen[telid] = foclen
            #geom = io.CameraGeometry.guess(x, y, foclen)
            

            # Get the calibration data sets (pedestals and single-pe)
            ped = get_pedestal(telid)
            calib = get_calibration(telid)

            # Integrate pixels traces and substract pedestal
            # See pixel_integration_mc function documentation in mc.py
            # for the different algorithms options
            start = time.process_time()
            for i in range(nlooptime):
                int_adc_pix, peak_adc_pix = pixel_integration_mc(event, cam,
                                                                 ped, telid,
                                                                 parameters)
            end = time.process_time()

            logger.debug(" Time pixel integration %.3e sec",
                         (end-start)/nlooptime)

            # Convert integrated ADC counts into p.e.
            # selecting also the HG/LG channel (currently hard-coded)
            start = time.process_time()
            for i in range(nlooptime):
                pe_pix = calibrate_amplitude_mc(int_adc_pix, calib,
                                                telid, parameters)
            end = time.process_time()
            logger.debug(" pixel amplitude calibration %.3e sec",
                         (end-start)/nlooptime)
            # Including per telescope metadata in the DL1 container
            # load_dl1_results(event.dl0,container.dl1)
            # if telid not in container.meta.pixel_pos:
            #    container.meta.pixel_pos[telid] = event.meta.pixel_pos[telid]
            container.dl1.tel[telid] = CalibratedCameraData(telid)
            container.dl1.tel[telid].pe_charge = pe_pix
            container.dl1.tel[telid].tom = peak_adc_pix

            # FOR THE CTA USERS:
            # From here you can include your code.
            # It should take as input the last data level calculated here (DL1)
            # or call reconstruction algorithms (reco module) to be called.
            # For example: you could ask to calculate the tail cuts cleaning
            # using the tailcuts_clean in reco/cleaning.py module
            #
            # if 'tail_cuts' in parameters:
            #    clean_mask = tailcuts_clean(geom,
            #    image=np.array(pe_pix),pedvars=1,
            #    picture_thresh=parameters['tail_cuts'][0],
            #    boundary_thresh=parameters['tail_cuts'][1])
            #    container.dl1.tel[telid].pe_charge = np.array(pe_pix) *
            #    np.array(clean_mask)
            #    container.dl1.tel[telid].tom = np.array(peak_adc_pix[0]) *
            #    np.array(clean_mask)
            #

        sys.stdout.flush()
        if disp_args is None:
            continue
        # Display
        if 'event' in disp_args:
            ello = input("See evt. %d?<[n]/y/q> " % container.dl1.event_id)
            if ello == 'y':

                if 'telescope' in disp_args:
                    for telid in container.dl1.tels_with_data:
                        ello = input(
                            "See telescope/evt. %d?[CT%d]<[n]/y/q/e> " %
                            (container.dl1.event_id, telid))
                        if ello == 'y':
                            display_telescope(container, telid)
                            plt.pause(0.1)
                        elif ello == 'q':
                            break
                        elif ello == 'e':
                            return None
                        else:
                            continue
                else:
                    plt.pause(0.1)
            elif ello == 'q':
                return None

    print("Total NEVT", nt)
Example of using the instrument module and reading data from a hessio, a
fits, and a sim_telarray-config file.
"""

from ctapipe.instrument import InstrumentDescription as ID
from ctapipe.utils.datasets import get_path
import matplotlib.pyplot as plt

if __name__ == '__main__':
    
    filename1 = get_path('PROD2_telconfig.fits.gz')
    filename2 = get_path('gamma_test.simtel.gz')
    filename3 = get_path('CTA-ULTRA6-SCT.cfg')
    
    tel1,cam1,opt1 = ID.load(filename1)
    tel2,cam2,opt2 = ID.load(filename2)
    tel3,cam3,opt3 = ID.load(filename3)
    tel4,cam4,opt4 = ID.load()
    
    #To check which tables are in the dictionaries, do:
    print('Print the name of the tables present in the dictionaries taken',\
    'from the fits file:')
    print(tel1.keys(),cam1.keys(),opt1.keys())
    print('As you can see, in the fits file, only the first dictionary is',\
    'filled with tables.')
    print('------------------------------------------------------------------')
    print('Print the name of the tables present in the dictionaries taken',\
    'from the hessio file:')
    print(tel2.keys(),cam2.keys(),opt2.keys())
    print('------------------------------------------------------------------')