예제 #1
0
except:
    data = nc.variables['z'][:] / zscale
    lons = nc.variables['x'][:]
    lats = nc.variables['y'][:]

# 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//trev//Documents//DATA//GMT//cpt//mby_topo-bath.cpt'
#cptfile = '//Users//tallen//Documents//DATA//GMT//cpt//gray.cpt'
cmap, zvals = cpt2colormap(cptfile, 256)
cmap = remove_last_cmap_colour(cmap)
        
# make shading
print('Making map...')
ls = LightSource(azdeg = 180, altdeg = 45)
norm = mpl.colors.Normalize(vmin=-8000/zscale, vmax=5000/zscale)#myb
rgb = ls.shade(topodat, cmap=cmap, norm=norm)
im = m.imshow(rgb, alpha=0.6)

'''
##########################################################################################
# add epicentres
##########################################################################################

ncols = 18
예제 #2
0
elif pltProb == '2':
    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 = []
예제 #3
0
zscale = 20.  #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
try:
    cptfile = '//Users//trev//Documents//DATA//GMT//cpt//wiki-2.0.cpt'
    cmap, zvals = cpt2colormap(cptfile, 30)
except:
    cptfile = '/nas/active/ops/community_safety/ehp/georisk_earthquake/hazard/DATA/cpt/wiki-2.0.cpt'
    cmap, zvals = cpt2colormap(cptfile, 30)

cmap = remove_last_cmap_colour(cmap)

# make shading
print('Making map...')
ls = LightSource(azdeg=180, altdeg=5)
#norm = mpl.colors.Normalize(vmin=-8000/zscale, vmax=5000/zscale)#myb
norm = mpl.colors.Normalize(vmin=-1000 / zscale, vmax=1900 / zscale)  #wiki

rgb = ls.shade(topodat.data, cmap=cmap, norm=norm)
im = m.imshow(rgb, alpha=1.0)
예제 #4
0
from gmt_tools import cpt2colormap, remove_last_cmap_colour
from os import getcwd
import matplotlib as mpl
from matplotlib import colors, colorbar
mpl.style.use('classic')

##########################
# get colours
##########################

if getcwd().startswith('/nas'):
    cptfile = '/nas/active/ops/community_safety/ehp/georisk_earthquake/hazard/DATA/cpt/mi_pop.cpt'
else:
    cptfile = '//Users//trev//Documents//DATA//GMT//cpt//mi_pop.cpt'
ncols = 10
cmap, zvals = cpt2colormap(cptfile, ncols + 1, rev=False)
cmap = remove_last_cmap_colour(cmap)
cs = (cmap(arange(ncols)))

##########################
# set mmi
##########################

rand_mmi = 10 * random.rand(49) / 2 + 1
rand_mmi[10] = 7.
rand_mmi[29] = 7.

idx = rand_mmi < 2.5
rand_mmi[idx] = 3.
rand_mmi[21] = 2.
rand_mmi[4] = 2.
예제 #5
0
lons = nc.variables['lon'][:]
lats = nc.variables['lat'][:]
'''
# transform to metres
nx = int((m.xmax - m.xmin) / 30.) + 1
ny = int((m.ymax - m.ymin) / 30.) + 1

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

print('Getting colormap...')
# get colormap
if getcwd().startswith('/nas'):
    cptfile = '/nas/active/ops/community_safety/ehp/georisk_earthquake/hazard/DATA/cpt/wiki-2.0.cpt'
else:
    cptfile = '//Users//trev//Documents//DATA//GMT//cpt//wiki-2.0.cpt'
cmap, zvals = cpt2colormap(cptfile, 117)
print(len(zvals))
cmap = remove_last_cmap_colour(cmap)

# make shading
print('Making map...')
ls = LightSource(azdeg=180, altdeg=5)
#norm = mpl.colors.Normalize(vmin=-8000/zscale, vmax=5000/zscale)
norm = mpl.colors.Normalize(vmin=-1000 / zscale, vmax=1900 / zscale)  #wiki
rgb = ls.shade(topodat.data, cmap=cmap, norm=norm)
im = m.imshow(rgb, alpha=1.)

