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 = toymodel.generate_2d_shower_model(centroid=centroid, width=width, length=length, psi=angle * u.deg) image, sig, bg = toymodel.make_toymodel_shower_image(geom, model.pdf, intensity=intens, nsb_level_pe=5000) # alternate between cleaned and raw images if self._counter > 20: plt.suptitle("Image Cleaning ON") cleanmask = cleaning.tailcuts_clean(geom, image, pedvars=80) for ii in range(3): cleaning.dilate(geom, cleanmask) image[cleanmask == 0] = 0 # zero noise pixels if self._counter >= 40: plt.suptitle("Image Cleaning OFF") self._counter = 0 disp.image = image disp.set_limits_percent(100) self._counter += 1
def test_dilate(): geom = CameraGeometry.from_name("LSTCam") mask = np.zeros_like(geom.pix_id, dtype=bool) mask[100] = True # a single pixel far from a border is true. assert mask.sum() == 1 # dilate a single row dmask = cleaning.dilate(geom, mask) assert dmask.sum() == 1 + 6 # dilate a second row dmask = cleaning.dilate(geom, dmask) assert dmask.sum() == 1 + 6 + 12 # dilate a third row dmask = cleaning.dilate(geom, dmask) assert dmask.sum() == 1 + 6 + 12 + 18
def clean_tail(self, img, cam_geom): mask = tailcuts_clean( cam_geom, img, picture_thresh=self.tail_thresholds[cam_geom.cam_id][1], boundary_thresh=self.tail_thresholds[cam_geom.cam_id][0]) if self.dilate: dilate(cam_geom, mask) img[~mask] = 0 self.cutflow.count("tailcut cleaning") if "ASTRI" in cam_geom.cam_id: # turn into 2d to apply island cleaning img = astri_to_2d_array(img) # if set, remove all signal patches but the biggest one new_img = self.island_cleaning(img) # turn back into 1d array new_img = array_2d_to_astri(new_img) new_geom = cam_geom else: # turn into 2d to apply island cleaning rot_geom, rot_img = convert_geometry_hex1d_to_rect2d( cam_geom, img, cam_geom.cam_id) # if set, remove all signal patches but the biggest one cleaned_img = self.island_cleaning(rot_img, self.hex_neighbours_1ring) # turn back into 1d array unrot_geom, unrot_img = convert_geometry_rect2d_back_to_hexe1d( rot_geom, cleaned_img, cam_geom.cam_id) new_img = unrot_img new_geom = unrot_geom if self.cutflow.cut("edge event", img=new_img, geom=new_geom): raise EdgeEvent return new_img, new_geom
def test_dilate(): geom = io.CameraGeometry.from_name("HESS", 1) mask = np.zeros_like(geom.pix_id, dtype=bool) mask[100] = True # a single pixel far from a border is true. assert mask.sum() == 1 # dilate a single row cleaning.dilate(geom, mask) assert mask.sum() == 1 + 6 # dilate a second row cleaning.dilate(geom, mask) assert mask.sum() == 1 + 6 + 12 # dilate a third row cleaning.dilate(geom, mask) assert mask.sum() == 1 + 6 + 12 + 18
def display_event(event, calibrate = 0, max_tel = 4, cleaning=None): """an extremely inefficient display. It creates new instances of CameraDisplay for every event and every camera, and also new axes for each event. It's hacked, but it works """ print("Displaying... please wait (this is an inefficient implementation)") global fig ntels = min(max_tel, len(event.dl0.tels_with_data)) fig.clear() plt.suptitle("EVENT {}".format(event.dl0.event_id)) disps = [] mc_sum = None all_moments = [] for ii, tel_id in enumerate(event.dl0.tels_with_data): if ii >= max_tel: break print("\t draw cam {}...".format(tel_id)) nn = int(ceil((ntels)**.5)) ax = plt.subplot(nn, 2*nn, 2*(ii+1)-1) x, y = event.inst.pixel_pos[tel_id] geom = io.CameraGeometry.guess(x, y, event.inst.optical_foclen[tel_id]) disp = visualization.CameraDisplay(geom, ax=ax, title="CT{0} DetectorResponse".format(tel_id)) disp.pixels.set_antialiaseds(False) disp.autoupdate = False disp.cmap = plt.cm.hot chan = 0 signals = event.dl0.tel[tel_id].adc_sums[chan].astype(float)[:] if calibrate: signals = apply_mc_calibration_ASTRI(event.dl0.tel[tel_id].adc_sums, tel_id) if cleaning == 'tailcut': mask = tailcuts_clean(geom, signals, 1,picture_thresh=10.,boundary_thresh=8.) dilate(geom, mask) signals[mask==False] = 0 moments = hillas_parameters_2(geom.pix_x, geom.pix_y, signals) disp.image = signals disp.overlay_moments(moments, color='seagreen', linewidth=3) disp.set_limits_percent(95) disp.add_colorbar() disps.append(disp) ax = plt.subplot(nn, 2*nn, 2*(ii+1)) geom = io.CameraGeometry.guess(x, y, event.inst.optical_foclen[tel_id]) disp = visualization.CameraDisplay(geom, ax=ax, title="CT{0} PhotoElectrons".format(tel_id)) disp.pixels.set_antialiaseds(False) disp.autoupdate = False disp.cmap = plt.cm.hot chan = 0 #print (event.mc.tel[tel_id].photo_electrons) for jj in range(len(event.mc.tel[tel_id].photo_electron_image)): event.dl0.tel[tel_id].adc_sums[chan][jj] = event.mc.tel[tel_id].photo_electron_image[jj] signals2 = event.dl0.tel[tel_id].adc_sums[chan].astype(float) moments2 = hillas_parameters_2(geom.pix_x, geom.pix_y, signals2) all_moments.append(moments2) if mc_sum is None: mc_sum = signals2 else: scale = 3 if tel_id == 37 else 1 for i, val in enumerate(signals2): mc_sum[i] += val/scale disp.image = mc_sum for moments2 in all_moments: disp.overlay_moments(moments2, color='seagreen', linewidth=2) disp.set_limits_percent(95) disp.add_colorbar() disps.append(disp) return disps