shuffle(pairs) else: raise NotImplementedError # Sampling points points = pairs.points # TODO Add design points; e.g. corners of the plot #from plotting import lllat, lllon, urlat, urlon #grid = np.rec.fromarrays(np.mgrid[lllat:urlat:5j, lllon:urlon:5j], dtype=dt_latlon) #points = np.concatenate( (pairs.points, grid.flatten())) # A priori assumptions mu_C = np.full_like(points, mu, dtype=np.float) # The velocity models a priori mean # A priori covariance cov_CC = gauss_kernel(points[:, np.newaxis], points[np.newaxis, :], tau, ell) # Open HDF5 file handle output_file = config.get('Output', 'filename') fh = h5py.File(output_file, 'w') # Store stations fh.create_dataset('stations', data=pairs.stations) # Store discretization fh.create_dataset('points', data=points) # Store prior covariance matrix fh.create_dataset('cov_CC_pri', data=cov_CC) # Create datasets for mean, standard deviation and misfit dset_mu = fh.create_dataset('mu', (len(pairs) + 1, ) + mu_C.shape) dset_sd = fh.create_dataset('sd', (len(pairs) + 1, ) + mu_C.shape) increment = 20 shp_misfit = (max(1, len(pairs) / increment) + 1, )
def __call__(self, crd): res = np.full_like(crd, self._v0, dtype=np.float) for v, x, r in zip(self._vs, self._xs, self._rs): res += v * gauss_kernel(crd, x, ell=r, tau=1) return res
# Open HDF5 file handle output_file = config.get('Output', 'filename') fh = h5py.File(output_file, 'w') # Store stations fh.create_dataset('stations', data=pairs.stations) # Get discretization points = pairs.points # Store discretization fh.create_dataset('points', data=points) # A priori mean and assumed covariance mu_C = np.full_like(points, mu, dtype=np.float) cov_CC = gauss_kernel(points.reshape(1, -1), points.reshape(-1, 1), ell=ell, tau=tau) # Prior predictive mean and covariance mu_D_pri = pairs.mu_T(mu_C) cov_DD_pri = pairs.cov_TT(mu_C, cov_CC) # Store prior assumptions dset_mu = fh.create_dataset('mu', (2, ) + mu_C.shape) dset_mu[0, :] = mu_C dset_sd = fh.create_dataset('sd', (2, ) + mu_C.shape) dset_sd[0, :] = np.sqrt(cov_CC.diagonal()) fh.create_dataset('cov_DD_pri', data=cov_DD_pri) # Store prior misfit dt_misfit = np.dtype([('evd', np.int), ('val', float)]) dset_misfit = fh.create_dataset('misfit', (2, ), dtype=dt_misfit) dset_misfit[0] = 0, pairs.misfit(mu_C, cov_CC)
zorder=10) # Find stations which are the furtherest apart pair = max(pairs, key=lambda pair: pair.central_angle) # Middle point of the great circle path p = pair.great_circle_path[12] # Make a lat, lon grid round the middle point N = 100j lllat = p['lat'] - 1 urlat = p['lat'] + 1 lllon = p['lon'] - 1.5 urlon = p['lon'] + 1.5 grid = np.rec.fromarrays(np.mgrid[lllat:urlat:N, lllon:urlon:N], dtype=dt_latlon) # Calculate kernel at the middle point K = gauss_kernel(p, grid, tau=tau, ell=ell) K = np.ma.masked_less(K, K.max() / 50) # Plot correlation kernel; pcolor needs points in between lat, lon = np.mgrid[lllat:urlat:N + 1j, lllon:urlon:N + 1j] pcol = m.pcolormesh(lon, lat, K, latlon=True, cmap=cmap_sd, rasterized=True, \ vmin=0, vmax=K.max(), zorder=1) # Make colorbar cbar = plt.colorbar(pcol, cax=ax_cbr, orientation='horizontal') cbar.set_label(r'$m^2 s^{-2}$') cbar.solids.set_edgecolor("face") plt.savefig('../fig_kernel_pri.pgf')
# Find stations which are the furtherest apart pair = max(pairs, key=lambda pair: pair.central_angle) # Parametrization of the great circle path path = pair.great_circle_path # Make a lat, lon grid with the extent of the path N = 200j lllat = min(pair.st1['lat'], pair.st2['lat']) - 0.5 urlat = max(pair.st1['lat'], pair.st2['lat']) + 0.5 lllon = min(pair.st1['lon'], pair.st2['lon']) - 1 urlon = max(pair.st1['lon'], pair.st2['lon']) + 1 grid = np.rec.fromarrays(np.mgrid[lllat:urlat:N, lllon:urlon:N], dtype=dt_latlon) # Calculate Correlations amongst great circle segment and grid K = gauss_kernel(path.reshape((-1, 1, 1)), grid, tau=tau, ell=ell) # Highlight parametrization of the great circle segment m.plot(path['lon'], path['lat'], latlon=True, lw=0.5, color='g') m.scatter(path['lon'][1:-1], path['lat'][1:-1], latlon=True, s=1, marker='.', color='g') xr, yr = m(path[-1]['lon'], path[-1]['lat']) xs, ys = m(path[0]['lon'], path[0]['lat']) ax_map.text(xr, yr, 'r', fontsize=12,