Example #1
0
def process_input(config_filename):

	# load the config file
	with open('./params/batcher_config/' + config_filename) as data:
		conf = fancyyaml.load(data)

	tracks = [(track_segmentation.dxf_to_segments(x.dxf, x.segment_distance), x.steady_state, x.dxf) for x in conf.tracks]
	model = sims.Simulation(conf.model)
	out = (conf.filename, conf.data_percentage)

	return (conf.tests, conf.vehicle, tracks, model, out)
Example #2
0
def process_input(config_filename):

    # load the config file
    with open('./params/batcher_config/' + config_filename) as data:
        conf = fancyyaml.load(data, True)

    tracks = [process_track(x, "./params/tracks/") for x in conf.tracks]
    model = sims.Simulation(conf.model)
    out = (conf.filename, conf.data_percentage)

    return (conf.tests, conf.vehicle, tracks, model, out)
Example #3
0
def load(filename):
    vehicle_YAML = './Vehicles/' + filename
    with open(vehicle_YAML) as data:
        v_OBJ = yaml.load(data)

    for key in v_OBJ:
        if isinstance(v_OBJ[key], int):
            v_OBJ[key] = float(v_OBJ[key])
        setattr(v, key, v_OBJ[key])
    v.mass /= g
    v.g = g

    v.v_OBJ = v_OBJ
Example #4
0
def process_web_input(conf):
    vehicle_stream = io.StringIO(conf.vehicle)
    conf.vehicle = vehicle.Vehicle(fancyyaml.load(vehicle_stream, False))
    vehicle_stream.close()

    for x in conf.tracks:
        x.name = x.file
        x.file = x.path

    tracks = [process_track(x) for x in conf.tracks]
    model = sims.Simulation(conf.model)
    out = (conf.filename, conf.data_percentage)

    return (conf.tests, conf.vehicle, tracks, model, out)
Example #5
0
def run(filename):
    print('Beginning Mesh Convergence Study')
    mcstudy = {}
    with open('./Studies/' + filename) as f:
        mcstudy = yaml.load(f)

    vehicle.load(mcstudy["vehicle"])

    if not "model" in mcstudy:
        mcstudy['model'] = 'twotires'
    model = mcstudy['model']

    if model == 'twotires':
        sim_pkg = sim_twotires
    else:
        sim_pkg = sim_pointmass

    fig, ax = plt.subplots()
    fig.canvas.set_window_title('Mesh Convergence Results')

    for track in mcstudy['track']:
        meshes = mcstudy['track'][track]
        tf = []
        print('    Track: ' + track)
        for mesh in meshes:
            print('        Segment Size: ' + str(mesh))
            segs = track_segmentation.dxf_to_segments("./DXFs/" + track, mesh)
            output = sim_pkg.solve(vehicle.v, segs)
            tf.append(output[-1, O_TIME])

        ax.plot(meshes, tf, label=track, marker='x', linestyle='-', picker=5)

    ax.grid(True)
    ax.legend()

    plt.title("Mesh Convergence Study")
    plt.xlabel("Segment Size")
    plt.ylabel("Track Time")

    print('Finished!')

    plt.show()
Example #6
0
def v_load(filename):
    vehicle_YAML = './params/vehicles/' + filename
    with open(vehicle_YAML) as data:
        v_OBJ = yaml.load(data)
    v.v_OBJ = v_OBJ
