def get_vlayer(offset_km=-5, layer='LAB'): z = np.arange(0, 300, 0.5) lats = np.arange(33, 43) lons = np.arange(-115, -102) t_LAB = 5 vs, bls, bis = define_models.load_all_models(z, lats, lons, t_LAB, '_highQ') # offset_km = -5 vlayer = np.zeros_like(vs[:, :, 0]) for ila in range(vs.shape[0]): for ilo in range(vs.shape[1]): if offset_km <= 0: if layer == 'Moho': # above top of Moho BL = bis[ila, ilo, 0] if layer == 'LAB': # above top of LAB BL = bis[ila, ilo, 2] else: if layer == 'Moho': # below bottom of Moho BL = bis[ila, ilo, 1] if layer == 'LAB': # below bottom of LAB BL = bis[ila, ilo, 3] offset = int(offset_km // np.diff(z[:2])) dind = BL + offset vlayer[ila, ilo] = vs[ila, ilo, dind] return vlayer
def load_stuff(): z = np.arange(0, 300, 0.5) lats = np.arange(33, 43) lons = np.arange(-115, -102) t_LAB = 5 vs, bls, bis = define_models.load_all_models(z, lats, lons, t_LAB, '_highQ') half_tlab_i = int(t_LAB / np.diff(z[:2]) / 2) v_above_LAB = np.zeros_like(vs[:, :, 0]) v_below_LAB = np.zeros_like(v_above_LAB) v_above_Moho = np.zeros_like(v_above_LAB) v_below_Moho = np.zeros_like(v_above_LAB) av_grad_SCLM = np.zeros_like(v_above_LAB) max_grad_SCLM = np.zeros_like(v_above_LAB) min_grad_SCLM = np.zeros_like(v_above_LAB) for ila in range(vs.shape[0]): for ilo in range(vs.shape[1]): v_above_Moho[ila, ilo] = vs[ila, ilo, bis[ila, ilo, 0]] v_below_Moho[ila, ilo] = vs[ila, ilo, bis[ila, ilo, 1]] v_above_LAB[ila, ilo] = vs[ila, ilo, bis[ila, ilo, 2]] v_below_LAB[ila, ilo] = vs[ila, ilo, bis[ila, ilo, 3]] av_grad_SCLM[ila, ilo] = ( (v_above_LAB[ila, ilo] - v_below_Moho[ila, ilo]) / (z[bis[ila, ilo, 2]] - z[bis[ila, ilo, 1]])) max_grad_SCLM[ila, ilo] = (max( np.diff(vs[ila, ilo, bis[ila, ilo, 1]:bis[ila, ilo, 2] + 1]) / np.diff(z[:2]))) min_grad_SCLM[ila, ilo] = (min( np.diff(vs[ila, ilo, bis[ila, ilo, 1]:bis[ila, ilo, 2] + 1]) / np.diff(z[:2]))) return (z, lats, lons, vs, bls, bis, v_above_LAB, v_below_LAB, v_above_Moho, v_below_Moho, av_grad_SCLM, max_grad_SCLM, min_grad_SCLM)
def load_models(zmax=350): z = np.arange(0, min((zmax, 350)), 0.5) lats = np.arange(34, 41) #(33, 41) lons = np.arange(-114, -106) #(-117, -102) t_LAB = 5 vs, bls, bis = define_models.load_all_models(z, lats, lons, t_LAB, '_smoothed') return vs, bls, bis, z, lats, lons
def plot_v_model_comparison_on_map(): z = np.arange(0, 300, 0.5) lats = np.arange(33, 43) lons = np.arange(-115, -105) t_LAB = 5. vs, bls, bis = define_models.load_all_models(z, lats, lons, t_LAB) lit_models = ('Y14','P14','P15','C15','S15','SR16','F18') vs_lit = np.zeros((vs.shape[0], vs.shape[1], vs.shape[2], len(lit_models))) cp_outline = pd.read_csv('data/earth_models/CP_outline.csv').values cp_outline = np.vstack((cp_outline, cp_outline[0, :])) f = plt.figure(figsize=(8, 12)) a = f.add_axes([0.1, 0.1, 0.7, 0.8], aspect=1.2) a.plot(cp_outline[:, 1], cp_outline[:, 0], '-', color='#BDBDBD') a.set(xlim=[lons[0]-0.5, lons[-1]+0.5], ylim=[lats[0]-0.5, lats[-1]+0.5], xlabel='Longitude (W)', ylabel='Latitude (N)') a_leg = f.add_axes([0.85, 0.3, 0.1, 0.4]) i = 0 cols = [] for mod in lit_models: vs_lit[:, :, :, i] = constraints.interpolate_lit_model(mod, z, lats, lons) p = a_leg.plot([0, 1], [i] * 2) cols += [p[0].get_color()] a_leg.text(1.5, i, mod, va='center') i += 1 a_leg.set_axis_off() a_leg.set_xlim([0, 3]) vlim = (3.5, 4.7) zlim = (0, 150) vz = vs[:, :, (zlim[0] <= z) & (z < zlim[1])] vs_lit_z = vs_lit[:, :, (zlim[0] <= z) & (z < zlim[1]), :] for ila in range(len(lats)): for ilo in range(len(lons)): pz = np.linspace(lats[ila] + 0.5, lats[ila] - 0.5, vz.shape[2]) i = 0 for mod in lit_models: a.plot(_scale_vel_profile(vs_lit_z[ila, ilo, :, i], vlim, lons[ilo]), pz, linewidth=2, color=cols[i]) i += 1 a.plot(_scale_vel_profile(vz[ila, ilo, :], vlim, lons[ilo]), pz, 'k-', linewidth=2) a.plot(lons[ilo] + np.array([-0.5, -0.5, 0.5, 0.5, -0.5]), lats[ila] + np.array([-0.5, 0.5, 0.5, -0.5, -0.5]), color='#F7F7F7', linewidth=2)
def plot_BLs_dVs_map(t_LAB=5.): f = plt.figure(figsize=(14, 6)) ax_bl1 = f.add_axes([0.1, 0.2, 0.4, 0.7]) ax_bl2 = f.add_axes([0.55, 0.2, 0.4, 0.7]) z = np.arange(0, 300, 5) lats = np.arange(33, 43) lons = np.arange(-115, -105) vs, bls, bis = define_models.load_all_models(z, lats, lons, t_LAB) cp_outline = pd.read_csv('data/earth_models/CP_outline.csv').values cp_outline = np.vstack((cp_outline, cp_outline[0, :])) im = ax_bl1.imshow(bls[:, :, 2] * 100, cmap=plt.cm.RdBu_r, aspect=1.4, vmin=0, vmax=np.quantile(bls[:, :, 2], 0.95) * 100) ax_bl1.set(xticks=range(len(lons)), xticklabels = abs(lons), yticks=range(len(lats)), yticklabels = lats, xlabel='Longitude (W)', ylabel='Latitude (N)') c1 = plt.colorbar(im, cax=f.add_axes([0.15, 0.1, 0.3, 0.02]), orientation='horizontal') c1.ax.set_xlabel('Moho dVs (%)') ax_bl1.set_title('Moho dVs') ax_bl1.set_ylim((0, len(lats) - 1)) ax_bl1.plot(cp_outline[:, 1] - lons[0], cp_outline[:, 0] - lats[0], 'k:') im2 = ax_bl2.imshow(bls[:, :, 3] * 100, cmap=plt.cm.RdBu, aspect=1.4, vmin=np.quantile(bls[:, :, 3], 0.05) * 100, vmax=0) ax_bl2.set(xticks=range(len(lons)), xticklabels = abs(lons), yticks=range(len(lats)), yticklabels = lats, xlabel='Longitude (W)', ylabel='Latitude (N)') c2 = plt.colorbar(im2, cax=f.add_axes([0.6, 0.1, 0.3, 0.02]), orientation='horizontal') c2.ax.set_xlabel('LAB dVs (%)') ax_bl2.set_title('LAB dVs') ax_bl2.set_ylim((0, len(lats) - 1)) ax_bl2.plot(cp_outline[:, 1] - lons[0], cp_outline[:, 0] - lats[0], 'k:') plt.savefig( '/media/sf_VM_Shared/rftests/map_BLdVs.png' )
def plot_results_map(depth, t_LAB=5., vmi=0, vma=0, ifsave=False): f = plt.figure(figsize=(6, 6)) ax_map = f.add_axes([0.1, 0.2, 0.8, 0.7]) z = np.arange(0, 300, 5) lats = np.arange(33, 43) lons = np.arange(-115, -105) vs, bls, bis = define_models.load_all_models(z, lats, lons, t_LAB) cp_outline = pd.read_csv('data/earth_models/CP_outline.csv').values cp_outline = np.vstack((cp_outline, cp_outline[0, :])) idep = np.argmin(abs(z - depth)) if vmi == 0: if z[idep] < 40: vmi = 3. vma = 4. else: vmi = 3.75 vma = 4.5 im = ax_map.imshow(vs[:, :, idep], cmap=plt.cm.RdBu, aspect=1.4, vmin=vmi, vmax=vma) ax_map.set(xticks=range(len(lons)), xticklabels = abs(lons), yticks=range(len(lats)), yticklabels = lats, xlabel='Longitude (W)', ylabel='Latitude (N)') c = plt.colorbar(im, cax=f.add_axes([0.15, 0.1, 0.7, 0.02]), orientation='horizontal') c.ax.set_xlabel('Vsv (km/s)') ax_map.set_title('Velocity slice at {} km'.format(z[idep])) ax_map.set_ylim((0, len(lats) - 1)) ax_map.plot(cp_outline[:, 1] - lons[0], cp_outline[:, 0] - lats[0], 'k:') if ifsave: plt.savefig( '/media/sf_VM_Shared/rftests/map_{}kmLAB_{}kmDepth.png'.format( t_LAB, z[idep] ) ) return ax_map
def plot_all_v_models_on_map(): z = np.arange(0, 350, 0.5) lats = np.arange(34, 41) lons = np.arange(-114, -106) t_LAB = 5 vs_older, bls, bis = define_models.load_all_models(z, lats, lons, 5, '_highQ') vs_old, bls, bis = define_models.load_all_models(z, lats, lons, 5, '_damped') vs, bls, bis = define_models.load_all_models(z, lats, lons, t_LAB, '_smoothed') #vs = constraints.interpolate_lit_model('P15', z, lats, lons) cp_outline = pd.read_csv('data/earth_models/CP_outline.csv').values cp_outline = np.vstack((cp_outline, cp_outline[0, :])) f = plt.figure(figsize=(10, 12)) a = f.add_axes([0.1, 0.1, 0.8, 0.8], aspect=1.2) a.plot(cp_outline[:, 1], cp_outline[:, 0], 'k-') a.set(xlim=[lons[0]-0.5, lons[-1]+0.5], ylim=[lats[0]-0.5, lats[-1]+0.5], xlabel='Longitude (W)', ylabel='Latitude (N)') vlim = (3.2, 4.8) zlim = (0, 350) vz = vs[:, :, (zlim[0] <= z) & (z < zlim[1])] #iiz = vz.shape[2] #np.argmax(z > 120) # vsold = vs_old[:, :, (zlim[0] <= z) & (z < zlim[1])] vsolder = vs_older[:, :, (zlim[0] <= z) & (z < zlim[1])] # maxv = (np.quantile(np.quantile(vz, 0.75, 0), 0.75, 0) - vlim[0]) / np.diff(vlim) - 0.5 # minv = (np.quantile(np.quantile(vz, 0.25, 0), 0.25, 0) - vlim[0]) / np.diff(vlim) - 0.5 lit_models = ('Y14', 'P14','P15','C15','S15','SR16','F18') vs_lit = np.zeros((vs.shape[0], vs.shape[1], vs.shape[2], len(lit_models))) i = 0 for mod in lit_models: vs_lit[:, :, :, i] = constraints.interpolate_lit_model(mod, z, lats, lons) i += 1 i = 0 for mod in lit_models: ds = constraints.load_literature_vel_model(mod) z_a = ds.depth.values if zlim[0] < z_a[0]: iz = np.argmax(z_a[0] < z) vs_lit[:, :, :iz, i] = np.median(vs_lit[:, :, :iz, :], 3) if z_a[-1] < zlim[1]: iz = np.argmax(z_a[-1] < z) vs_lit[:, :, iz:, i] = np.median(vs_lit[:, :, iz:, :], 3) i += 1 vs_lit_z = vs_lit[:, :, (zlim[0] <= z) & (z < zlim[1]), :] maxv = (np.max(vs_lit_z, 3) - vlim[0]) / np.diff(vlim) - 0.5 minv = (np.min(vs_lit_z, 3) - vlim[0]) / np.diff(vlim) - 0.5 maxv[maxv < -0.5] = -0.5 minv[minv < -0.5] = -0.5 for ila in range(len(lats)): for ilo in range(len(lons)): pz = np.linspace(lats[ila] + 0.5, lats[ila] - 0.5, vz.shape[2]) # a.fill(np.append(maxv + lons[ilo], minv[::-1] + lons[ilo]), # np.append(pz, pz[::-1]), color='#8B8B8B') a.fill(np.append(maxv[ila, ilo, :] + lons[ilo], minv[ila, ilo, ::-1] + lons[ilo]), np.append(pz, pz[::-1]), color='#8B8B8B') v = (vsolder[ila, ilo, :] - vlim[0]) / np.diff(vlim) - 0.5 v[v < -0.5] = -0.5 v += lons[ilo] a.plot(v, pz, 'c-', linewidth=1.5) v = (vsold[ila, ilo, :] - vlim[0]) / np.diff(vlim) - 0.5 v[v < -0.5] = -0.5 v += lons[ilo] a.plot(v, pz, 'b-', linewidth=1) v = (vz[ila, ilo, :] - vlim[0]) / np.diff(vlim) - 0.5 ilab = np.argmax(z > bls[ila, ilo, 1] + 5) # im = np.argmax(np.diff(v[ilab:-200]) <= 0) + ilab#np.argmin(v[ilab:]) + ilab v[v < -0.5] = -0.5 v += lons[ilo] a.plot([lons[ilo]] * len(pz), pz, 'k-', linewidth=0.5) a.plot(lons[ilo] + [-0.5, 0.5], [lats[ila]] * 2, 'k-', linewidth=0.5) a.plot(v, pz, 'r-', linewidth=1) # a.plot(v[:iiz], pz[:iiz], 'r-', linewidth=1) # if im > ilab: # a.plot(v, pz, 'b-', linewidth=1) a.plot(lons[ilo] + np.array([-0.5, -0.5, 0.5, 0.5, -0.5]), lats[ila] + np.array([-0.5, 0.5, 0.5, -0.5, -0.5]), color='#F7F7F7', linewidth=2)