示例#1
0
def get_orbit_tally(data, orbit, pre=True):
    """
    set pre = False if you already added orbit columns to data
    tallys up the count of objects per year in orbit
    returns a dataframe w/ columns orbit (containing counts)
    and 'LaunchYear', orbit may be LEO, MEO, GEO or HighEarthOrbit
    """
    if pre:
        data = get_launch_years_column(data)
        data = get_orbit_columns(data)
    data = data[data[orbit]]
    data = data[['LaunchYear', orbit]]
    data = data.groupby(['LaunchYear'], as_index=False).count()
    for i in range(1, len(data)):
        data.loc[i, orbit] += data.loc[i - 1, orbit]
    return data
示例#2
0
def compare_by_alt(data):
    """
    takes a dataframe of orbital debris data and adds columns
    with information about orbits. Creates a scatter plot of
    altitude vs launch year
    """
    data = get_launch_years_column(data)
    data = get_orbit_columns(data)
    data.plot(kind='scatter',
              x='LaunchYear',
              y='Apoapsis',
              figsize=(7, 5),
              color="#0f4c81")
    plt.title("Altitude vs Year Launched")
    plt.xlabel('Launch Year')
    plt.ylabel('Altitude (km)')
    plt.savefig('visualizations/alt_vs_launch_year.png')
示例#3
0
def bar_plot_LEO(data):
    """
    takes a dataframe from process_data and creates a
    bar plot for count by launch year from dataframe
    (for LEO)
    """
    data = get_orbit_columns(data)
    data = data[data['LEO']]
    data = data['InternationalDesignator']
    data = data.dropna()
    data = data.apply(get_launch_year)
    data = data.groupby(data).count()
    data.plot(kind='bar', figsize=(17, 10), color='#0f4c81')
    plt.title("Orbital Debris Count Increase Per Year (LEO)")
    plt.xlabel('Launch Year')
    plt.ylabel('Count')
    plt.savefig('visualizations/count_by_launch_year.png')
示例#4
0
def polynomial_fit_probability(data):
    """
    from a dataframe, makes a polynomial
    best fit model of the probability of impact
    per year. Creates a plot of the model
    overtop a scatter plot of the data points.
    Prints some information about the model,
    includung the R-squared value. Creates a
    plot of the residuals.
    """
    # get the data in the right format
    data = get_orbit_columns(data)
    data = data[data['LEO']]
    data = get_probability_tally(data)
    x = np.array(list(data['LaunchYear']))
    y = np.array(list(data['Probability']))
    # create the model
    prob_func = np.poly1d(np.polyfit(x, y, 2))
    # plot the scatter plot & line of best fit
    # plt.scatter(x, y)
    fig, ax = plt.subplots(1)
    plt.scatter(x, y, color='#ffa372')
    line = np.linspace(1963, 2020, 6)
    # m = (line*0) + (1/10000)
    plt.plot(line, prob_func(line), color='#0f4c81')
    # plt.plot(line, m, color='red')
    plt.title("Polynomial Model of Probability of Impact Per Year (LEO)")
    plt.xlabel('Year')
    plt.ylabel('Count')
    fig.savefig('poly_fit_probability.png')
    # print some information about the model
    print()
    print('Polynomial fit for probability:')
    print('Eq: ')
    print(prob_func)
    print('R-squared: ', r2_score(y, prob_func(x)))
    # plot the residuals
    fig, ax = plt.subplots(1)
    res = y - prob_func(x)
    d = {'x': x, 'res': res}
    df = pd.DataFrame(d)
    df.plot(kind='scatter', x='x', y='res', ax=ax, color='#0f4c81')
    plt.title("Probability Model Residuals")
    plt.xlabel('Year')
    plt.ylabel('Error')
    fig.savefig('probability_residuals.png')
示例#5
0
def polynomial_fit_count(data):
    """
    from a dataframe, makes a polynomial
    best fit model of the count of objects
    per year. Creates a plot of the model
    overtop a scatter plot of the data points.
    Prints some information about the model,
    includung the R-squared value. Creates a
    plot of the residuals.
    """
    # get the data in the right format
    data = get_orbit_columns(data)
    data = data[data['LEO']]
    data = get_launch_year_tally(data)
    x = np.array(list(data['Year']))
    y = np.array(list(data['Total']))
    # create the model
    count_func = np.poly1d(np.polyfit(x, y, 2))
    # plot the scatter plot & line of best fit
    fig, ax = plt.subplots(1)
    line = np.linspace(1958, 2020, 18000)
    plt.scatter(x, y, color='#ffa372')
    plt.plot(line, count_func(line), color='#0f4c81')
    plt.title("Polynomial Model of Count Per Year (LEO)")
    plt.xlabel('Year')
    plt.ylabel('Count')
    fig.savefig('poly_fit_count.png')
    # print some information about the model
    print('Polynomial fit for number of objects:')
    print('Eq: ')
    print(count_func)
    print('R-squared: ', r2_score(y, count_func(x)))
    # plot the residuals
    fig, ax = plt.subplots(1)
    res = y - count_func(x)
    d = {'x': x, 'res': res}
    df = pd.DataFrame(d)
    df.plot(kind='scatter', x='x', y='res', ax=ax, color='#0f4c81')
    plt.title("Object Count Model Residuals")
    plt.xlabel('Year')
    plt.ylabel('Error')
    fig.savefig('count_residuals.png')
