示例#1
0
def plot_erroneous_ne_to_latlon():
    import gmtpy
    import random
    import subprocess
    import time

    while True:
        w, h = 20, 15

        gsize = random.uniform(0., 1.) * 4. * 10.**random.uniform(4., 7.)
        north_grid, east_grid = num.meshgrid(
            num.linspace(-gsize / 2., gsize / 2., 11),
            num.linspace(-gsize / 2., gsize / 2., 11))

        north_grid = north_grid.flatten()
        east_grid = east_grid.flatten()

        lat_delta = gsize / earthradius * r2d * 2.
        lon = random.uniform(-180., 180.)
        lat = random.uniform(-90., 90.)

        print(gsize / 1000.)

        lat_grid, lon_grid = orthodrome.ne_to_latlon(lat, lon, north_grid,
                                                     east_grid)
        lat_grid_alt, lon_grid_alt = \
            orthodrome.ne_to_latlon_alternative_method(
                lat, lon, north_grid, east_grid)

        maxerrlat = num.max(num.abs(lat_grid - lat_grid_alt))
        maxerrlon = num.max(num.abs(lon_grid - lon_grid_alt))
        eps = 1.0e-8
        if maxerrlon > eps or maxerrlat > eps:
            print(lat, lon, maxerrlat, maxerrlon)

            gmt = gmtpy.GMT(
                config={
                    'PLOT_DEGREE_FORMAT': 'ddd.xxxF',
                    'PAPER_MEDIA': 'Custom_%ix%i' %
                    (w * gmtpy.cm, h * gmtpy.cm),
                    'GRID_PEN_PRIMARY': 'thinnest/0/50/0'
                })

            south = max(-85., lat - 0.5 * lat_delta)
            north = min(85., lat + 0.5 * lat_delta)

            lon_delta = lat_delta / math.cos(lat * d2r)

            delta = lat_delta / 360. * 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 = (west, east), (south, north)
            xax = gmtpy.Ax(mode='min-max', approx_ticks=4.)
            yax = gmtpy.Ax(mode='min-max', approx_ticks=4.)
            scaler = gmtpy.ScaleGuru(data_tuples=[(x, y)], axes=(xax, yax))
            scaler['R'] = '-Rg'
            layout = gmt.default_layout()
            mw = 2.5 * gmtpy.cm
            layout.set_fixed_margins(mw, mw, mw / gmtpy.golden_ratio,
                                     mw / gmtpy.golden_ratio)
            widget = layout.get_widget()
            # widget['J'] =  ('-JT%g/%g'  % (lon, lat)) + '/%(width)gp'
            widget['J'] = (
                '-JE%g/%g/%g' % (lon, lat, min(lat_delta/2., 180.)))\
                + '/%(width)gp'
            aspect = gmtpy.aspect_for_projection(*(widget.J() + scaler.R()))
            widget.set_aspect(aspect)

            gmt.psbasemap(B='5g5',
                          L=('x%gp/%gp/%g/%g/%gk' %
                             (widget.width() / 2., widget.height() / 7., lon,
                              lat, scale_km)),
                          *(widget.JXY() + scaler.R()))

            gmt.psxy(in_columns=(lon_grid, lat_grid),
                     S='x10p',
                     W='1p/200/0/0',
                     *(widget.JXY() + scaler.R()))
            gmt.psxy(in_columns=(lon_grid_alt, lat_grid_alt),
                     S='c10p',
                     W='1p/0/0/200',
                     *(widget.JXY() + scaler.R()))

            gmt.save('orthodrome.pdf')
            subprocess.call(['xpdf', '-remote', 'ortho', '-reload'])
            time.sleep(2)
        else:
            print('ok', gsize, lat, lon)
