Example #1
0
def run():
    
    data_file = '%s/latest.tsv' % config.sink_dir
    
    data = np.loadtxt(
        open(data_file, 'rb'),
        delimiter = "\t",
        skiprows = 1
    )
    
    for axis_y in config.interesting_y_axes:
    
        x = data[:, tsv_get_column_index(data_file, 'config_Z')]
        y = data[:, tsv_get_column_index(data_file, axis_y['column'])]
        
        plt.figure()
        
        plt.plot(x, y)
        plt.title(axis_y['name'])
        plt.xlabel(r'Hub Location $Z$')
        plt.ylabel(axis_y['name'])
        plt.grid(True)
        #plt.show()
        
        fig_path = '%s/plot_%s.pdf' % (config.sink_dir, axis_y['column'])
        fig_path = fig_path.replace('/runs/', '/plots/')
        fig_path = fig_path.replace('/sink/', '/')
        make_sure_path_exists(os.path.dirname(fig_path))
        plt.savefig(fig_path)
Example #2
0
def run():

    data_file = "%s/latest.tsv" % config.sink_dir

    data = np.loadtxt(open(data_file, "rb"), delimiter="\t", skiprows=1)

    for axis_y in config.interesting_y_axes:

        x = data[:, tsv_get_column_index(data_file, "config_count_hubs")]
        y = data[:, tsv_get_column_index(data_file, axis_y["column"])]

        plt.figure()

        plt.plot(x, y)
        plt.xlim(min(x), max(x))
        plt.xticks(x)
        plt.ylim(0.0, 0.05)
        plt.title(axis_y["name"])
        plt.xlabel(r"Hub Count $H$")
        plt.ylabel(axis_y["name"])
        plt.grid(True)
        # plt.show()

        fig_path = "%s/plot_%s.pdf" % (config.sink_dir, axis_y["column"])
        fig_path = fig_path.replace("/runs/", "/plots/")
        fig_path = fig_path.replace("/sink/", "/")
        make_sure_path_exists(os.path.dirname(fig_path))
        plt.savefig(fig_path)
Example #3
0
def run_graph():

    data_file = '%s/latest.tsv' % config.sink_dir

    data = np.loadtxt(open(data_file, 'rb'), delimiter="\t", usecols=(4, ))

    x = np.arange(0.01, 1, .01)
    y = []

    for criterium in x:
        count = 0
        for value in data:
            if value >= criterium:
                count += 1
        y.append(count)

    plt.title(r'Formation Suitability')
    plt.ylabel(r'Number of aircraft')
    plt.xlabel(r'Suitability Criterium $C_{min}$')
    plt.plot(x, y)
    #plt.show()

    fig_path = '%s/plot.pdf' % (config.sink_dir)
    fig_path = fig_path.replace('/runs/', '/plots/')
    fig_path = fig_path.replace('/sink/', '/')
    make_sure_path_exists(os.path.dirname(fig_path))
    plt.savefig(fig_path, bbox_inches='tight')
Example #4
0
def plot_flow_rate(data):

    timestamps = []
    values = []

    for key in sorted(data.iterkeys()):
        timestamps.append(key)
        values.append(data[key])

    # For testing/debugging
    #timestamps = np.arange(0, 1440, 60)
    #values = np.linspace(0, 35, len(timestamps))

    time_labels = []

    for timestamp in timestamps:

        # Normalize time to be reset after midnight (if > 1440, then subtract 1440)
        timestamp = timestamp % 1440
        hours = math.floor(timestamp / 60)
        minutes = math.floor(timestamp - hours * 60)

        time_labels.append('%02d:%02d' % (hours, minutes))

    plt.rc(('xtick.major', 'ytick.major'), pad=10)

    plt.bar(timestamps,
            values,
            width=interval_length - 5,
            linewidth=0,
            color='#999999')

    t = plt.title(r'Traffic Density at hub ($C_{min}=%s$)' % config.min_P)
    #t.set_y(1.03)
    plt.subplots_adjust(top=0.85, bottom=0.2)
    plt.grid()

    plt.xlabel(r'Time of day (UTC)', labelpad=10)
    plt.ylabel(r'Number of flights', labelpad=5)

    plt.xlim(0, 1440)
    plt.ylim(0, 40)

    xt = plt.xticks([0, 240, 480, 720, 960, 1200, 1440], [
        '00:00', '04:00', '08:00', '12:00', '16:00', '18:00', '22:00', '00:00'
    ])

    fig_path = '%s/plot_%s.pdf' % (config.sink_dir, str(config.min_P).replace(
        '.', '_'))
    fig_path = fig_path.replace('/runs/', '/plots/')
    fig_path = fig_path.replace('/sink/', '/')

    make_sure_path_exists(os.path.dirname(fig_path))

    #plt.show()
    plt.savefig(fig_path, bbox_inches='tight')
