def predict_seismic(moho, lat, lon): """ Calculate the predicted Moho depth at the seismic points from the estimated model. Values are interpolated onto (lat, lon) from the given 'moho'. """ estimated = gridder.interp_at(moho.clat.ravel(), moho.clon.ravel(), moho.relief, lat, lon, extrapolate=True) return estimated
area = (lat.min(), lat.max(), lon.min(), lon.max()) sediments = { 'lon': lon, 'lat': lat, 'thickness': thickness, 'shape': shape, 'area': area } # Create top and bottom of sediments layer # ---------------------------------------- # Regrid dem to sediments regular grid sediments_top = gridder.interp_at(topography["lat"], topography["lon"], topography["topo"], sediments["lat"], sediments["lon"], algorithm="linear") sediments_top[np.isnan(sediments["thickness"])] = np.nan # Compute the median of the topography on basin points nans = np.isnan(sediments_top) sediments_top[~nans] = np.median(sediments_top[~nans]) # Add top and bottom arrays to sediments dictionary sediments["top"] = sediments_top sediments["bottom"] = sediments_top - sediments["thickness"] # Create Tesseroids model of the sediments layer # ---------------------------------------------- bottom, top = sediments["bottom"].copy(), sediments["top"].copy() top[nans] = 0 bottom[nans] = 0
p1, p2 = p #%% # find point position with respect to line equation defined by p1 and p2 U_a, p_a, bool_above, U_b, p_b = MALM.isabove(xp, yp, Uini, np.array(p1), np.array(p2)) # Compute p1 and p2 line equation ax + by + c = 0 a, b, c = MALM.slope(p1, p2) # Mirror points with respect to p1p2 line Umirror, xy_mirror = MALM.mirrorU_alongLine(U_a, p_a, bool_above, a, b, c) U_a_int = gridder.interp_at(xy_mirror[:, 0], xy_mirror[:, 1], Umirror, xp, yp, algorithm='cubic', extrapolate=True) # U_mirror_int = np.copy(U_a_int) U_mirror_int = np.copy(Uini) U_mirror_int[np.where(bool_above == True)[0]] = U_a_int[np.where( bool_above == True)[0]] plt.figure() plt.scatter(xp, yp, c=U_mirror_int, cmap='viridis', vmax=0.25) plt.colorbar() plt.axis('square') plt.show() #%% choose raw or mirrored field
p1, p2 = p #%% # find point position with respect to line equation defined by p1 and p2 U_a, p_a, bool_above, U_b, p_b = MALM.isabove(xp_r, yp_r, Uini, np.array(p1), np.array(p2)) # Compute p1 and p2 line equation ax + by + c = 0 a, b, c = MALM.slope(p1, p2) # Mirror points with respect to p1p2 line Umirror, xy_mirror = MALM.mirrorU_alongLine(U_a, p_a, bool_above, a, b, c) U_a_int = gridder.interp_at(xy_mirror[:, 0], xy_mirror[:, 1], Umirror, xp_r, yp_r, algorithm='nearest', extrapolate=True) U = np.copy(Uini) U[np.where(bool_above == True)[0]] = U_a_int[np.where(bool_above == True)[0]] plt.figure() plt.scatter(xp_r, yp_r, c=U, cmap='viridis', vmax=0.25) plt.colorbar() plt.axis('square') plt.show() plt.figure() plt.scatter(xp_r, yp_r, c=U_a_int, cmap='viridis', vmax=0.25) plt.colorbar() plt.axis('square')
def load_MALM_LandfillPorto(path, filename, shape=None, field=True, interp=True, radius=20): if field == True: file = open(path + 'PortoM.pkl', 'rb') u = pickle._Unpickler(file) u.encoding = 'latin1' data_struct = u.load() data_struct['HZ'] xA = (data_struct['HZ'][0][0] + data_struct['HZ'][0][1]) / 2 yA = data_struct['HZ'][0][2] AnoPos = [xA, yA] # x , y, z, U_raw = load_field_u_LandfillPorto(path, filename + '_uz0.dat') print('load' + str(path + filename) + '_uz0_grid.dat') x, y, z, U_raw = np.loadtxt(path + filename + '_uz0_grid.dat', unpack=True) # x , y, z = mesh_xyz # ------------------------------- Plot the data # plt.figure() # plt.scatter(x, y,c=U_raw, cmap='viridis',vmin=None, vmax=1) # plt.colorbar() # plt.axis('square') # plt.show() else: U_raw = load_obs(path, filename + '.txt') # load observation data RemLineNb, Injection, coordE, pointsE = load_geom( path) # find the geom file in the folder path nb, x, y, z = np.array(coordE[:-3]).T AnoPos = [] data_struct = [] # path2files="example_2add_later/Landfill_3d/Ano_0_E13/" # Test elec outside landfill # # path2files="example_2add_later/Landfill_3d/Ano_0_E89/" # Test 2 elec outside landfill # # path2files="example_2add_later/Landfill_3d/Ano_0_EA/" # Real A position without anomaly # # path2files="example_2add_later/Landfill_3d/Ano_1_BH_EA/" # Real A position with big hole anomaly # path2files="example_2add_later/Landfill_3d/Ano_1_SH_EA/" # Real A position with small hole anomaly # # path2files="examples/Landfill_3d/RealData_Ano_0/" # Real data / without anomaly # # path2files="examples/Landfill_3d/RealData_Ano_1_SH/" # Real data / with (small) anomaly # ----------------------------------------------------------------------------------------- if shape is None: shape = (31, 31) else: shape = shape # print(AnoPosxAyA) coords_liner, p1, p2, B = definep1p2(path, radius, AnoPos) xnew, ynew = creategrid(coords_liner, B, shape) # ------------- Raw data ----------------------------------------- # pEXP.plot_line(x, y, U_raw,p1,p2, title='U_raw', interp=interp) #, vmin=0.01, vmax=0.1, print(len(x)) print(len(U_raw)) print(len(xnew)) # ------------- Interpolation ----------------------------------------- U_int = gridder.interp_at(x, y, U_raw, xnew, ynew, algorithm='cubic', extrapolate=True) # xp,yp,U_int = gridder.interp(xnew,ynew,U,shape) # pEXP.plot_line(xnew, ynew, U_int,p1,p2,title='U_int', interp=interp) # ------------- correction of B + interpolation ---------------------- # remove influence of B if field == False: Ucor = uEXP.cor_field_B(x, y, z, U_raw, B, rho=10) else: Ucor = U_raw Ucor_int = gridder.interp_at(x, y, Ucor, xnew, ynew, algorithm='cubic', extrapolate=True) # xp,yp,Ucor_int = gridder.interp(xnew,ynew,Ucorint_tmp,shape) # pEXP.plot_line(xnew, ynew, Ucor_int,p1,p2, title='U_cor&int', interp=interp) # --------------- plot 2d maps ----------------------------------------- # plt.figure(figsize=(20,10)) # plt.subplot(2,2,1) # plt.tricontourf(x, y, U_raw, 50, cmap='viridis', vmin = 0.01, vmax = 1) # cbar = plt.colorbar(orientation='vertical', aspect=50) # cbar.set_label('$u_{B}$ (V)') # plt.plot(coords_liner[:,0],coords_liner[:,1],'*-') # plt.axis('square') # plt.subplot(2,2,2) # plt.tricontourf(x, y, Ucor, 50, cmap='viridis', vmin = 0.01, vmax = 1) # cbar = plt.colorbar(orientation='vertical', aspect=50) # cbar.set_label('$u_{Bcor}$ (V)') # plt.plot(coords_liner[:,0],coords_liner[:,1],'*-') # plt.axis('square') # plt.subplot(2,2,3) # plt.tricontourf(xnew, ynew, U_int, 50, cmap='viridis', vmin = 0.01, vmax = 1) # cbar = plt.colorbar(orientation='vertical', aspect=50) # cbar.set_label('$u_{Binterp}$ (V)') # plt.plot(coords_liner[:,0],coords_liner[:,1],'*-') # plt.axis('square') # plt.subplot(2,2,4) # plt.tricontourf(xp, yp, Ucor_int, 50, cmap='viridis', vmin = 0.01, vmax = 1) # cbar = plt.colorbar(orientation='vertical', aspect=50) # cbar.set_label('$u_{Bint&cor}$ (V)') # plt.plot(coords_liner[:,0],coords_liner[:,1],'*-') # plt.axis('square') # --------------------------------------- zp = 0 z = zp # --------------------------------------- p = [p1, p2] U = [U_raw, Ucor, U_int, Ucor_int] coord_xyz = [x, y, z] coord_xyz_int = [xnew, ynew, zp] max_elevation = 50 return coord_xyz, coord_xyz_int, U, coords_liner, shape, max_elevation, p, data_struct
#%% Mirror field against p1p2 # find point position with respect to line equation defined by p1 and p2 U_af, p_af, bool_abovef, U_bf, p_bf = MALM.isabove(xf, yf, uf, np.array(p1), np.array(p2)) # Compute p1 and p2 line equation ax + by + c = 0 af, bf, cf = MALM.slope(p1, p2) # Mirror points with respect to p1p2 line Umirrorf, xy_mirrorf = MALM.mirrorU_alongLine(U_af, p_af, bool_abovef, af, bf, cf) U_a_intf = gridder.interp_at(xy_mirrorf[:, 0], xy_mirrorf[:, 1], Umirrorf, xf, yf, algorithm='cubic', extrapolate=True) # U_mirror_int = np.copy(U_a_int) U_mirror_intf = np.copy(uf) U_mirror_intf[np.where(bool_abovef == True)[0]] = U_a_intf[np.where( bool_abovef == True)[0]] xf_mirror = np.hstack([xy_mirrorf[:, 0], p_af[:, 0]]) yf_mirror = np.hstack([xy_mirrorf[:, 1], p_af[:, 1]]) uf_mirror = np.hstack([Umirrorf, U_af]) #%% choose raw or mirrored field Uf = np.copy(uf)
plt.xlabel('x (m)') plt.ylabel('y (m)') prl = 60 # shape = shape (max(xp)-min(xp))/ # shape = (115,115) xint_scipy, yint_scipy = gridder.regular( (min(xp) - prl, max(xp) + prl, min(yp) - prl, max(yp) + prl), shape=shape) #%% Solution 1 # extrapolate False and fill with 0 before derivative - mask them later on U_int_scipy = gridder.interp_at(xp, yp, U, xint_scipy, yint_scipy, algorithm='cubic', extrapolate=False) InterpData = np.array([xint_scipy, yint_scipy, U_int_scipy]).T where_are_NaNs = np.isnan(InterpData) InterpData[where_are_NaNs] = 0.0074 xint_scipy, yint_scipy, U_int_scipy = InterpData.T plt.scatter(xint_scipy, yint_scipy) plt.scatter(xp, yp) #%% Solution 2 # Extrapolate = True # U_int_scipy = gridder.interp_at(xp,yp,U, xint_scipy, yint_scipy, algorithm='cubic', extrapolate=True)