Beispiel #1
0
    def test_simple(self):

        x = num.linspace(0., 2*math.pi)
        y = num.sin(x)
        y2 = num.cos(x)

        for version in gmtpy.all_installed_gmt_versions():
            for ymode in ['off', 'symmetric', 'min-max', 'min-0', '0-max']:
                plot = gmtpy.Simple(gmtversion=version, ymode=ymode)
                plot.plot((x, y), '-W1p,%s' % gmtpy.color('skyblue2'))
                plot.plot((x, y2), '-W1p,%s' % gmtpy.color(
                    gmtpy.color_tup('scarletred2')))
                plot.text((3., 0.5, 'hello'), size=20.)
                fname = 'gmtpy_test_simple_%s.png' % ymode
                fpath = self.fpath(fname)
                plot.save(fpath)
Beispiel #2
0
def draw_shakemap( gmt, widget, scaler, axes, shakemap_range, shakemap_cpt, lat, lon, *datasets):
    
    zax = gmtpy.Ax(mode='0-max', limits=shakemap_range, scaled_unit_factor=100., scaled_unit='cm/s^2', label='Peak Ground Acceleration', masking=False )
    
    zscaler = gmtpy.ScaleGuru([ (lat,lon,dataset) for dataset in datasets ],
        axes=(axes[0],axes[1],zax), 
        aspect=widget.height()/widget.width() )

    grdfile =  gmt.tempfilename()

    R = scaler.R()
    par = scaler.get_params()
    inc_interpol = (0.1*(par['xmax']-par['xmin'])/math.sqrt(len(datasets[0])),
                    0.1*(par['ymax']-par['ymin'])/math.sqrt(len(datasets[0])))
    rxyj = R + widget.XYJ()
        
    colors = gmtpy.color(0), gmtpy.color(1)

    zpar = zscaler.get_params()
    
    clip = (zpar['zinc']/2., zpar['zmax'])
        
    fn_cpt = gmt.tempfilename()
    gmt.makecpt( C=shakemap_cpt, out_filename=fn_cpt,  suppress_defaults=True, *zscaler.T())
    
    if len(datasets[0]) > 3:
        for dataset, color in zip(datasets, colors):
        
            gmt.surface( 
                in_columns=(lon,lat,dataset), 
                T=1,
                G=grdfile, 
                I=inc_interpol, 
                out_discard=True, 
                *R )
        
            gmt.grdimage( 
                grdfile,
                C=fn_cpt,
                #W='2p,%s' % color, 
                #G='d5c', 
                #L=clip,
                *rxyj )
                
    return fn_cpt, zscaler
Beispiel #3
0
def plot_phases_zpk(zpks, filename_pdf, fmin=0.001, fmax=100., nf=100):
    
    import gmtpy
    
    p = gmtpy.LogLinPlot(width=30*gmtpy.cm)
    for i, (zeros, poles, constant) in enumerate(zpks):
        f, h = evaluate(zeros, poles, constant, fmin, fmax, nf)
        phase = num.unwrap(num.angle(h)) /d2r
        p.plot((f, phase), '-W1p,%s' % gmtpy.color(i))

    p.save(filename_pdf)
Beispiel #4
0
def plot_phases_zpk(zpks, filename_pdf, fmin=0.001, fmax=100., nf=100):
    
    import gmtpy
    
    p = gmtpy.LogLinPlot(width=30*gmtpy.cm)
    for i, (zeros, poles, constant) in enumerate(zpks):
        f, h = evaluate(zeros, poles, constant, fmin, fmax, nf)
        phase = num.unwrap(num.angle(h)) /d2r
        p.plot((f, phase), '-W1p,%s' % gmtpy.color(i))

    p.save(filename_pdf)