示例#2
0
def plot_erroneous_ne_to_latlon():
    import sys
    import gmtpy
    import random
    import subprocess
    import time
    
    while True:
        w,h = 20,15
    
        km = 1000.
        gsize = random.uniform(0.,1.)*4.*10.**random.uniform(4.,7.)
        north_grid, east_grid = num.meshgrid(num.linspace(-gsize/2.,gsize/2.,11) ,
                                             num.linspace(-gsize/2.,gsize/2.,11) )
        
        north_grid = north_grid.flatten()
        east_grid = east_grid.flatten()
        
        lat_delta = gsize/config.earthradius*r2d*2.
        lon = random.uniform(-180.,180.)
        lat = random.uniform(-90.,90.)
        
        print gsize/1000.
        
        lat_grid, lon_grid = ne_to_latlon(lat, lon, north_grid, east_grid)
        lat_grid_alt, lon_grid_alt = ne_to_latlon_alternative_method(lat, lon, north_grid, east_grid)
    
    
        maxerrlat = num.max(num.abs(lat_grid-lat_grid_alt))
        maxerrlon = num.max(num.abs(lon_grid-lon_grid_alt))
        eps = 1.0e-8
        if maxerrlon > eps or maxerrlat > eps:
            print lat, lon, maxerrlat, maxerrlon
        
            gmt = gmtpy.GMT( config={ 'PLOT_DEGREE_FORMAT':'ddd.xxxF',
                                    'PAPER_MEDIA':'Custom_%ix%i' % (w*gmtpy.cm,h*gmtpy.cm),
                                    'GRID_PEN_PRIMARY': 'thinnest/0/50/0' } )
        
            south = max(-85., lat - 0.5*lat_delta)
            north = min(85., lat + 0.5*lat_delta)
                
            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 = (west, east), (south,north)
            xax = gmtpy.Ax(mode='min-max', approx_ticks=4.)
            yax = gmtpy.Ax(mode='min-max', approx_ticks=4.)
            scaler = gmtpy.ScaleGuru( data_tuples=[(x,y)], axes=(xax,yax))    
            scaler['R'] = '-Rg'
            layout = gmt.default_layout()
            mw = 2.5*gmtpy.cm
            layout.set_fixed_margins(mw,mw,mw/gmtpy.golden_ratio,mw/gmtpy.golden_ratio)
            widget = layout.get_widget()
            # widget['J'] =  ('-JT%g/%g'  % (lon, lat)) + '/%(width)gp'
            widget['J'] =  ('-JE%g/%g/%g'  % (lon, lat, min(lat_delta/2.,180.))) + '/%(width)gp'
            aspect = gmtpy.aspect_for_projection( *(widget.J() + scaler.R()) )
            widget.set_aspect(aspect)
            
            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,
                           B='5g5',
                        L=('x%gp/%gp/%g/%g/%gk' % (widget.width()/2., widget.height()/7.,lon,lat,scale_km) ),
                        *(widget.JXY()+scaler.R()) )
            
            gmt.psxy( in_columns=(lon_grid,lat_grid), S='x10p', W='1p/200/0/0', *(widget.JXY()+scaler.R()) )
            gmt.psxy( in_columns=(lon_grid_alt,lat_grid_alt), S='c10p', W='1p/0/0/200', *(widget.JXY()+scaler.R()) )
            
            gmt.save('orthodrome.pdf')
            subprocess.call( [ 'xpdf', '-remote', 'ortho', '-reload' ] )
            time.sleep(2)
        else:
            print 'ok', gsize, lat, lon
示例#3
0
文件: orthodrome.py 项目: emolch/kiwi
            gmt = gmtpy.GMT(
                config={
                    "PLOT_DEGREE_FORMAT": "ddd.xxxF",
                    "PAPER_MEDIA": "Custom_%ix%i" % (w * gmtpy.cm, h * gmtpy.cm),
                    "GRID_PEN_PRIMARY": "thinnest/0/50/0",
                }
            )

            south = max(-85.0, lat - 0.5 * lat_delta)
            north = min(85.0, lat + 0.5 * lat_delta)

            lon_delta = lat_delta / math.cos(lat * d2r)

            delta = lat_delta / 360.0 * config.earthradius * 2.0 * math.pi
            scale_km = gmtpy.nice_value(delta / 10.0) / 1000.0

            west = lon - 0.5 * lon_delta
            east = lon + 0.5 * lon_delta

            x, y = (west, east), (south, north)
            xax = gmtpy.Ax(mode="min-max", approx_ticks=4.0)
            yax = gmtpy.Ax(mode="min-max", approx_ticks=4.0)
            scaler = gmtpy.ScaleGuru(data_tuples=[(x, y)], axes=(xax, yax))
            scaler["R"] = "-Rg"
            layout = gmt.default_layout()
            mw = 2.5 * gmtpy.cm
            layout.set_fixed_margins(mw, mw, mw / gmtpy.golden_ratio, mw / gmtpy.golden_ratio)
            widget = layout.get_widget()
            # widget['J'] =  ('-JT%g/%g'  % (lon, lat)) + '/%(width)gp'
            widget["J"] = ("-JE%g/%g/%g" % (lon, lat, min(lat_delta / 2.0, 180.0))) + "/%(width)gp"
