Esempio n. 1
0
def rupture_plot(filename, source_infos, conf_overrides=None, gmtconfig=None):
    conf = dict(**config.rupture_plot_config)
    if conf_overrides is not None:
        conf.update( conf_overrides )
    w = conf.pop('width')
    h = conf.pop('height')
    margins = conf.pop('margins')
    
    if gmtconfig is None:
        gmtconfig = {'LABEL_FONT_SIZE': '12p'}
    
    gmtconfig['PAPER_MEDIA'] = 'Custom_%ix%i' % (w,h)
    
    gmt = gmtpy.GMT( config=gmtconfig ) 
    
    layout = gmt.default_layout(with_palette=True)
    layout.set_fixed_margins(*margins)

    widget = layout.get_widget().get_widget(0,0)
    palette_widget = layout.get_widget().get_widget(2,0)
    
    xax, yax, zax = [ gmtpy_ax_from_autoplot_conf(conf,x) for x in ('x','y','z') ]    
    widget['J'] = '-JX%(width)gp/-%(height)gp'
    
    try:
        scaler, cptfile = draw_rupture(gmt, widget, source_infos, axes=(xax,yax,zax))
        gmt.psbasemap( *(widget.JXY() + scaler.RB(ax_projection=True)) )
        gmtpy.nice_palette( gmt, palette_widget, scaler, cptfile, zlabeloffset=1.5*gmtpy.cm )
    except NoOutlineFound:
        scaler = gmtpy.ScaleGuru([([0],[0])], axes=(xax,yax))
        gmt.pstext( in_rows=[(0,0,12,0,0,'MC','No rupture data!')],  *(scaler.R() + widget.XYJ()) )
    
    gmt.save(filename)
Esempio n. 2
0
guru = gmtpy.ScaleGuru([(xx, yy, zz)], axes=(xax, yax, zax))

grdfile = gmt.tempfilename()
cptfile = gmt.tempfilename()

par = guru.get_params()
inc_interpol = ((par['xmax'] - par['xmin']) /
                (widget.width() / gmtpy.inch * 50.),
                (par['ymax'] - par['ymin']) /
                (widget.height() / gmtpy.inch * 50.))

rxyj = guru.R() + widget.XYJ()

gmt.surface(T=0.3,
            G=grdfile,
            I=inc_interpol,
            in_columns=(xx, yy, zz),
            out_discard=True,
            *guru.R())
gmt.makecpt(I=True, C="hot", Z=True, out_filename=cptfile, *guru.T())
gmt.psclip(in_columns=outline, *rxyj)
gmt.grdimage(grdfile, C=cptfile, *rxyj)
gmt.grdcontour(grdfile, C=cptfile, *rxyj)
gmt.psclip(C=True, *widget.XY())
gmt.psbasemap(*(widget.JXY() + guru.RB(ax_projection=True)))

gmtpy.nice_palette(gmt, palette_widget, guru, cptfile)

gmt.save('example5.pdf', bbox=layout.bbox())
Esempio n. 3
0
def misfogram_plot_2d_gmtpy(data, filename, conf_overrides, apply_moment_to_magnitude_hack=False):
    
    conf = dict(**config.misfogram_plot_2d_gmtpy_config)
    if conf_overrides is not None:
        conf.update( conf_overrides )
        
    if apply_moment_to_magnitude_hack:
        data = list(data)
        moment_to_magnitude_hack( conf, data, 'x')
        moment_to_magnitude_hack( conf, data, 'y')            
                
    w = conf.pop('width')
    h = conf.pop('height')
    margins = conf.pop('margins')
    symbols_SGW = conf.pop('symbols_SGW')
    misfit_cpt = conf.pop('misfit_cpt')
    zlabeloffset = conf.pop('zlabeloffset')
    
    gmtconfig = {}
    for k in conf.keys():
        if k.upper() == k:
            gmtconfig[k] = conf[k]
    
    gmtconfig['PAPER_MEDIA'] = 'Custom_%ix%i' % (w,h)
    
    gmt = gmtpy.GMT( config=gmtconfig ) 
    
    layout = gmt.default_layout(with_palette=True)
    layout.set_fixed_margins(*margins)

    widget = layout.get_widget().get_widget(0,0)
    palette_widget = layout.get_widget().get_widget(2,0)
    
    axes = [ gmtpy_ax_from_autoplot_conf(conf,x) for x in ('x','y','z') ]
    scaler = gmtpy.ScaleGuru( data[0:2], axes=axes )
    
    grdfile = gmt.tempfilename()
    cptfile = gmt.tempfilename()
    
    par = scaler.get_params()
    inc_interpol = ((par['xmax']-par['xmin'])/(widget.width()/gmtpy.inch*150.),
                    (par['ymax']-par['ymin'])/(widget.height()/gmtpy.inch*150.))
    inc_interpol = (1./(widget.width()/gmtpy.inch*150.),
                    1./(widget.height()/gmtpy.inch*150.))
    
    r = scaler.R()
    rxyj = scaler.R() + widget.JXY()
    x,y,z = data[0]
    x, xo, xs = to_01(x)
    y, yo, ys = to_01(y)
    xyz_sorted = sorted([ xyz_ for xyz_ in zip(x,y,z) ])
    xyz_sorted.sort()
        
    gmt.triangulate(in_rows=xyz_sorted, G=grdfile, I=inc_interpol, out_discard=True, R=(0,1,0,1))#*r)
    gmt.grdedit( grdfile, R=(xo,xo+xs,yo,yo+ys), out_discard=True)
    gmt.makecpt( I=True, C=misfit_cpt, Z=True, out_filename=cptfile, *scaler.T())
    gmt.grdimage( grdfile, C=cptfile, *rxyj)
    gmt.grdcontour( grdfile, W='1p', C=cptfile, *rxyj )
    gmtpy.nice_palette( gmt, palette_widget, scaler, cptfile, zlabeloffset=zlabeloffset)
    gmt.psxy( in_columns=data[2], *(symbols_SGW[1].split()+rxyj) )
    gmt.psxy( in_columns=data[1], *(symbols_SGW[0].split()+rxyj) )
    gmt.psbasemap( *(widget.JXY() + scaler.RB(ax_projection=True)) )

    gmt.save(filename)