Beispiel #5
0
def plot_amplitudes_zpk(zpks, filename_pdf, fmin=0.001, fmax=100., nf=100, fnorm=None):
    
    import gmtpy
    
    p = gmtpy.LogLogPlot(width=30*gmtpy.cm, yexp=0)
    for i, (zeros, poles, constant) in enumerate(zpks):
        f, h = evaluate(zeros, poles, constant, fmin, fmax, nf)
        if fnorm is not None:
            h /= evaluate_at(zeros, poles, constant, fnorm)

        amp = num.abs(h)
        p.plot((f, amp), '-W2p,%s' % gmtpy.color(i))

    p.save(filename_pdf)
Beispiel #6
0
def plot_amplitudes_zpk(zpks, filename_pdf, fmin=0.001, fmax=100., nf=100, fnorm=None):
    
    import gmtpy
    
    p = gmtpy.LogLogPlot(width=30*gmtpy.cm, yexp=0)
    for i, (zeros, poles, constant) in enumerate(zpks):
        f, h = evaluate(zeros, poles, constant, fmin, fmax, nf)
        if fnorm is not None:
            h /= evaluate_at(zeros, poles, constant, fnorm)

        amp = num.abs(h)
        p.plot((f, amp), '-W2p,%s' % gmtpy.color(i))

    p.save(filename_pdf)
Beispiel #7
0
def beachball_mt(mt, filename, sdr=None, **conf_overrides):
    
    conf = dict(**config.beachball_config)
    if conf_overrides is not None:
        conf.update( conf_overrides )
    
    w = conf.pop('width')
    h = conf.pop('height')
    margins = conf.pop('margins')
    
    indicate_plane = 0
    if 'indicate_plane' in conf:
        indicate_plane = conf.pop('indicate_plane')
    
    gmtconfig = {}
    for k in conf.keys():
        if k.upper() == k:
            gmtconfig[k] = conf[k]
    
    gmtconfig['PAPER_MEDIA'] = 'Custom_%ix%i' % (w,h)
    gmtconfig['PS_MITER_LIMIT'] = '180'
    
    gmt = gmtpy.GMT( config=gmtconfig ) 
    
    layout = gmt.default_layout()
    layout.set_fixed_margins(*margins)

    widget = layout.get_widget()
    
    if mt is not None:
        strike, dip, rake = mt.both_strike_dip_rake()[0]
    else:
        strike, dip, rake = sdr
    
    kwargs = dict( R=(-1.,1.,-1.,1.), S='a%gc' % (((w-margins[0]-margins[1])/gmtpy.cm)-2./28.34), in_rows=[[
                        0., 0., 1.,
                        strike, dip, rake, 
                        5., 0.,0., '' ]]) 
    
    #gmt.psmeca( *widget.JXY(), **kwargs )
    if indicate_plane == 0:
        gmt.psmeca( L='2p,black', G=conf['fillcolor'], *widget.JXY(), **kwargs )
    else:
        gmt.psmeca( L='1p,black,.', G=conf['fillcolor'], *widget.JXY(), **kwargs )        
        gmt.psmeca( T='%i/2p,%s' % (indicate_plane, gmtpy.color('black')), *widget.JXY(), **kwargs )
                
    gmt.save(filename)
    return filename
    
    
Beispiel #8
0
 def colors(self, color_key):
     return gmtpy.color(self.color_index[color_key])
Beispiel #9
0
 def colors(self, color_key):
     return gmtpy.color(self.color_index[color_key])
Beispiel #10
0
    zlabel = 'Time',
    zunit = 's',
)

rupture_vis_config = dict(
    symbol_nucleation_point = symbol_best_result.split(),
    rupture_cpt = kiwi_aux_file('cpt', 'rupture.cpt'),    
)

wh = 2.0*gmtpy.cm
mw = 0.1*gmtpy.cm
beachball_config = dict(
    width = wh,
    height= wh,
    margins = (mw,mw,mw,mw),
    fillcolor = gmtpy.color((0, 88, 156))
)

