示例#1
0
def run_single(n, d=30000):
    """Run multiple simulations for example scenario."""
    start = Location(-14.0, 47.0)
    finish = Location(-6.0, 47.0)
    craft = return_boat_perf()
    no_nodes = n
    r = Route(start, finish, no_nodes, no_nodes, d, craft)
    wind_fname = "/Users/thomasdickson/Documents/sail_routing/routing/domain_application/data_dir/wind_forecast.nc"
    diagram_path = "/Users/thomasdickson/Documents/python_routing/analysis/output/multiple"
    time = datetime(2014, 7, 1, 0, 0)
    x, y, land = return_co_ords(r.start.long, r.finish.long, r.start.lat,
                                r.finish.lat, r.n_ranks, r.n_width, r.d_node)
    jt, et, pf_vals = min_time_calculate(r, wind_fname, time, craft)
    plot_route(time, r, x, y, et, jt, pf_vals,
               diagram_path + "/single_route_%.0f_%.0f.png" % (n, d))
    return jt, et, pf_vals
示例#2
0
def run_simulation():
    start = Location(-14.0, 47.0)
    finish = Location(-6.0, 47.0)
    craft = return_boat_perf()
    no_nodes = 10
    r = Route(start, finish, no_nodes, no_nodes, 30000.0, craft)
    wind_fname = "/Users/thomasdickson/Documents/sail_routing/routing/domain_application/data_dir/wind_forecast.nc"
    diagram_path = "/Users/thomasdickson/Documents/python_routing/analysis/output/multiple"
    t = datetime(2014, 7, 1, 0, 0)
    x, y, land = return_co_ords(r.start.long, r.finish.long, r.start.lat,
                                r.finish.lat, r.n_ranks, r.n_width, r.d_node)
    jt, et, pf_vals = min_time_calculate(r, wind_fname, time, craft)
    vt = datetime.fromtimestamp(jt) - t
    print("Journey time is: ", vt)
    plot_route(time, r, x, y, et, jt, pf_vals,
               diagram_path + "/single_route.png")
示例#3
0
def run_uncertain_performance_simulation():
    """Run routing simulations for a given day with uncertain performance."""
    start = Location(-149.426, -17.651)
    finish = Location(-157.92, 21.83)
    start_date = datetime(1976, 5, 1, 0, 0)
    n_nodes = 150
    n_width = n_nodes
    print("Nodes in rank: ", n_nodes)
    print("Nodes in width: ", n_width)
    dist, bearing = haversine(start.long, start.lat, finish.long, finish.lat)
    node_distance = 2000 * dist / n_width
    print("Node height distance is ", dist / n_nodes * 1000, " m")
    print("Node width distance is ", node_distance, " m")
    area = node_distance * dist / n_nodes * 1000
    total_area = n_nodes * n_width * area
    h = (1 / (n_nodes * n_width) * total_area)**0.5
    print("h = {0} ".format(h))
    pyroute_path = "/Users/thomasdickson/Documents/python_routing/"
    wind_fname = pyroute_path + "analysis/poly_data/data_dir/finney_wind_forecast.nc"
    waves_fname = pyroute_path + "analysis/poly_data/data_dir/finney_wave_data.nc"
    dia_path = pyroute_path + "analysis/poly_data/finney_sims"
    unc = np.linspace(0.95, 1.05, 3)
    results = np.zeros_like(unc)
    route_x = []
    route_y = []
    fm = gen_env_model()
    for n, i in enumerate(unc):
        craft = tong_uncertain(i, 1.0, fm)
        r = Route(start, finish, n_nodes, n_width, node_distance, craft)
        x, y, land = return_co_ords(r.start.long, r.finish.long, r.start.lat,
                                    r.finish.lat, r.n_ranks, r.n_width,
                                    r.d_node)
        tws, twd = process_wind(wind_fname, x, y)
        wd, wh, wp = process_waves(waves_fname, x, y)
        jt, et, x_r, y_r = min_time_calculate(r, start_date, craft, x, y, land,
                                              tws, twd, wd, wh, wp)
        vt = datetime.fromtimestamp(jt) - start_date
        results[n] = vt.total_seconds() / (60.0 * 60.0)
        print(results[n] / 24)
        route_x.append(x_r)
        route_y.append(y_r)
    plot_uncertainty(unc, results)
    plt.savefig(dia_path + "/unc_vt_test_" + str(h) + ".png")
    plot_uncertain_routes(start, r, x, y, unc, route_x, route_y, results)
    plt.savefig(dia_path + "/unc_vt_routes_test_" + str(h) + ".png")
