def test_fit_core(): ''' creating some great circles pointing in different directions (two north-south, two east-west) and that have a slight position errors (+- 0.1 m in one of the four cardinal directions ''' circle1 = GreatCircle([[1, 0, 0], [0, 0, 1]]) circle1.pos = [0, 0.1]*u.m circle1.trace = [1, 0, 0] circle2 = GreatCircle([[0, 1, 0], [0, 0, 1]]) circle2.pos = [0.1, 0] * u.m circle2.trace = [0, 1, 0] circle3 = GreatCircle([[1, 0, 0], [0, 0, 1]]) circle3.pos = [0, -.1] * u.m circle3.trace = [1, 0, 0] circle4 = GreatCircle([[0, 1, 0], [0, 0, 1]]) circle4.pos = [-.1, 0] * u.m circle4.trace = [0, 1, 0] ''' creating the fit class and setting the the great circle member ''' fit = FitGammaHillas() fit.circles = {1: circle1, 2: circle2, 3: circle3, 4: circle4} ''' performing the position fit with a seed that is quite far away ''' pos_fit = fit.fit_core([100, 1000]*u.m) print("position test fit:", pos_fit) ''' the result should be close to the origin of the coordinate system ''' np.testing.assert_allclose(pos_fit/u.m, [0, 0], atol=1e-3)
def test_FitGammaHillas(): ''' a test on one event of the complete fit procedure including: • tailcut cleaning • hillas parametrisation • GreatCircle creation • direction fit • position fit in the end, proper units in the output are asserted ''' filename = get_path("gamma_test.simtel.gz") fit = FitGammaHillas() cam_geom = {} tel_phi = {} tel_theta = {} source = hessio_event_source(filename) for event in source: hillas_dict = {} for tel_id in event.dl0.tels_with_data: if tel_id not in cam_geom: cam_geom[tel_id] = CameraGeometry.guess( event.inst.pixel_pos[tel_id][0], event.inst.pixel_pos[tel_id][1], event.inst.optical_foclen[tel_id]) tel_phi[tel_id] = 180.*u.deg tel_theta[tel_id] = 20.*u.deg pmt_signal = event.dl0.tel[tel_id].adc_sums[0] mask = tailcuts_clean(cam_geom[tel_id], pmt_signal, 1, picture_thresh=10., boundary_thresh=5.) pmt_signal[mask == 0] = 0 try: moments = hillas_parameters(event.inst.pixel_pos[tel_id][0], event.inst.pixel_pos[tel_id][1], pmt_signal) hillas_dict[tel_id] = moments except HillasParameterizationError as e: print(e) continue if len(hillas_dict) < 2: continue fit_result = fit.predict(hillas_dict, event.inst, tel_phi, tel_theta) print(fit_result) fit_result.alt.to(u.deg) fit_result.az.to(u.deg) fit_result.core_x.to(u.m) assert fit_result.is_valid return
def test_FitGammaHillas(): ''' a test of the complete fit procedure on one event including: • tailcut cleaning • hillas parametrisation • GreatCircle creation • direction fit • position fit in the end, proper units in the output are asserted ''' filename = get_path("gamma_test.simtel.gz") fit = FitGammaHillas() cam_geom = {} tel_phi = {} tel_theta = {} source = hessio_event_source(filename) for event in source: hillas_dict = {} for tel_id in event.dl0.tels_with_data: if tel_id not in cam_geom: cam_geom[tel_id] = CameraGeometry.guess( event.inst.pixel_pos[tel_id][0], event.inst.pixel_pos[tel_id][1], event.inst.optical_foclen[tel_id]) tel_phi[tel_id] = 0.*u.deg tel_theta[tel_id] = 20.*u.deg pmt_signal = event.dl0.tel[tel_id].adc_sums[0] mask = tailcuts_clean(cam_geom[tel_id], pmt_signal, 1, picture_thresh=10., boundary_thresh=5.) pmt_signal[mask == 0] = 0 try: moments = hillas_parameters(event.inst.pixel_pos[tel_id][0], event.inst.pixel_pos[tel_id][1], pmt_signal) hillas_dict[tel_id] = moments except HillasParameterizationError as e: print(e) continue if len(hillas_dict) < 2: continue fit_result = fit.predict(hillas_dict, event.inst, tel_phi, tel_theta) print(fit_result) fit_result.alt.to(u.deg) fit_result.az.to(u.deg) fit_result.core_x.to(u.m) assert fit_result.is_valid return
def reco(single_telescope_data): fit = FitGammaHillas() inst = broadcastInst.value hillas_dict, tel_phi, tel_theta = single_telescope_data fit_result = fit.predict(hillas_dict, inst, tel_phi, tel_theta) return fit_result
def test_fit_core(): ''' creating some great circles pointing in different directions (two north-south, two east-west) and that have a slight position errors (+- 0.1 m in one of the four cardinal directions ''' circle1 = GreatCircle([[1, 0, 0], [0, 0, 1]]) circle1.pos = [0, 0.1] * u.m circle1.trace = [1, 0, 0] circle2 = GreatCircle([[0, 1, 0], [0, 0, 1]]) circle2.pos = [0.1, 0] * u.m circle2.trace = [0, 1, 0] circle3 = GreatCircle([[1, 0, 0], [0, 0, 1]]) circle3.pos = [0, -.1] * u.m circle3.trace = [1, 0, 0] circle4 = GreatCircle([[0, 1, 0], [0, 0, 1]]) circle4.pos = [-.1, 0] * u.m circle4.trace = [0, 1, 0] ''' creating the fit class and setting the the great circle member ''' fit = FitGammaHillas() fit.circles = {1: circle1, 2: circle2, 3: circle3, 4: circle4} ''' performing the position fit with a seed that is quite far away ''' pos_fit = fit.fit_core([100, 1000] * u.m) print("position test fit:", pos_fit) ''' the result should be close to the origin of the coordinate system ''' np.testing.assert_allclose(pos_fit / u.m, [0, 0], atol=1e-3)
def test_fit_core(): ''' creating some great circles pointing in different directions (two north-south, two east-west) and that have a slight position errors (+- 0.1 m in one of the four cardinal directions ''' circle1 = GreatCircle([[1, 0, 0], [0, 0, 1]]) circle1.pos = [0, 0.1] * u.m circle1.trace = [1, 0, 0] circle2 = GreatCircle([[0, 1, 0], [0, 0, 1]]) circle2.pos = [0.1, 0] * u.m circle2.trace = [0, 1, 0] circle3 = GreatCircle([[1, 0, 0], [0, 0, 1]]) circle3.pos = [0, -.1] * u.m circle3.trace = [1, 0, 0] circle4 = GreatCircle([[0, 1, 0], [0, 0, 1]]) circle4.pos = [-.1, 0] * u.m circle4.trace = [0, 1, 0] # creating the fit class and setting the the great circle member fit = FitGammaHillas() fit.circles = {1: circle1, 2: circle2, 3: circle3, 4: circle4} # performing the position fit with the minimisation algorithm # and a seed that is quite far away pos_fit_minimise = fit.fit_core_minimise([100, 1000] * u.m) print("position fit test minimise:", pos_fit_minimise) print() # performing the position fit with the geometric algorithm pos_fit_crosses, err_est_pos_fit_crosses = fit.fit_core_crosses() print("position fit test crosses:", pos_fit_crosses) print("error estimate:", err_est_pos_fit_crosses) print() # the results should be close to the origin of the coordinate system np.testing.assert_allclose(pos_fit_minimise / u.m, [0, 0], atol=1e-3) np.testing.assert_allclose(pos_fit_crosses / u.m, [0, 0], atol=1e-3)
def test_fit_origin(): ''' creating some great circles pointing in different directions (two north-south, two east-west) and that have a slight position errors (+- 0.1 m in one of the four cardinal directions ''' circle1 = GreatCircle([[1, 0, 0], [0, 0, 1]]) circle1.pos = [0, 0.1] * u.m circle1.trace = [1, 0, 0] circle2 = GreatCircle([[0, 1, 0], [0, 0, 1]]) circle2.pos = [0.1, 0] * u.m circle2.trace = [0, 1, 0] circle3 = GreatCircle([[1, 0, 0], [0, 0, 1]]) circle3.pos = [0, -.1] * u.m circle3.trace = [1, 0, 0] circle4 = GreatCircle([[0, 1, 0], [0, 0, 1]]) circle4.pos = [-.1, 0] * u.m circle4.trace = [0, 1, 0] # creating the fit class and setting the the great circle member fit = FitGammaHillas() fit.circles = {1: circle1, 2: circle2, 3: circle3, 4: circle4} # performing the direction fit with the minimisation algorithm # and a seed that is perpendicular to the up direction dir_fit_minimise = fit.fit_origin_minimise((0.1, 0.1, 1)) print("direction fit test minimise:", dir_fit_minimise) print() # performing the direction fit with the geometric algorithm dir_fit_crosses = fit.fit_origin_crosses()[0] print("direction fit test crosses:", dir_fit_crosses) print() # the results should be close to the direction straight up # np.testing.assert_allclose(dir_fit_minimise, [0, 0, 1], atol=1e-1) np.testing.assert_allclose(dir_fit_crosses, [0, 0, 1], atol=1e-3)
def test_fit_origin(): ''' creating some great circles pointing in different directions (two north-south, two east-west) and that have a slight position errors (+- 0.1 m in one of the four cardinal directions ''' circle1 = GreatCircle([[1, 0, 0], [0, 0, 1]]) circle1.pos = [0, 0.1]*u.m circle1.trace = [1, 0, 0] circle2 = GreatCircle([[0, 1, 0], [0, 0, 1]]) circle2.pos = [0.1, 0] * u.m circle2.trace = [0, 1, 0] circle3 = GreatCircle([[1, 0, 0], [0, 0, 1]]) circle3.pos = [0, -.1] * u.m circle3.trace = [1, 0, 0] circle4 = GreatCircle([[0, 1, 0], [0, 0, 1]]) circle4.pos = [-.1, 0] * u.m circle4.trace = [0, 1, 0] # creating the fit class and setting the the great circle member fit = FitGammaHillas() fit.circles = {1: circle1, 2: circle2, 3: circle3, 4: circle4} # performing the direction fit with the minimisation algorithm # and a seed that is perpendicular to the up direction dir_fit_minimise = fit.fit_origin_minimise((0.1, 0.1, 1)) print("direction fit test minimise:", dir_fit_minimise) # performing the direction fit with the geometric algorithm dir_fit_crosses = fit.fit_origin_crosses()[0] print("direction fit test crosses:", dir_fit_crosses) # the results should be close to the direction straight up # np.testing.assert_allclose(dir_fit_minimise, [0, 0, 1], atol=1e-1) np.testing.assert_allclose(dir_fit_crosses, [0, 0, 1], atol=1e-3)
def test_fit_core(): ''' creating some great circles pointing in different directions (two north-south, two east-west) and that have a slight position errors (+- 0.1 m in one of the four cardinal directions ''' circle1 = GreatCircle([[1, 0, 0], [0, 0, 1]]) circle1.pos = [0, 0.1]*u.m circle1.trace = [1, 0, 0] circle2 = GreatCircle([[0, 1, 0], [0, 0, 1]]) circle2.pos = [0.1, 0] * u.m circle2.trace = [0, 1, 0] circle3 = GreatCircle([[1, 0, 0], [0, 0, 1]]) circle3.pos = [0, -.1] * u.m circle3.trace = [1, 0, 0] circle4 = GreatCircle([[0, 1, 0], [0, 0, 1]]) circle4.pos = [-.1, 0] * u.m circle4.trace = [0, 1, 0] # creating the fit class and setting the the great circle member fit = FitGammaHillas() fit.circles = {1: circle1, 2: circle2, 3: circle3, 4: circle4} # performing the position fit with the minimisation algorithm # and a seed that is quite far away pos_fit_minimise = fit.fit_core_minimise([100, 1000]*u.m) print("position fit test minimise:", pos_fit_minimise) # performing the position fit with the geometric algorithm pos_fit_crosses = fit.fit_core_crosses() print("position fit test crosses:", pos_fit_crosses) # the results should be close to the origin of the coordinate system np.testing.assert_allclose(pos_fit_minimise/u.m, [0, 0], atol=1e-3) np.testing.assert_allclose(pos_fit_crosses/u.m, [0, 0], atol=1e-3)
def test_FitGammaHillas(): filename = get_path("gamma_test.simtel.gz") fit = FitGammaHillas() fit.setup_geometry(*load_hessio(filename), phi=180 * u.deg, theta=20 * u.deg) tel_geom = {} source = hessio_event_source(filename) for event in source: hillas_dict = {} for tel_id in set(event.trig.tels_with_trigger) & set( event.dl0.tels_with_data): if tel_id not in tel_geom: tel_geom[tel_id] = CameraGeometry.guess( fit.cameras(tel_id)['PixX'].to(u.m), fit.cameras(tel_id)['PixY'].to(u.m), fit.telescopes['FL'][tel_id - 1] * u.m) pmt_signal = event.dl0.tel[tel_id].adc_sums[0] mask = tailcuts_clean(tel_geom[tel_id], pmt_signal, 1, picture_thresh=10., boundary_thresh=5.) pmt_signal[mask is False] = 0 try: moments, moms2 = hillas_parameters( fit.cameras(tel_id)['PixX'], fit.cameras(tel_id)['PixY'], pmt_signal) hillas_dict[tel_id] = moments except HillasParameterizationError as e: print(e) continue if len(hillas_dict) < 2: continue fit_result = fit.predict(hillas_dict) print(fit_result) assert fit_result return
def test_FitGammaHillas(): filename = get_path("gamma_test.simtel.gz") fit = FitGammaHillas() fit.setup_geometry(*load_hessio(filename), phi=180 * u.deg, theta=20 * u.deg) tel_geom = {} source = hessio_event_source(filename) for event in source: hillas_dict = {} for tel_id in set(event.trig.tels_with_trigger) & set(event.dl0.tels_with_data): if tel_id not in tel_geom: tel_geom[tel_id] = CameraGeometry.guess( fit.cameras(tel_id)["PixX"].to(u.m), fit.cameras(tel_id)["PixY"].to(u.m), fit.telescopes["FL"][tel_id - 1] * u.m, ) pmt_signal = event.dl0.tel[tel_id].adc_sums[0] mask = tailcuts_clean(tel_geom[tel_id], pmt_signal, 1, picture_thresh=10.0, boundary_thresh=5.0) pmt_signal[mask is False] = 0 try: moments, moms2 = hillas_parameters(fit.cameras(tel_id)["PixX"], fit.cameras(tel_id)["PixY"], pmt_signal) hillas_dict[tel_id] = moments except HillasParameterizationError as e: print(e) continue if len(hillas_dict) < 2: continue fit_result = fit.predict(hillas_dict) print(fit_result) assert fit_result return