class Config:
    def __init__(self, *configs):
        '''Create configuration opject, based on config files, other config
           objects and dicts. Later entries override earlier.'''
        
        self.configs = configs
    
    def update(self, config):
        self.configs.append( config )
    
    def get_config(self, keys=None):
        
        configdict = {}
Beispiel #11
0
 def colors(self, color_key):
     ind = self.color_index[color_key]
     if ind == 0:
         return '0.5p,%s,6_4:2p' % gmtpy.color('black')
     else:
         return '0.5p,%s' % gmtpy.color(ind - 1)
Beispiel #12
0
    zsnap=True,
    zlabel='Time',
    zunit='s',
)

rupture_vis_config = dict(
    symbol_nucleation_point=symbol_best_result.split(),
    rupture_cpt=kiwi_aux_file('cpt', 'rupture.cpt'),
)

wh = 2.0 * gmtpy.cm
mw = 0.1 * gmtpy.cm
beachball_config = dict(width=wh,
                        height=wh,
                        margins=(mw, mw, mw, mw),
                        fillcolor=gmtpy.color((0, 88, 156)))


class Config:
    def __init__(self, *configs):
        '''Create configuration opject, based on config files, other config
           objects and dicts. Later entries override earlier.'''

        self.configs = configs

    def update(self, config):
        self.configs.append(config)

    def get_config(self, keys=None):

        configdict = {}
Beispiel #13
0
def mktrace(n):
    tmin = 1234567890.
    t = trace.Trace(tmin=tmin, deltat=0.05, ydata=num.empty(n,dtype=num.float))
    return t
    
def bandpass(t):
    t.bandpass(4, 0.1, 5.)
    
def lowpass_highpass(t):    
    t.lowpass(4,  5.)
    t.highpass(4, 0.1)

def bandpass_fft(t):
    t.bandpass_fft(0.1, 5.)
    
tab = []
for n in range(1,22):
    a = timeit(lambda: bandpass(mktrace(2**n)))
    b = timeit(lambda: lowpass_highpass(mktrace(2**n)))
    c = timeit(lambda: bandpass_fft(mktrace(2**n)))
    print 2**n, a, b, c
    tab.append((2**n, a,b,c))
   
a = num.array(tab).T
p = gmtpy.Simple()

for i in range(1,4):
    p.plot((a[0],a[i]), '-W1p,%s' % gmtpy.color(i))

p.save('speed_filtering.pdf')
Beispiel #14
0
    zsnap=True,
    zlabel='Time',
    zunit='s',
)

rupture_vis_config = dict(
    symbol_nucleation_point=symbol_best_result.split(),
    rupture_cpt=kiwi_aux_file('cpt', 'rupture.cpt'),
)

wh = 2.0 * gmtpy.cm
mw = 0.1 * gmtpy.cm
beachball_config = dict(width=wh,
                        height=wh,
                        margins=(mw, mw, mw, mw),
                        fillcolor=gmtpy.color((166, 179, 131)))


class Config:
    def __init__(self, *configs):
        '''Create configuration opject, based on config files, other config
           objects and dicts. Later entries override earlier.'''

        self.configs = configs

    def update(self, config):
        self.configs.append(config)

    def get_config(self, keys=None):

        configdict = {}
Beispiel #15
0
    zlabel = 'Time',
    zunit = 's',
)

rupture_vis_config = dict(
    symbol_nucleation_point = symbol_best_result.split(),
    rupture_cpt = kiwi_aux_file('cpt', 'rupture.cpt'),    
)

wh = 2.0*gmtpy.cm
mw = 0.1*gmtpy.cm
beachball_config = dict(
    width = wh,
    height= wh,
    margins = (mw,mw,mw,mw),
    fillcolor = gmtpy.color((166,179,131))
)

class Config:
    def __init__(self, *configs):
        '''Create configuration opject, based on config files, other config
           objects and dicts. Later entries override earlier.'''
        
        self.configs = configs
    
    def update(self, config):
        self.configs.append( config )
    
    def get_config(self, keys=None):
        
        configdict = {}