示例#4
0
def run_simulation_over_days():
    """Run routing simulations between tahiti and marquesas."""
    tahiti = Location(-149.426, -17.651)
    hawaii = Location(-157.92, 21.83)
    fm = gen_env_model()
    craft = tong_uncertain(1.0, 1.0, fm)
    n_nodes = 40
    n_width = n_nodes
    print("Nodes in rank: ", n_nodes)
    print("Nodes in width: ", n_width)
    dist, bearing = haversine(tahiti.long, tahiti.lat, hawaii.long,
                              hawaii.lat)
    node_distance = 4000*dist/n_width
    print("Node height distance is ", dist/n_nodes*1000, " m")
    print("Node width distance is ", node_distance, " m")
    area = node_distance*dist/n_nodes*1000
    total_area = n_nodes * n_width * area
    h = (1/(n_nodes * n_width) * total_area)**0.5
    print("h = {0} ".format(h))
    r = Route(tahiti, hawaii, n_nodes, n_width,
              node_distance, craft)
    wind_fname = pp + "analysis/poly_data/data_dir/finney_wind_forecast.nc"
    waves_fname = pp + "analysis/poly_data/data_dir/finney_wave_data.nc"
    dia_path = pp + "analysis/poly_data/finney_sims/"
    sd = datetime(1976, 5, 1, 0, 0)
    ed = datetime(1976, 5, 2, 0, 0)
    dt = [d for d in datetime_range(sd, ed, {'days': 1, 'hours': 0})]
    for t in dt:
        x, y, land = return_co_ords(r.start.long, r.finish.long,
                                    r.start.lat, r.finish.lat,
                                    r.n_ranks, r.n_width, r.d_node)
        tws, twd = process_wind(wind_fname, x, y)
        wd, wh, wp = process_waves(waves_fname, x, y)
        jt, et, x_r, y_r = min_time_calculate(r, t, craft,
                                              x, y, land,
                                              tws, twd, wd, wh, wp)
        vt = datetime.fromtimestamp(jt) - t
        print("Journey time is: ", vt)
        fill = 10
        string = str(t)+"_"+str(craft.apf)+"_"+str(craft.unc)+"_"+str(n_nodes)
        plot_mt_route(t, r, x, y, x_r, y_r,
                      et, jt, fill,
                      dia_path+string+"_")
示例#5
0
def reliability_uncertainty_routing():
    """Routing for a range of uncertainty and reliability levels."""
    rel_levels = np.array([0.81, 0.91, 1.0])
    unc_levels = np.array([0.95, 1.0, 1.05])
    test_matrix = np.array(np.meshgrid(rel_levels,
                                       unc_levels)).T.reshape(-1, 2)
    fts = []
    start = Location(-2.3700, 50.256)
    finish = Location(-61.777, 17.038)
    fm = gen_env_model()
    craft = asv_uncertain(1.0, 1.0, fm)
    weather_path = pp + "analysis/asv_transat/2016_jan_march.nc"
    diagram_path = pp + "analysis/asv_transat/results/"
    sd = datetime(2016, 1, 2, 6, 0)
    dist, bearing = haversine(start.long, start.lat,
                              finish.long, finish.lat)
    nodes = 60
    node_distance = 4000*dist/nodes
    r = Route(start, finish, nodes, nodes,
              node_distance*1000.0, craft)
    x, y, land = return_co_ords(r.start.long, r.finish.long,
                                r.start.lat, r.finish.lat,
                                r.n_ranks, r.n_width, r.d_node)
    tws, twd, wd, wh, wp = process_era5_weather(weather_path, x, y)
    for i in range(test_matrix.shape[0]):
        craft = asv_uncertain(test_matrix[i, 1], test_matrix[i, 0], fm)

        jt, et, x_r, y_r = min_time_calculate(r, sd, craft,
                                              x, y, land,
                                              tws, twd, wd, wh, wp)
        vt = datetime.fromtimestamp(jt) - sd
        fts.append(vt.total_seconds())
    results = np.array(fts)
    print(results)
    save_array = np.hstack((test_matrix, results[..., None]))
    print(save_array)
    with open(diagram_path+"unc_reliability_routing_"+strftime("""%Y-%m-%d
                                                               %H:%M:%S""",
                                                              gmtime())+".txt",
             'wb') as f:
        np.savetxt(f, save_array, delimiter='\t', fmt='%1.3f')