##########################################################################################
# add simple faults
##########################################################################################
if getcwd().startswith('/nas'):
예제 #6
0
    
hazFactAS1170 = array(hazFactAS1170)
hazFactNSHA10 = array(hazFactNSHA10)
hazFactNSHA2 = array(hazFactNSHA2)   

# set min AS1170.4 value to 0.08
idx = hazFactAS1170 < 0.08
hazFactAS1170[idx] = 0.08

##########################################################################################
# get cmap
##########################################################################################
ncols = 17
try:
    cptfile = '//Users//tallen//Documents//DATA//GMT//cpt//temp_18lev.cpt'
    cmap, zvals = cpt2colormap(cptfile, ncols)
except:
    cptfile = '/nas/active/ops/community_safety/ehp/georisk_earthquake/hazard/DATA/cpt/temp_19lev.cpt'
    cmap, zvals = cpt2colormap(cptfile, ncols)
    
cmap = remove_last_cmap_colour(cmap)
cs = (cmap(arange(ncols-1)))

##########################################################################################
# make first plot AS1170.4-2018 / NSHA 10%
##########################################################################################


llcrnrlat = -44
urcrnrlat = -8.
llcrnrlon = 107.
예제 #7
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
예제 #8
0
zscale = 10.  #colour
data = nc.variables['z'][:] / zscale
lons = nc.variables['x'][:]
lats = nc.variables['y'][:]

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

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

print 'Getting colormap...'
# get colormap
cptfile = '//Users//tallen//Documents//DATA//GMT//cpt//mby_topo-bath_mod.cpt'
#cptfile = '//Users//tallen//Documents//DATA//GMT//cpt//gray.cpt'
cmap, zvals = cpt2colormap(cptfile, 256)
#cmap = cm.get_cmap('terrain', 256)

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

##########################################################################################
# plot epicentres
##########################################################################################
fig = plt.figure(1, figsize=(10, 10))
ncols = 10
#cmap = plt.cm.get_cmap('Spectral', ncols)
예제 #9
0
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
try:
    cptfile = '//Users//trev//Documents//DATA//GMT//cpt//wiki-2.0.cpt'
except:
    cptfile = '/nas/active/ops/community_safety/ehp/georisk_earthquake/hazard/DATA/cpt/wiki-2.0.cpt'

cmap, zvals = cpt2colormap(cptfile, 30)
cmap = remove_last_cmap_colour(cmap)

# make shading
print('Making map...')
ls = LightSource(azdeg=180, altdeg=5)
#norm = mpl.colors.Normalize(vmin=-8000/zscale, vmax=5000/zscale)
norm = mpl.colors.Normalize(vmin=-1000 / zscale, vmax=1900 / zscale)  #wiki

rgb = ls.shade(topodat.data, cmap=cmap, norm=norm)
im = m.imshow(rgb, alpha=1.0)

##########################################################################################
# add epicentres
##########################################################################################
# get colormap
예제 #10
0
ftypes = ['Intraslab', 'Outer Rise', 'Strike-Slip']
grads = [lengrd1, widgrd1, areagrd1, mxsgrd, avsgrd, lwgrd]
fmag = [intra_fmag, outer_fmag, trans_fmag]
flen = [intra_flen, outer_flen, trans_flen]
fwid = [intra_fwid, outer_fwid, trans_fwid]
farea = [intra_farea, outer_farea, trans_farea]
fmxs = [intra_fmxs, outer_fmxs, trans_fmxs]
favs = [intra_favs, outer_favs, trans_favs]
mrng = arange(7.2, 9.61, 0.01)
omrng = arange(7.0, 8.71, 0.01)

