Exemplo n.º 1
0
def test_baseline():
    for event in event_stream(example_file_path):

        for tel_id in event.r0.tels_with_data:

            assert (event.r0.tel[tel_id].digicam_baseline == np.zeros(N_PIXELS)
                    ).all()

    for event in event_stream(example_file_path_2):

        for tel_id in event.r0.tels_with_data:

            baseline = event.r0.tel[tel_id].digicam_baseline
            np.testing.assert_array_equal(baseline, EXPECTED_BASELINE)
def test_calibration_event_stream():

    max_events = 10
    calib_stream = calibration_event_stream(example_file_path,
                                            max_events=max_events)

    values = []

    for event_calib in calib_stream:

        values.append([
            event_calib.data.adc_samples, event_calib.data.digicam_baseline,
            event_calib.pixel_id
        ])
    assert len(values) == max_events

    del calib_stream

    obs_stream = event_stream(example_file_path, max_events=max_events)

    for i, event in enumerate(obs_stream):

        event = list(event.r0.tel.values())[0]

        assert (values[i][0] == event.adc_samples).all()

        assert (values[i][1] == event.digicam_baseline).all()

        assert len(values[i][2]) == event.adc_samples.shape[0]
def test_event_source_old_style():

    for _ in event_stream(
            [example_file_path],
            camera=digicam,
            camera_geometry=digicam_geometry):
        pass
def make_dark_base_line():
    from digicampipe.calib.camera import filter
    from digicampipe.io.event_stream import event_stream
    from digicampipe.io.save_adc import save_dark

    with TemporaryDirectory() as temp_dir:
        outfile_path = os.path.join(temp_dir, "dark_baseline.npz")

        data_stream = event_stream(example_file_path)
        data_stream = filter.set_pixels_to_zero(
            data_stream,
            unwanted_pixels=[],
        )
        data_stream = filter.filter_event_types(data_stream, flags=[8])
        data_stream = save_dark(data_stream, outfile_path)
        for event_counter, _ in enumerate(data_stream):
            pass
        assert event_counter >= 5

        npz_file = np.load(outfile_path)
        assert not np.any(np.isnan(npz_file['baseline']))
        assert not np.any(np.isnan(npz_file['standard_deviation']))
        assert len(npz_file['baseline']) == 1296

    return npz_file
Exemplo n.º 5
0
def test_compare_trigger_input_7():
    events_digi = event_stream([example_file_path], disable_bar=True)
    events_digi = fill_trigger_input_7(events_digi)

    events_comp = event_stream([example_file_path], disable_bar=True)
    events_comp = fill_digicam_baseline(events_comp)
    events_comp = fill_trigger_patch(events_comp)
    events_comp = fill_trigger_input_7(events_comp)
    for event_digi, event_comp in zip(events_digi, events_comp):
        tel = event_digi.r0.tels_with_data[0]
        ti7_digi = event_digi.r0.tel[tel].trigger_input_7
        ti7_comp = event_comp.r0.tel[tel].trigger_input_7
        abs_diff = np.abs(ti7_digi - ti7_comp)
        sum_ti7 = ti7_digi + ti7_comp
        assert np.mean(abs_diff) < 3
        assert np.nanmean(abs_diff / sum_ti7) < .05
Exemplo n.º 6
0
def test_event_stream():
    events = event_stream([example_file_path])
    for event in events:
        event_id = event.r0.event_id
        energy = event.mc.energy
        break
    assert event_id == EVENT_ID
    assert energy == ENERGY
Exemplo n.º 7
0
def test_compute_trigger_input_7():
    events = event_stream([example_file_path])
    events = fill_digicam_baseline(events)
    events = fill_trigger_patch(events)
    events = fill_trigger_input_7(events)
    for event in events:
        tel = event.r0.tels_with_data[0]
        assert np.all(np.isfinite(event.r0.tel[tel].trigger_input_7))
Exemplo n.º 8
0
def main(baseline_file_path, urls, unwanted_pixels=[]):

    data_stream = event_stream(urls)
    data_stream = filter.set_pixels_to_zero(data_stream,
                                            unwanted_pixels=unwanted_pixels)
    data_stream = filter.filter_event_types(data_stream, flags=[8])
    data_stream = save_dark(data_stream, baseline_file_path)

    for _ in tqdm(data_stream):
        pass