示例#6
0
def total_bar_stacked_LEO(data):
    '''
    from a dataframe of orbital data
    creates a stacked bar chart that shows
    the total count of objects per year
    highlighting the increase each year in
    a different color
    (for LEO)
    '''
    data = get_orbit_columns(data)
    data = data[data['LEO']]
    data = get_launch_year_tally(data)
    data['PrevSum'] = data['Total'] - data['Count']
    fig, ax = plt.subplots(1, figsize=(17, 10))
    data.plot(y='Total', x='Year', kind='bar', color="#ed6663", ax=ax)
    data.plot(y='PrevSum', x='Year', kind='bar', color="#0f4c81", ax=ax)
    plt.title("Orbital Debris Total Count Over Time (LEO)")
    plt.xlabel('Year')
    plt.ylabel('Count')
    fig.savefig('visualizations/stacked_bar_count.png')
示例#7
0
def total_line_and_scatter_plot_LEO(data):
    '''
    takes a dataframe from process_data
    creates line and bar plots for the
    total count of objects present per year
    (for LEO)
    '''
    data = get_orbit_columns(data)
    data = data[data['LEO']]
    data = get_launch_year_tally(data)
    data.plot(kind='line', x='Year', y='Total', color='#0f4c81')
    plt.title("Orbital Debris Total Count Over Time (LEO)")
    plt.xlabel('Year')
    plt.ylabel('Count')
    plt.savefig('visualizations/total_count_over_years_line.png')
    data.plot(kind='scatter', x='Year', y='Total', color='#0f4c81')
    plt.title("Orbital Debris Total Count Over Time (LEO)")
    plt.xlabel('Year')
    plt.ylabel('Count')
    plt.savefig('visualizations/total_count_scatter.png', figsize=(17, 10))
示例#8
0
def compare_years_by_orbit(data):
    """
    takes a dataframe of orbital debris data and adds columns
    with information about orbits. Creates three visualizations:
    1. A set of four bar graphs showing objects per year by orbit
    2. A bar graph showing total count per orbit
    3. A stacked bar showing objects per year colored by orbit
    """
    # processing
    data = get_launch_years_column(data)
    data = get_orbit_columns(data)
    data = data[['LaunchYear', 'LEO', 'MEO', 'GEO', 'HighEarthOrbit']]
    data = data.dropna()
    data_LEO = get_orbit_tally(data, 'LEO', False)
    data_MEO = get_orbit_tally(data, 'MEO', False)
    data_GEO = get_orbit_tally(data, 'GEO', False)
    data_HEO = get_orbit_tally(data, 'HighEarthOrbit', False)
    df = data_LEO.merge(data_MEO,
                        left_on='LaunchYear',
                        right_on='LaunchYear',
                        how='outer')
    df = df.merge(data_GEO,
                  left_on='LaunchYear',
                  right_on='LaunchYear',
                  how='outer')
    df = df.merge(data_HEO,
                  left_on='LaunchYear',
                  right_on='LaunchYear',
                  how='outer')
    df = df.fillna(0)
    # first plot
    fig, [ax1, ax2, ax3, ax4] = plt.subplots(4,
                                             figsize=(17, 30),
                                             subplot_kw={'ylim': (0, 16000)})
    df.plot(kind='bar', y='LEO', x='LaunchYear', ax=ax1, color="#0f4c81")
    df.plot(kind='bar', y='MEO', x='LaunchYear', ax=ax2, color="#0f4c81")
    df.plot(kind='bar', y='GEO', x='LaunchYear', ax=ax3, color="#0f4c81")
    df.plot(kind='bar',
            y='HighEarthOrbit',
            x='LaunchYear',
            ax=ax4,
            color="#0f4c81")
    ax1.set_title('LEO')
    ax2.set_title('MEO')
    ax3.set_title('GEO')
    ax4.set_title('High Earth Orbit')
    plt.setp([ax1, ax2, ax3, ax4], xlabel='Year')
    plt.setp([ax1, ax2, ax3, ax4], ylabel='Count')
    fig.savefig('visualizations/orbit_years_comp.png')
    # second plot
    fig, ax = plt.subplots(1)
    leo = len(data[data['LEO']])
    meo = len(data[data['MEO']])
    geo = len(data[data['GEO']])
    heo = len(data[data['HighEarthOrbit']])
    y = np.arange(4)
    x = [leo, meo, geo, heo]
    plt.bar(y, x)
    fig.savefig('visualizations/orbit_bar.png')
    # third plot
    fig, ax = plt.subplots(1, figsize=(17, 10))
    df['HighEarthOrbit'] += (df['LEO'] + df['MEO'] + df['GEO'])
    df['GEO'] = df['LEO'] + df['MEO'] + df['GEO']
    df['MEO'] = df['LEO'] + df['MEO']
    df.plot(y='HighEarthOrbit',
            x='LaunchYear',
            kind='bar',
            color="#ffa372",
            ax=ax)
    df.plot(y='GEO', x='LaunchYear', kind='bar', color="#ed6663", ax=ax)
    df.plot(y='MEO', x='LaunchYear', kind='bar', color="#3282b8", ax=ax)
    df.plot(y='LEO', x='LaunchYear', kind='bar', color="#0f4c81", ax=ax)
    plt.title("Orbital Debris Total Count Over Time, by Orbit")
    plt.xlabel('Year')
    plt.ylabel('Count')
    fig.savefig('visualizations/stacked_bar_orbits.png')