from gmt_tools import cpt2colormap 
cptfile = '/Users/tallen/Documents/DATA/GMT/cpt/GMT_no_green.cpt'
#cptfile = '/Users/tallen/Documents/DATA/GMT/cpt/temperature.cpt'
#cptfile = '/Users/tallen/Documents/DATA/GMT/cpt/gay-flag-1978.cpt'
cmap = cpt2colormap(cptfile, 6)[0]

#cmap = plt.cm.get_cmap('hsv', 5)
#cs = (cmap(arange(5)))
#cols = [cs[1], cs[2], cs[3]]

cptfile = '/Users/tallen/Documents/DATA/GMT/cpt/temp-c.cpt'
ncolours = 6
cmap2, zvals = cpt2colormap(cptfile, ncolours, rev=False)
cs2 = (cmap2(arange(ncolours)))
#cs2 = vstack(([cs2[0], cs2[2:4], cs2[5:]]))
#cols = [cs2[1], cs2[2], cs2[3]]

ncolours = 6
cmap = plt.cm.get_cmap('Spectral', ncolours)
colours = (cmap(arange(ncolours)))
예제 #11
0
            bounds = array([
                0, 0.01, 0.015, 0.02, 0.025, 0.03, 0.04, 0.05, 0.06, 0.08,
                0.12, 0.16, 0.2, 0.3
            ])
        else:
            bounds = array([
                0, 0.001, 0.002, 0.003, 0.004, 0.005, 0.007, 0.015, 0.03, 0.04,
                0.05, 0.06, 0.1, 0.16
            ])
    ncolours = 13

    if getcwd().startswith('/nas'):
        cptfile = '/nas/active/ops/community_safety/ehp/georisk_earthquake/modelling/sandpits/tallen/NSHA2018/postprocessing/maps/cw1-013_mod.cpt'
    else:
        cptfile = '/Users/tallen/Documents/Geoscience_Australia/NSHA2018/postprocessing/maps/cw1-013_mod.cpt'
    cmap, zvals = cpt2colormap(cptfile, ncolours, rev=True)
    rgbTable = cmap2rgb(cmap, ncolours)[0] * 255

    # make gdal cpt file
    cpttxt = ''
    for bound, rgb in zip(bounds, rgbTable):
        cpttxt += '\t'.join(
            (str(bound), str(rgb[0]), str(rgb[1]), str(rgb[2]))) + '\n'

    f = open('gdal_cpt.dat', 'wb')
    f.write(cpttxt)
    f.close()

    # recolour geoTiff
    intiff = path.join('geotiff', '_'.join(('nsha18', period, p50 + '.tiff')))
    outtiff = intiff[0:-4] + '_colour.tiff'
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
try:
    cptfile = '//Users//trev//Documents//DATA//GMT//cpt//wiki-2.0.cpt'
    cptfile = '//Users//trev//Documents//DATA//GMT//cpt//lightgrey.cpt'
    cptfile = '//Users//trev//Documents//DATA//GMT//cpt//grey_fade.cpt'
except:
    cptfile = '/nas/active/ops/community_safety/ehp/georisk_earthquake/hazard/DATA/cpt/wiki-2.0.cpt'

#cmap, zvals = cpt2colormap(cptfile, 30) # wiki
cmap, zvals = cpt2colormap(cptfile, 31)  # grey
#cmap = remove_last_cmap_colour(cmap)

#cmap = ListedColormap

# make shading
print('Making map...')
ls = LightSource(azdeg=135, altdeg=10)
#norm = mpl.colors.Normalize(vmin=-8000/zscale, vmax=5000/zscale)#myb
#norm = mpl.colors.Normalize(vmin=-1000/zscale, vmax=1900/zscale)#wiki
norm = mpl.colors.Normalize(vmin=-2000 / zscale, vmax=3500 / zscale)  #wiki

rgb = ls.shade(topodat.data, cmap=cmap, norm=norm)
im = m.imshow(rgb, alpha=1.0)

