def plot_events_and_GP(X, y, sgp): Xorig = X X = np.array(X[:, 0:2]) s = Sigvisa() fitz_location = [s.earthmodel.site_info("FITZ", 0)[0:2]] print fitz_location f = Figure((11, 8)) ax = f.add_subplot(111) fmean = lambda x, y: sgp.predict(np.array(((x, y, 0.0),))) fvar = lambda x, y: np.sqrt(sgp.variance(np.array(((x, y, 0.0),)))) hm = EventHeatmap(f=fmean, autobounds=X, autobounds_quantile=0.96, calc=True, n=200) hm.init_bmap(axes=ax) hm.plot_earth(y_fontsize=16, x_fontsize=16) hm.plot_locations(fitz_location, labels=None, marker="x", ms=10, mfc="none", mec="blue", mew=4, alpha=1) # hm.plot_locations(X, marker=".", ms=6, mfc="red", mec="none", mew=0, alpha=0.2) scplot = hm.plot_locations(X, marker=".", s=40, edgecolors="none", alpha=0.5, yvals=y, yval_colorbar=True) ax.set_frame_on(False) canvas = FigureCanvasAgg(f) canvas.draw() f.savefig("fitz_X.png", bbox_inches="tight", dpi=300, transparent=True) hm.plot_density(smooth=True, colorbar=False, nolines=True, cm=scplot.get_cmap(), vmin=0.0, vmax=2.4) canvas = FigureCanvasAgg(f) canvas.draw() f.savefig("fitz_X_gp.png", bbox_inches="tight", dpi=300, transparent=True) f = Figure((11, 8)) ax = f.add_subplot(111) hm = EventHeatmap(f=fvar, autobounds=X, autobounds_quantile=0.96, calc=True, n=200) hm.init_bmap(axes=ax) hm.plot_earth(y_fontsize=16, x_fontsize=16) hm.plot_locations(fitz_location, labels=None, marker="x", ms=10, mfc="none", mec="blue", mew=4, alpha=1) # hm.plot_locations(X, marker=".", ms=6, mfc="red", mec="none", mew=0, alpha=0.2) ax.set_frame_on(False) hm.plot_density(smooth=True, colorbar=True, nolines=True) canvas = FigureCanvasAgg(f) canvas.draw() f.savefig("fitz_X_gp_std.png", bbox_inches="tight", dpi=300, transparent=True)
def plot_tree(fname, include_points=True, max_depth=9999): X = np.loadtxt("fitzX.txt") f = open("fitztree.txt", "r") pts = [] for line in f: lon, lat, r, d = line.split(" ") if int(d) < max_depth: pts.append((float(lon), float(lat), float(r), int(d))) mypts = np.asarray(pts) pts = mypts # [0:5999:10, :] f = Figure((11, 8)) ax = f.add_subplot(111) hm = EventHeatmap(f=None, autobounds=X, autobounds_quantile=0.96, calc=False) normed_locations = [hm.normalize_lonlat(*location) for location in pts[:, 0:2]] hm.init_bmap(axes=ax, nofillcontinents=not include_points, coastlines=True) if include_points: hm.plot_earth(y_fontsize=16, x_fontsize=16) hm.add_stations(("FITZ",)) fitz_location = [Sigvisa().earthmodel.site_info("FITZ", 0)[0:2]] hm.plot_locations(fitz_location, labels=None, marker="x", ms=10, mfc="none", mec="blue", mew=4, alpha=1) for enum, ev in enumerate(normed_locations): x, y = hm.bmap(ev[0], ev[1]) radius = pts[enum, 2] / 111.0 depth = pts[enum, 3] if radius == 0 and include_points: hm.bmap.plot([x], [y], zorder=1, marker=".", ms=6, mfc="red", mec="none", mew=0, alpha=0.2) else: alpha = 1.0 / (np.sqrt(np.sqrt(depth) + 1.0)) ka = {"facecolor": "none", "edgecolor": "black", "linewidth": 1, "alpha": alpha} ax.add_patch(Circle((x, y), radius, **ka)) ax.set_frame_on(False) canvas = FigureCanvasAgg(f) canvas.draw() f.savefig(fname, bbox_inches="tight", dpi=300, transparent=True)