Example #5
0
def run_graph():
    
    data_file = '%s/latest.tsv' % config.sink_dir
    
    data = np.loadtxt(
        open(data_file, 'rb'),
        delimiter = "\t",
        usecols = (4,)
    )
    
    x = np.arange(0.01, 1, .01)
    y = []
    
    for criterium in x:
        count = 0
        for value in data:
            if value >= criterium:
                count += 1
        y.append(count)
    
    plt.title(r'Formation Suitability')
    plt.ylabel(r'Number of aircraft')
    plt.xlabel(r'Suitability Criterium $C_{min}$')
    plt.plot(x, y)
    #plt.show()
    
    fig_path = '%s/plot.pdf' % (config.sink_dir)
    fig_path = fig_path.replace('/runs/', '/plots/')
    fig_path = fig_path.replace('/sink/', '/')
    make_sure_path_exists(os.path.dirname(fig_path))
    plt.savefig(
        fig_path,
        bbox_inches='tight'
    )
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
Example #6
0
def init(directory):

    path = '%s/%s.tsv' % (directory,
                          datetime.now().strftime('%Y-%m-%d %H:%M:%S'))

    print "Sinking to %s" % path

    global writer, print_header
    print_header = True
    make_sure_path_exists(os.path.dirname(path))
    writer = csv.writer(open(path, 'w'), delimiter='\t')

    # Update the symlink to point to the latest data file
    force_symlink(path, '%s/latest.tsv' % os.path.dirname(path))
Example #7
0
def execute():

    planes = run.single_run()
    
    segments = create_segments(planes)

    plt, ax = run.render(segments)

    name = str(config.min_P).replace('.','_')
    fig_path = '%s/plot_%s.pdf' % (config.sink_dir, name)
    fig_path = fig_path.replace('/runs/', '/plots/')
    fig_path = fig_path.replace('/sink/', '/')

    make_sure_path_exists(os.path.dirname(fig_path))
    
    plt.savefig(fig_path, bbox_inches='tight')
Example #8
0
def execute():

    planes = run.single_run()

    segments = create_segments(planes)

    plt, ax = run.render(segments)

    name = 'count_hubs_%d' % config.count_hubs
    fig_path = '%s/plot_%s.pdf' % (config.sink_dir, name)
    fig_path = fig_path.replace('/runs/', '/plots/')
    fig_path = fig_path.replace('/sink/', '/')

    make_sure_path_exists(os.path.dirname(fig_path))

    plt.savefig(fig_path, bbox_inches='tight')
Example #9
0
def do_plot(data, title, ylabel, filename, formatter = None):
    
    means = []
    errors = []
    for hub_savings_list in data:
        means.append(np.mean(hub_savings_list))
        errors.append(np.std(hub_savings_list))

    means = np.array(means)
    errors = np.array(errors)
    
    plt.figure()
    plt.grid(True)
    
    (mean_line, caps, _) = plt.errorbar(
        np.arange(1, len(means)+1),
        means, yerr = errors, elinewidth = 2
    )

    mean_line.set_color('#000000')
    
    for cap in caps:
        cap.set_markeredgewidth(2)
    
    plt.xlim(0.5, len(means)+.5)
    plt.xticks(config.simhubs)
    plt.ylim(0, max(means)*1.1)
    plt.title(title)
    plt.xlabel(r'Number of hubs $H$')
    plt.ylabel(ylabel)
    
    if formatter is not None:
        locs, labels = plt.yticks()
        plt.yticks(locs, formatter(locs, labels))
    
    fig_path = '%s/%s.pdf' % (config.sink_dir, filename)
    fig_path = fig_path.replace('/runs/', '/plots/')
    fig_path = fig_path.replace('/sink/', '/')
    
    make_sure_path_exists(os.path.dirname(fig_path))
    plt.savefig(
        fig_path,
        bbox_inches='tight'
    )
