Example #1
0
def do_labels(fd):
    """Perform the fuzzy labelling using Junzi's method.

    Add an additional force label of aircraft with 'onground=True' to
    the 'GND' label category.
    Input:
        -   A dict of flight data, such as that returned by preproc_data()
    Returns:
        -   A numpy array containing categorised flight phases.

    """
    try:
        labels = flph.fuzzylabels(fd['time'],
                                  fd['alts'],
                                  fd['spds'],
                                  fd['rocs'],
                                  twindow=15)
    except Exception as e:
        print("Error creating spline", e, fd['call'])
        quit()
    pts = (fd['ongd']).nonzero()
    labels[pts] = 'GND'

    return labels
plt.figure(figsize=(10, 4))

res = mcoll.find()
for r in res:
    icao = r['icao']

    times = np.array(r['ts']).astype(int)
    times = times - times[0]
    lats = np.array(r['lat'])
    lons = np.array(r['lon'])
    alts = np.array(r['alt'])
    spds = np.array(r['spd'])
    rocs = np.array(r['roc'])

    try:
        labels = flightphase.fuzzylabels(times, alts, spds, rocs)
    except:
        continue

    colormap = {'GND': 'black', 'CL': 'green', 'CR': 'blue',
                'DE': 'orange', 'LVL': 'purple', 'NA': 'red'}

    colors = [colormap[l] for l in labels]

    # setup mercator map projection.
    plt.suptitle('press any key to continue to next example...')

    plt.subplot(121)
    m = Basemap(llcrnrlon=min(lons)-2, llcrnrlat=min(lats)-2,
                urcrnrlon=max(lons)+2, urcrnrlat=max(lats)+2,
                resolution='l', projection='merc')
    if 'alt' in r:
        alts = np.array(df['alt'])
        spds = np.array(df['spd'])
        rocs = np.array(df['roc'])
    elif 'H' in r:
        Hs = np.array(df['H'])
        vgxs = np.array(df['vgx'])
        vgys = np.array(df['vgy'])
        vhs = np.array(df['vh'])
        alts = Hs / 0.3048
        spds = np.sqrt(vgxs**2 + vgys**2) / 0.5144
        rocs = vhs / 0.00508

    try:
        labels = flightphase.fuzzylabels(times, alts, spds, rocs)
    except:
        continue

    colormap = {'GND': 'black', 'CL': 'green', 'CR': 'blue',
                'DE': 'orange', 'LVL': 'purple', 'NA': 'red'}

    colors = [colormap[l] for l in labels]

    # setup mercator map projection.
    plt.suptitle('press any key to continue to next example...')

    plt.subplot(121)
    m = Basemap(llcrnrlon=min(lons)-2, llcrnrlat=min(lats)-2,
                urcrnrlon=max(lons)+2, urcrnrlat=max(lats)+2,
                resolution='l', projection='merc')