Ejemplo n.º 1
0
def confl_check(lat_1, lon_1, lat_2, lon_2):

    d = calc_coord_dst((lat_1, lon_1), (lat_2, lon_2))

    if d < ipz_range:
        return 1
    else:
        return 0
Ejemplo n.º 2
0
def get_tcps(b):

    _cps_1 = []
    _cps_2 = []

    for i, t in enumerate(b['ts_1']):

        _hdg_cp_1 = b['hdg_e_1'][i]
        _crd_cp_1 = (b['lat_1'][i], b['lon_1'][i])

        _hdg_cp_2 = b['hdg_e_2'][i]
        _crd_cp_2 = (b['lat_2'][i], b['lon_2'][i])

        _next_wp_hdgs_1 = [h for h in b['hdg_e_1'][i:] if h != b['hdg_e_1'][i]]

        _next_wp_hdgs_2 = [h for h in b['hdg_e_2'][i:] if h != b['hdg_e_2'][i]]

        if len(_next_wp_hdgs_1) > 0:
            _hdg_cp_1 = _next_wp_hdgs_1[0]
            _crd_cp_1 = [
                (c[0], c[1])
                for c in zip(b['lat_1'][i:], b['lon_1'][i:], b['hdg_e_1'][i:])
                if c[2] == _hdg_cp_1
            ][0]

        if len(_next_wp_hdgs_2) > 0:
            _hdg_cp_2 = _next_wp_hdgs_2[0]
            _crd_cp_2 = [
                (c[0], c[1])
                for c in zip(b['lat_2'][i:], b['lon_2'][i:], b['hdg_e_2'][i:])
                if c[2] == _hdg_cp_2
            ][0]

        _dst_cp_1 = calc_coord_dst(_crd_cp_1, (b['lat_1'][i], b['lon_1'][i]))

        _dst_cp_2 = calc_coord_dst(_crd_cp_2, (b['lat_2'][i], b['lon_2'][i]))

        _t_cp_1 = _dst_cp_1 / (b['spd_e_1'][i] * knts_ms_ratio)
        _t_cp_2 = _dst_cp_2 / (b['spd_e_2'][i] * knts_ms_ratio)

        _cps_1.append((_t_cp_1, _hdg_cp_1))
        _cps_2.append((_t_cp_2, _hdg_cp_2))

    return _cps_1, _cps_2
def check_flight_overlap(f1crd, f2crd):

    start_dst = calc_coord_dst((f1crd[0][0], f1crd[0][1]),
                               (f2crd[0][0], f2crd[0][1]))

    if start_dst < (f1crd[0][6] * knts_ms_ratio * max_t_startpoints):
        return True

    else:
        return False
Ejemplo n.º 4
0
def time_to_conflict(tr1, tr2):

    for i in range(len(tr1)):
        cdst = calc_coord_dst(
            (tr1['proj_lat'].iloc[i], tr1['proj_lon'].iloc[i]),
            (tr2['proj_lat'].iloc[i], tr2['proj_lon'].iloc[i]))

        if cdst <= ipz_range:
            ttc = tr1['ts'].iloc[i] - tr1['ts'].iloc[0]

            return ttc

    return None
Ejemplo n.º 5
0
def get_delta_dst_t(lat_1, lon_1, lat_2, lon_2, hdg_1, hdg_2, spd_1, spd_2, t):

    _gamma, _alpha, _beta = gamma_angle(lat_1, lon_1, lat_2, lon_2, hdg_1,
                                        hdg_2)

    if np.isnan(_gamma):
        return np.nan
    else:
        dx_1, dx_2, dy_1, dy_2 = get_dx_dy(_alpha, _beta, spd_1, spd_2)
        s_init = calc_coord_dst((lat_1, lon_1), (lat_2, lon_2))

        di = get_ac_distance_time(s_init, dx_1, dx_2, dy_1, dy_2, t)

        return abs(s_init - di)