Exemplo n.º 9
0
def entry():
    args = docopt(__doc__)

    event_id = args['--event_id']
    event_id = int(event_id) if event_id != 'None' else None
    data_stream = event_stream.event_stream(args['<INPUT>'],
                                            event_id=event_id - 1)
    for _, i in zip(data_stream, range(int(args['--start']))):
        pass
    display = EventViewer(data_stream)
    display.draw()
def main(infile):

    baselines = []
    for data in tqdm(event_stream(infile)):
        for r0 in data.r0.tel.values():
            baselines.append(r0.digicam_baseline)
    baselines = np.array(baselines)

    plt.figure()
    plt.plot(baselines[0])
    plt.plot(baselines[1])
    plt.plot(baselines[2])
    plt.plot(baselines[-1])
    plt.show()
Exemplo n.º 11
0
def main(output_directory, urls, unwanted_patches, unwanted_clusters,
         blinding):
    dark_file_path = path.join(output_directory, 'dark.npz')
    dark_trigger_file_path = path.join(output_directory, 'bias_curve_dark.npz')

    thresholds = np.arange(0, 400, 10)

    data_stream = event_stream(urls, camera=DigiCam)
    data_stream = filter.set_patches_to_zero(data_stream,
                                             unwanted_patch=unwanted_patches)
    data_stream = r0.fill_trigger_input_7(data_stream)
    # Fill the flags (to be replaced by Digicam)
    data_stream = filter.filter_event_types(data_stream, flags=[8])

    data_stream = save_bias_curve(data_stream,
                                  thresholds=thresholds,
                                  blinding=blinding,
                                  output_filename=dark_trigger_file_path,
                                  unwanted_cluster=unwanted_clusters)

    data_stream = save_dark(data_stream, dark_file_path)

    for _ in tqdm(data_stream):
        pass

    # Filter the events for display
    data_dark = np.load(dark_file_path)
    data_rate = np.load(dark_trigger_file_path)

    plt.figure()
    plt.hist(data_dark['baseline'], bins='auto')
    plt.xlabel('dark baseline [LSB]')
    plt.ylabel('count')

    plt.figure()
    plt.hist(data_dark['standard_deviation'], bins='auto')
    plt.xlabel('dark std [LSB]')
    plt.ylabel('count')

    fig = plt.figure()
    axis = fig.add_subplot(111)
    axis.errorbar(x=data_rate['threshold'],
                  y=data_rate['rate'] * 1E9,
                  yerr=data_rate['rate_error'] * 1E9,
                  label='Blinding : {}'.format(blinding))
    axis.set_ylabel('rate [Hz]')
    axis.set_xlabel('threshold [LSB]')
    axis.set_yscale('log')
    axis.legend(loc='best')
    plt.show()
Exemplo n.º 12
0
def test_add_slow_data():
    data_stream = event_stream(example_file_path, max_events=100)
    data_stream = add_slow_data(data_stream, basepath=aux_basepath)
    ts_slow = []
    ts_data = []

    for event in data_stream:
        tel_id = event.r0.tels_with_data[0]
        ts_slow.append(event.slow_data.DriveSystem.timestamp * 1e-3)
        ts_data.append(event.r0.tel[tel_id].local_camera_clock * 1e-9)
    ts_slow = np.array(ts_slow)
    ts_data = np.array(ts_data)
    diff = ts_data - ts_slow
    assert (diff <= 1.1).all()
Exemplo n.º 13
0
def main(urls, outfile_path, baseline_path, do_plots=False):
    baseline = np.load(baseline_path)

    digicam = Camera()
    data_stream = event_stream(urls,
                               expert_mode=True,
                               camera=digicam,
                               camera_geometry=digicam.geometry)
    data_stream = random_triggers.fill_baseline_r0(data_stream, n_bins=1050)
    data_stream = filter.filter_missing_baseline(data_stream)
    data_stream = filter.filter_event_types(data_stream, flags=[8])
    data_stream = r1.calibrate_to_r1(data_stream, baseline)
    data_stream = filter.filter_period(data_stream, period=10 * u.second)

    save_external_triggers(data_stream,
                           output_filename=outfile_path,
                           pixel_list=np.arange(1296))

    if do_plots:
        make_plots(outfile_path)