Example #10
0
def init(directory):
    
    path = '%s/%s.tsv' % (
        directory,
        datetime.now().strftime('%Y-%m-%d %H:%M:%S')
    )
    
    print "Sinking to %s" % path

    global writer, print_header
    print_header = True
    make_sure_path_exists(os.path.dirname(path))
    writer = csv.writer(open(path, 'w'), delimiter = '\t')
    
    # Update the symlink to point to the latest data file
    force_symlink(
        path,
        '%s/latest.tsv' % os.path.dirname(path)
    )
Example #11
0
def do_plot(data, title, ylabel, filename, formatter=None):

    means = []
    errors = []
    for hub_savings_list in data:
        means.append(np.mean(hub_savings_list))
        errors.append(np.std(hub_savings_list))

    means = np.array(means)
    errors = np.array(errors)

    plt.figure()
    plt.grid(True)

    (mean_line, caps, _) = plt.errorbar(np.arange(1,
                                                  len(means) + 1),
                                        means,
                                        yerr=errors,
                                        elinewidth=2)

    mean_line.set_color('#000000')

    for cap in caps:
        cap.set_markeredgewidth(2)

    plt.xlim(0.5, len(means) + .5)
    plt.xticks(config.simhubs)
    plt.ylim(0, max(means) * 1.1)
    plt.title(title)
    plt.xlabel(r'Number of hubs $H$')
    plt.ylabel(ylabel)

    if formatter is not None:
        locs, labels = plt.yticks()
        plt.yticks(locs, formatter(locs, labels))

    fig_path = '%s/%s.pdf' % (config.sink_dir, filename)
    fig_path = fig_path.replace('/runs/', '/plots/')
    fig_path = fig_path.replace('/sink/', '/')

    make_sure_path_exists(os.path.dirname(fig_path))
    plt.savefig(fig_path, bbox_inches='tight')
Example #12
0
def execute():

    planes = run.single_run()

    segments = create_segments(planes)

    plt, ax = run.render(segments)

    name = 'count_hubs_%d' % config.count_hubs
    fig_path = '%s/plot_%s.pdf' % (config.sink_dir, name)
    fig_path = fig_path.replace('/runs/', '/plots/')
    fig_path = fig_path.replace('/sink/', '/')

    make_sure_path_exists(os.path.dirname(fig_path))

    plt.title(r'$H=%d$, $Z=%.2f$, $S_f=%.2f$' %
              (config.count_hubs, config.Z,
               statistics.vars['formation_success_rate']))

    plt.savefig(fig_path, bbox_inches='tight')
Example #13
0
def execute():

    planes = run.single_run()
    
    segments = create_segments(planes)

    plt, ax = run.render(segments)

    name = 'count_hubs_%d' % config.count_hubs
    fig_path = '%s/plot_%s.pdf' % (config.sink_dir, name)
    fig_path = fig_path.replace('/runs/', '/plots/')
    fig_path = fig_path.replace('/sink/', '/')

    make_sure_path_exists(os.path.dirname(fig_path))
    
    plt.title(r'$H=%d$, $Z=%.2f$, $S_f=%.2f$' % (
        config.count_hubs,
        config.Z,
        statistics.vars['formation_success_rate']
    ))
    #plt.show()
    plt.savefig(fig_path, bbox_inches='tight')