Esempio n. 4
0
def location_map( filename, lat, lon, lat_delta, conf_overrides, source=None, 
                source_model_infos=None, receivers=None, 
                with_palette=False, shakemap_data=None, shakemap_range=None, shakemap_cpt=None, show_topo=True):

    conf = dict(**config.location_map_config)
    conf.update( conf_overrides )
    
    w = conf.pop('width')
    h = conf.pop('height')
    margins = conf.pop('margins')
        
    d2r = math.pi/180.0
    if source:
        slat, slon = lat, lon
        lat, lon = orthodrome.ne_to_latlon(lat,lon, source['north-shift'], source['east-shift'])
    
    south = lat - 0.5*lat_delta
    north = lat + 0.5*lat_delta
    if lat_delta > 20. or south < -80. or north > 80.:
        resolution = 5
        coastline_resolution = 'i'
        rivers=[]
    else:
        resolution = 1
        coastline_resolution = 'f'
        rivers = ['-Ir',]
        
    lon_delta = lat_delta/math.cos(lat*d2r)
    
    delta = lat_delta/360.*config.earthradius*2.*math.pi
    scale_km = gmtpy.nice_value(delta/10.)/1000.
    
    west = lon - 0.5*lon_delta
    east = lon + 0.5*lon_delta
    
    x,y,z = (west, east), (south,north), (-6000.,4500.)
    xax = gmtpy.Ax(mode='min-max', approx_ticks=4.)
    yax = gmtpy.Ax(mode='min-max', approx_ticks=4.)
    zax = gmtpy.Ax(mode='min-max', inc=1000., label='Height', scaled_unit='km', scaled_unit_factor=0.001)
    scaler = gmtpy.ScaleGuru( data_tuples=[(x,y,z)], axes=(xax,yax,zax))
    
    curcfg = {'TICK_PEN': '1.25p',
                                'TICK_LENGTH': '0.2c',
                                'ANNOT_FONT_PRIMARY': '1',
                                'ANNOT_FONT_SIZE_PRIMARY': '14p',
                                'LABEL_FONT': '1',
                                'LABEL_FONT_SIZE': '14p',
                                'CHAR_ENCODING': 'ISOLatin1+',
                                'D_FORMAT': '%.1f',
                                'PLOT_DEGREE_FORMAT':'DF',
                                'PAPER_MEDIA':'Custom_%ix%i' % (w,h),
                                'GRID_PEN_PRIMARY': 'thinnest/0/0/0' }
    
    #degree_format = 'dddF'
    #if scaler.get_params()['xinc'] < 1. or scaler.get_params()['yinc'] < 1.:
    #    degree_format = 'ddd:mmF'
        
    gmt = gmtpy.GMT( config=curcfg )
    
    if with_palette:
        layout = gmt.default_layout(with_palette=True)
        layout.set_fixed_margins(*margins)
        widget = layout.get_widget().get_widget(0,0)
        palette_layout = gmtpy.FrameLayout()
        palette_layout.set_policy( *layout.get_widget().get_widget(2,0).get_policy() )
        layout.get_widget().set_widget(2,0,palette_layout)
        inset = h-margins[2]-margins[3]
        palette_layout.set_fixed_margins(0.,0.,inset/6., inset/6.)
        palette_widget = palette_layout.get_widget()
    else:
        layout = gmt.default_layout()
        layout.set_fixed_margins(*margins)
        widget = layout.get_widget()
        
    widget['J'] =  ('-JT%g/%g'  % (lon, lat)) + '/%(width)gp'
    aspect = gmtpy.aspect_for_projection( *(widget.J() + scaler.R()) )
    widget.set_aspect(aspect)
    
    if show_topo:
        cptfile = draw_topo(gmt, widget.JXY(), (west,east,south,north), resolution, coastline_resolution, rivers, conf)
    
    zscaler = scaler
    if shakemap_data is not None:
        cptfile, zscaler = draw_shakemap( gmt, widget, scaler, (xax,yax,zax), 
                shakemap_range, shakemap_cpt, *shakemap_data)
        draw_coastlines(gmt, widget.JXY(), (west,east,south,north),  coastline_resolution, rivers)
    
    if source_model_infos and source:
        try:
            draw_rupture(gmt, widget, source_model_infos, axes=(xax,yax,zax), view='from-top', source_loc=(slat,slon), outer_scaler=scaler, with_centroids=False)
        except NoOutlineFound:
            gmt.psxy( in_rows=[[lon,lat]], S='c20p', W='2p,0/0/0',  *(widget.JXY()+scaler.R()))
    
    else:
        if source and 'strike' in source.keys() and 'dip' in source.keys() and 'slip-rake' in source.keys():
            gmt.psmeca( in_rows=[[lon, lat, 1., source['strike'], source['dip'], source['slip-rake'], 6., 0.,0., '' ]],
                     S='a0.3', *(widget.JXY()+scaler.R()) )
        else:
            gmt.psxy( in_rows=[[lon,lat]], S='c20p', W='2p,0/0/0',  *(widget.JXY()+scaler.R()))
    
    if receivers:
        rlats, rlons, rnames = receivers
        gmt.psxy( in_columns=(rlons, rlats), S='t12p', W='1p,black', G='red', *(widget.JXY()+scaler.R()))
        
        nr = len(rnames)
        size = [7]*nr
        angle = [0]*nr
        fontno = [1]*nr
        justify = ['MC']*nr
        gmt.pstext( in_columns=(rlons,rlats,size,angle,fontno,justify,rnames), D=(0.,-0.1), *(widget.JXY()+scaler.R()))
        
    if lat > 0:
        axes_layout = 'WSen'
    else:
        axes_layout = 'WseN'
        
    gmt.psbasemap( B=('%(xinc)gg%(xinc)g:%(xlabel)s:/%(yinc)gg%(yinc)g:%(ylabel)s:' % scaler.get_params())+axes_layout,
                   L=('x%gp/%gp/%g/%g/%gk' % (widget.width()/2., widget.height()/7.,lon,lat,scale_km) ),
                   *(widget.JXY()+scaler.R()) )
                   
    if with_palette and (show_topo or shakemap_data is not None):
        gmtpy.nice_palette(gmt, palette_widget, zscaler, cptfile, innerticks=False, zlabeloffset=1.5*gmtpy.cm)
    gmt.save(filename)
