def test_calc_pedestals_from_traces():
    """ test calc_pedestals_from_traces """
    from ctapipe.calib.camera.pedestals import calc_pedestals_from_traces
    # create some test data (all ones, but with a 2 stuck in for good measure):
    npix = 1000
    nsamp = 32
    traces = np.ones(shape=(npix, nsamp), dtype=np.int32)
    traces[:, 2] = 2

    # calculate pedestals over samples 0-10
    peds, pedvars = calc_pedestals_from_traces(traces, 0, 10)

    # check the results. All pedestals should be 1.1 and vars 0.09:

    assert np.all(peds == 1.1)
    assert np.all(pedvars == 0.09)
    assert peds.shape[0] == npix
    assert pedvars.shape[0] == npix

    # try another sample range, where there should be no variances and
    # all 1.0 peds:
    peds, pedvars = calc_pedestals_from_traces(traces, 12, 32)

    assert np.all(peds == 1.0)
    assert np.all(pedvars == 0)
Exemple #2
0
    # loop over all events, all telescopes and all channels and call
    # the calc_peds function defined above to do some work:
    for event in EventSource(filename):
        for telid in event.r0.tel.keys():
            for chan in range(event.r0.tel[telid].waveform.shape[0]):

                print(f"CT{telid} chan {chan}:")

                traces = event.r0.tel[telid].waveform[chan, ...]

                # skip telescopes without timeseries data
                if traces.shape[1] == 1:
                    continue

                peds, pedvars = pedestals.calc_pedestals_from_traces(
                    traces, start, end)

                print("Number of samples: {}".format(traces.shape[1]))
                print(f"Calculate over window:({start},{end})")
                print("PEDS:", peds)
                print("VARS:", pedvars)
                print("-----")

    # as an example, for the final event, let's plot the pedestals and
    # variances: (you could also move this into the for-loop, but
    # would then have tons of plots)

    plot_peds(peds, pedvars)
    plt.show()

    # note with the sample data you'll get a warning about "Wrong