Example #14
0
def run():

    data_file = '%s/latest.tsv' % config.sink_dir

    data = np.loadtxt(open(data_file, 'rb'), delimiter="\t", skiprows=1)

    axis_x = config.axis_x
    axis_y = config.axis_y

    i = 0
    for axis_z in config.interesting_z_axes:

        i += 1

        print 'Plotting %s (%d of %d)' % (axis_z['column'], i,
                                          len(config.interesting_z_axes))

        plt.figure()

        x = data[:, tsv_get_column_index(data_file, axis_x['column'])]
        y = data[:, tsv_get_column_index(data_file, axis_y['column'])]
        z = data[:, tsv_get_column_index(data_file, axis_z['column'])]

        # Note that we must convert the lock time into the lock distance L
        if axis_x['column'] == 'config_lock_time':
            x = 300 * x / 60
        if axis_y['column'] == 'config_lock_time':
            y = 300 * y / 60

        try:
            nx = config.output_nx
            ny = config.output_ny
        except AttributeError:
            N = len(z)
            nx = math.sqrt(N)
            ny = nx
        #
        #print 'variable: %s, nx = %d, ny = %d, count z = %d. z = %s' % (
        #    axis_z['column'],
        #    nx, ny, len(z), z
        #)

        x = x.reshape(nx, ny)
        y = y.reshape(nx, ny)
        z = z.reshape(nx, ny)

        plt.xlabel(axis_x['name'])
        plt.ylabel(axis_y['name'])

        plt.grid(True)

        try:
            cs = plt.contour(x, y, z, axis_z['levels'])
        except KeyError:
            cs = plt.contour(x, y, z, 10)

        plt.clabel(cs)

        plt.colorbar()

        #plt.title(r'%s ($n=%d$)' % (axis_z['name'], config.count_hubs))
        t = plt.title(r'%s' % axis_z['name'])
        #t.set_y(1.03)

        fig_path = '%s/plot_%s.pdf' % (config.sink_dir, axis_z['column'])
        fig_path = fig_path.replace('/runs/', '/plots/')
        fig_path = fig_path.replace('/sink/', '/')
        make_sure_path_exists(os.path.dirname(fig_path))
        print fig_path
        #plt.show()
        #return
        plt.savefig(fig_path)
Example #15
0
def plot_flow_rate(data):

    timestamps = []
    values     = []
    
    for key in sorted(data.iterkeys()):
        timestamps.append(key)
        values.append(data[key])
    
    # For testing/debugging
    #timestamps = np.arange(0, 1440, 60)
    #values = np.linspace(0, 35, len(timestamps))

    time_labels = []

    for timestamp in timestamps:
    
        # Normalize time to be reset after midnight (if > 1440, then subtract 1440)
        timestamp = timestamp % 1440
        hours     = math.floor(timestamp / 60)
        minutes   = math.floor(timestamp - hours * 60)
        
        time_labels.append('%02d:%02d' % (hours, minutes))

    plt.rc(('xtick.major', 'ytick.major'), pad = 10)
    
    plt.bar(
        timestamps,
        values,
        width = interval_length - 5,
        linewidth = 0,
        color = '#999999'
    )
    
    t = plt.title(r'Traffic Density at hub ($C_{min}=%s$)' % config.min_P)
    #t.set_y(1.03) 
    plt.subplots_adjust(top = 0.85, bottom = 0.2)
    plt.grid()
    
    plt.xlabel(r'Time of day (UTC)', labelpad = 10)
    plt.ylabel(r'Number of flights', labelpad = 5)
    
    plt.xlim(0, 1440)
    plt.ylim(0, 40)
    
    xt = plt.xticks(
        [0,
         240,
         480,
         720,
         960,
         1200,
         1440],
        ['00:00',
         '04:00',
         '08:00',
         '12:00',
         '16:00',
         '18:00',
         '22:00',
         '00:00']
    )
    
    fig_path = '%s/plot_%s.pdf' % (
        config.sink_dir,
        str(config.min_P).replace('.','_')
    )
    fig_path = fig_path.replace('/runs/', '/plots/')
    fig_path = fig_path.replace('/sink/', '/')
    
    make_sure_path_exists(os.path.dirname(fig_path))
    
    #plt.show()
    plt.savefig(
        fig_path,
        bbox_inches='tight'
    )