Exemplo n.º 14
0
def test_event_id():
    event_id = LAST_EVENT_ID - 3

    for data in zfits_event_source(example_file_path,
                                   event_id=event_id):
        tel_id = 1
        r0 = data.r0.tel[tel_id]
        number = r0.camera_event_number

        break

    assert number == event_id

    for data in event_stream(example_file_path, event_id=event_id):
        tel_id = 1
        r0 = data.r0.tel[tel_id]
        number = r0.camera_event_number

        break

    assert number == event_id
Exemplo n.º 15
0
def compute(files, output_filename, thresholds, n_samples=1024):

    thresholds = thresholds.astype(float)

    data_stream = event_stream(files)
    # data_stream = trigger.fill_event_type(data_stream, flag=8)
    data_stream = filters.filter_event_types(data_stream,
                                             flags=CameraEventType.INTERNAL)
    data_stream = baseline.fill_baseline_r0(data_stream, n_bins=n_samples)
    data_stream = filters.filter_missing_baseline(data_stream)
    data_stream = trigger.fill_trigger_patch(data_stream)
    data_stream = trigger.fill_trigger_input_7(data_stream)
    data_stream = trigger.fill_trigger_input_19(data_stream)
    output = compute_bias_curve(
        data_stream,
        thresholds=thresholds,
    )

    rate, rate_error, cluster_rate, cluster_rate_error, thresholds, \
    start_event_id, end_event_id, start_event_time, end_event_time = output

    with fitsio.FITS(output_filename, mode='rw', clobber=True) as f:

        f.write([
            np.array([start_event_id, end_event_id]),
            np.array([start_event_time, end_event_time])
        ],
                extname='meta',
                names=['event_id', 'time'])
        f.write(thresholds, extname='threshold', compress='gzip')
        f.write([rate, rate_error],
                extname='camera',
                names=['rate', 'error'],
                compress='gzip')
        f.write([cluster_rate, cluster_rate_error],
                names=['rate', 'error'],
                extname='cluster',
                compress='gzip')

    return output
Exemplo n.º 16
0
def trigger_uniformity(files,
                       plot="show",
                       event_types=None,
                       disable_bar=False):
    events = event_stream(files, disable_bar=disable_bar)
    if event_types is not None:
        events = filter_event_types(events, flags=event_types)
    # patxh matrix is a bool of size n_patch x n_pixel
    patch_matrix = compute_patch_matrix(camera=DigiCam)
    n_patch, n_pixel = patch_matrix.shape
    top7 = np.zeros([n_patch], dtype=np.float32)
    n_event = 0
    for event in events:
        n_event += 1
        tel = event.r0.tels_with_data[0]
        top7 += np.sum(event.r0.tel[tel].trigger_output_patch7, axis=1)
    patches_rate = top7 / n_event
    pixels_rate = patches_rate.reshape([1, -1]).dot(patch_matrix).flatten()
    print('pixels_rate from', np.min(pixels_rate), 'to', np.max(pixels_rate),
          'trigger/event')
    if plot is None:
        return pixels_rate
    fig1 = plt.figure()
    ax = plt.gca()
    display = CameraDisplay(DigiCam.geometry,
                            ax=ax,
                            title='Trigger uniformity')
    display.add_colorbar()
    display.image = pixels_rate
    output_path = os.path.dirname(plot)
    if plot == "show" or not os.path.isdir(output_path):
        if not plot == "show":
            print('WARNING: Path ' + output_path + ' for output trigger ' +
                  'uniformity does not exist, displaying the plot instead.\n')
        plt.show()
    else:
        plt.savefig(plot)
    plt.close(fig1)
    return pixels_rate
Exemplo n.º 17
0
def main(files, output_filename, display=False):

    n_bins = 1024
    thresholds = np.arange(0, 400, 10)
    blinding = True

    data_stream = event_stream(files)
    data_stream = r0.fill_event_type(data_stream, flag=8)
    data_stream = random_triggers.fill_baseline_r0(data_stream, n_bins=n_bins)
    data_stream = filter.filter_missing_baseline(data_stream)
    data_stream = r0.fill_trigger_patch(data_stream)
    data_stream = r0.fill_trigger_input_7(data_stream)
    data_stream = r0.fill_trigger_input_19(data_stream)
    output = compute_bias_curve(
        data_stream,
        thresholds=thresholds,
        blinding=blinding,
    )

    rate, rate_error, cluster_rate, cluster_rate_error, thresholds = output

    np.savez(file=output_filename,
             rate=rate,
             rate_error=rate_error,
             cluster_rate=cluster_rate,
             cluster_rate_error=cluster_rate_error,
             thresholds=thresholds)

    if display:

        fig = plt.figure()
        axes = fig.add_subplot(111)
        axes.errorbar(thresholds, rate * 1E9, yerr=rate_error * 1E9)
        axes.set_yscale('log')
        axes.set_xlabel('Threshold [LSB]')
        axes.set_ylabel('Rate [Hz]')

        plt.show()