Esempio n. 5
0
xx, yy, zz = to_flat_xyz(x, y, z)

xax = gmtpy.Ax(label="Distance from Yoda")
yax = gmtpy.Ax(label="Height over Yoda")
zax = gmtpy.Ax(snap=True, label="The Force")

guru = gmtpy.ScaleGuru([(xx, yy, zz)], axes=(xax, yax, zax))

grdfile = gmt.tempfilename()
cptfile = gmt.tempfilename()

par = guru.get_params()
inc_interpol = (
    (par["xmax"] - par["xmin"]) / (widget.width() / gmtpy.inch * 50.0),
    (par["ymax"] - par["ymin"]) / (widget.height() / gmtpy.inch * 50.0),
)

rxyj = guru.R() + widget.XYJ()

gmt.surface(T=0.3, G=grdfile, I=inc_interpol, in_columns=(xx, yy, zz), out_discard=True, *guru.R())
gmt.makecpt(I=True, C="hot", Z=True, out_filename=cptfile, *guru.T())
gmt.psclip(in_columns=outline, *rxyj)
gmt.grdimage(grdfile, C=cptfile, *rxyj)
gmt.grdcontour(grdfile, C=cptfile, *rxyj)
gmt.psclip(C=True, *widget.XY())
gmt.psbasemap(*(widget.JXY() + guru.RB(ax_projection=True)))

gmtpy.nice_palette(gmt, palette_widget, guru, cptfile)

gmt.save("example5.pdf", bbox=layout.bbox())