Example #16
0
def run():
    
    data_file = '%s/latest.tsv' % config.sink_dir
    
    data = np.loadtxt(
        open(data_file, 'rb'),
        delimiter = "\t",
        skiprows = 1
    )
    
    axis_x = config.axis_x
    axis_y = config.axis_y

    i = 0
    for axis_z in config.interesting_z_axes:
        
        i += 1
        
        print 'Plotting %s (%d of %d)' % (
            axis_z['column'], i, len(config.interesting_z_axes)
        )
        
        plt.figure()
    
        x = data[:, tsv_get_column_index(data_file, axis_x['column'])]
        y = data[:, tsv_get_column_index(data_file, axis_y['column'])]
        z = data[:, tsv_get_column_index(data_file, axis_z['column'])]
        
        # Note that we must convert the lock time into the lock distance L
        if axis_x['column'] == 'config_lock_time':
            x = 300 * x / 60
        if axis_y['column'] == 'config_lock_time':
            y = 300 * y / 60

        try:
            nx = config.output_nx
            ny = config.output_ny
        except AttributeError:
            N = len(z)
            nx = math.sqrt(N)
            ny = nx
        #    
        #print 'variable: %s, nx = %d, ny = %d, count z = %d. z = %s' % (
        #    axis_z['column'],
        #    nx, ny, len(z), z
        #)

        x = x.reshape(nx, ny)
        y = y.reshape(nx, ny)
        z = z.reshape(nx, ny)
        
        plt.xlabel(axis_x['name'])
        plt.ylabel(axis_y['name'])
        
        plt.grid(True)
        
        try:
            cs = plt.contour(x, y, z, axis_z['levels'])
        except KeyError:
            cs = plt.contour(x, y, z, 10)

        plt.clabel(cs)
        
        plt.colorbar()
        
        #plt.title(r'%s ($n=%d$)' % (axis_z['name'], config.count_hubs))
        t = plt.title(r'%s' % axis_z['name'])
        #t.set_y(1.03)
        
        fig_path = '%s/plot_%s.pdf' % (config.sink_dir, axis_z['column'])
        fig_path = fig_path.replace('/runs/', '/plots/')
        fig_path = fig_path.replace('/sink/', '/')
        make_sure_path_exists(os.path.dirname(fig_path))
        print fig_path
        #plt.show()
        #return
        plt.savefig(fig_path)
Example #17
0
def run():

    data_file = '%s/latest.tsv' % config.sink_dir

    data = np.loadtxt(
        open(data_file, 'rb'),
        delimiter = "\t",
        skiprows = 1
    )

    j = 0
    for axis_y in config.axes_y:
        
        print 'Plotting %s (%d of %d)' % (
            axis_y['column'], (j+1), len(config.axes_y)
        )
        
        axis_x = config.axis_x
    
        fig = plt.figure(j)
        ax  = fig.add_subplot(111)
    
        x = data[:, tsv_get_column_index(data_file, axis_x['column'])]
        y = data[:, tsv_get_column_index(data_file, axis_y['column'])]
        
        # Note that we must convert the lock time into the lock distance L
        if axis_x['column'] == 'config_lock_time':
            raise Error('lock time needs conversion')
        
        nx = len(config.x)
        ny = len(config.y)

        x = x.reshape(nx, ny)
        y = y.reshape(nx, ny)
        
        plt.xlabel(axis_x['name'])
        plt.ylabel(axis_y['name'])
        
        i = 0
        for line in config.x:

            horizontal = x[0,:]
            vertical = y[i,:]

            plt.plot(horizontal, vertical, label = config.legend % line)
            i += 1
    
        plt.grid(True)
        t = plt.title(r'%s' % axis_y['name'])
        #t.set_y(1.03)
        #plt.subplots_adjust(top = 0.85, bottom = 0.2) 
        
        lgd = ax.legend(
            loc='upper center',
            bbox_to_anchor=(0.5,-0.15),
            ncol = 2
        )

        fig_path = '%s/plot_%s.pdf' % (config.sink_dir, axis_y['column'])
        fig_path = fig_path.replace('/runs/', '/plots/')
        fig_path = fig_path.replace('/sink/', '/')
        
        make_sure_path_exists(os.path.dirname(fig_path))
        
        locs, labels = plt.yticks()
        
        try:
            f = axis_y['yticks_formatter']
            plt.yticks(locs, f(locs, labels))
        except KeyError:
            pass
        
        #plt.show()
        #return
        
        plt.savefig(
            fig_path,
            bbox_extra_artists=(lgd,),
            bbox_inches='tight'
        )
        
        j += 1