def ac_dist_stoch(t, cte_1, ate_1, cte_2, ate_2, lat_1, lon_1, lat_2, lon_2,
                  hdg_1, hdg_2, spd_1, spd_2):

    knots_to_ms = knts_ms_ratio
    ipz_lim = ipz_range  # meters

    alpha_1 = heading_diff(
        calc_compass_bearing((lat_1, lon_1), (lat_2, lon_2)), hdg_1)

    alpha_2 = heading_diff(
        calc_compass_bearing((lat_2, lon_2), (lat_1, lon_1)), hdg_2)

    gamma = 180 - (alpha_1 + alpha_2)

    if gamma < 0:
        return np.nan
    else:
        dx1_e = math.sin(math.radians(heading_diff(0, hdg_1))) * ate_1 + \
            math.cos(math.radians(heading_diff(0, hdg_1))) * cte_1

        dy1_e = math.sin(math.radians(heading_diff(hdg_1, 0))) * cte_1 + \
            math.cos(math.radians(heading_diff(hdg_1, 0))) * ate_1

        dx2_e = math.sin(math.radians(heading_diff(0, hdg_2))) * ate_2 + \
            math.cos(math.radians(heading_diff(0, hdg_2))) * cte_2

        dy2_e = math.sin(math.radians(heading_diff(hdg_2, 0))) * cte_2 + \
            math.cos(math.radians(heading_diff(hdg_2, 0))) * ate_2

        dy_1 = math.cos(math.radians(heading_diff(hdg_1, 0))) * spd_1 * \
            knots_to_ms + (dy1_e / t)

        dy_2 = math.cos(math.radians(heading_diff(hdg_2, 0))) * spd_2 * \
            knots_to_ms + (dy2_e / t)

        dx_1 = math.sin(math.radians(heading_diff(hdg_1, 0))) * spd_1 * \
            knots_to_ms + (dx1_e / t)

        dx_2 = math.sin(math.radians(heading_diff(hdg_2, 0))) * spd_2 * \
            knots_to_ms + (dx2_e / t)

        dx = abs(dx_1 - dx_2) * t
        dy = abs(dy_1 - dy_2) * t

        s = calc_coord_dst((lat_1, lon_1), (lat_2, lon_2))
        d = s - np.sqrt((dy**2 + dx**2))

        return d
Ejemplo n.º 7
0
def get_ttc_est(lat_1, lon_1, lat_2, lon_2, hdg_1, hdg_2, spd_1, spd_2, _tmax):

    _gamma, _alpha, _beta = gamma_angle(lat_1, lon_1, lat_2, lon_2, hdg_1,
                                        hdg_2)

    if np.isnan(_gamma):
        return np.nan
    else:
        dx_1, dx_2, dy_1, dy_2 = get_dx_dy(_alpha, _beta, spd_1, spd_2)
        s_init = calc_coord_dst((lat_1, lon_1), (lat_2, lon_2))

        for t in range(_tmax):
            di = get_ac_distance_time(s_init, dx_1, dx_2, dy_1, dy_2, t)
            if di < ipz_range:
                return t

        return np.nan
def closest_distance_box(f1, f2, b):
    """Flights should be zipped list like zip(lat,lon)"""

    f1_res = [(lat, lon, ts) for lat, lon, ts in f1
              if (b[0] <= lat <= b[1]) & (b[2] <= lon <= b[3])]
    f2_res = [(lat, lon, ts) for lat, lon, ts in f2
              if (b[0] <= lat <= b[1]) & (b[2] <= lon <= b[3])]

    x = [[np.sqrt((c1[0] - c2[0])**2 + (c1[1] - c2[1])**2) for c1 in f1_res]
         for c2 in f2_res]
    dmin = np.nanmin(x)
    if2, if1 = np.where(x == dmin)

    c2 = f2_res[if2[0]]
    c1 = f1_res[if1[0]]
    dmin_m = calc_coord_dst(c1, c2)

    ifg1 = [i for i, x in enumerate(f1) if x[2] == f1_res[if1[0]][2]][0]
    ifg2 = [i for i, x in enumerate(f2) if x[2] == f2_res[if2[0]][2]][0]

    return dmin_m, c1, c2, ifg1, ifg2
Ejemplo n.º 9
0
def get_proba_ttc_est(lat_1, lon_1, lat_2, lon_2, hdg_1, hdg_2, spd_1, spd_2,
                      pct, i_kde_dict, _tmax):

    assert str(pct) in list(i_kde_dict.keys()), "Percentage not in dict"

    _gamma, _alpha, _beta = gamma_angle(lat_1, lon_1, lat_2, lon_2, hdg_1,
                                        hdg_2)

    kde_bounds = (i_kde_dict[str(pct)], i_kde_dict[str(100 - pct)])

    if np.isnan(_gamma):
        return np.nan
    else:
        dx_1, dx_2, dy_1, dy_2 = get_dx_dy(_alpha, _beta, spd_1, spd_2)
        s_init = calc_coord_dst((lat_1, lon_1), (lat_2, lon_2))

        for t in range(_tmax):
            di = get_ac_distance_time(s_init, dx_1, dx_2, dy_1, dy_2, t)
            if any((di + b * di * t) < ipz_range for b in kde_bounds):
                return t

        return np.nan
