コード例 #1
0
ファイル: test_utils.py プロジェクト: pgrespan/cta-lstchain
def test_camera_to_sky():
    pos_x = np.array([0, 0]) * u.m
    pos_y = np.array([0, 0]) * u.m
    focal = 28*u.m
    pointing_alt = np.array([1.0, 1.0]) * u.rad
    pointing_az = np.array([0.2, 0.5]) * u.rad
    sky_coords = utils.camera_to_sky(pos_x, pos_y, focal, pointing_alt, pointing_az)
    np.testing.assert_allclose(sky_coords.alt, pointing_alt, rtol=1e-4)
    np.testing.assert_allclose(sky_coords.az, pointing_az, rtol=1e-4)
コード例 #2
0
def test_change_frame_camera_sky():
    from lstchain.reco.utils import sky_to_camera, camera_to_sky
    import astropy.units as u
    x = np.random.rand(1) * u.m
    y = np.random.rand(1) * u.m
    focal_length = 5 * u.m
    pointing_alt = np.pi / 3. * u.rad
    pointing_az = 0. * u.rad

    sky_pos = camera_to_sky(x, y, focal_length, pointing_alt, pointing_az)
    cam_pos = sky_to_camera(sky_pos.alt, sky_pos.az, focal_length,
                            pointing_alt, pointing_az)
    np.testing.assert_almost_equal([x, y], [cam_pos.x, cam_pos.y])
コード例 #3
0
        # TEMPORARY - just to speed up the code for tests as astropy transformations takes ages
        #################################################
        f = 0.1 / 0.05  # deg / m
        src_separation_approx = f * np.sqrt((x_reco.value - np.array(param_test['src_x'])[0])**2 + (y_reco.value - np.array(param_test['src_y'])[0])**2)
        sorted = np.sort(src_separation_approx)
        index_68 = int(0.6827 * sorted.size)
        resolution_approx = sorted[index_68] * u.deg
        print("APPROXIMATIVE Resolution (68% containment): {:.4f}".format(resolution_approx))
        ################################################
    else:
        # Resolution for all energy bins together
        # transformation of reconstructed coordinates to horizon frame: (az, alt) in deg
        # - transformace vcetne vypoctu .separation a rozliseni funguje dobre - overeno aproximacnim
        #   vypoctem pomoci prepoctu vzdalenosti v metrech s pomoci faktoru 0.1 deg / 0.05 m, coz
        #   je rozliseni a velikost jednoho pixelu LST kamery
        sky_coords_reco = utils.camera_to_sky(x_reco, y_reco, focal_length,  pointing_alt, pointing_az)
        # Transformation of true source coordinates to horizon frame
        sky_coords_source = utils.camera_to_sky(np.array(param_test['src_x'])[0] * u.m, np.array(param_test['src_y'])[0] * u.m, focal_length,  pointing_alt[0], pointing_az[0])
        # Angular distance of each reconstructed position to the true position of the source
        src_separation = sky_coords_reco.separation(sky_coords_source)
        # 68 % containment
        sorted = np.sort(src_separation)
        index_68 = int(0.6827 * sorted.size)
        resolution = sorted[index_68]
        print("Resolution (68% containment): {:.4f}".format(resolution))


    # FIGURES

    # Plotting feature importance
    plt.figure()
コード例 #4
0
 source_position = [np.array(param_gamma['src_x'])[0], np.array(param_gamma['src_y'])[0]] # source position in the FOV [m]
 pointing_alt_gamma = np.array(param_gamma['mc_alt_tel']) * u.rad
 pointing_az_gamma = np.array(param_gamma['mc_az_tel']) * u.rad
 pointing_alt_gamma_diffuse = np.array(param_gamma_diffuse['mc_alt_tel']) * u.rad
 pointing_az_gamma_diffuse = np.array(param_gamma_diffuse['mc_az_tel']) * u.rad
 pointing_alt_proton = np.array(param_proton['mc_alt_tel']) * u.rad
 pointing_az_proton = np.array(param_proton['mc_az_tel']) * u.rad
 focal_length = 28 * u.m
 if args.fast:
     # TEMPORARY - rychly vypocet bez transformace souradnic
     f = 0.1 / 0.05  # deg / m
     param_gamma['theta2'] = f**2 * ((source_position[0]-param_gamma['reco_src_x'])**2 + (source_position[1]-param_gamma['reco_src_y'])**2)
     param_proton['theta2'] = f**2 * ((source_position[0]-param_proton['reco_src_x'])**2 + (source_position[1]-param_proton['reco_src_y'])**2)
     param_proton['theta2_true'] = f**2 * ((source_position[0]-param_proton['src_x'])**2 + (source_position[1]-param_proton['src_y'])**2)
 else:
     sky_coords_reco_gamma = utils.camera_to_sky(np.array(param_gamma['reco_src_x']) * u.m, np.array(param_gamma['reco_src_y']) * u.m, focal_length,  pointing_alt_gamma, pointing_az_gamma)
     sky_coords_true_gamma = utils.camera_to_sky(np.array(param_gamma['src_x']) * u.m, np.array(param_gamma['src_y']) * u.m, focal_length,  pointing_alt_gamma, pointing_az_gamma)
     sky_coords_reco_gamma_diffuse = utils.camera_to_sky(np.array(param_gamma_diffuse['reco_src_x']) * u.m, np.array(param_gamma_diffuse['reco_src_y']) * u.m, focal_length,  pointing_alt_gamma_diffuse, pointing_az_gamma_diffuse)
     sky_coords_true_gamma_diffuse = utils.camera_to_sky(np.array(param_gamma_diffuse['src_x']) * u.m, np.array(param_gamma_diffuse['src_y']) * u.m, focal_length,  pointing_alt_gamma_diffuse, pointing_az_gamma_diffuse)
     sky_coords_reco_proton = utils.camera_to_sky(np.array(param_proton['reco_src_x']) * u.m, np.array(param_proton['reco_src_y']) * u.m, focal_length,  pointing_alt_proton, pointing_az_proton)
     sky_coords_true_proton = utils.camera_to_sky(np.array(param_proton['src_x']) * u.m, np.array(param_proton['src_y']) * u.m, focal_length,  pointing_alt_proton, pointing_az_proton)
     sky_coords_source_gamma = utils.camera_to_sky(source_position[0] * u.m, source_position[1] * u.m, focal_length,  pointing_alt_gamma[0], pointing_az_gamma[0])
     sky_coords_source_gamma_diffuse = utils.camera_to_sky(source_position[0] * u.m, source_position[1] * u.m, focal_length,  pointing_alt_gamma[0], pointing_az_gamma[0])
     sky_coords_source_proton = utils.camera_to_sky(source_position[0] * u.m, source_position[1] * u.m, focal_length,  pointing_alt_proton[0], pointing_az_proton[0])
     sky_coords_camera_center =  utils.camera_to_sky(0 * u.m, 0 * u.m, focal_length,  pointing_alt_gamma_diffuse[0], pointing_az_gamma_diffuse[0])
     param_gamma['offaxis_angle'] = sky_coords_true_gamma.separation(sky_coords_camera_center)
     param_gamma_diffuse['offaxis_angle'] = sky_coords_true_gamma_diffuse.separation(sky_coords_camera_center)
     param_proton['offaxis_angle'] = sky_coords_true_proton.separation(sky_coords_camera_center)
     # Theta2
     param_gamma['theta2'] = sky_coords_reco_gamma.separation(sky_coords_source_gamma)**2
     param_gamma['theta2_true'] = sky_coords_true_gamma.separation(sky_coords_source_gamma)**2