Example #18
0
def do_plot(plotconf, data):

    plt.figure()

    column = plotconf['column']
    print 'Drawing plot for %s' % column

    data_file = '%s/latest.tsv' % config.sink_dir

    x = data[:, tsv_get_column_index(data_file, 'hub_lon')]
    y = data[:, tsv_get_column_index(data_file, 'hub_lat')]
    z = data[:, tsv_get_column_index(data_file, column)]

    minlat = np.min(y)
    maxlat = np.max(y)
    minlon = np.min(x)
    maxlon = np.max(x)

    m = Basemap(projection='merc',
                resolution='c',
                llcrnrlat=minlat,
                urcrnrlat=maxlat,
                llcrnrlon=minlon,
                urcrnrlon=maxlon)

    # Reverse Y-axis (high lat = low y)
    #y = y[::-1]

    #x, y = np.meshgrid(x, y)

    N = len(z)
    #print N
    nx = math.sqrt(N)
    ny = nx

    x = x.reshape(nx, ny)
    y = y.reshape(nx, ny)
    z = z.reshape(nx, ny)

    #print x
    #print y
    #print z

    m.drawcoastlines()
    m.drawstates()
    m.drawcountries()

    # draw lat/lon grid lines every 10 degrees.
    parallels = np.arange(-360., 360., 10.)
    meridians = np.arange(-360., 360., 20.)
    m.drawparallels(parallels, labels=[1, 0, 0, 0])
    m.drawmeridians(meridians, labels=[0, 0, 0, 1])

    # Midpoints were determined in runs/singlehub/trunk
    #midpoint_origins = Point(50., 8.)
    midpoint_origins = Waypoint('LUX')
    #midpoint_destinations = Point(35.,-87.)
    midpoint_destinations = Waypoint('PIT')

    lon1 = midpoint_origins.lon
    lat1 = midpoint_origins.lat
    lon2 = midpoint_destinations.lon
    lat2 = midpoint_destinations.lat

    # Draw the trunk route
    m.drawgreatcircle(lon1, lat1, lon2, lat2, linewidth=3, color='#000000')

    x, y = m(x, y)
    cs = m.contourf(x, y, z, plotconf['levels'])

    plt.colorbar(cs, orientation='vertical', shrink=0.65)
    plt.title(plotconf['title'])

    #plt.show()

    fig_path = '%s/plot_%s.pdf' % (config.sink_dir, column)
    fig_path = fig_path.replace('/runs/', '/plots/')
    fig_path = fig_path.replace('/sink/', '/')
    make_sure_path_exists(os.path.dirname(fig_path))
    plt.savefig(fig_path, bbox_inches='tight')
