def update(frame): centroid = np.random.uniform(-0.5, 0.5, size=2) width = np.random.uniform(0, 0.01) length = np.random.uniform(0, 0.03) + width angle = np.random.uniform(0, 360) intens = np.random.exponential(2) * 50 model = mock.generate_2d_shower_model( centroid=centroid, width=width, length=length, psi=angle * u.deg, ) image, sig, bg = mock.make_mock_shower_image( geom, model.pdf, intensity=intens, nsb_level_pe=5000, ) image /= image.max() disp.image = image
if __name__ == '__main__': # Load the camera geom = io.CameraGeometry.from_name("hess", 1) disp = visualization.CameraDisplay(geom) disp.set_limits_minmax(0, 300) disp.add_colorbar() # Create a fake camera image to display: model = mock.generate_2d_shower_model(centroid=(0.2, 0.0), width=0.01, length=0.1, psi='35d') image, sig, bg = mock.make_mock_shower_image(geom, model.pdf, intensity=50, nsb_level_pe=1000) # Apply really stupid image cleaning (single threshold): clean = image.copy() clean[image <= 3.0 * image.mean()] = 0.0 # Calculate image parameters hillas = hillas_parameters(geom.pix_x, geom.pix_y, clean) print(hillas) # Show the camera image and overlay Hillas ellipse disp.image = image disp.overlay_moments(hillas, color='seagreen', linewidth=3) # Draw the neighbors of pixel 100 in red, and the neighbor-neighbors in
"""Example how to make a mock shower image and plot it. """ import matplotlib.pyplot as plt from ctapipe.io.camera import make_rectangular_camera_geometry from ctapipe.image.mock import generate_2d_shower_model, make_mock_shower_image NX = 40 NY = 40 geom = make_rectangular_camera_geometry(NX, NY) showermodel = generate_2d_shower_model(centroid=[0.25, 0.0], length=0.1, width=0.02, psi='40d') image, signal, noise = make_mock_shower_image(geom, showermodel.pdf, intensity=20, nsb_level_pe=30) # make them into 2D arrays so we can plot them with imshow image.shape = (NX, NY) signal.shape = (NX, NY) noise.shape = (NX, NY) # here we just plot the images using imshow(). For a more general # case, one should use a ctapipe.visualization.CameraDisplay plt.figure(figsize=(10, 3)) plt.subplot(1, 3, 1) plt.imshow(signal, interpolation='nearest', origin='lower') plt.title("Signal") plt.colorbar() plt.subplot(1, 3, 2) plt.imshow(noise, interpolation='nearest', origin='lower')
from ctapipe.image import mock from ctapipe.io import CameraGeometry from ctapipe.visualization import CameraDisplay from matplotlib import pyplot as plt if __name__ == '__main__': plt.style.use('ggplot') fig = plt.figure(figsize=(12, 8)) ax = fig.add_subplot(1, 1, 1) geom = CameraGeometry.from_name('hess', 1) disp = CameraDisplay(geom, ax=ax) disp.add_colorbar() model = mock.generate_2d_shower_model( centroid=(0.05, 0.0), width=0.005, length=0.025, psi='35d' ) image, sig, bg = mock.make_mock_shower_image( geom, model.pdf, intensity=50, nsb_level_pe=20 ) disp.image = image mask = disp.image > 15 disp.highlight_pixels(mask, linewidth=3) plt.show()
import matplotlib.pyplot as plt from ctapipe.io.camera import make_rectangular_camera_geometry from ctapipe.image.mock import generate_2d_shower_model, make_mock_shower_image NX = 40 NY = 40 geom = make_rectangular_camera_geometry(NX, NY) showermodel = generate_2d_shower_model(centroid=[0.25, 0.0], length=0.1, width=0.02, psi='40d') image, signal, noise = make_mock_shower_image(geom, showermodel.pdf, intensity=20, nsb_level_pe=30) # make them into 2D arrays so we can plot them with imshow image.shape = (NX, NY) signal.shape = (NX, NY) noise.shape = (NX, NY) # here we just plot the images using imshow(). For a more general # case, one should use a ctapipe.visualization.CameraDisplay plt.figure(figsize=(10, 3)) plt.subplot(1, 3, 1) plt.imshow(signal, interpolation='nearest', origin='lower') plt.title("Signal") plt.colorbar() plt.subplot(1, 3, 2)
def mock_event_source(geoms, events=100, single_tel=False, n_channels=1, n_samples=25, p_trigger=0.3): """ An event source that produces array Parameters ---------- geoms : list of CameraGeometry instances Geometries for the telescopes to simulate events : int, default: 100 maximum number of events to create n_channels : int how many channels per telescope n_samples : int how many adc samples per pixel p_trigger : float mean trigger probability for the telescopes """ n_telescopes = len(geoms) container = EventContainer() container.meta.add_item('mock__max_events', events) container.meta.source = "mock" tel_ids = np.arange(n_telescopes) for event_id in range(events): n_triggered = np.random.poisson(n_telescopes * 0.3) if n_triggered > n_telescopes: n_triggered = n_telescopes triggered_tels = np.random.choice(tel_ids, n_triggered, replace=False) container.dl0.event_id = event_id container.dl0.tels_with_data = triggered_tels container.count = event_id # handle single-telescope case (ignore others: if single_tel: if single_tel not in container.dl0.tels_with_data: continue container.dl0.tels_with_data = [single_tel, ] container.dl0.tel = dict() # clear the previous telescopes t = np.arange(n_samples) for tel_id in container.dl0.tels_with_data: geom = geoms[tel_id] # fill pixel position dictionary, if not already done: if tel_id not in container.meta.pixel_pos: container.meta.pixel_pos[tel_id] = ( geom.pix_x.value, geom.pix_y.value, ) centroid = np.random.uniform(geom.pix_x.min(), geom.pix_y.max(), 2) length = np.random.uniform(0.02, 0.2) width = np.random.uniform(0.01, length) psi = np.random.randint(0, 360) intensity = np.random.poisson(int(10000 * width * length)) model = mock.generate_2d_shower_model( centroid, width, length, '{}d'.format(psi) ) image, _, _ = mock.make_mock_shower_image( geom, model.pdf, intensity, ) container.dl0.tel[tel_id] = RawCameraData(tel_id) container.dl0.tel[tel_id].num_channels = n_channels n_pix = len(geom.pix_id) samples = np.empty((n_pix, n_samples)) means = np.random.normal(15, 1, (n_pix, 1)) stds = np.random.uniform(3, 6, (n_pix, 1)) samples = image[:, np.newaxis] * norm.pdf(t, means, stds) for chan in range(n_channels): container.dl0.tel[tel_id].adc_samples[chan] = samples container.dl0.tel[tel_id].adc_sums[chan] = image yield container