示例#6
0
def asv_grid_error():
    """
    Check convergence of solution.

    Using Maribot Vane performance estimates for the transatlantic voyage.
    """
    start = Location(-2.3700, 50.256)
    finish = Location(-61.777, 17.038)
    fm = gen_env_model()
    craft = asv_uncertain(1.0, 1.0, fm)
    weather_path = pp + "analysis/asv_transat/2016_jan_march.nc"
    diagram_path = pp + "analysis/asv_transat/results/"
    sd = datetime(2016, 1, 1, 6, 0)
    dist, bearing = haversine(start.long, start.lat,
                              finish.long, finish.lat)
    nodes = np.array([640])
    times = []
    h_vals = []
    for count, node in enumerate(nodes):
        node_distance = 4000*dist/node
        r = Route(start, finish, node, node,
                  node_distance*1000.0, craft)
        x, y, land = return_co_ords(r.start.long, r.finish.long,
                                    r.start.lat, r.finish.lat,
                                    r.n_ranks, r.n_width, r.d_node)
        tws, twd, wd, wh, wp = process_era5_weather(weather_path, x, y)
        jt, et, x_r, y_r = min_time_calculate(r, sd, craft,
                                              x, y, land,
                                              tws, twd, wd, wh, wp)
        vt = datetime.fromtimestamp(jt) - sd
        print("Journey time is: ", vt)
        h_vals.append(calc_h(node, node_distance**2))
        vt = datetime.fromtimestamp(jt) - sd
        print(h_vals[-1], "  ", vt)
        times.append(vt.total_seconds())
    h_vals, times = np.array(h_vals), np.array(times)
    with open(diagram_path+"asv_convergence_"+strftime("%Y-%m-%d %H:%M:%S",
                                                       gmtime())+".txt", 'wb') as f:
        np.savetxt(f, np.c_[nodes, h_vals, times], delimiter='\t')
示例#7
0
def run_simulation_over_days():
    """Run transat routing simulations."""
    # Specify the bounds of the whole region
    lon1 = -59.9
    lat1 = -1.77
    lon2 = -6.4
    lat2 = 61.5
    start = Location(-12.0, 45.0)
    finish = Location(-60.0, 17.5)
    fm = gen_env_model()
    craft = asv_uncertain(1.0, 0.89, fm)
    n_nodes = 40
    n_width = n_nodes
    print("Nodes in rank: ", n_nodes)
    print("Nodes in width: ", n_width)
    dist, bearing = haversine(start.long, start.lat,
                              finish.long, finish.lat)
    node_distance = 4000*dist/n_width
    print("Node height distance is ", dist/n_nodes*1000, " m")
    print("Node width distance is ", node_distance, " m")
    area = node_distance*dist/n_nodes*1000
    total_area = n_nodes * n_width * area
    h = (1/(n_nodes * n_width) * total_area)**0.5
    print("h = {0} ".format(h))
    r = Route(start, finish, n_nodes, n_width,
              node_distance, craft)
    weather_path = pp + "analysis/asv_transat/2016_jan_march.nc"
    dia_path = pp + "analysis/asv_transat/results/"
    sd = datetime(2008, 1, 2, 6, 0)
    ed = datetime(2008, 1, 3, 6, 0)
    dt = [d for d in datetime_range(sd, ed, {'days': 1, 'hours': 0})]
    x, y, land = return_co_ords(r.start.long, r.finish.long,
                                r.start.lat, r.finish.lat,
                                r.n_ranks, r.n_width, r.d_node)
    tws, twd, wd, wh, wp = process_era5_weather(weather_path, x, y)
    tws = change_area_values(tws, 15.0, lon1, lat1, lon2, lat2)
    twd = change_area_values(twd, 0.0, lon1, lat1, lon2, lat2)
    wd = change_area_values(wd, 0.0, lon1, lat1, lon2, lat2)
    wh = change_area_values(wh, 0.0, lon1, lat1, lon2, lat2)
    a2 = 5.0
    lon1_area2 = -40.0-a2
    lon2_area2 = -40.0+a2
    lat1_area2 = 33.0-a2
    lat2_area2 = 33.0+a2
    wh = change_area_values(wh, 4.0, lon1_area2, lat1_area2, lon2_area2,
                            lat2_area2)
    a1 = 3.0
    lon1_area1 = -40.0-a1
    lon2_area1 = -40.0+a1
    lat1_area1 = 33.0-a1
    lat2_area1 = 33.0+a1
    wd = change_area_values(wd, 240.0, lon1_area1, lat1_area1,
                            lon2_area1, lat2_area1)
    for t in dt:
        jt, et, x_r, y_r = min_time_calculate(r, t, craft,
                                              x, y, land,
                                              tws, twd, wd, wh, wp)
        vt = datetime.fromtimestamp(jt) - t
        print("Journey time is: ", vt)
        fill = 10
        string = str(t)+"_"+str(craft.apf)+"_"+str(craft.unc)+"_"+str(n_nodes)
        plot_failure_route(t, r, x, y, x_r, y_r,
                           et, jt, fill,
                           dia_path+string+"_")
