# get domain polygons dom_shapes = dsf.shapes() dom = [] mmax = [] trt = [] dep_b = [] ycomp = [] mcomp = [] bval_fix = [] bval_sig_fix = [] # loop through ARUP zones for code, poly in zip(codes, shapes): # get centroid of leonard sources clon, clat = get_shp_centroid(poly.points) point = Point(clon, clat) print clon, clat # loop through domains and find point in poly matchidx = -99 for i in range(0, len(dom_shapes)): dom_poly = Polygon(dom_shapes[i].points) # check if AUS6 centroid in domains poly if point.within(dom_poly): matchidx = i if code == 'WLBY' or code == 'PAPU' or code == 'BLHB' or code == 'EPPL' \ or code == 'SCOT': matchidx = -1
nodal_plane_dist = PMF([(0.17, NodalPlane(strikes[0], 30, 90)), (0.17, NodalPlane(strikes[1], 30, 90)), (0.04, NodalPlane(strikes[2], 30, 90)), (0.04, NodalPlane(strikes[3], 30, 90)), (0.04, NodalPlane(strikes[4], 30, 90)), (0.04, NodalPlane(strikes[5], 30, 90)), (0.17, NodalPlane(strikes[0], 90, 0)), (0.17, NodalPlane(strikes[1], 90, 0)), (0.04, NodalPlane(strikes[2], 90, 0)), (0.04, NodalPlane(strikes[3], 90, 0)), (0.04, NodalPlane(strikes[4], 90, 0)), (0.04, NodalPlane(strikes[5], 90, 0))]) dom_poly = Polygon(dom_shape.shape.points) for i, shape in enumerate(shapes): centroid = get_shp_centroid(shape.points) shapely_pt = shapely.geometry.Point(centroid[0], centroid[1]) #print centroid if shapely_pt.within(dom_poly): pt = Point(centroid[0], centroid[1], depth) # Openquake geometry Point tectonic_region_type = dom['GMM_TRT'] nodal_plane_distribution = nodal_plane_dist # FIXME! update based on data extracted from shapefile hypocenter_distribution = hypo_depth_dist rupture_aspect_ratio = 2 mfd = TruncatedGRMFD(min_mag, max_mag, 0.1, a_values[i], b_values[i]) new_mfd = gr2inc_mmax(mfd, mmaxs[dom['CODE']], mmaxs_w[dom['CODE']], model_weight=1.)
def get_simple_neotectonic_domain_params(target_sf, refShpFile): import shapefile from shapely.geometry import Point, Polygon from tools.nsha_tools import get_field_data, get_shp_centroid # load target shapefile polygons = target_sf.shapes() # load domains shp domshp = open(refShpFile).read() dsf = shapefile.Reader(domshp) # get domains neo_doms = get_field_data(dsf, 'DOMAIN', 'float') neo_min_reg = get_field_data(dsf, 'MIN_RMAG', 'float') neo_mmax = get_field_data(dsf, 'MMAX_BEST', 'float') neo_bval = get_field_data(dsf, 'BVAL_BEST', 'float') neo_bval_l = get_field_data(dsf, 'BVAL_LOWER', 'float') neo_trt = get_field_data(dsf, 'TRT', 'str') neo_usd = get_field_data(dsf, 'USD', 'float') neo_lsd = get_field_data(dsf, 'LSD', 'float') neo_dep_b = get_field_data(dsf, 'DEP_BEST', 'float') neo_dep_u = get_field_data(dsf, 'DEP_UPPER', 'float') neo_dep_l = get_field_data(dsf, 'DEP_LOWER', 'float') # get bval sigma bval_sig = neo_bval_l - neo_bval # get domain polygons dom_shapes = dsf.shapes() domain = [] min_rmag = [] mmax = [] trt = [] bval_fix = [] bval_sig_fix = [] usd = [] lsd = [] dep_b = [] dep_u = [] dep_l = [] # loop through target zones for poly in polygons: # get centroid of target sources clon, clat = get_shp_centroid(poly.points) point = Point(clon, clat) # loop through domains and find point in poly matchidx = -99 for i in range(0, len(dom_shapes)): # make sure trts match dom_poly = Polygon(dom_shapes[i].points) # check if target centroid in domains poly if point.within(dom_poly): matchidx = i # set dummy values if matchidx == -99: domain.append(-99) min_rmag.append(3.5) mmax.append(8.5) trt.append('') bval_fix.append(-99) bval_sig_fix.append(-99) usd.append(-99) lsd.append(-99) dep_b.append(-99) dep_u.append(-99) dep_l.append(-99) # fill real values else: domain.append(neo_doms[matchidx]) min_rmag.append(neo_min_reg[matchidx]) mmax.append(neo_mmax[matchidx]) trt.append(neo_trt[matchidx]) bval_fix.append(neo_bval[matchidx]) bval_sig_fix.append(bval_sig[matchidx]) usd.append(neo_usd[matchidx]) lsd.append(neo_lsd[matchidx]) dep_b.append(neo_dep_b[matchidx]) dep_u.append(neo_dep_u[matchidx]) dep_l.append(neo_dep_l[matchidx]) return domain, min_rmag, mmax, trt, bval_fix, bval_sig_fix, usd, lsd, dep_b, dep_u, dep_l
def get_completeness_model(src_codes, src_shapes, domains, singleCorner): ''' singleCorner 1 = do singleCorner (True) 0 = do not do singleCorner (False) ''' from os import path import shapefile from shapely.geometry import Point, Polygon from tools.nsha_tools import get_field_data, get_shp_centroid from mapping_tools import distance # load completeness shp if singleCorner == 1: compshp = path.join('..', 'Other', 'Mcomp_NSHA18_single.shp') # single corner else: #compshp = path.join('..','Other','Mcomp_NSHA18_multi.shp') # multi corner compshp = path.join('..', 'Other', 'gridded_polygons_3d_completeness.shp' ) # gridded model for updated Mc - Jan 2020 mcsf = shapefile.Reader(compshp) # get completeness data mc_ycomp = get_field_data(mcsf, 'YCOMP', 'str') mc_mcomp = get_field_data(mcsf, 'MCOMP', 'str') # get completeness polygons mc_shapes = mcsf.shapes() # set empty completeness values ycomp = [] mcomp = [] min_rmag = [] # loop through Mcomp zones for code, poly, dom in zip(src_codes, src_shapes, domains): # get centroid of completeness sources clon, clat = get_shp_centroid(poly.points) point = Point(clon, clat) print(clon, clat) # loop through target and find point in poly mccompFound = False dist_to_comp_cent = 9999. for i, mc_shape in enumerate(mc_shapes): mc_poly = Polygon(mc_shape.points) mclon, mclat = get_shp_centroid(mc_shape.points) # check if target centroid in completeness poly if point.within(mc_poly) or point.touches(mc_poly): # get dist to centroids rngkm = distance(clat, clon, mclat, mclon)[0] if rngkm < dist_to_comp_cent: tmp_ycmp = mc_ycomp[i] tmp_mcmp = mc_mcomp[i] mccompFound = True # now fill completeness if True if mccompFound == True: ycomp.append(tmp_ycmp) mcomp.append(tmp_mcmp) # if no Mcomp model assigned, use conservative model elif mccompFound == False: if dom >= 1 and dom <= 8: # for single-corner if singleCorner == 1: ycomp.append('1980;1980') mcomp.append('3.5;3.5') # for mult-corner else: ycomp.append('1980;1964;1900') mcomp.append('3.5;5.0;6.0') # use approx ISC-GEM completeness else: ycomp.append('1975;1964;1904') mcomp.append('5.75;6.25;7.5') # set rmin range min_rmag.append(max([3.0, float(mcomp[-1].split(';')[0])])) return ycomp, mcomp, min_rmag
def get_completeness_model_point(clat, clon, singleCorner): ''' singleCorner 1 = do singleCorner (True) 0 = do not do singleCorner (False) assume AU, dom = 0 ''' dom = 0 from os import path, getcwd import shapefile from shapely.geometry import Point, Polygon from tools.nsha_tools import get_field_data, get_shp_centroid from mapping_tools import distance # load completeness shp if getcwd().startswith('/Users'): if singleCorner == 1: compshp = path.join( '/Users/trev/Documents/Geoscience_Australia/NSHA2018/source_models/zones/shapefiles/Other/Mcomp_NSHA18_single.shp' ) # single corner else: compshp = path.join( '/Users/trev/Documents/Geoscience_Australia/NSHA2018/source_models/zones/shapefiles/Other/gridded_polygons_3d_completeness.shp' ) # multi corner else: if singleCorner == 1: compshp = path.join( '/nas/active/ops/community_safety/ehp/georisk_earthquake/modelling/sandpits/trev/NSHA2018/source_models/zones/shapefiles/Other/Mcomp_NSHA18_single.shp' ) # single corner else: #compshp = path.join('/nas/active/ops/community_safety/ehp/georisk_earthquake/modelling/sandpits/trev/NSHA2018/source_models/zones/shapefiles/Other/Mcomp_NSHA18_multi.shp') # multi corner compshp = path.join( '/nas/active/ops/community_safety/ehp/georisk_earthquake/modelling/sandpits/trev/NSHA2018/source_models/zones/shapefiles/Other/Mcomp_NSHA18_multi_20191217.shp' ) # multi corner mcsf = shapefile.Reader(compshp) # get completeness data mc_ycomp = get_field_data(mcsf, 'YCOMP', 'str') mc_mcomp = get_field_data(mcsf, 'MCOMP', 'str') # get completeness polygons mc_shapes = mcsf.shapes() # set empty completeness values ycomp = [] mcomp = [] min_rmag = [] point = Point(clon, clat) print(clon, clat) # loop through target and find point in poly mccompFound = False dist_to_comp_cent = 9999. for i, mc_shape in enumerate(mc_shapes): mc_poly = Polygon(mc_shape.points) mclon, mclat = get_shp_centroid(mc_shape.points) # check if target centroid in completeness poly if point.within(mc_poly) or point.touches(mc_poly): # get dist to centroids rngkm = distance(clat, clon, mclat, mclon)[0] print(rngkm) if rngkm < dist_to_comp_cent: ycomp.append(mc_ycomp[i]) mcomp.append(mc_mcomp[i]) mccompFound = True print(mc_poly) # if no Mcomp model assigned, use conservative model if mccompFound == False: if dom <= 8: # for single-corner if singleCorner == 1: ycomp = '1980;1980' mcomp = '3.5;3.5' # for mult-corner else: ycomp = '1980;1964;1900' mcomp = '3.5;5.0;6.0' # use approx ISC-GEM completeness else: ycomp = '1975;1964;1904' mcomp = '5.75;6.25;7.5' # set rmin range min_rmag.append(max([3.0, float(mcomp.split(';')[0])])) return ycomp, mcomp, min_rmag