Exemplo n.º 18
0
def test_add_slow_data():
    data_stream = event_stream(example_file_path, max_events=100)
    data_stream = add_slow_data(data_stream,
                                basepath=aux_basepath,
                                aux_services=(
                                    'DigicamSlowControl',
                                    'MasterSST1M',
                                    'PDPSlowControl',
                                    'SafetyPLC',
                                    'DriveSystem',
                                ))
    ts_digicam = []
    ts_master = []
    ts_pdp = []
    ts_safety = []
    ts_drive = []
    ts_data = []
    for event in data_stream:
        tel_id = event.r0.tels_with_data[0]
        ts_digicam.append(event.slow_data.DigicamSlowControl.timestamp * 1e-3)
        ts_master.append(event.slow_data.MasterSST1M.timestamp * 1e-3)
        ts_pdp.append(event.slow_data.PDPSlowControl.timestamp * 1e-3)
        ts_safety.append(event.slow_data.SafetyPLC.timestamp * 1e-3)
        ts_drive.append(event.slow_data.DriveSystem.timestamp * 1e-3)
        ts_data.append(event.r0.tel[tel_id].local_camera_clock * 1e-9)
    ts_digicam = np.array(ts_digicam)
    ts_master = np.array(ts_master)
    ts_pdp = np.array(ts_pdp)
    ts_safety = np.array(ts_safety)
    ts_drive = np.array(ts_drive)
    ts_data = np.array(ts_data)
    assert ((ts_data - ts_digicam) <= 1.1).all()
    assert ((ts_data - ts_master) <= 1.1).all()
    assert ((ts_data - ts_pdp) <= 1.1).all()
    assert ((ts_data - ts_safety) <= 1.1).all()
    assert ((ts_data - ts_drive) <= 1.1).all()