示例#8
0
def failure_controlled_weather():
    """Load weather file for simulations."""
    rel_levels = np.array([0.81, 0.95, 1.0])
    unc_levels = np.array([1.0])
    test_matrix = np.array(np.meshgrid(rel_levels,
                                       unc_levels)).T.reshape(-1, 2)
    fts = []
    start = Location(-2.3700, 50.256)
    finish = Location(-61.777, 17.038)
    fm = gen_env_model()
    craft = asv_uncertain(1.0, 1.0, fm)
    weather_path = pp + "analysis/asv_transat/2016_jan_march.nc"
    diagram_path = pp + "analysis/failure_model/"
    sd = datetime(2008, 1, 2, 6, 0)
    dist, bearing = haversine(start.long, start.lat, finish.long, finish.lat)
    nodes = 20
    node_distance = 4000 * dist / nodes
    r = Route(start, finish, nodes, nodes, node_distance * 1000.0, craft)
    x, y, land = return_co_ords(r.start.long, r.finish.long, r.start.lat,
                                r.finish.lat, r.n_ranks, r.n_width, r.d_node)
    tws, twd, wd, wh, wp = process_era5_weather(weather_path, x, y)
    # Alter the weather for the entire domain
    lon1 = -59.9
    lat1 = -1.77
    lon2 = -6.4
    lat2 = 61.5
    tws = change_area_values(tws, 15.0, lon1, lat1, lon2, lat2)
    twd = change_area_values(twd, 270.0, lon1, lat1, lon2, lat2)
    #  Alter the wave conditions
    wd = change_area_values(wd, 90.0, lon1, lat1, lon2, lat2)
    wh = change_area_values(wh, 0.0, lon1, lat1, lon2, lat2)

    # # Alter the weather for the smaller area
    a1 = 3.0
    lon1_area1 = -40.0 - a1
    lon2_area1 = -40.0 + a1
    lat1_area1 = 33.0 - a1
    lat2_area1 = 33.0 + a1
    wd = change_area_values(wd, 180.0, lon1_area1, lat1_area1, lon2_area1,
                            lat2_area1)
    a2 = 5.0
    lon1_area2 = -40.0 - a2
    lon2_area2 = -40.0 + a2
    lat1_area2 = 33.0 - a2
    lat2_area2 = 33.0 + a2
    wh = change_area_values(wh, 4.0, lon1_area2, lat1_area2, lon2_area2,
                            lat2_area2)

    for i in range(test_matrix.shape[0]):
        craft = asv_uncertain(test_matrix[i, 1], test_matrix[i, 0], fm)

        jt, et, x_r, y_r = min_time_calculate(r, sd, craft, x, y, land, tws,
                                              twd, wd, wh, wp)
        vt = datetime.fromtimestamp(jt) - sd
        fts.append(vt.total_seconds())
    results = np.array(fts)
    print(results)
    save_array = np.hstack((test_matrix, results[..., None]))
    print(save_array)
    with open(
            diagram_path + "control_" +
            strftime("""%Y-%m-%d %H:%M:%S""", gmtime()) + ".txt", 'wb') as f:
        np.savetxt(f, save_array, delimiter='\t', fmt='%1.3f')