示例#1
0
def test_multidimensional_power_law_fitting():
    np.random.seed(0)  # Set a seed for repeatability.

    ### Make some data z(x,y)
    x = np.logspace(0, 3)
    y = np.logspace(0, 3)
    X, Y = np.meshgrid(x, y, indexing="ij")
    noise = np.random.lognormal(mean=0, sigma=0.05)
    Z = 0.5 * X**0.75 * Y**1.25 * noise

    ### Fit data
    def model(x, p):
        return (p["multiplier"] * x["X"]**p["X_power"] * x["Y"]**p["Y_power"])

    x_data = {
        "X": X.flatten(),
        "Y": Y.flatten(),
    }

    fitted_model = FittedModel(
        model=model,
        x_data=x_data,
        y_data=Z.flatten(),
        parameter_guesses={
            "multiplier": 1,
            "X_power": 1,
            "Y_power": 1,
        },
        parameter_bounds={
            "multiplier": (None, None),
            "X_power": (None, None),
            "Y_power": (None, None),
        },
        put_residuals_in_logspace=True
        # Putting residuals in logspace minimizes the norm of log-error instead of absolute error
    )

    ### Check that the fit is right
    assert fitted_model.parameters["multiplier"] == pytest.approx(0.546105,
                                                                  abs=1e-3)
    assert fitted_model.parameters["X_power"] == pytest.approx(0.750000,
                                                               abs=1e-3)
    assert fitted_model.parameters["Y_power"] == pytest.approx(1.250000,
                                                               abs=1e-3)
        volume_insulator = area_insulator * wire_length
        mass_insulator = insulator_density * volume_insulator
    else:
        mass_insulator = 0

    # Total them up
    return mass_conductor + mass_insulator


if __name__ == '__main__':
    print(motor_electric_performance(rpm=100, current=3))
    print(motor_electric_performance(rpm=4700, torque=0.02482817))

    print(mass_battery_pack(100))

    pows = np.logspace(2, 5, 300)
    mass_mot_burton = mass_motor_electric(pows, method="burton")
    mass_mot_hobbyking = mass_motor_electric(pows, method="hobbyking")
    mass_mot_astroflight = mass_motor_electric(pows, method="astroflight")

    import matplotlib.pyplot as plt
    import seaborn as sns

    sns.set(palette=sns.color_palette("husl"))

    fig, ax = plt.subplots(1, 1, figsize=(6.4, 4.8), dpi=200)
    plt.loglog(pows, np.array(mass_mot_burton), "-", label="Burton Model")
    plt.plot(pows, np.array(mass_mot_hobbyking), "--", label="Hobbyking Model")
    plt.plot(pows,
             np.array(mass_mot_astroflight),
             "-.",
示例#3
0
    import plotly.express as px
    import pandas as pd

    # # Oxamide Function tests
    # oxamides = np.linspace(-0.3,0.5,200)
    # burn_rate_coefficients = burn_rate_coefficient(oxamides).toarray()
    # c_stars = c_star(oxamides)
    # min_combustion_pressures = dubious_min_combustion_pressure(oxamides)
    # gammas = gamma(oxamides)
    # px.scatter(x=oxamides,y=burn_rate_coefficients,labels={"x": "Oxamide", "y": "Burn Rate Coeff"}).show()
    # px.scatter(x=oxamides,y=c_stars,labels={"x": "Oxamide", "y": "c_star"}).show()
    # px.scatter(x=oxamides,y=min_combustion_pressures,labels={"x": "Oxamide", "y": "Min. Combustion Pressure"}).show()
    # px.scatter(x=oxamides,y=gammas,labels={"x": "Oxamide", "y": "Gamma"}).show()

    # # ER_from_P test
    chamber_pressure_inputs = np.logspace(5, 6, 200)
    exit_pressure_inputs = np.logspace(4, 5, 200)
    ox_for_test = 0
    chamber_pressures = []
    exit_pressures = []
    ers = []
    for chamber_pressure in chamber_pressure_inputs:
        for exit_pressure in exit_pressure_inputs:
            chamber_pressures.append(chamber_pressure)
            exit_pressures.append(exit_pressure)
            ers.append(
                expansion_ratio_from_pressure(chamber_pressure, exit_pressure,
                                              gamma(ox_for_test), ox_for_test))
    data = pd.DataFrame({
        'chamber_pressure': chamber_pressures,
        'exit_pressure': exit_pressures,