Example #19
0
def do_plot(plotconf, data):
    
    plt.figure()
    
    column = plotconf['column']
    print 'Drawing plot for %s' % column
    
    data_file = '%s/latest.tsv' % config.sink_dir
    
    x = data[:, tsv_get_column_index(data_file, 'hub_lon')]
    y = data[:, tsv_get_column_index(data_file, 'hub_lat')]
    z = data[:, tsv_get_column_index(data_file, column)]
    
    minlat = np.min(y)
    maxlat = np.max(y)
    minlon = np.min(x)
    maxlon = np.max(x)
    
    m = Basemap(
        projection = 'merc', resolution = 'c',
        llcrnrlat = minlat, urcrnrlat = maxlat,
        llcrnrlon = minlon, urcrnrlon = maxlon
    )
    
    # Reverse Y-axis (high lat = low y)
    #y = y[::-1]
    
    #x, y = np.meshgrid(x, y)
    
    N = len(z)
    #print N
    nx = math.sqrt(N)
    ny = nx
    
    x = x.reshape(nx, ny)
    y = y.reshape(nx, ny)
    z = z.reshape(nx, ny)

    #print x
    #print y
    #print z
    
    m.drawcoastlines()
    m.drawstates()
    m.drawcountries()
    
    # draw lat/lon grid lines every 10 degrees.
    parallels = np.arange(-360.,360.,10.)
    meridians = np.arange(-360.,360.,20.)
    m.drawparallels(parallels,labels=[1,0,0,0])
    m.drawmeridians(meridians,labels=[0,0,0,1])

    # Midpoints were determined in runs/singlehub/trunk
    #midpoint_origins = Point(50., 8.)
    midpoint_origins = Waypoint('LUX')
    #midpoint_destinations = Point(35.,-87.)
    midpoint_destinations = Waypoint('PIT')

    lon1 = midpoint_origins.lon
    lat1 = midpoint_origins.lat
    lon2 = midpoint_destinations.lon
    lat2 = midpoint_destinations.lat
    
    # Draw the trunk route
    m.drawgreatcircle(lon1, lat1, lon2, lat2, linewidth = 3, color='#000000')
    
    x, y = m(x, y)
    cs = m.contourf(x, y, z, plotconf['levels'])

    plt.colorbar(cs, orientation = 'vertical', shrink = 0.65)
    plt.title(plotconf['title'])
    
    #plt.show()
    
    fig_path = '%s/plot_%s.pdf' % (config.sink_dir, column)
    fig_path = fig_path.replace('/runs/', '/plots/')
    fig_path = fig_path.replace('/sink/', '/')
    make_sure_path_exists(os.path.dirname(fig_path))
    plt.savefig(fig_path, bbox_inches='tight')
Example #20
0
def run():

    data_file = '%s/latest.tsv' % config.sink_dir

    data = np.loadtxt(open(data_file, 'rb'), delimiter="\t", skiprows=1)

    j = 0
    for axis_y in config.axes_y:

        print 'Plotting %s (%d of %d)' % (axis_y['column'],
                                          (j + 1), len(config.axes_y))

        axis_x = config.axis_x

        fig = plt.figure(j)
        ax = fig.add_subplot(111)

        x = data[:, tsv_get_column_index(data_file, axis_x['column'])]
        y = data[:, tsv_get_column_index(data_file, axis_y['column'])]

        # Note that we must convert the lock time into the lock distance L
        if axis_x['column'] == 'config_lock_time':
            raise Error('lock time needs conversion')

        nx = len(config.x)
        ny = len(config.y)

        x = x.reshape(nx, ny)
        y = y.reshape(nx, ny)

        plt.xlabel(axis_x['name'])
        plt.ylabel(axis_y['name'])

        i = 0
        for line in config.x:

            horizontal = x[0, :]
            vertical = y[i, :]

            plt.plot(horizontal, vertical, label=config.legend % line)
            i += 1

        plt.grid(True)
        t = plt.title(r'%s' % axis_y['name'])
        #t.set_y(1.03)
        #plt.subplots_adjust(top = 0.85, bottom = 0.2)

        lgd = ax.legend(loc='upper center',
                        bbox_to_anchor=(0.5, -0.15),
                        ncol=2)

        fig_path = '%s/plot_%s.pdf' % (config.sink_dir, axis_y['column'])
        fig_path = fig_path.replace('/runs/', '/plots/')
        fig_path = fig_path.replace('/sink/', '/')

        make_sure_path_exists(os.path.dirname(fig_path))

        locs, labels = plt.yticks()

        try:
            f = axis_y['yticks_formatter']
            plt.yticks(locs, f(locs, labels))
        except KeyError:
            pass

        #plt.show()
        #return

        plt.savefig(fig_path, bbox_extra_artists=(lgd, ), bbox_inches='tight')

        j += 1