示例#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)
示例#5
0
            gmt = gmtpy.GMT(
                config={
                    'PLOT_DEGREE_FORMAT': 'ddd.xxxF',
                    'PAPER_MEDIA': 'Custom_%ix%i' %
                    (w * gmtpy.cm, h * gmtpy.cm),
                    'GRID_PEN_PRIMARY': 'thinnest/0/50/0'
                })

            south = max(-85., lat - 0.5 * lat_delta)
            north = min(85., lat + 0.5 * lat_delta)

            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 = (west, east), (south, north)
            xax = gmtpy.Ax(mode='min-max', approx_ticks=4.)
            yax = gmtpy.Ax(mode='min-max', approx_ticks=4.)
            scaler = gmtpy.ScaleGuru(data_tuples=[(x, y)], axes=(xax, yax))
            scaler['R'] = '-Rg'
            layout = gmt.default_layout()
            mw = 2.5 * gmtpy.cm
            layout.set_fixed_margins(mw, mw, mw / gmtpy.golden_ratio,
                                     mw / gmtpy.golden_ratio)
            widget = layout.get_widget()
            # widget['J'] =  ('-JT%g/%g'  % (lon, lat)) + '/%(width)gp'
示例#6
0
def plot_erroneous_ne_to_latlon():
    import sys
    import gmtpy
    import random
    import subprocess
    import time

    while True:
        w, h = 20, 15

        km = 1000.0
        gsize = random.uniform(0.0, 1.0) * 4.0 * 10.0 ** random.uniform(4.0, 7.0)
        north_grid, east_grid = num.meshgrid(
            num.linspace(-gsize / 2.0, gsize / 2.0, 11), num.linspace(-gsize / 2.0, gsize / 2.0, 11)
        )

        north_grid = north_grid.flatten()
        east_grid = east_grid.flatten()

        lat_delta = gsize / config.earthradius * r2d * 2.0
        lon = random.uniform(-180.0, 180.0)
        lat = random.uniform(-90.0, 90.0)

        print gsize / 1000.0

        lat_grid, lon_grid = ne_to_latlon(lat, lon, north_grid, east_grid)
        lat_grid_alt, lon_grid_alt = ne_to_latlon_alternative_method(lat, lon, north_grid, east_grid)

        maxerrlat = num.max(num.abs(lat_grid - lat_grid_alt))
        maxerrlon = num.max(num.abs(lon_grid - lon_grid_alt))
        eps = 1.0e-8
        if maxerrlon > eps or maxerrlat > eps:
            print lat, lon, maxerrlat, maxerrlon

            gmt = gmtpy.GMT(
                config={
                    "PLOT_DEGREE_FORMAT": "ddd.xxxF",
                    "PAPER_MEDIA": "Custom_%ix%i" % (w * gmtpy.cm, h * gmtpy.cm),
                    "GRID_PEN_PRIMARY": "thinnest/0/50/0",
                }
            )

            south = max(-85.0, lat - 0.5 * lat_delta)
            north = min(85.0, lat + 0.5 * lat_delta)

            lon_delta = lat_delta / math.cos(lat * d2r)

            delta = lat_delta / 360.0 * config.earthradius * 2.0 * math.pi
            scale_km = gmtpy.nice_value(delta / 10.0) / 1000.0

            west = lon - 0.5 * lon_delta
            east = lon + 0.5 * lon_delta

            x, y = (west, east), (south, north)
            xax = gmtpy.Ax(mode="min-max", approx_ticks=4.0)
            yax = gmtpy.Ax(mode="min-max", approx_ticks=4.0)
            scaler = gmtpy.ScaleGuru(data_tuples=[(x, y)], axes=(xax, yax))
            scaler["R"] = "-Rg"
            layout = gmt.default_layout()
            mw = 2.5 * gmtpy.cm
            layout.set_fixed_margins(mw, mw, mw / gmtpy.golden_ratio, mw / gmtpy.golden_ratio)
            widget = layout.get_widget()
            # widget['J'] =  ('-JT%g/%g'  % (lon, lat)) + '/%(width)gp'
            widget["J"] = ("-JE%g/%g/%g" % (lon, lat, min(lat_delta / 2.0, 180.0))) + "/%(width)gp"
            aspect = gmtpy.aspect_for_projection(*(widget.J() + scaler.R()))
            widget.set_aspect(aspect)

            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,
                B="5g5",
                L=("x%gp/%gp/%g/%g/%gk" % (widget.width() / 2.0, widget.height() / 7.0, lon, lat, scale_km)),
                *(widget.JXY() + scaler.R())
            )

            gmt.psxy(in_columns=(lon_grid, lat_grid), S="x10p", W="1p/200/0/0", *(widget.JXY() + scaler.R()))
            gmt.psxy(in_columns=(lon_grid_alt, lat_grid_alt), S="c10p", W="1p/0/0/200", *(widget.JXY() + scaler.R()))

            gmt.save("orthodrome.pdf")
            subprocess.call(["xpdf", "-remote", "ortho", "-reload"])
            time.sleep(2)
        else:
            print "ok", gsize, lat, lon