예제 #1
0
def test_sky_to_camera():
    alt = np.array([1, 1]) * u.rad
    az = np.array([0.2, 0.5]) * u.rad
    focal = 28*u.m
    pointing_alt = np.array([1.0, 1.0]) * u.rad
    pointing_az = np.array([0.2, 0.5]) * u.rad
    camera_coords = utils.sky_to_camera(alt, az, focal, pointing_alt, pointing_az)
    np.testing.assert_allclose(camera_coords.x.value, np.array([0, 0]), rtol=1e-4, atol=1e-4)
    np.testing.assert_allclose(camera_coords.y.value, np.array([0, 0]), rtol=1e-4, atol=1e-4)
예제 #2
0
def test_change_frame_camera_sky():
    from lstchain.reco.utils import sky_to_camera, camera_to_altaz
    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_altaz(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], decimal=4)
def add_disp_to_parameters_table(dl1_file, table_path):
    """
    Reconstruct the disp parameters and source position from a DL1 parameters table and write the result in the file

    Parameters
    ----------
    dl1_file: HDF5 DL1 file containing the required field in `table_path`:
        - mc_alt
        - mc_az
        - mc_alt_tel
        - mc_az_tel

    table_path: path to the parameters table in the file
    """
    with tables.open_file(dl1_file) as hfile:
        run_array_dir = copy.copy(
            hfile.root.simulation.run_config.col('run_array_direction')[0])
        focal = copy.copy(
            hfile.root.instrument.subarray.telescope.optics.col(
                'equivalent_focal_length')[0])

    df = pd.read_hdf(dl1_file, key=table_path)
    source_pos_in_camera = sky_to_camera(
        df.mc_alt.values * u.rad,
        df.mc_az.values * u.rad,
        focal * u.m,
        run_array_dir[1] * u.rad,
        run_array_dir[0] * u.rad,
    )

    disp_parameters = disp.disp(df.x.values * u.m, df.y.values * u.m,
                                source_pos_in_camera.x, source_pos_in_camera.y)

    with tables.open_file(dl1_file, mode="a") as file:
        tab = file.root[table_path]
        add_column_table(tab, tables.Float32Col, 'disp_dx',
                         disp_parameters[0].value)
        tab = file.root[table_path]
        add_column_table(tab, tables.Float32Col, 'disp_dy',
                         disp_parameters[1].value)
        tab = file.root[table_path]
        add_column_table(tab, tables.Float32Col, 'disp_norm',
                         disp_parameters[2].value)
        tab = file.root[table_path]
        add_column_table(tab, tables.Float32Col, 'disp_angle',
                         disp_parameters[3].value)
        tab = file.root[table_path]
        add_column_table(tab, tables.Float32Col, 'disp_sign',
                         disp_parameters[4])
        tab = file.root[table_path]
        add_column_table(tab, tables.Float32Col, 'src_x',
                         source_pos_in_camera.x.value)
        tab = file.root[table_path]
        add_column_table(tab, tables.Float32Col, 'src_y',
                         source_pos_in_camera.y.value)
        tab = file.root[table_path]
        add_column_table(tab, tables.Float32Col, 'mc_alt_tel',
                         np.ones(len(df)) * run_array_dir[1])
        tab = file.root[table_path]
        add_column_table(tab, tables.Float32Col, 'mc_az_tel',
                         np.ones(len(df)) * run_array_dir[0])
        if 'gamma' in dl1_file:
            tab = file.root[table_path]
            add_column_table(tab, tables.Float32Col, 'mc_type',
                             np.zeros(len(df)))
        if 'electron' in dl1_file:
            tab = file.root[table_path]
            add_column_table(tab, tables.Float32Col, 'mc_type',
                             np.ones(len(df)))
        if 'proton' in dl1_file:
            tab = file.root[table_path]
            add_column_table(tab, tables.Float32Col, 'mc_type',
                             101 * np.ones(len(df)))