Exemplo n.º 19
0
def main(args):
    # Input/Output files
    dark_baseline = np.load(args['--baseline_path'])

    digicam = Camera(
        # Source coordinates (in camera frame)
        source_x=0. * u.mm,
        source_y=0. * u.mm,
    )

    # Config for NSB + baseline evaluation
    n_bins = 1000

    # Config for Hillas parameters analysis
    reclean = True

    # Noisy pixels not taken into account in Hillas
    pixel_not_wanted = [
        1038, 1039, 1002, 1003, 1004, 966, 967, 968, 930, 931, 932, 896
    ]
    additional_mask = np.ones(1296)
    additional_mask[pixel_not_wanted] = 0
    additional_mask = additional_mask > 0

    # Integration configuration (signal reco.)
    time_integration_options = {
        'mask': None,
        'mask_edges': None,
        'peak': None,
        'window_start': 3,
        'window_width': 7,
        'threshold_saturation': np.inf,
        'n_samples': 50,
        'timing_width': 6,
        'central_sample': 11
    }

    peak_position = utils.fake_timing_hist(
        time_integration_options['n_samples'],
        time_integration_options['timing_width'],
        time_integration_options['central_sample'])

    (time_integration_options['peak'], time_integration_options['mask'],
     time_integration_options['mask_edges']) = utils.generate_timing_mask(
         time_integration_options['window_start'],
         time_integration_options['window_width'], peak_position)

    # Image cleaning configuration
    picture_threshold = 15
    boundary_threshold = 10
    shower_distance = 200 * u.mm

    # Define the event stream
    data_stream = event_stream(args['<files>'], camera=digicam)
    # Clean pixels
    data_stream = filter.set_pixels_to_zero(data_stream,
                                            unwanted_pixels=pixel_not_wanted)
    # Compute baseline with clocked triggered events
    # (sliding average over n_bins)
    data_stream = random_triggers.fill_baseline_r0(data_stream, n_bins=n_bins)
    # Stop events that are not triggered by DigiCam algorithm
    # (end of clocked triggered events)
    data_stream = filter.filter_event_types(data_stream, flags=[1, 2])
    # Do not return events that have not the baseline computed
    # (only first events)
    data_stream = filter.filter_missing_baseline(data_stream)

    # Run the r1 calibration (i.e baseline substraction)
    data_stream = r1.calibrate_to_r1(data_stream, dark_baseline)
    # Run the dl0 calibration (data reduction, does nothing)
    data_stream = dl0.calibrate_to_dl0(data_stream)
    # Run the dl1 calibration (compute charge in photons + cleaning)
    data_stream = dl1.calibrate_to_dl1(data_stream,
                                       time_integration_options,
                                       additional_mask=additional_mask,
                                       picture_threshold=picture_threshold,
                                       boundary_threshold=boundary_threshold)
    # Return only showers with total number of p.e. above min_photon
    data_stream = filter.filter_shower(data_stream,
                                       min_photon=args['--min_photon'])
    # Run the dl2 calibration (Hillas)
    data_stream = dl2.calibrate_to_dl2(data_stream,
                                       reclean=reclean,
                                       shower_distance=shower_distance)

    if args['--display']:

        with plt.style.context('ggplot'):
            display = EventViewer(data_stream)
            display.draw()
    else:
        save_hillas_parameters_in_text(data_stream=data_stream,
                                       output_filename=args['--outfile_path'])
        'central_sample': 11
    }

    peak_position = utils.fake_timing_hist(
        time_integration_options['n_samples'],
        time_integration_options['timing_width'],
        time_integration_options['central_sample'])

    time_integration_options['peak'], time_integration_options['mask'], \
        time_integration_options['mask_edges'] = utils.generate_timing_mask(
        time_integration_options['window_start'],
        time_integration_options['window_width'],
        peak_position)

    # Define the event stream
    data_stream = event_stream(urls,
                               camera_geometry=digicam_geometry,
                               expert_mode=True)

    # Fill the flags (to be replaced by Digicam)
    data_stream = filter.fill_flag(data_stream, unwanted_patch=unwanted_patch)
    # Fill the baseline (to be replaced by Digicam)
    data_stream = random_triggers.fill_baseline_r0(data_stream, n_bins=3000)
    #    data_stream = filter.filter_event_types(data_stream, flags=[1])
    data_stream = filter.filter_missing_baseline(data_stream)

    save_to_pickle_gz(data_stream,
                      'test.pickle',
                      overwrite=True,
                      max_events=100)
def test_calibrate_to_dl1():
    from digicampipe.calib.camera.dl1 import calibrate_to_dl1

    # The next 50 lines are just setp.
    dark_baseline = make_dark_base_line()

    n_bins = 50
    pixel_not_wanted = [
        1038, 1039, 1002, 1003, 1004, 966, 967, 968, 930, 931, 932, 896
    ]
    additional_mask = np.ones(1296)
    additional_mask[pixel_not_wanted] = 0
    additional_mask = additional_mask > 0

    time_integration_options = {
        'mask': None,
        'mask_edges': None,
        'peak': None,
        'window_start': 3,
        'window_width': 7,
        'threshold_saturation': np.inf,
        'n_samples': 50,
        'timing_width': 6,
        'central_sample': 11
    }

    peak_position = utils.fake_timing_hist(
        time_integration_options['n_samples'],
        time_integration_options['timing_width'],
        time_integration_options['central_sample'])

    (time_integration_options['peak'], time_integration_options['mask'],
     time_integration_options['mask_edges']) = utils.generate_timing_mask(
         time_integration_options['window_start'],
         time_integration_options['window_width'], peak_position)

    data_stream = event_stream(example_file_path)
    data_stream = filter.set_pixels_to_zero(
        data_stream,
        unwanted_pixels=pixel_not_wanted,
    )
    data_stream = random_triggers.fill_baseline_r0(
        data_stream,
        n_bins=n_bins,
    )
    data_stream = filter.filter_event_types(data_stream, flags=[1, 2])
    data_stream = filter.filter_missing_baseline(data_stream)

    data_stream = r1.calibrate_to_r1(data_stream, dark_baseline)
    data_stream = dl0.calibrate_to_dl0(data_stream)

    # This is the function under test
    data_stream = calibrate_to_dl1(
        data_stream,
        time_integration_options,
        additional_mask=additional_mask,
        picture_threshold=15,
        boundary_threshold=10,
    )

    # This is the actual test:
    for event_counter, event in enumerate(data_stream):
        for dl1 in event.dl1.tel.values():

            assert dl1.cleaning_mask.shape == (1296, )
            assert dl1.cleaning_mask.dtype == np.bool

            assert not np.isnan(dl1.time_spread)

            assert dl1.pe_samples.shape == (1296, )
            assert dl1.pe_samples.dtype == np.float64

            assert dl1.on_border.shape == ()
            assert dl1.on_border.dtype == np.bool

    assert event_counter >= 86
