Beispiel #1
0
def test_waveform_model():
    from ctapipe.image.toymodel import Gaussian

    geom = CameraGeometry.from_name("CHEC")
    readout = CameraReadout.from_name("CHEC")

    ref_duration = 67
    n_ref_samples = 100
    pulse_sigma = 3
    ref_x_norm = np.linspace(0, ref_duration, n_ref_samples)
    ref_y_norm = norm.pdf(ref_x_norm, ref_duration / 2, pulse_sigma)

    readout.reference_pulse_shape = ref_y_norm[np.newaxis, :]
    readout.reference_pulse_sample_width = u.Quantity(
        ref_x_norm[1] - ref_x_norm[0], u.ns)
    readout.sampling_rate = u.Quantity(2, u.GHz)

    centroid_x = u.Quantity(0.05, u.m)
    centroid_y = u.Quantity(0.05, u.m)
    length = u.Quantity(0.03, u.m)
    width = u.Quantity(0.008, u.m)
    psi = u.Quantity(70, u.deg)
    time_gradient = u.Quantity(50, u.ns / u.m)
    time_intercept = u.Quantity(20, u.ns)

    _, charge, _ = Gaussian(x=centroid_x,
                            y=centroid_y,
                            width=width,
                            length=length,
                            psi=psi).generate_image(geom, 10000)
    time = obtain_time_image(
        geom.pix_x,
        geom.pix_y,
        centroid_x,
        centroid_y,
        psi,
        time_gradient,
        time_intercept,
    )
    time[charge == 0] = 0

    waveform_model = WaveformModel.from_camera_readout(readout)
    waveform = waveform_model.get_waveform(charge, time, 96)
    np.testing.assert_allclose(waveform.sum(axis=1), charge, rtol=1e-3)
    np.testing.assert_allclose(waveform.argmax(axis=1) /
                               readout.sampling_rate.to_value(u.GHz),
                               time,
                               rtol=1e-1)

    time_2 = time + 1
    time_2[charge == 0] = 0
    waveform_2 = waveform_model.get_waveform(charge, time_2, 96)
    np.testing.assert_allclose(waveform_2.sum(axis=1), charge, rtol=1e-3)
    np.testing.assert_allclose(
        waveform_2.argmax(axis=1) / readout.sampling_rate.to_value(u.GHz),
        time_2,
        rtol=1e-1,
    )
    assert (waveform_2.argmax(axis=1)[charge != 0] >
            waveform.argmax(axis=1)[charge != 0]).all()
Beispiel #2
0
def test_camera_from_name(camera_name):
    """ check we can construct all cameras from name"""

    try:
        camera = CameraReadout.from_name(camera_name)
        assert str(camera) == camera_name
    except FileNotFoundError:
        # these don't have readout definitions on the dataserver
        if camera_name not in ["MAGICCam", "Whipple109", "FACT"]:
            raise
Beispiel #3
0
def test_camera_from_name(camera_geometry):
    """ check we can construct all cameras from name"""

    try:
        camera = CameraReadout.from_name(camera_geometry.camera_name)
        assert str(camera) == camera_geometry.camera_name
    except FileNotFoundError:
        # Most non-cta cameras don't have readout provided on the data server
        if camera_geometry.camera_name in [
                "LSTCam", "NectarCam", "FlashCam", "CHEC"
        ]:
            raise
Beispiel #4
0
def test_camera_from_name(camera_name):
    """ check we can construct all cameras from name"""
    camera = CameraReadout.from_name(camera_name)
    assert str(camera) == camera_name