示例#1
0
    probidx = 2
'''

altPlaces = False

pltLog = False

# get colours
if getcwd().startswith('/nas'):
    cptfile = '/nas/active/ops/community_safety/ehp/georisk_earthquake/hazard/DATA/cpt/gay-flag-1978.cpt'
else:
    cptfile = '//Users//trev//Documents//DATA//GMT//cpt//gay-flag-1978.cpt'

ncolours = 9
cmap, zvals = cpt2colormap(cptfile, ncolours)
cmap = remove_last_cmap_colour(cmap)
cs = (cmap(arange(ncolours - 1)))

###############################################################################
# parse uhs file
###############################################################################

lines = open(uhsfile).readlines()
headers = [x for x in lines[1].strip().split(',')]

# get keys from uhs file
keys = lines[1].strip().split(',')[2:]

# get peridos in keys
periods = []
tmpProb = []
示例#2
0
def get_basemap(llcrnrlon, urcrnrlon, llcrnrlat, urcrnrlat, res, fig,
                useGEBCO):
    '''
    useGEBCO = True: use GEBCO data
    useGEBCO = False: use shadedrelief
    '''
    from mpl_toolkits.basemap import Basemap
    import matplotlib as mpl
    from matplotlib.colors import LightSource
    from netCDF4 import Dataset as NetCDFFile
    from os import getcwd

    cwd = getcwd()

    lon_0 = mean([llcrnrlon, urcrnrlon])
    lat_1 = percentile([llcrnrlat, urcrnrlat], 25)
    lat_2 = percentile([llcrnrlat, urcrnrlat], 75)

    plt.tick_params(labelsize=16)
    ax = fig.add_subplot(111)

    m = Basemap(projection='lcc',lat_1=lat_1,lat_2=lat_2,lon_0=lon_0,\
                llcrnrlon=llcrnrlon,llcrnrlat=llcrnrlat, \
                urcrnrlon=urcrnrlon,urcrnrlat=urcrnrlat,\
                rsphere=6371200.,resolution=res,area_thresh=10.)

    # draw coastlines, state and country boundaries, edge of map.
    if useGEBCO == False:
        m.shadedrelief()

    m.drawcoastlines()
    m.drawstates()
    m.drawcountries()
    m.drawparallels(arange(-90., 90., 1.),
                    labels=[1, 0, 0, 0],
                    fontsize=16,
                    dashes=[2, 2],
                    color='0.5',
                    linewidth=0.75)
    m.drawmeridians(arange(0., 360., 2.),
                    labels=[0, 0, 0, 1],
                    fontsize=16,
                    dashes=[2, 2],
                    color='0.5',
                    linewidth=0.75)
    #m.drawmapscale(144, -34.8, 146., -38.5, 400, fontsize = 16, barstyle='fancy', zorder=100)

    ##########################################################################################
    # plot gebco
    ##########################################################################################
    if useGEBCO == True:
        print 'Reading netCDF file...'
        if cwd.startswith('/nas'):
            nc = NetCDFFile(
                '//nas//gemd//ehp//georisk_earthquake//hazard//DATA//GEBCO//au_gebco.nc'
            )
            cptfile = '//nas//gemd//ehp//georisk_earthquake//hazard//DATA//cpt//mby_topo-bath.cpt'
            #cptfile = '//nas//gemd//ehp//georisk_earthquake//hazard//DATA//cpt//gray.cpt'
            #cptfile = '//nas//gemd//ehp//georisk_earthquake//hazard//DATA//cpt//mby_topo-bath_mod.cpt'
        else:
            nc = NetCDFFile(
                '//Users//tallen//Documents//DATA//GMT//GEBCO//Australia_30c.nc'
            )
            cptfile = '//Users//tallen//Documents//DATA//GMT//cpt//mby_topo-bath.cpt'

        zscale = 20.  #gray
        zscale = 30.  #colour
        data = nc.variables['elevation'][:] / zscale
        lons = nc.variables['lon'][:]
        lats = nc.variables['lat'][:]

        # transform to metres
        nx = int((m.xmax - m.xmin) / 500.) + 1
        ny = int((m.ymax - m.ymin) / 500.) + 1

        topodat = m.transform_scalar(data, lons, lats, nx, ny)

        print 'Getting colormap...'
        # get colormap

        #cptfile = '//Users//tallen//Documents//DATA//GMT//cpt//gray.cpt'
        cmap, zvals = cpt2colormap(cptfile, 256)
        cmap = remove_last_cmap_colour(cmap)
        #cmap = remove_last_cmap_colour(cmap)

        # make shading
        print 'Making map...'
        ls = LightSource(azdeg=300, altdeg=45)
        norm = mpl.colors.Normalize(vmin=-8000 / zscale,
                                    vmax=5000 / zscale)  #myb
        rgb = ls.shade(topodat, cmap=cmap, norm=norm)  #norm=norm)
        im = m.imshow(rgb, alpha=0.4)

    return m, ax