print( "either ydata or xdata contain NaNs, or if incompatible options are used" ) popt, pcov = [np.nan, np.nan], [[np.nan, np.nan], [np.nan, np.nan]] except OptimizeWarning: print("Covariance of the parameters could not be estimated.") # popt, pcov = [np.nan, np.nan], [[np.nan, np.nan],[np.nan, np.nan]] Sy = abs(popt[0]) T = abs(popt[1]) # calculate the fitted power spectra Shh_fitted = shh_analytical((frequency_input, Sww), Sy, T, x, L, m=n, n=m, norm=norm) # get the characteristic time tc = calc_tc(L, Sy, T, which="dupuit") # define a (discharge constant) # a = np.pi ** 2 * T / (4 * L ** 2) # define tc (characteristic time scale) # tc = Sy / a data = np.vstack((Shh, Shh_fitted)) labels = ["Shh numerical", "Shh fitted"] linestyle = ["-", "-"]
p0=initial_guess) return popt, pcov if __name__ == "__main__": popt, pcov = shh_analytical_fit( power_spectrum_input, power_spectrum_output, frequency_input, location=500, length=1000, m=2, n=2, norm=False, ) plt.loglog(power_spectrum_output, label="data", color="blue") plt.loglog( shh_analytical( (frequency_input, power_spectrum_input), popt[0], popt[1], x=500, L=1000, norm=False, ), label="fit", color="red", ) plt.legend() plt.show()
"aquifer_length": aquifer_length, "aquifer_thickness": aquifer_thickness, "len_scale": len_scale, "variance": var, "geomean": geomean, "harmean": harmean, "arimean": arimean, "mean": mean, "seed": seed, "dim": dim } results = results.append(other=results_temp, ignore_index=True, sort=False) # calculate the power spectra: Shh from ogs runs, Shh theoretical (geo, har, ari), Shh fitted Shh_geo = shh_analytical( (frequency, Sww), S, T_in_geo, obs_loc, aquifer_length, m=m, n=n, norm=norm ) Shh_har = shh_analytical( (frequency, Sww), S, T_in_har, obs_loc, aquifer_length, m=m, n=n, norm=norm ) Shh_ari = shh_analytical( (frequency, Sww), S, T_in_ari, obs_loc, aquifer_length, m=m, n=n, norm=norm ) Shh_fitted = shh_analytical( (frequency, Sww), popt[0], popt[1], obs_loc, aquifer_length, m=n, n=m,
"which": which, "recharge": get_filename_from_rfd_top_com(path_to_project), "aquifer_length": aquifer_length, "aquifer_thickness": aquifer_thickness, } results = results.append(other=results_temp, ignore_index=True, sort=False) # calculate the fitted power spectra Shh_fitted = shh_analytical( (frequency, Sww), popt[0], popt[1], obs_loc, aquifer_length, m=n, n=m, norm=norm, ) if norm == True: data = np.vstack((Shh_Sww, Shh_fitted)) elif norm == False: data = np.vstack((Shh, Shh_fitted)) labels = ["Shh numerical", "Shh fitted"] linestyle = ["-", "-"] # lims = [(1e-9,6e-6),(1e-6,1e5)] marker = ["", "d"] figtxt = "OGS Input Parameter: S = %1.3e, T1 = %1.3e, T2 = %1.3e" % (
"err_tc_ari": percent_difference_fraction( calc_tc(aquifer_length, S, T_in_ari), calc_tc(aquifer_length, popt[0], popt[1]) ), "obs_loc": obs_loc, "time_step_size": time_step_size, "time_steps": time_steps, "model_period": time_step_size * time_steps / 86400, "which": which, "recharge": get_filename_from_rfd_top_com(path_to_project) } results = results.append(other=results_temp, ignore_index=True, sort=False) # plot the power spectra: Shh from ogs runs, Shh theoretical, Shh fitted Shh_numerical = Shh Shh_theoretical = shh_analytical( (frequency, Sww), S, T, obs_loc, aquifer_length, m=5, n=5, norm=False ) Shh_fitted = shh_analytical( (frequency, Sww), popt[0], popt[1], obs_loc, aquifer_length, m=5, n=5, norm=False, ) data = np.vstack((Shh_numerical, Shh_fitted, Shh_geo, Shh_har, Shh_ari)) labels = ["Shh numerical", "Shh fitted", "Shh geometric mean", "Shh harmonic mean", "Shh arithmetic mean"] linestyle = ["-", "-", "--", "--", "--"] #lims = [(1e-9,6e-6),(1e-6,1e5)]
def plot_shh_anal_loc(): """ Function to plot multiple analytical power spectra along e.g. an aquifer in a 3D plot. Still not working because plot3d has issues with log scale ... """ # set parameters data_points = 8000 time_step_size = 86400 aquifer_length = 1000 Sy = 1e-1 T = 0.001 from calc_tc import calc_tc tc = calc_tc(aquifer_length, Sy, T) print(tc) import sys # add search path for own modules sys.path.append("/Users/houben/PhD/python/scripts/spectral_analysis") from shh_analytical import shh_analytical import numpy as np import matplotlib.pyplot as plt from matplotlib import cm from mpl_toolkits.mplot3d import Axes3D import scipy.fftpack as fftpack # create an input signal np.random.seed(123456789) input = np.random.rand(data_points) spectrum = fftpack.fft(input) # erase first half of spectrum spectrum = abs(spectrum[:round(len(spectrum) / 2)])**2 spectrum = spectrum # [1:] # X contains the different locations X = np.linspace(0, aquifer_length - 1, 10) X = [100, 900] # Y contains the frequencies, erase first data point because it's 0 Y = abs(fftpack.fftfreq(len(input), time_step_size))[:round(len(input) / 2)] Y = np.log10(Y[1:]) Z = np.zeros((len(Y), len(X))) for i, loc in enumerate(X): Z[:, i] = np.log10( shh_analytical((Y, spectrum), Sy=Sy, T=T, x=loc, L=aquifer_length, m=5, n=5, norm=False)) # erase first data point from Z for each location print(Z) print(Y) import matplotlib.pyplot as plt plt.plot(Y, Z[:, 0]) # plt.loglog(Y,Z[:,0]) # X, Y = np.meshgrid(X, Y) # fig = plt.figure() # ax = Axes3D(fig) # surf = ax.plot_surface( # X, Y, Z, rstride=1, cstride=2, shade=False, linewidth=1, cmap="Spectral_r" # ) # surf = ax.plot_wireframe(X, Y, Z, rstride=0, cstride=1, cmap=cm.magma) # surf.set_edgecolors(surf.to_rgba(surf._A)) # surf.set_facecolors("white") # ax1 = ax.plot_wireframe(X, Y, Z, rstride=1, cstride=0) # ax.set_xlabel("Location [m]") # ax.set_ylabel("Frequency [Hz]") # ax.set_zlabel("log Spectral Density") # ax.set_zscale("log") # ax.yaxis.set_scale("log") # ax.zaxis._set_scale('log') # ax.set_yscale("log") plt.show()
"either ydata or xdata contain NaNs, or if incompatible options are used" ) popt, pcov = [np.nan, np.nan], [[np.nan, np.nan], [np.nan, np.nan]] except OptimizeWarning: print("Covariance of the parameters could not be estimated.") #popt, pcov = [np.nan, np.nan], [[np.nan, np.nan],[np.nan, np.nan]] x = abs(popt[0]) L = abs(popt[1]) print("Obtained " + str(x) + "for x and " + str(L) + " for L.") # calculate the fitted power spectra Shh_fitted = shh_analytical( (frequency_input, Sww), Sy=Sy, T=T, x=x, L=L, m=n, n=m, norm=norm, ) Shh_target = shh_analytical( (frequency_input, Sww), Sy=Sy, T=T, x=200, L=1000, m=n, n=m, norm=norm, )
import numpy as np import matplotlib.pyplot as plt plt.ioff() T_list = [1e-2, 1e-3, 1e-4, 1e-5] S_list = [0.5, 0.4, 0.3, 0.2, 1e-1, 1e-2, 1e-3, 1e-4, 1e-5] length_list = [100, 200, 500, 1000, 2000, 5000, 10000, 20000, 50000] sww = np.loadtxt("/Users/houben/Desktop/shh_analytical_multi/sww.txt") frequency = np.loadtxt( "/Users/houben/Desktop/shh_analytical_multi/frequency.txt") directory = "/Users/houben/Desktop/shh_analytical_multi" X = (frequency, sww) for T in T_list: for S in S_list: for L in length_list: for x in np.linspace(0, L, 5): shh = shh_analytical(X, S, T, x, L, m=5, n=5, norm=False) plt.title("Transmissivity: " + str(T) + "\n" + "Storativity: " + str(S) + "\n" + "Length: " + str(L) + "\n" + "Location: " + str(x)) plt.loglog(frequency, shh) plt.ylim(10e-7, 10e13) plt.savefig(directory + "/" + str(T) + "_" + str(S) + "_" + str(L) + "_" + str(x) + ".png") print("saving " + str(T) + "_" + str(S) + "_" + str(L) + "_" + str(x) + ".png") plt.close()