linewidth=0.5) cindex = [] # loop thru b values for b, n0 in zip(src_bval, src_n0): if not isnan(n0): idx = interp(b, [b_min, b_max], [0, ncolours - 1]) cindex.append(int(round(idx))) # plt source zone boundary drawshapepoly(m2, plt, sf, cindex=cindex, cmap=cmap, ncolours=ncolours, fillshape=True, edgecolor='r', lw=1.) #labelpolygon(m2, plt, sf, 'CODE', value='CBGZ', col='k', fweight='normal', fsize=14, addOutline=False) #x,y = m2(130., -35.35) #plt.text(x, y, 'EBGZ', va='center', ha='center', fontsize=14) xlim = ax.get_xlim() xtxt = xlim[1] * 0.02 ylim = ax.get_ylim() ytxt = ylim[1] * 0.02 plt.text(xtxt, ytxt, 'a)', fontsize=20, va='bottom', ha='left')
x, y = m(133.37-txtoff, -16.25+txtoff) plt.text(x, y, 'Daly Waters', size=14, ha='right', weight='normal', path_effects=path_effects) x, y = m(133.54, -17.55) plt.plot(x, y, 's', markerfacecolor='k', markeredgecolor='k', markeredgewidth=0.5, markersize=6, zorder=11000) x, y = m(133.54-txtoff, -17.55+txtoff) plt.text(x, y, 'Elliott', size=14, ha='right', weight='normal', path_effects=path_effects) """ ########################################################################################## # add shapefiles ########################################################################################## shpfile = '../NT/shapefiles/PetroleumTitles28August2019.shp' shpfile = 'PetroleumTitles28August2019.shp' sf = shapefile.Reader(shpfile) drawshapepoly(m, plt, sf, col='r', lw=0.75, alpha=0.5, fillshape=True) jsonfile = 'NSW_CSG_Boreholes.geojson' csg_data = return_csg_data(jsonfile) status = dictlist2array(csg_data, 'status') csg_lon = dictlist2array(csg_data, 'lon') csg_lat = dictlist2array(csg_data, 'lat') idx1 = where(status == 'Permanently Sealed') x, y = m(csg_lon[idx1], csg_lat[idx1]) plt.plot(x, y, 'ro', ms=7, label='Permanently Sealed') idx1 = where(status == 'Not Producing Gas') x, y = m(csg_lon[idx1], csg_lat[idx1]) plt.plot(x, y, 'o', c='orange', ms=7, label='Not Producing Gas')
year = cat.data['year'] idx = where((mags >= 3.0) & (year >= 1977))[0] x, y = m(lons[idx], lats[idx]) m.plot(x, y, 'o', ms=2, mfc='0.4', mec='0.4', zorder=1) idx = where((mags >= 5.6) & (year >= 1880))[0] x, y = m(lons[idx], lats[idx]) m.plot(x, y, 'o', ms=7, mfc='maroon', mec='w', mew=1, zorder=2) ########################################################################################## # add shapefiles ########################################################################################## shpfile = '../../Catalogue/Completeness_NSHA18/Leonard_17_mcomp_d.shp' sf = shapefile.Reader(shpfile) drawshapepoly(m, plt, sf, col='r', lw=2) # label shapes labelpolygon(m, plt, sf, 'NAME', fweight='normal', fsize=16, addOutline=True) # add subplot letter x, y = m(llcrnrlon + 1, urcrnrlat - 1) plt.text(x, y, '(a)', size=22, ha='left', va='top', weight='normal') ########################################################################################## # add 2nd axis ########################################################################################## ax = fig.add_subplot(122) plt.tick_params(labelsize=8)
cmap, zvals = cpt2colormap(cptfile, ncols + 1) cmap = remove_last_cmap_colour(cmap) cs = (cmap(arange(ncols))) # load shape import shapefile shpfile = 'shapefiles/2021_nac_gmm_zones.shp' sf = shapefile.Reader(shpfile) shapes = sf.shapes() zone_code = get_field_data(sf, 'CODE', 'str') polygons = [] for poly in shapes: polygons.append(Polygon(poly.points)) drawshapepoly(m, plt, sf, edgecolor='k', lw=2) # get net IDs netid = [] stas = [] unets = ['AU', 'GE', 'S1', 'II', 'IU', 'OA', '2O'] netsym = ['^', 'H', 'd', 's', 'v', 'p', 'D'] msize = [10, 10, 10, 8, 10, 10, 7] # loop thru zones i = 0 for j, poly in enumerate(polygons): if zone_code[j] == 'BS': eqlo = []
im = m.imshow(rgb) ''' ########################################################################################## # parse mag zones ########################################################################################## import shapefile from shapely.geometry import Point, Polygon from mapping_tools import get_field_data, drawshapepoly, labelpolygon shpfile = 'shapefile/australia_ml_regions.shp' sf = shapefile.Reader(shpfile) shapes = sf.shapes() drawshapepoly(m, plt, sf, fillcolor='none', edgecolor='r', lw=2.5, zorder=0) labelpolygon(m, plt, sf, 'ML_REGION', fsize=24, addOutline=True) ########################################################################################## # add ficticious earthquakes ########################################################################################## import matplotlib.patheffects as path_effects data = loadtxt('ficticious_eq_locs.csv', delimiter=',') x, y = m(data[:, 0], data[:, 1]) plt.plot(x, y, '*', mfc='k', mec='k', mew=0,
m.fillcontinents(color='w', lake_color='0.8') m.drawparallels(arange(-90., 90., grdsize), labels=[0, 0, 0, 0], fontsize=12, dashes=[2, 2], color='0.5', linewidth=0.75) m.drawmeridians(arange(0., 360., grdsize * 2), labels=[0, 0, 0, 0], fontsize=12, dashes=[2, 2], color='0.5', linewidth=0.75) # drow zones drawshapepoly(m, plt, sf, lw=2.) # find grd points inside zones shla = [] shlo = [] for shape in shapes: poly = Polygon(shape.points) for slo, sla in zip(logrd, lagrd): pt = Point(slo, sla) if pt.within(poly): shlo.append(slo) shla.append(sla) shlo = array(shlo) shla = array(shla)
m.drawmeridians(arange(0., 360., 6.), labels=[0, 0, 0, 1], fontsize=16, dashes=[2, 2], color='0.5', linewidth=0.75) ########################################################################################## # add shapefiles ########################################################################################## shpfile = '/Users/tallen/Documents/Geoscience_Australia/NSHA2018/source_models/zones/shapefiles/Leonard2008/source_model_leonard_2008.shp' #shpfile = '/Users/tallen/Documents/Geoscience_Australia/NSHA2018/source_models/zones/shapefiles/Domains/Domains_Sep2011.shp' #shpfile = '/Users/tallen/Documents/Geoscience_Australia/NSHA2018/source_models/zones/shapefiles/ARUP_Background/ARUP_background_source_model.shp' shpfile = '/Users/tallen/Documents/Geoscience_Australia/NSHA2018/source_models/zones/shapefiles/NSHA13/NSHA13_regional_source_model_simplified.shp' sfz = shapefile.Reader(shpfile) drawshapepoly(m, plt, sfz, col='blue', lw=1.75) # label shapes #labelpolygon(m, plt, sf, 'NAME', fweight='normal', fsize=16, addOutline=True) ########################################################################################## # plt stress vectors ########################################################################################## shpfile = '/Users/tallen/Documents/Geoscience_Australia/NSHA2018/source_models/zones/shapefiles/Other/SHMax_Rajabi_2016.shp' sfv = shapefile.Reader(shpfile) lat = get_field_data(sfv, 'LAT', 'float') lon = get_field_data(sfv, 'LON', 'float') shmax = get_field_data(sfv, 'SHMAX', 'float')
alpha=1., zorder=len(cat.data['magnitude']) + 1, lw=2) legh.append(h[0]) l = plt.legend(legh, ('MW 3.0', 'MW 5.0', 'MW 7.0'), loc=1, numpoints=1) l.set_zorder(len(cat.data['magnitude']) + 5) ########################################################################################## # add source zones ########################################################################################## import shapefile shpfile = '../sources/area_sources/2020_H_model/shapefiles/2020_H_model_slab.shp' sf = shapefile.Reader(shpfile) drawshapepoly(m, plt, sf, lw=2.) shpfile = '../sources/area_sources/2015_H_model/shapefiles/2015_H_merged_slab.shp' sf = shapefile.Reader(shpfile) drawshapepoly(m, plt, sf, lw=2., col='r', ls='--') ''' ########################################################################################## # add cities ########################################################################################## clat = [-37.814, -42.882, -35.282] clon = [144.964, 147.324, 149.129] cloc = ['Melbourne', 'Hobart', 'Canberra'] x, y = m(clon, clat) plt.plot(x, y, 'o', markerfacecolor='maroon', markeredgecolor='w', markeredgewidth=2, markersize=14)
rgb = ls.shade(topodat.data, cmap=cmap, norm=norm) im = m.imshow(rgb, alpha=1.) ########################################################################################## # add basins ########################################################################################## import matplotlib.patheffects as PathEffects path_effects = [PathEffects.withStroke(linewidth=2.5, foreground="w")] shpfile = '../2012_moe_earthquake/gis/gippslans_bass_basin_wgs84.shp' sf = shapefile.Reader(shpfile) drawshapepoly(m, plt, sf, col='r', fillcolor='r', edgecolor='r', lw=0.75, alpha=0.2, fillshape=True) # label polygons x, y = m(146, -40.1) plt.text(x, y, 'Bass\nBasin', size=12, c='r', ha='center', va='top', weight='normal',
triLats.append(reckon(dla, dlo, halfTriLen, daz + 180)[1]) # pt3 - assum equilateral triange triHeight = sqrt(triLen**2 - halfTriLen**2) arrowAng = adirn * 90. triLons.append(reckon(dla, dlo, triHeight, daz - arrowAng)[0]) triLats.append(reckon(dla, dlo, triHeight, daz - arrowAng)[1]) xx, yy = m(triLons, triLats) #plt.plot(xx, yy, 'o', c='r', lw=2, ) plt.fill(xx, yy, facecolor=acol, edgecolor='k', linewidth=0.5, alpha=1) # add Flores-Wetar shpfile = 'fault_geometries/flores-wetar.shp' sf = shapefile.Reader(shpfile) flolas = drawshapepoly(m, plt, sf, lw=1.5, polyline=True) lons = flolas[0][0] lats = flolas[0][1] map_fault_dip_dirn(m, plt, lons, lats, discLen, triLen, fc='0.5', ec='k', lw=0.5, invArrow=True) ########################################################################################## # annotate text
mask_outside_polygons(polys, '0.9', plt) # get lake ploygons polygons = [] for polygon in m.lakepolygons: poly = polygon.get_coords() plt.fill(poly[:,0], poly[:,1], '0.9') polygons.append(poly) ########################################################################################## # finish off ########################################################################################## # overlay domains sf = shapefile.Reader('/Users/trev/Documents/Geoscience_Australia/NSHA2018/source_models/zones/shapefiles/Domains/Domains_Sep2011.shp') drawshapepoly(m, plt, sf, lw=0.75, edgecolor='r', fillshape=False) # set colorbar plt.gcf().subplots_adjust(bottom=0.1) cax = fig.add_axes([0.33,0.05,0.34,0.02]) # setup colorbar axes. norm = colors.Normalize(vmin=b_min, vmax=b_max) cb = colorbar.ColorbarBase(cax, cmap=cmap, norm=norm, orientation='horizontal', alpha=1.0) # set cb labels #linticks = array([0.01, 0.03, 0.1, 0.3 ]) ticks = arange(b_min, b_max+0.1, 0.1) cb.set_ticks(ticks) labels = [str('%0.1f' % x) for x in ticks] #cb.set_ticklabels(labels, fontsize=10) cb.ax.set_xticklabels(labels, fontsize=10)
b_min = 0.8 b_max = 1.3 cindex = [] # loop thru b values for b, n0 in zip(src_bval, src_n0): if not isnan(n0): idx = interp(b, [b_min, b_max], [0, ncolours-1]) cindex.append(int(round(idx))) # get cmap cmap = plt.get_cmap('YlOrRd', ncolours) # plt source zone boundary drawshapepoly(m2, plt, sf, cindex=cindex, cmap=cmap, ncolours=ncolours, fillshape=True) labelpolygon(m2, plt, sf, 'CODE', value='CBGZ', col='k', fweight='normal', fsize=14, addOutline=False) x,y = m2(130., -35.35) plt.text(x, y, 'EBGZ', va='center', ha='center', fontsize=14) xlim = ax.get_xlim() xtxt = xlim[1] * 0.02 ylim = ax.get_ylim() ytxt = ylim[1] * 0.02 plt.text(xtxt, ytxt, 'a)', fontsize=17, va='bottom', ha='left') # label polygons #labelpolygon(m2, plt, sf, 'CODE') ###############################################################################
World_Topo_Map ESRI_Imagery_World_2D - good sat image NatGeo_World_Map - nice road map - hard to read ''' ########################################################################################## # add cities ########################################################################################## numCities = 10 #annotate_cities(numCities, plt, m, marker='s') ########################################################################################## # add earthquakes ########################################################################################## ''' shpfile = '../NT/shapefiles/PetroleumTitles28August2019.shp' shpfile = 'PetroleumTitles28August2019.shp' sf = shapefile.Reader(shpfile) drawshapepoly(m, plt, sf, col='r',lw=0.75, alpha=0.5, fillshape = True) ''' #gadat = parse_ga_event_query('earthquakes_export_2012-16_250.edit.csv') gadat = parse_ga_event_query('2014-2016_earthquakes_export.edit.csv') la = dictlist2array(gadat, 'lat') lo = dictlist2array(gadat, 'lon') mag = dictlist2array(gadat, 'mag_ml') x, y = m(lo, la) scatter = plt.scatter(x, y, s=-75 + mag * 80,
# get lake ploygons polygons = [] for polygon in m.lakepolygons: poly = polygon.get_coords() plt.fill(poly[:, 0], poly[:, 1], 'lightskyblue') polygons.append(poly) ########################################################################################## # add source zones ########################################################################################## import shapefile shpfile = 'SECan_H2.shp' sf = shapefile.Reader(shpfile) drawshapepoly(m, plt, sf, lw=1.5, col='r') ''' shpfile = 'swcan_crustal.shp' sf = shapefile.Reader(shpfile) drawshapepoly(m, plt, sf, lw=2., col='b', ls='--', polyline=True) shpfile = 'swcan_slab.shp' sf = shapefile.Reader(shpfile) drawshapepoly(m, plt, sf, lw=2., col='k', ls='-', polyline=True) ''' # set legend m.plot([0, 0], [10, 10], 'r-', lw=1.5, label='Shallow Area Sources') plt.legend(loc=1, fontsize=16) ''' # label thrusts x, y = m(-132.5, 52.5)
def map_haz(fig, plt, haz_map_file, sitelon, sitelat, **kwargs): ''' kwargs: shpfile: path to area source - is a list of files resolution: c (crude), l (low), i (intermediate), h (high), f (full) mbuffer: map buffer in degrees ''' from openquake.nrmllib.hazard.parsers import GMFScenarioParser from mpl_toolkits.basemap import Basemap from numpy import arange, array, log10, mean, mgrid, percentile from matplotlib.mlab import griddata from matplotlib import colors, colorbar, cm from os import path from mapping_tools import drawshapepoly, labelpolygon import shapefile # set kwargs drawshape = False res = 'c' mbuff = -0.3 keys = ['shapefile', 'resolution', 'mbuffer'] for key in keys: if key in kwargs: if key == 'shapefile': shpfile = kwargs[key] drawshape = True if key == 'resolution': res = kwargs[key] if key == 'mbuffer': mbuff = kwargs[key] gmfsp = GMFScenarioParser(haz_map_file).parse() metadata, values = parse_nrml_hazard_map(haz_map_file) hazvals = [] latlist = [] lonlist = [] for val in values: lonlist.append(val[0]) latlist.append(val[1]) hazvals.append(val[2]) # get map bounds llcrnrlat = min(latlist) - mbuff / 2. urcrnrlat = max(latlist) + mbuff / 2. llcrnrlon = min(lonlist) - mbuff urcrnrlon = max(lonlist) + mbuff lon_0 = mean([llcrnrlon, urcrnrlon]) lat_1 = percentile([llcrnrlat, urcrnrlat], 25) lat_2 = percentile([llcrnrlat, urcrnrlat], 75) m = Basemap(llcrnrlon=llcrnrlon,llcrnrlat=llcrnrlat, \ urcrnrlon=urcrnrlon,urcrnrlat=urcrnrlat, projection='lcc',lat_1=lat_1,lat_2=lat_2,lon_0=lon_0, resolution=res,area_thresh=1000.) m.drawcoastlines(linewidth=0.5, color='k') m.drawcountries() # draw parallels and meridians. m.drawparallels(arange(-90., 90., 1.), labels=[1, 0, 0, 0], fontsize=10, dashes=[2, 2], color='0.5', linewidth=0.5) m.drawmeridians(arange(0., 360., 1.), labels=[0, 0, 0, 1], fontsize=10, dashes=[2, 2], color='0.5', linewidth=0.5) # make regular grid N = 150j extent = (min(lonlist), max(lonlist), min(latlist), max(latlist)) xs, ys = mgrid[extent[0]:extent[1]:N, extent[2]:extent[3]:N] resampled = griddata(array(lonlist), array(latlist), log10(array(hazvals)), xs, ys) ############################################################################# # transform grid to basemap # get 1D lats and lons for map transform lons = ogrid[extent[0]:extent[1]:N] lats = ogrid[extent[2]:extent[3]:N] # transform to map projection if max(lonlist) - min(lonlist) < 1: transspace = 500 elif max(lonlist) - min(lonlist) < 5: transspace = 1000 elif max(lonlist) - min(lonlist) < 10: transspace = 2000 else: transspace = 5000 nx = int((m.xmax - m.xmin) / transspace) + 1 ny = int((m.ymax - m.ymin) / transspace) + 1 transhaz = m.transform_scalar(resampled.T, lons, lats, nx, ny) m.imshow(transhaz, cmap='Spectral_r', extent=extent, vmin=-2, vmax=log10(2.), zorder=0) # plot site xx, yy = m(sitelon, sitelat) plt.plot(xx, yy, '*', ms=20, mec='k', mew=2.0, mfc="None") # superimpose area source shapefile if drawshape == True: for shp in shpfile: sf = shapefile.Reader(shp) drawshapepoly(m, plt, sf, col='k', lw=1.5, polyline=True) labelpolygon(m, plt, sf, 'CODE', fsize=14) # set colourbar # set cb for final fig plt.gcf().subplots_adjust(bottom=0.1) cax = fig.add_axes([0.6, 0.05, 0.25, 0.02]) # setup colorbar axes. norm = colors.Normalize(vmin=-2, vmax=log10(2.)) cb = colorbar.ColorbarBase(cax, cmap=cm.Spectral_r, norm=norm, orientation='horizontal') # set cb labels #linticks = array([0.01, 0.03, 0.1, 0.3 ]) logticks = arange(-2, log10(2.), 0.25) cb.set_ticks(logticks) labels = [str('%0.2f' % 10**x) for x in logticks] cb.set_ticklabels(labels) # get map probabiltiy from filename mprob = path.split(haz_map_file)[-1].split('_')[-1].split('-')[0] probstr = str(int(float(mprob) * 100)) # set colourbar title if metadata['statistics'] == 'mean': titlestr = ''.join((metadata['imt'], ' ', metadata['sa_period'], ' s ', \ probstr,'% in ',metadata['investigation_time'][0:-2], \ ' Year Mean Hazard (g)')) #cb.set_ticklabels(labels) cb.set_label(titlestr, fontsize=12) return plt
mfc='k', markersize=(-10 + lm * 5), alpha=1., zorder=len(mag) + 1, lw=2) legh.append(h[0]) l = plt.legend(legh, ('MW 4.0', 'MW 5.0', 'MW 6.0'), loc=2, numpoints=1) l.set_zorder(len(mag) + 5) ########################################################################################## # add domains ########################################################################################## shpfile = '/nas/active/ops/community_safety/ehp/georisk_earthquake/modelling/sandpits/tallen/NSHA2018/source_models/zones/shapefiles/Domains/Domains_Sep2011.shp' sfz = shapefile.Reader(shpfile) drawshapepoly(m, plt, sfz, edgecolor='r', col='r', lw=1., zorder=1) ########################################################################################## # make map inset ########################################################################################## from mpl_toolkits.axes_grid1.inset_locator import zoomed_inset_axes axins = zoomed_inset_axes(ax, 0.115, loc=1) m2 = Basemap(projection='merc',\ llcrnrlon=109,llcrnrlat=-45, \ urcrnrlon=156,urcrnrlat=-9,\ rsphere=6371200.,resolution='l',area_thresh=10000) m2.drawmapboundary(fill_color='0.8') m2.fillcontinents(color='w', lake_color='0.8') #, zorder=0)
x, y = m(0, 0) h = m.plot(x, y, 'ko', mfc='k', markersize=(-4 + lm*3.2), alpha=1., zorder=len(cat.data['magnitude'])+1, lw=2) legh.append(h[0]) l = plt.legend(legh, ('MW 3.0', 'MW 5.0', 'MW 7.0'), loc=1, numpoints=1) l.set_zorder(len(cat.data['magnitude'])+5) ''' ########################################################################################## # add source zones ########################################################################################## import shapefile shpfile = 'swcan_shallow_area.shp' sf = shapefile.Reader(shpfile) drawshapepoly(m, plt, sf, lw=1.5, col='r') shpfile = 'swcan_crustal.shp' sf = shapefile.Reader(shpfile) drawshapepoly(m, plt, sf, lw=2., col='b', ls='--', polyline=True) shpfile = 'swcan_slab.shp' sf = shapefile.Reader(shpfile) drawshapepoly(m, plt, sf, lw=2., col='k', ls='-', polyline=True) # set legend m.plot([0,0],[10, 10], 'r-', lw=1.5, label='Shallow Area Sources') m.plot([0,0],[10, 10], 'b--', lw=2.0, label='Transform Fault Sources') m.plot([0,0],[10, 10], 'k-', lw=2.5, label='Thrust Fault Sources') plt.legend(loc=1, fontsize=16)
data = loadtxt('scenario_lat_lons.csv', delimiter=',') x, y = m(data[:, 1], data[:, 0]) plt.plot(x, y, '*', mfc='r', mec='k', mew=0.25, markersize=8, label='Scenario Localities') ''' path_effect=[path_effects.withStroke(linewidth=3, foreground='w')] x, y = m(data[:,0]+0.75, data[:,1]+0.5) for i in range(0, len(x)): plt.text(x[i], y[i], 'E'+str(i+1), fontsize=14, c='b', \ va='bottom', ha='left', style='italic', path_effects=path_effect) ''' plt.legend(loc=3, fontsize=14, numpoints=1) # add neotectonic domains shpfile = '/nas/active/ops/community_safety/ehp/georisk_earthquake/modelling/sandpits/tallen/NSHA2018/source_models/zones/shapefiles/Domains/Domains_Sep2011.shp' sf = shapefile.Reader(shpfile) drawshapepoly(m, plt, sf, col='k', lw=.5) plt.savefig('scenario_locations.png', format='png', dpi=300, bbox_inches='tight') #plt.savefig('neac_ml_zones.svg', format='svg', bbox_inches='tight') plt.show()