def test_hillas_failure(): geom, image = create_sample_image(psi='0d') blank_image = zeros_like(image) with pytest.raises(HillasParameterizationError): hillas_parameters_1(geom, blank_image) with pytest.raises(HillasParameterizationError): hillas_parameters_2(geom, blank_image) with pytest.raises(HillasParameterizationError): hillas_parameters_3(geom, blank_image) with pytest.raises(HillasParameterizationError): hillas_parameters_4(geom, blank_image)
def do_test_hillas(withunits=True): """ test all Hillas-parameter routines on a sample image and see if they agree with eachother and with the toy model (assuming the toy model code is correct) """ # try all quadrants for psi_angle in ['30d', '120d', '-30d', '-120d']: px, py, image = create_sample_image(psi_angle) results = {} if withunits: px = px * u.cm py = py * u.cm results['v1'] = hillas_parameters_1(px, py, image) results['v2'] = hillas_parameters_2(px, py, image) results['v3'] = hillas_parameters_3(px, py, image) results['v4'] = hillas_parameters_4(px, py, image) # compare each method's output for aa in results: for bb in results: if aa is not bb: print("comparing {} to {}".format(aa, bb)) compare_result(results[aa].length, results[bb].length) compare_result(results[aa].width, results[bb].width) compare_result(results[aa].r, results[bb].r) compare_result(results[aa].phi.deg, results[bb].phi.deg) compare_result(results[aa].psi.deg, results[bb].psi.deg) compare_result(results[aa].miss, results[bb].miss) compare_result(results[aa].skewness, results[bb].skewness)
def test_hillas(): """ test all Hillas-parameter routines on a sample image and see if they agree with eachother and with the toy model (assuming the toy model code is correct) """ px, py, image = create_sample_image() results = {} results['v1'] = hillas_parameters_1(px, py, image) results['v2'] = hillas_parameters_2(px, py, image) results['v3'] = hillas_parameters_3(px, py, image) results['v4'] = hillas_parameters_4(px, py, image) # compare each method's output for aa in results: for bb in results: if aa is not bb: print("comparing {} to {}".format(aa, bb)) assert isclose(results[aa].length, results[bb].length) assert isclose(results[aa].width, results[bb].width) assert isclose(results[aa].r, results[bb].r) assert isclose(results[aa].phi.deg, results[bb].phi.deg) assert isclose(results[aa].psi.deg, results[bb].psi.deg) assert isclose(results[aa].miss, results[bb].miss) assert isclose(results[aa].skewness, results[bb].skewness)
def do_test_hillas(withunits=True): """ test all Hillas-parameter routines on a sample image and see if they agree with eachother and with the toy model (assuming the toy model code is correct) """ px, py, image = create_sample_image() results = {} if withunits: px = px * u.cm py = py * u.cm results['v1'] = hillas_parameters_1(px, py, image) results['v2'] = hillas_parameters_2(px, py, image) results['v3'] = hillas_parameters_3(px, py, image) results['v4'] = hillas_parameters_4(px, py, image) # compare each method's output for aa in results: for bb in results: if aa is not bb: print("comparing {} to {}".format(aa,bb)) compare_result(results[aa].length, results[bb].length) compare_result(results[aa].width, results[bb].width) compare_result(results[aa].r, results[bb].r) compare_result(results[aa].phi.deg, results[bb].phi.deg) compare_result(results[aa].psi.deg, results[bb].psi.deg) compare_result(results[aa].miss, results[bb].miss) compare_result(results[aa].skewness, results[bb].skewness)
def get_hillas_parameters(geom: CameraGeometry, image, implementation=4): r"""Return Hillas parameters [hillas]_ of the given ``image``. Short description of Hillas parameters: * x: x position of the ellipse's center (in meter) * y: y position of the ellipse's center (in meter) * length: measure of the RMS extent along the major axis (in meter) (length >= width) * width: measure of the RMS extent along the minor axis (in meter) (length >= width) * intensity: the number of photoelectrons in the image (in PE) (size = np.sum(image)) * psi: angle of the shower (in radian) * phi: polar coordinate of centroid (in radian) * r: radial coordinate of centroid (in meter) * kurtosis: Kurtosis is a measure of whether the data are heavy-tailed or light-tailed relative to a normal distribution. That is, data sets with high kurtosis tend to have heavy tails, or outliers. Data sets with low kurtosis tend to have light tails, or lack of outliers. See http://www.itl.nist.gov/div898/handbook/eda/section3/eda35b.htm * skewness: Skewness is a measure of symmetry, or more precisely, the lack of symmetry. A distribution, or data set, is symmetric if it looks the same to the left and right of the center point. See http://www.itl.nist.gov/div898/handbook/eda/section3/eda35b.htm See https://github.com/cta-observatory/ctapipe/blob/master/ctapipe/image/hillas.py#L83 for more information. Parameters ---------- geom : CameraGeomatry The geometry of the image to parametrize image : Numpy array The image to parametrize implementation : integer Tell which ctapipe's implementation to use (1 or 2). Returns ------- namedtuple Hillas parameters for the given ``image`` References ---------- .. [hillas] Appendix of the Whipple Crab paper Weekes et al. (1998) http://adsabs.harvard.edu/abs/1989ApJ...342..379W """ # Copy image to prevent tricky bugs image = image.copy() if implementation == 1: params = hillas_parameters_1(geom, image) elif implementation == 2: params = hillas_parameters_2(geom, image) elif implementation == 3: params = hillas_parameters_3(geom, image) elif implementation == 4: params = hillas_parameters_4(geom, image) else: raise ValueError("Wrong Hillas implementation ID.") return params