Exemplo n.º 1
0
def calc_source_features_sim(
    source_x,
    source_y,
    source_zd,
    source_az,
    pointing_position_zd,
    pointing_position_az,
    cog_x,
    cog_y,
    delta,
):
    result = calc_source_features_common(
        source_x,
        source_y,
        source_zd,
        source_az,
        pointing_position_zd,
        pointing_position_az,
    )
    source_x, source_y = horizontal_to_camera(
        az=source_az,
        zd=source_zd,
        az_pointing=pointing_position_az,
        zd_pointing=pointing_position_zd,
    )

    true_disp, true_sign = calc_true_disp(
        source_x,
        source_y,
        cog_x,
        cog_y,
        delta,
    )
    result['true_disp'] = true_disp * true_sign
    return result
Exemplo n.º 2
0
def calc_source_features_sim(
    source_x,
    source_y,
    source_zd,
    source_az,
    pointing_position_zd,
    pointing_position_az,
    cog_x,
    cog_y,
    delta,
):
    result = calc_source_features_common(
        source_x,
        source_y,
        source_zd,
        source_az,
        pointing_position_zd,
        pointing_position_az,
    )
    source_x, source_y = horizontal_to_camera(
        az=source_az,
        zd=source_zd,
        az_pointing=pointing_position_az,
        zd_pointing=pointing_position_zd,
    )

    true_disp, true_sign = calc_true_disp(
        source_x, source_y,
        cog_x, cog_y,
        delta,
    )
    result['true_disp'] = true_disp * true_sign

    return result
Exemplo n.º 3
0
def calc_delta_delta(event, mask):

    # if 'source_position_zd' not in df.columns:
    frame = AltAz(location=LOCATION,
                  obstime=to_astropy_time(
                      pd.to_datetime(event.observation_info.time)))

    crab_altaz = crab.transform_to(frame)

    source_position_zd_phs = crab_altaz.zen.deg
    source_position_az_phs = crab_altaz.az.deg

    source_x, source_y = horizontal_to_camera(
        source_position_zd_phs,
        source_position_az_phs,
        event.zd,
        event.az,
    )

    # safe x, y and t components of Photons. shape = (#photons,3)
    xyt = event.photon_stream.point_cloud
    lol = event.photon_stream.list_of_lists
    x, y, t = xyt.T
    x = np.rad2deg(x) / camera_distance_mm_to_deg(1)
    y = np.rad2deg(y) / camera_distance_mm_to_deg(1)

    cleaned_photons = np.zeros(len(x), dtype=bool)
    for i in range(len(lol)):
        if mask[i]:
            for j in range(len(lol[i])):
                cleaned_photons[i] = True

    cog_x = np.mean(x[cleaned_photons])
    cog_y = np.mean(y[cleaned_photons])

    true_delta = np.arctan2(cog_y - source_y, cog_x - source_x)

    delta = calc_delta(phs2image(event.photon_stream.list_of_lists), mask)
    delta_delta = true_delta - delta
    if delta_delta < -np.pi / 2:
        delta_delta += 2 * np.pi


#    if delta_delta < -90:
#        delta_delta += 360

    return delta_delta
Exemplo n.º 4
0
def test_there_and_back_again_horizontal():
    from fact.coordinates import camera_to_horizontal, horizontal_to_camera

    df = pd.DataFrame({
        'az_tracking': [0, 90, 270],
        'zd_tracking': [0, 10, 20],
        'timestamp':
        pd.date_range('2017-10-01 22:00Z', periods=3, freq='10min'),
        'x': [-100, 0, 150],
        'y': [0, 100, 0],
    })

    zd, az = camera_to_horizontal(df.x, df.y, df.zd_tracking, df.az_tracking)
    x, y = horizontal_to_camera(zd, az, df.zd_tracking, df.az_tracking)

    assert np.allclose(x, df.x)
    assert np.allclose(y, df.y)
Exemplo n.º 5
0
def load_training_data_position(N=-1, path_gamma='./data/gamma_images.hdf5'):
    '''
    Loads gamma dl2 data and use the source position of the true source position in x y camera coordinates.
    '''
    df_gammas, images_gammas = read_rows(path_gamma, N=N)
    X = scale_images(images_gammas)

    # az_offset_between_magnetic_and_geographic_north = -0.12217305  # aboout -7 degrees
    # az_offset_between_corsika_and_ceres = - np.pi + az_offset_between_magnetic_and_geographic_north

    source_az = np.rad2deg(-np.pi + df_gammas.corsika_phi + -0.12217305)
    source_zd = np.rad2deg(df_gammas.corsika_theta)

    pointing_az = df_gammas.az
    pointing_zd = df_gammas.zd

    x, y = horizontal_to_camera(source_zd, source_az, pointing_zd, pointing_az)
    Y = np.vstack([x, y]).T

    return X, Y
Exemplo n.º 6
0
def calc_source_features_sim(
    prediction_x,
    prediction_y,
    source_zd,
    source_az,
    pointing_position_zd,
    pointing_position_az,
    cog_x,
    cog_y,
    delta,
    project_disp=False,
):
    result = calc_source_features_common(
        prediction_x,
        prediction_y,
        source_zd,
        source_az,
        pointing_position_zd,
        pointing_position_az,
    )
    source_x, source_y = horizontal_to_camera(
        az=source_az,
        zd=source_zd,
        az_pointing=pointing_position_az,
        zd_pointing=pointing_position_zd,
    )

    true_disp, true_sign = calc_true_disp(
        source_x,
        source_y,
        cog_x,
        cog_y,
        delta,
        project_disp=project_disp,
    )
    result["true_disp"] = true_disp * true_sign

    return result
if args.threshold:
    phs = phs.query(f'gamma_prediction >= {args.threshold}').copy()

if 'source_position_zd' not in df.columns:
    frame = AltAz(location=LOCATION,
                  obstime=to_astropy_time(pd.to_datetime(df['timestamp'])))

    crab = SkyCoord.from_name('Crab Nebula')
    crab_altaz = crab.transform_to(frame)

    df['source_position_zd_phs'] = crab_altaz.zen.deg
    df['source_position_az_phs'] = crab_altaz.az.deg

df['source_x'], df['source_y'] = horizontal_to_camera(
    df['source_position_zd'],
    df['source_position_az'],
    df['pointing_position_zd_phs'],
    df['pointing_position_az_phs'],
)

df['true_delta'] = np.arctan2(df['cog_y_phs'] - df['source_y'],
                              df['cog_x_phs'] - df['source_x'])

df['delta_delta'] = df['true_delta'] - df['delta_phs']
df['delta_delta'][df['delta_delta'] < -np.pi / 2] += 2 * np.pi

mask = df['disp_prediction_phs'] < 0
plt.hist(df.loc[mask, 'delta_delta'],
         bins=np.linspace(-np.pi / 2, 3 / 2 * np.pi, 101),
         alpha=0.3)
plt.hist(df.loc[~mask, 'delta_delta'],
         bins=np.linspace(-np.pi / 2, 3 / 2 * np.pi, 101),