##########################################################################################
예제 #13
0
# http://stackoverflow.com/questions/23477775/matplotlib-mixed-subplots-with-plot-and-pcolormesh-to-have-the-same-x-axis-len

import matplotlib.pyplot as plt
from numpy import array, arange, random, linspace, meshgrid, dstack, amax, \
                  percentile, shape, where, mean
from scipy.stats import multivariate_normal
from gmt_tools import cpt2colormap
import matplotlib
matplotlib.rc('xtick', labelsize=16)
matplotlib.rc('ytick', labelsize=16)

cptfile = 'U:\\DATA\\GMT\\cpt\\grays.cpt'
cptfile = '//Users//tallen//Documents//DATA//GMT//cpt//grays.cpt'

ncolours = 11
cmap, zvals = cpt2colormap(cptfile, ncolours, rev=False)
#cmap = plt.cm.get_cmap('gray_r', ncolours)
flen = 400  # km
fwid = 200  # km
subfsize = 10  # km
#cmap = cm.rainbow
vmin = 0.
vmax = 33.

random.seed(1000)
# Generate some interesting-looking random data...
xnum = flen / subfsize + 1
ynum = fwid / subfsize + 1
rndgrid = random.rand(ynum, xnum)
x = linspace(0, flen, xnum)
y = linspace(0, fwid, ynum)
예제 #14
0
'''

import matplotlib.pyplot as plt
#import matplotlib as mpl

pltpga = [0.1, 0.4]

mpl.rcParams['pdf.fonttype'] = 42
plt.rcParams['xtick.labelsize'] = 14
plt.rcParams['ytick.labelsize'] = 14 

numcols = 6
cptfile = '/Users/tallen/Documents/DATA/GMT/cpt/temperature.cpt'
cptfile = '//Users//tallen//Documents//DATA//GMT//cpt//qual-dark-06.cpt' # try me!
cptfile = '//Users//tallen//Documents//DATA//GMT//cpt//humidity.cpt'
cmap, zvals = cpt2colormap(cptfile, numcols)
cmap = remove_last_cmap_colour(cmap)
cs = (cmap(arange(numcols)))

# remove yellow
#idx=array([0, 1, 3, 4, 5])
#cs = cs[idx]

legtxt = ['Site Class B (Ae)', 'Site Class B/C (Be)', 'Site Class C (Ce)', 'Site Class D (De)', \
          'Site Class E (Ee)'] #, 'F(T)', 'Fa & Fv']

figure = plt.figure(1,figsize=(19,8))

# Boarcherdt 1994 for 0.1 and 0.4 g
Fa01 = [0.6, 0.7, 1.0, 1.5, 1.5]
Fa04 = [1.1, 1.0, 1.0, 0.9, 0.9]
예제 #15
0
'''
########################################################################################
'''
# export coeffs
f = open('interface_coeffs.csv', 'wb')
f.write(coeftxt)
f.close()
'''
########################################################################################
'''

#from gmt_tools import cpt2colormap

#cptfile = 'U:\\DATA\\GMT\\cpt\\GMT_no_green.cpt'
cptfile = '/Users/tallen/Documents/DATA/GMT/cpt/GMT_no_green.cpt'
cmap = cpt2colormap(cptfile, 5)[0]  # colormap for data
cs = (cmap(arange(5)))

cptfile = '/Users/tallen/Documents/DATA/GMT/cpt/gay-flag-1979.cpt'
#cptfile = '/Users/tallen/Documents/DATA/GMT/cpt/GMT_rainbow.cpt'
ncolours = 7
cmap2, zvals = cpt2colormap(cptfile, ncolours, rev=False)
cs2 = (cmap2(arange(ncolours)))
#cs2 = vstack(([cs2[0:4], cs2[5:]]))
'''
########################################################################################
'''
# plot length
fig = plt.figure(1, figsize=(11.5, 17))
ax = plt.subplot(3, 2, 1, aspect=1)
plt.axis('equal')