Ejemplo n.º 10
0
def realign_conflict(b):
    cfl_dst = ipz_range

    if len(b['lon_1']) != len(b['lon_2']):
        print('Flights not the same length')
        return None

    for i in range(1, len(b)):

        if calc_coord_dst((b['lon_1'][-i], b['lat_1'][-i]),
                          (b['lon_2'][-i], b['lat_2'][-i])) >= cfl_dst:

            for k in [
                    'ts_1', 'lat_1', 'lon_1', 'alt_1', 'spd_1', 'hdg_1',
                    'roc_1', 'ts_2', 'lat_2', 'lon_2', 'alt_2', 'spd_2',
                    'hdg_2', 'roc_2'
            ]:

                b[k] = b[k][:-(i - 1)]

            return b

    return None
def box_area(box):
    w = calc_coord_dst([box[0], box[2]], [box[1], box[2]])
    h = calc_coord_dst([box[0], box[2]], [box[0], box[3]])

    return w * h
Ejemplo n.º 12
0
def get_intent_ttc_est(lat_1, lon_1, lat_2, lon_2, hdg_1, hdg_2, spd_1, spd_2,
                       _tmax, _wps_1, _wps_2):

    wps_seq_1 = sequentialize(_wps_1)
    wps_seq_2 = sequentialize(_wps_2)

    lat_n_1, lon_n_1, lat_n_2, lon_n_2 = lat_1, lon_1, lat_2, lon_2

    try:

        try:

            if not len(wps_seq_1) < 2:
                wp1_curr_iter = iter(wps_seq_1)
                wp1_next_iter = iter(wps_seq_1[1:])
                _wp1_curr = next(wp1_curr_iter, wps_seq_1[-2])
                _wp1_next = next(wp1_next_iter, wps_seq_1[-1])

            else:
                wp1_curr_iter, wp1_next_iter, _wp1_curr, _wp1_next = \
                    None, None, None, None

            if not len(wps_seq_2) < 2:
                wp2_curr_iter = iter(wps_seq_2)
                wp2_next_iter = iter(wps_seq_2[1:])
                _wp2_curr = next(wp2_curr_iter, wps_seq_2[-2])
                _wp2_next = next(wp2_next_iter, wps_seq_2[-1])

            else:
                wp2_curr_iter, wp2_next_iter, _wp2_curr, _wp2_next = \
                    None, None, None, None

        except Exception as e1:
            print('wp init failed')
            print(e1)

        for t in range(1, _tmax):

            if t == 1:
                lat_n_1, lon_n_1 = get_next_crd(lat_1, lon_1, hdg_1, spd_1)
                lat_n_2, lon_n_2 = get_next_crd(lat_2, lon_2, hdg_2, spd_2)

            else:
                lat_n_1, lon_n_1 = get_next_crd(lat_n_1, lon_n_1, hdg_1, spd_1)
                lat_n_2, lon_n_2 = get_next_crd(lat_n_2, lon_n_2, hdg_2, spd_2)

            di = calc_coord_dst((lat_n_1, lon_n_1), (lat_n_2, lon_n_2))

            if di < ipz_range:
                return t

            if not len(wps_seq_1) < 2:
                _hdiff1 = hdg_diff_next_wp(lat_n_1, lon_n_1, _wp1_curr,
                                           _wp1_next)
                dst_currwp_1 = calc_coord_dst((lat_n_1, lon_n_1), _wp1_curr)

                if abs(_hdiff1) < 5 and dst_currwp_1 < 8000:
                    hdg_1 = calc_compass_bearing(_wp1_curr, _wp1_next)
                    _wp1_curr = next(wp1_curr_iter, sequentialize(_wps_1)[-2])
                    _wp1_next = next(wp1_next_iter, sequentialize(_wps_1)[-1])

            if not len(wps_seq_2) < 2:
                _hdiff2 = hdg_diff_next_wp(lat_n_2, lon_n_2, _wp2_curr,
                                           _wp2_next)

                dst_currwp_2 = calc_coord_dst((lat_n_2, lon_n_2), _wp2_curr)

                if abs(_hdiff2) < 5 and dst_currwp_2 < 8000:
                    hdg_2 = calc_compass_bearing(_wp2_curr, _wp2_next)
                    _wp2_curr = next(wp2_curr_iter, sequentialize(_wps_2)[-2])
                    _wp2_next = next(wp2_next_iter, sequentialize(_wps_2)[-1])

        return np.nan

    except Exception as e:
        print('intent ttc func failed')
        print(e)
        return np.nan