Example #7
0
def run(filename):
    timestamp_start = time.time()
    print("Loading test...")

    # load the study YAML into s_OBJ
    study_YAML = './Studies/' + filename
    with open(study_YAML) as data:
        s_OBJ = yaml.load(data)
        study_text = data.read()

    # load vehicle
    vehicle.load(s_OBJ["vehicle"])

    print("Setting up tests...")

    if not 'model' in s_OBJ:
        s_OBJ['model'] = 'twotires'
    model = s_OBJ['model']
    print(repr(model))

    if model == 'pointmass':
        print('point mass model')
        sim_pkg = sim_pointmass
    else:
        print('two tire model')
        sim_pkg = sim_twotires

    # set up track
    tracks = s_OBJ["track"]
    meshes = s_OBJ["segment_distance"]
    segList = [
        track_segmentation.dxf_to_segments("./DXFs/" + tracks[i], meshes[i])
        for i in range(len(tracks))
    ]

    # # the following lines were lost under the sweeping branch of the new regime
    # tests = np.array(s_OBJ["test_points"])
    # test_op = s_OBJ["test_operation"]

    # set up tests
    tests = s_OBJ["tests"]
    targets = [tests[x]["target"] for x in range(len(tests))]
    operations = [tests[x]["operation"] for x in range(len(tests))]
    test_points = [tests[x]["test_vals"] for x in range(len(tests))]
    output = []

    try:  # run 3D test
        tests2 = s_OBJ["tests2"]
        targets2 = [tests2[x]["target"] for x in range(len(tests2))]
        operations2 = [tests2[x]["operation"] for x in range(len(tests2))]
        test_points2 = [tests2[x]["test_vals"] for x in range(len(tests2))]

        num_xtests = len(test_points[0])
        num_ytests = len(test_points2[0])

        if "plot_x_points" in s_OBJ and isinstance(s_OBJ["plot_x_points"],
                                                   list):
            pass
        else:
            s_OBJ['plot_x_points'] = tests[0]["test_vals"]
        if "plot_y_points" in s_OBJ and isinstance(s_OBJ["plot_y_points"],
                                                   list):
            pass
        else:
            s_OBJ['plot_y_points'] = tests2[0]["test_vals"]

        # set up some preliminary values
        times = np.zeros((len(segList), num_xtests, num_ytests))
        co2s = np.zeros((len(segList), num_xtests, num_ytests))
        lat_accels = np.zeros((len(segList), num_xtests, num_ytests))

        for seg_no in range(len(segList)):
            print("\tTesting track " + str(seg_no + 1) + "...")

            for test_no in range(num_xtests):
                print("\t\tTesting parameter row " + str(test_no + 1) + "...")

                # alter the test variables as need be
                for var_no, var in enumerate(targets):
                    test_op = operations[var_no]
                    test_vals = test_points[var_no]

                    if test_op == "product":
                        vehicle.setVar(
                            var,
                            vehicle.getOriginalVal(var) * test_vals[test_no])
                    elif test_op == "inverse-product":
                        vehicle.setVar(
                            var,
                            vehicle.getOriginalVal(var) / test_vals[test_no])
                    elif test_op == "replace":
                        vehicle.setVar(var, test_vals[test_no])

                    # alter the test2 variables as need be
                    for test2_no in range(num_ytests):
                        # alter the variables as need be
                        for var2_no, var2 in enumerate(targets2):
                            test_op2 = operations2[var2_no]
                            test_vals2 = test_points2[var2_no]

                            if test_op2 == "product":
                                vehicle.setVar(
                                    var2,
                                    vehicle.getOriginalVal(var2) *
                                    test_vals2[test2_no])
                            elif test_op2 == "inverse-product":
                                vehicle.setVar(
                                    var2,
                                    vehicle.getOriginalVal(var2) /
                                    test_vals2[test2_no])
                            elif test_op2 == "replace":
                                vehicle.setVar(var2, test_vals2[test2_no])

                        # solve under the new conditions
                        if s_OBJ["steady_state"][seg_no]:
                            #print('steady as she goes')
                            output.append(
                                sim_pkg.steady_solve(vehicle.v,
                                                     segList[seg_no]))
                        else:
                            output.append(
                                sim_pkg.solve(vehicle.v, segList[seg_no]))

                        times[seg_no, test_no, test2_no] = output[-1][-1,
                                                                      O_TIME]
                        co2s[seg_no, test_no, test2_no] = output[-1][-1, O_CO2]
                        lat_accels[seg_no, test_no,
                                   test2_no] = output[-1][-2, O_LAT_ACC]

                        print("\t\t\tTest parameter " + str(test2_no + 1) +
                              " complete!")

        print("Done!")
        return StudyRecord(filename, study_text, timestamp_start, time.time(),
                           output, times, co2s, lat_accels, segList, s_OBJ,
                           "3D")

    except KeyError as e:  # run 2D test
        print("Running tests...")

        # set up some preliminary values
        num_tests = len(test_points[0])
        if "plot_points" in s_OBJ and isinstance(s_OBJ["plot_points"], list):
            pass
        else:
            s_OBJ['plot_points'] = tests[0]["test_vals"]

        times = np.zeros((len(segList), num_tests))
        co2s = np.zeros((len(segList), num_tests))

        lat_accels = np.zeros((len(segList), num_tests))

        # run 1D study
        for seg_no in range(len(segList)):
            print("\tTesting track " + str(seg_no + 1) + "...")

            for test_no in range(num_tests):
                # alter the variables as need be
                for var_no, var in enumerate(targets):
                    test_op = operations[var_no]
                    test_vals = test_points[var_no]

                    if test_op == "product":
                        vehicle.setVar(
                            var,
                            vehicle.getOriginalVal(var) * test_vals[test_no])
                    elif test_op == "inverse-product":
                        vehicle.setVar(
                            var,
                            vehicle.getOriginalVal(var) / test_vals[test_no])
                    elif test_op == "replace":
                        vehicle.setVar(var, test_vals[test_no])

                # solve under the new conditions
                if s_OBJ["steady_state"][seg_no]:
                    #print('steady as she goes')
                    output.append(
                        sim_pkg.steady_solve(vehicle.v, segList[seg_no]))
                else:
                    output.append(sim_pkg.solve(vehicle.v, segList[seg_no]))
                times[seg_no, test_no] = output[-1][-1, O_TIME]
                co2s[seg_no, test_no] = output[-1][-1, O_CO2]
                lat_accels[seg_no, test_no] = output[-1][-2, O_LAT_ACC]

                print("\t\tTest " + str(test_no + 1) + " complete!")
                # plot_velocity_and_events(output[test_no], "time")

        return StudyRecord(filename, study_text, timestamp_start, time.time(),
                           output, times, co2s, lat_accels, segList, s_OBJ)
Example #8
0
def process_web_config(config_text):
    config_stream = io.StringIO(config_text)
    conf = fancyyaml.load(config_stream, False)
    config_stream.close()

    return conf