Exemplo n.º 22
0
def main(
    files,
    outfile_path,
    outfile_suffix,
    picture_threshold=15,
    boundary_threshold=7,
    baseline0=9,
    baseline1=15,
):

    # Input/Output files
    digicam_config_file = args['--camera_config']

    dark_baseline = None

    # Source coordinates (in camera frame)
    source_x = 0. * u.mm
    source_y = 0. * u.mm

    # Camera and Geometry objects
    # (mapping, pixel, patch + x,y coordinates pixels)
    digicam = Camera(_config_file=digicam_config_file)
    digicam_geometry = geometry.generate_geometry_from_camera(
        camera=digicam, source_x=source_x, source_y=source_y)

    # Noisy pixels not taken into account in Hillas
    pixel_not_wanted = [
        1038, 1039, 1002, 1003, 1004, 966, 967, 968, 930, 931, 932, 896
    ]
    additional_mask = np.ones(1296)
    additional_mask[pixel_not_wanted] = 0
    additional_mask = additional_mask > 0

    # Integration configuration (signal reco.)
    time_integration_options = {
        'mask': None,
        'mask_edges': None,
        'peak': None,
        'window_start': 3,
        'window_width': 7,  # length of integration window
        'threshold_saturation': np.inf,
        'n_samples': 50,
        'timing_width': 6,
        'central_sample': 11
    }

    peak_position = utils.fake_timing_hist(
        time_integration_options['n_samples'],
        time_integration_options['timing_width'],
        time_integration_options['central_sample'])

    (time_integration_options['peak'], time_integration_options['mask'],
     time_integration_options['mask_edges']) = utils.generate_timing_mask(
         time_integration_options['window_start'],
         time_integration_options['window_width'], peak_position)

    # Image cleaning configuration
    shower_distance = 200 * u.mm

    # Filtering on big showers
    min_photon = 50

    # Config for Hillas parameters analysis
    n_showers = 100000000
    reclean = True

    # Define the event stream
    data_stream = event_stream(files,
                               camera_geometry=digicam_geometry,
                               camera=digicam)

    # Clean pixels
    data_stream = filter.set_pixels_to_zero(data_stream,
                                            unwanted_pixels=pixel_not_wanted)

    # Computation of baseline
    #
    # Methods:
    #
    # simtel_baseline.baseline_data()
    # Baseline is computed as a mean of 'n_bins0' first time samples,
    # 'n_bins1' last time samples.
    # A key assumption in this method is that the shower in simulated
    # data is somewhere in the middle of 50 samples.
    # Each pixel in each event has its own baseline
    #
    # simtel_baseline.baseline_simtel()
    # Baseline is taken as a value reported by sim_telarray
    # event.mc.tel[tel_id].pedestal/event.r0.tel[tel_id].num_samples.
    # That should be OK for all sim_telarray version from April
    # 2018, where an error for DC coupled simulations was corrected.

    data_stream = simtel_baseline.baseline_data(data_stream,
                                                n_bins0=baseline0,
                                                n_bins1=baseline1)

    # data_stream = simtel_baseline.baseline_simtel(data_stream)

    # Run the r1 calibration (i.e baseline substraction)
    data_stream = r1.calibrate_to_r1(data_stream, dark_baseline)

    # Run the dl1 calibration (compute charge in photons + cleaning)
    data_stream = dl1.calibrate_to_dl1(data_stream,
                                       time_integration_options,
                                       additional_mask=additional_mask,
                                       picture_threshold=picture_threshold,
                                       boundary_threshold=boundary_threshold)

    # Return only showers with total number of p.e. above min_photon
    data_stream = filter.filter_shower(data_stream, min_photon=min_photon)

    # Save cleaned events - pixels and corresponding values
    filename_pix = 'pixels.txt'
    filename_eventsimage = 'events_image_' + outfile_suffix + '.txt'
    data_stream = events_image.save_events(data_stream,
                                           outfile_path + filename_pix,
                                           outfile_path + filename_eventsimage)

    # Save simulated shower paramters
    filename_showerparam = 'pipedmc_param_' + outfile_suffix + '.txt'
    data_stream = mc_shower.save_shower(data_stream,
                                        outfile_path + filename_showerparam)

    # Run the dl2 calibration (Hillas)
    data_stream = dl2.calibrate_to_dl2(data_stream,
                                       reclean=reclean,
                                       shower_distance=shower_distance)

    # Save arrival times of photons in pixels passed cleaning
    filename_timing = 'timing_' + outfile_suffix + '.txt'
    data_stream = events_image.save_timing(data_stream,
                                           outfile_path + filename_timing)

    # Save mean baseline in event pixels
    filename_baseline = ('baseline_' + outfile_suffix + '_bas' +
                         str(baseline0).zfill(2) + str(baseline1).zfill(2) +
                         '.txt')
    # data_stream = simtel_baseline.save_mean_event_baseline(
    #    data_stream, directory + filename_baseline)

    if args['--display']:

        with plt.style.context('ggplot'):
            display = EventViewer(data_stream)
        display.draw()

    else:
        # Save Hillas
        hillas_filename = 'hillas_' + outfile_suffix
        save_hillas_parameters(data_stream=data_stream,
                               n_showers=n_showers,
                               output_filename=outfile_path + hillas_filename)
        # save_hillas_parameters_in_text(
        #    data_stream=data_stream,
        #    output_filename=outfile_path + hillas_filename)
    """
        [1.00000006e+08, 1.00000006e+08, 1.00000006e+08, 1.00000006e+08,
         9.98248525e+07, 4.58257597e+07, 7.87400834e+06],
        [1.44337576e+08, 1.44337576e+08, 1.44337576e+08, 1.44337576e+08,
         1.39066839e+08, 7.07843010e+07, 6.14071151e+07, 6.12372472e+07,
         6.12372472e+07, 6.12372472e+07, 6.12372472e+07, 6.12372472e+07]
    ]
    threshold_care = [
        [10., 25., 40., 55., 70., 85., 100.],
        [10., 20., 30., 40., 50., 60., 70.],
        [10., 20., 30., 40., 50., 60., 70., 80., 90., 100., 110., 120.]
    ]
    nsb_care = [1.5, 1.0, 0.9]

    # Define the event stream

    data_stream = event_stream(args['<fitsfiles>'])
    data_stream = filter.filter_event_types(data_stream, flags=[8])

    data = np.load(args['<outfile>'])

    fig = plt.figure()
    axis = fig.add_subplot(111)
    axis.errorbar(
        data['threshold'],
        data['rate'] * 1E9,
        yerr=data['rate_error'] * 1E9,
        label='Blinding : {}'.format(blinding)
    )
    axis.errorbar(
        threshold_care[0],
        rate_care[0],
def test_event_stream():

    for _ in event_stream(example_file_path):

        pass
 def func():
     for _, i in zip(event_stream(example_file_path), range(100)):
         pass
     assert i == 99
Exemplo n.º 26
0
def test_event_type_enum_behavior():
    for event in event_stream(example_file_path):
        for _, r0 in event.r0.tel.items():
            assert r0.camera_event_type.INTERNAL in r0.camera_event_type
Exemplo n.º 27
0
def test_event_source_new_style():
    for _ in event_stream(example_file_path):
        pass
def test_n_pixels():

    for event in event_stream(example_file_path):

        assert event.inst.num_pixels[TEL_WITH_DATA] == N_PIXELS
def test_tel_with_data():

    for event in event_stream(example_file_path):

        assert TEL_WITH_DATA in event.r0.tels_with_data
Exemplo n.º 30
0
from digicamviewer import viewer
from digicampipe.io import event_stream

if __name__ == '__main__':

    directory = '/home/alispach/data/CRAB_01/'

    camera_config_file = '/home/alispach/Documents/PhD/ctasoft/CTS/config/camera_config.cfg'
    file_basename = directory + 'CRAB_01_0_000.%.3d.fits.fz'
    file_list = [file_basename % i for i in range(1, 11)]
    print(file_list)
    data_stream = event_stream.event_stream(file_list=file_list,
                                            expert_mode=True,
                                            geom_file=camera_config_file,
                                            remapped=True)

    display = viewer.EventViewer2(
        data_stream, n_samples=50,
        camera_config_file=camera_config_file)  #, scale='lin')
    display.next(step=1)
    display.draw()