Esempio n. 1
0
def main(treedump_fname, out_fname):
    f = open(treedump_fname, 'r')
    pts = []
    for line in f:
        lon,lat,r, d = line.split(" ")
        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=pts, autobounds_quantile=.9995, calc=False, )
    normed_locations = [hm.normalize_lonlat(*location) for location in pts[:, 0:2]]

    hm.init_bmap(axes=ax)
    hm.plot_earth(y_fontsize=16, x_fontsize=16)
    #hm.add_stations(("FITZ",))
    #fitz_location = [hm.sitenames[n][0:2] for n in hm.stations]
    #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:
            hm.bmap.plot([x], [y], zorder=1, marker=".", ms=6, mfc="red", mec="none", mew=0, alpha=0.2)
            pass
        else:
            if depth < 10:
                alpha = min(1.0, 5.0/(depth**2+1.0))

                ka = {'facecolor': 'none', 'edgecolor': 'black', 'linewidth': 1.5, 'alpha': alpha}
                ax.add_patch(Circle((x,y), radius, **ka))


    #hm.plot_locations(pts[:, 0:2], labels=None,
    #

    canvas = FigureCanvasAgg(f)
    canvas.draw()
    f.savefig(out_fname, bbox_inches="tight")
Esempio n. 2
0
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)