Ejemplo n.º 1
0
def plot_spatial_with_dcs(events, eventsclusters, clusters, conf, plotdir):
    '''
    Plot map of seismicity clusters, with focal mechanisms
    '''
    lats = [ev.lat for ev in events]
    lons = [ev.lon for ev in events]
    #    deps = [ev.depth for ev in events]
    #    colors = [cluster_to_color(clid) for clid in eventsclusters]

    if conf.sw_filterevent:
        latmin, latmax = conf.latmin, conf.latmax
        lonmin, lonmax = conf.lonmin, conf.lonmax
        #        depmin, depmax = conf.depthmin, conf.depthmax
        if latmin > latmax:
            print('cases over lon +-180 still to be implemented')
            sys.exit()
        center = model.event(0.5 * (latmin + latmax), 0.5 * (lonmin + lonmax))
    else:
        latmin, latmax = min(lats) - 0.1, max(lats) + 0.1
        lonmin, lonmax = min(lons) - 0.1, max(lons) + 0.1
        #        depmin = 0.*km
        #        depmax = 1.05*max(deps)
        center = od.Loc(0.5 * (latmin + latmax), 0.5 * (lonmin + lonmax))

    # Map size
    if conf.sw_manual_radius:
        safe_radius = conf.map_radius
    else:
        corners = [od.Loc(latmin, lonmin), od.Loc(latmin, lonmax)]
        dist1 = od.distance_accurate50m(center, corners[0])
        dist2 = od.distance_accurate50m(center, corners[1])
        safe_radius = max(dist1, dist2)

    # Generate the basic map
    m = Map(lat=center.lat,
            lon=center.lon,
            radius=safe_radius,
            width=30.,
            height=30.,
            show_grid=False,
            show_topo=False,
            color_dry=(238, 236, 230),
            topo_cpt_wet='light_sea_uniform',
            topo_cpt_dry='light_land_uniform',
            illuminate=True,
            illuminate_factor_ocean=0.15,
            show_rivers=False,
            show_plates=False)

    if conf.sw_filterevent:
        rectlons = [lonmin, lonmin, lonmax, lonmax, lonmin]
        rectlats = [latmin, latmax, latmax, latmin, latmin]
        m.gmt.psxy(in_columns=(rectlons, rectlats),
                   W='thin,0/0/0,dashed',
                   *m.jxyr)

    # Draw some larger cities covered by the map area
    m.draw_cities()

    # Events in clusters
    factor_symbl_size = 5.
    beachball_symbol = 'd'

    for id_cluster in clusters:
        col = cluster_to_color(id_cluster)
        g_col = color2rgb(col)
        for iev, evcl in enumerate(eventsclusters):
            if evcl == id_cluster:
                ev = events[iev]
                if ev.moment_tensor is not None:
                    factor_symbl_size = ev.magnitude
                    devi = ev.moment_tensor.deviatoric()
                    beachball_size = 3. * factor_symbl_size
                    mt = devi.m_up_south_east()
                    mt = mt / ev.moment_tensor.scalar_moment() \
                        * pmt.magnitude_to_moment(5.0)
                    m6 = pmt.to6(mt)

                    if m.gmt.is_gmt5():
                        kwargs = dict(M=True,
                                      S='%s%g' % (beachball_symbol[0],
                                                  (beachball_size) / gmtpy.cm))
                    else:
                        kwargs = dict(S='%s%g' %
                                      (beachball_symbol[0],
                                       (beachball_size) * 2 / gmtpy.cm))

                    data = (ev.lon, ev.lat, 10) + tuple(m6) + (1, 0, 0)

                    m.gmt.psmeca(in_rows=[data],
                                 G=g_col,
                                 E='white',
                                 W='1p,%s' % g_col,
                                 *m.jxyr,
                                 **kwargs)

    figname = os.path.join(plotdir, 'plot_map_with_dcs.' + conf.figure_format)
    m.save(figname)
Ejemplo n.º 2
0
def plot_spatial(events, eventsclusters, clusters, conf, plotdir):
    '''
    Plot map of seismicity clusters
    '''
    lats = [ev.lat for ev in events]
    lons = [ev.lon for ev in events]
    #    deps = [ev.depth for ev in events]
    #    colors = [cluster_to_color(clid) for clid in eventsclusters]

    if conf.sw_filterevent:
        latmin, latmax = conf.latmin, conf.latmax
        lonmin, lonmax = conf.lonmin, conf.lonmax
        #        depmin, depmax = conf.depthmin, conf.depthmax
        if latmin > latmax:
            print('cases over lon +-180 still to be implemented')
            sys.exit()
        center = model.event(0.5 * (latmin + latmax), 0.5 * (lonmin + lonmax))
    else:
        latmin, latmax = min(lats) - 0.1, max(lats) + 0.1
        lonmin, lonmax = min(lons) - 0.1, max(lons) + 0.1
        #        depmin = 0.*km
        #        depmax = 1.05*max(deps)
        center = od.Loc(0.5 * (latmin + latmax), 0.5 * (lonmin + lonmax))

    # Map size
    if conf.map_radius is not None:
        safe_radius = conf.map_radius
    else:
        corners = [od.Loc(latmin, lonmin), od.Loc(latmin, lonmax)]
        dist1 = od.distance_accurate50m(center, corners[0])
        dist2 = od.distance_accurate50m(center, corners[1])
        safe_radius = max(dist1, dist2)

    # Generate the basic map
    m = Map(lat=center.lat,
            lon=center.lon,
            radius=safe_radius,
            width=30.,
            height=30.,
            show_grid=False,
            show_topo=False,
            color_dry=(238, 236, 230),
            topo_cpt_wet='light_sea_uniform',
            topo_cpt_dry='light_land_uniform',
            illuminate=True,
            illuminate_factor_ocean=0.15,
            show_rivers=False,
            show_plates=False)

    if conf.sw_filterevent:
        rectlons = [lonmin, lonmin, lonmax, lonmax, lonmin]
        rectlats = [latmin, latmax, latmax, latmin, latmin]
        m.gmt.psxy(in_columns=(rectlons, rectlats),
                   W='thin,0/0/0,dashed',
                   *m.jxyr)

    # Draw some larger cities covered by the map area
    m.draw_cities()

    # Events in clusters
    for id_cluster in clusters:
        col = cluster_to_color(id_cluster)
        mylats, mylons = [], []
        for iev, evcl in enumerate(eventsclusters):
            if evcl == id_cluster:
                mylats.append(events[iev].lat)
                mylons.append(events[iev].lon)
        m.gmt.psxy(in_columns=(mylons, mylats),
                   S='c7p',
                   G=color2rgb(col),
                   *m.jxyr)

    figname = os.path.join(plotdir, 'plot_map.' + conf.figure_format)
    m.save(figname)