Commit 93a0fde1 authored by Tung, Chi-Huan's avatar Tung, Chi-Huan
Browse files

handle with undetermined error

parent 40731907
Loading
Loading
Loading
Loading
Loading
+29 −4
Original line number Diff line number Diff line
@@ -110,15 +110,40 @@ def fit(initial_guess, file_name):
    # report_fit(result)
    
    for param in result.params.values():
        if param.stderr is None: 
            string = "%s:  %f +/- undetermined (init = %f)" % (param.name, param.value, param.init_value)
        else:
            string = "%s:  %f +/- %f (init = %f)" % (param.name, param.value, param.stderr, param.init_value)
        print(string)

    # plot the result
    fig = plt.figure(figsize=(6, 6))
    ax = plt.subplot(1, 1, 1)

    ax.plot(QD_exp,IQ_exp,'.b',label='SANS data')
    ax.plot(QD_exp,IQ_th(result.params, QD),'-r',label='SANS data')

    ax.set_yscale('log')
    ax.set_xscale('log')

    # ax.set_xlim([2,40])
    # ax.set_ylim([0.2,4000])
    ax.set_xlabel(r'$QD$',fontsize=20)
    ax.set_ylabel(r'$I(QD)$',fontsize=20)
    ax.tick_params(direction='in', axis='both', which='both', labelsize=18, pad=10)
    ax.legend(fontsize=16,frameon=False)
    plt.savefig('output.png')
    # plt.show()

    # print the result
    print('Printing results to output.txt')
    with open('/src/output.txt', 'w') as f:
        for param in result.params.values():
            if param.stderr is None: 
                string = "%s:  %f +/- undetermined (init = %f)" % (param.name, param.value, param.init_value)
            else:
                string = "%s:  %f +/- %f (init = %f)" % (param.name, param.value, param.stderr, param.init_value)
            print(string)
            f.write(string)


if __name__ == '__main__':