예제 #1
0
    data_values = initialize_data_values()
    # do the curve fitting
    for key in sorted(data):
        imin = 9
        imax = len(T)
        # fit the curve
        A, _ = opt.curve_fit(fitting_curve,
                             T[imin:imax],
                             data[key][imin:imax],
                             maxfev=1000000,
                             p0=(0., 1., 100., 1., 0.01, 0.01, 0.),
                             jac=jacobian_fitting_curve)
        A = round_parameters(*A)
        # compute the xi2 difference between the data values (in the fitting
        # interval) and the curve
        xi2 = sum((data[key][imin:imax] - fitting_curve(T[imin:imax], *A))**2)
        # output some info
        print "Transition:", key
        print_fit_variables(*A)
        print "convergence:", xi2
        print "validity: [", T[imin], ",", T[imax - 1], "]"
        # write the fitting code for this transition
        code += get_code("OII", transitions[key], *A)
        # add the values to the list strings
        append_data_values(data_values, *A)

        # plot the data and fit for visual comparison
        Trange = np.logspace(3., 5., 100)
        pl.plot(T, data[key], "k.")
        pl.plot(Trange, fitting_curve(Trange, *A), "r-")
        pl.xlim(0., 1.e5)
예제 #2
0
    imin = 0
    imax = len(T)
    # fit the curve
    A, _ = opt.curve_fit(
        fitting_curve,
        T[imin:imax],
        data[imin:imax],
        maxfev=1000000,
        method="trf",
        p0=(0.0, 1.0, 1.0, 1.0, 0.01, 0.01, 0.0),
        jac=jacobian_fitting_curve,
    )
    A = round_parameters(*A)
    # compute the xi2 difference between the data values (in the fitting
    # interval) and the curve
    xi2 = sum((data[imin:imax] - fitting_curve(T[imin:imax], *A)) ** 2)
    # output some info
    print("Transition: 0 to 1")
    print_fit_variables(*A)
    print("convergence:", xi2)
    print("validity: [", T[imin], ",", T[imax - 1], "]")
    # write the fitting code for this transition
    code += get_code("SIV", "REMOVE_THIS_BLOCK", *A)
    # add the values to the list strings
    append_data_values(data_values, *A)

    # plot the data and fit for visual comparison
    Trange = np.logspace(3.0, 5.0, 100)
    pl.plot(T, data, "k.")
    pl.plot(Trange, fitting_curve(Trange, *A), "r-")
    pl.xlim(0.0, 1.0e5)