예제 #1
0
def plot_result(params, labels, xmin, xmax):
    """
    Plot result of inversion
    """
    
    deposit_c = []
    totalthick = []
    symbollist = ['-','-.','--',':','-','-.']
    
    #Calculate results from given parameter sets
    for j in range(len(params)):
        deposit_c.append([])
        totalthick.append([])
        (x, C, x_dep, deposit_c[j]) = fmodel.forward(params[j]) #best result
        cnum = fmodel.cnum #number of grain size classes
        totalthick[j] = np.sum(deposit_c[j],axis=0)
    
    #Correction of offset of x coordinate
    #This is necessary because the seaward end of calculation domain is
    #assumed to be x=0
    x_dep = x_dep + spoints[0]
    
    
    #Formatting plot area
    plt.figure(num=None, figsize=(7, 8.5), dpi=150, facecolor='w', edgecolor='k')
    fp = FontProperties(size=9)
    plt.rcParams["font.size"] = 9
        
    plt.subplot(cnum+1,1,1)
    plt.plot(spoints, np.sum(deposit_o,axis=0),marker='o', markersize=4,\
             fillstyle='none', linestyle = 'None', label = "Observation")
    for l in range(len(params)):
        plt.plot(x_dep[xmin:xmax], totalthick[l][xmin:xmax], symbollist[l],\
                 linewidth = 0.75, label = labels[l])
    plt.title('Total Thickness')
    plt.ylabel('Thickness (m)')
    plt.yscale("log")
    plt.ylim(0,0.4)
    plt.legend(prop = fp, loc='best', borderaxespad=1)
    
    for i in range(cnum):
        plt.subplot(cnum+1,1,i+2) #Prepare graphs
        plt.plot(spoints, deposit_o[i,:], marker = 'o', markersize=4,\
                 fillstyle='none', color = 'k', linestyle = 'None',\
                 label = "Observation")
        for k in range(len(params)):
            plt.plot(x_dep[xmin:xmax], deposit_c[k][i,xmin:xmax],\
                     symbollist[k], linewidth = 0.75, label = labels[k])
        if i == cnum - 1:
            plt.xlabel('Distance (m)')
        plt.ylabel('Sed. Vol. per \n Unit Area (m)')
        d = fmodel.Ds[i]*10**6
        gclassname='{0:.0f} $\mu$m'.format(d[0])
        plt.yscale("log")
        plt.ylim(0,0.4)
        plt.title(gclassname)
    
    plt.subplots_adjust(hspace=0.7)
    plt.show()
예제 #2
0
def save_result(resultfile, spointfile, depositfile, res):
    """
    Save the inversion results
    """
    #Calculate the forward model using the inversion result
    (x, C, x_dep, deposit_c) = fmodel.forward(res.x)

    #Save the best result
    fmodel.export_result(spointfile, depositfile)
    np.savetxt(resultfile, res.x)
예제 #3
0
def costfunction(optim_params):
    """
    Calculate objective function that quantifies the difference between
    field observations and results of the forward model calculation

    Fist, this function runs the forward model using a given set of parameters.
    Then, the mean square error of results was calculated.
    """
    (x, C, x_dep, deposit_c) = fmodel.forward(optim_params)
    f = ip.interp1d(x_dep, deposit_c, kind='cubic', bounds_error=False, fill_value=0.0)
    deposit_c_interp = f(spoints)
    dep_norm = np.matrix(np.max(deposit_o, axis = 1)).T
    residual = np.array((deposit_o - deposit_c_interp)/dep_norm)
    cost = np.sum((residual) ** 2)
    return cost