def get_downdip_depth(lat1, lon1, lat2, lon2, dip): from mapping_tools import distance from numpy import sin, radians rupwid = distance(lat1, lon1, lat2, lon2)[0] return rupwid * sin(radians(dip))
def get_arclink_event_data(bulk, fname, dataless, event): from obspy.core.utcdatetime import UTCDateTime try: from obspy.arclink.client import Client except: from obspy.clients.arclink.client import Client #from obspy.clients.fdsn.client import Client from os import path from numpy import nan, isnan from mapping_tools import distance ''' Code to extract IRIS data, one station at a time. Exports mseed file to working directory datetime tuple fmt = (Y,m,d,H,M) sta = station ''' try: #first, check it site is in distance and azimuthal range for channel in ['SHZ', 'EHZ', 'BHZ', 'HHZ', 'BNZ', 'HNZ']: seedid = '.'.join((b[0], b[1], '00', channel)) #'AU.DPH.00.BNZ' try: staloc = dataless.get_coordinates(seedid, b[4]) except: a = 1 # dummy call # try another seed id fmt seedid = '.'.join((b[0], b[1], '', channel)) #'AU.DPH.00.BNZ' try: staloc = dataless.get_coordinates(seedid, b[4]) except: a = 1 # dummy call # now get distance and azimuth rngkm, az, baz = distance(event['lat'], event['lon'], staloc['latitude'], staloc['longitude']) #print(rngkm, az, baz) print('arclink', seedid) getRecord = False if rngkm <= 2000. and az > 110. and az < 250.: getRecord = True elif rngkm <= 50.: getRecord = True # check if file already exists if not path.isfile(fname) and getRecord == True: print('Getting:', fname) client = Client(user='******') st = client.get_waveforms(bulk[0], bulk[1], bulk[2], bulk[3], bulk[4], bulk[5]) st = st.merge(method=0, fill_value='interpolate') print('Writing file:', fname) st.write(fname, format="MSEED") except: print('No data for:', fname) return st
def get_mapping_extent_in_metres(bbox, lonoff): ''' bbox is an array of [lonmin, lonmax, latmin, latmax] ''' from numpy import mean, ceil # get central lon/lat lon_0 = mean([bbox[0], bbox[1]]) + float(lonoff) lat_0 = mean([bbox[2], bbox[3]]) # get xy extents xkm, az, baz = distance(lat_0, bbox[0], lat_0, bbox[1]) ykm, az, baz = distance(bbox[2], lon_0, bbox[3], lon_0) xm = 1000 * xkm ym = 1000 * ykm return lon_0, lat_0, xm, ym
def get_centre_ray(elon, elat, slon, slat): """ locates the centre point of a ray. An alternitive to this would be to locate the deepest point of the ray, but this is unessecery """ from mapping_tools import distance, reckon rngkm, az, baz = distance(elat, elon, slat, slon) clon, clat = reckon(elat, elon, rngkm/2., az) return clon, clat
def check_cwb_data(sta, ev): from data_fmt_tools import return_sta_data from mapping_tools import distance sta_data = return_sta_data(sta) rngkm, az, baz = distance(ev['lat'], ev['lon'], sta_data['stla'], sta_data['stlo']) if rngkm <= 2000. and az > 130. and az < 230.: get_sta_cwb_data(ev['time'].year, ev['time'].month, ev['time'].day, ev['time'].hour, \ ev['time'].minute, 0, 2100, sta)
def get_mapping_extent_from_shp(shpfile, lonoff): import shapefile from numpy import mean, ceil, floor sf = shapefile.Reader(shpfile) shapes = sf.shapes() bbox = [180, 90, -180, -90] padboxlat = 1 padboxlon = 1 for shape in shapes: sbbox = shape.bbox if sbbox[0] < bbox[0]: bbox[0] = sbbox[0] if sbbox[1] < bbox[1]: bbox[1] = sbbox[1] if sbbox[2] > bbox[2]: bbox[2] = sbbox[2] if sbbox[3] > bbox[3]: bbox[3] = sbbox[3] # pad bounding box and round to nearest degree bbox[0] = floor(bbox[0] - padboxlon) bbox[1] = floor(bbox[1] - padboxlat) bbox[2] = ceil(bbox[2] + padboxlon) bbox[3] = ceil(bbox[3] + padboxlat) # get central lon/lat lon_0 = mean([bbox[0], bbox[2]]) + float(lonoff) lat_0 = mean([bbox[1], bbox[3]]) # get xy extents xkm, az, baz = distance(lat_0, bbox[0], lat_0, bbox[2]) ykm, az, baz = distance(bbox[1], lon_0, bbox[3], lon_0) xm = 1000 * xkm ym = 1000 * ykm return lon_0, lat_0, xm, ym
def get_centre_ray(elat, elon, slat, slon, evdp): """ locates the centre point of a ray. An alternitive to this would be to locate the deepest point of the ray, but this is unessecery """ ''' ray = calculate_ray(elat, elon, slat, slon, evdp) centre_idx = int(len(ray)/2) ''' rngkm, az, baz = distance(elat, elon, slat, slon) lonlat = reckon(elat, elon, rngkm / 2., az) return lonlat
def dist_vect(lastlat, lastlon, latvect, lonvect): from numpy import array from mapping_tools import distance rng = [] az = [] baz = [] for l in range(0, len(latvect)): rngtmp, aztmp, baztmp = distance(lastlat, lastlon, latvect[l], lonvect[l]) rng.append(rngtmp) az.append(aztmp) baz.append(baztmp) return array(rng), array(az), array(baz)
from mapping_tools import reckon, distance lon1 = 131.0 lat1 = -11.5 lon2 = 134.5 lat2 = -17.0 rngkm, az, baz = distance(lat1, lon1, lat2, lon2) # get inc distance npts = 16 inckm = rngkm / (npts - 1) plats = [] plons = [] csvtxt = '' for i in range(0, npts): lon2d, lat2d = reckon(lat1, lon1, i * inckm, az) plats.append(lat2d) plons.append(lon2d) csvtxt += ','.join((str('%0.4f' % lon2d), str('%0.4f' % lat2d))) + '\n' f = open('north_aus_profile.csv', 'wb') f.write(csvtxt) f.close()
#print(rhyps[idx][didx]) # start writing txt for i in idx[didx]: rec = ts[i] # interpolate SA data sa_interp = exp(interp(log(T), log(rec['per']), log(rec['geom']))) sa_str = '' for sai in sa_interp: sa_str += ',' + str('%0.4e' % sai) inst_ty = rec['chstr'][0][0:2] + '*' if isnan(rec['azim']): azim = distance(rec['eqla'], rec['eqlo'], rec['stla'], rec['stlo'])[1] rec['azim'] = azim tabtxt += ','.join((rec['ev'], str('%0.3f' % rec['eqlo']), str('%0.3f' % rec['eqla']), \ str('%0.0f' % rec['dep']), str('%0.1f' % rec['mag']), rec['sta'], rec['net'], \ inst_ty, str('%0.0f' % rec['vs30']), str('%0.0f' % rec['rhyp']), \ str('%0.0f' % rec['azim']), str('%0.4e' % rec['pgv']), \ str('%0.4e' % rec['pga']))) + sa_str + '\n' if pklfile.startswith('stdict_ampfact'): f = open('submitted/base_amp_model_flatfile.csv', 'w') else: f = open('submitted/base_model_flatfile.csv', 'w') f.write(tabtxt) f.close()
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
# assign Mws to shapefile data ############################################################################### mmimw = ones_like(mmi) * nan repi = ones_like(mmi) * nan for mwd, mw in zip(mweqdt, evmw): printdate = True for i, eqd in enumerate(eqdt): if isinstance(eqd, dt.datetime): if mwd > eqd - dt.timedelta( seconds=60) and mwd < eqd + dt.timedelta(seconds=60): mmimw[i] = mw # calc distance repi[i] = distance(eqlat[i], eqlon[i], mmilat[i], mmilon[i])[0] # print(event if printdate == True: print(mwd, eqname[i]) printdate = False repi = array(repi) rhyp = sqrt(repi**2 + array(eqdep)**2) #################################################################################### # check fault files #################################################################################### print('Getting rrup ...')
'centroid': feature['properties']['center']['coordinates'], 'intensity': feature['properties']['intensityFine'], 'nresp': feature['properties']['nresp'] } if rec['nresp'] >= 2: dyfimmi.append(rec['intensity']) dyfilat.append(rec['centroid'][1]) dyfilon.append(rec['centroid'][0]) # calc DYFI hypo dist dyfilat = array(dyfilat) dyfilon = array(dyfilon) dyfirepi = [] for i in range(0, len(dyfilat)): dyfirepi.append(distance(eqlat, eqlon, dyfilat[i], dyfilon[i])[0]) dyfirhyp = sqrt(array(dyfirepi)**2 + eqdep**2) # now plot d3 = plt.semilogx(dyfirepi, dyfimmi, '+', lw=2., color='0.6', ms=6) #d3 = plt.semilogx(dyfirepi[0], dyfimmi[0], '+', lw=2., color='0.6', ms=6) # write DYFI MMI4SM #write_mmi_obs_raw('DYFI', dyfidict) #################################################################################### # parse AU ipe #################################################################################### lines = open('../au_ipe/au_ipe_coefs.dat').readlines() vert = 7.
#ev['datetime'] = UTCDateTime(1996,9,25,7,49,56) if st[0].stats.starttime > UTCDateTime(ev['datetime']-timedelta(seconds=601)) \ and st[0].stats.starttime < UTCDateTime(ev['datetime']+timedelta(seconds=300)): evFound = True eqlo = ev['lon'] eqla = ev['lat'] eqmag = ev['mag'] eqdp = ev['dep'] eqdt = ev['datetime'] if evFound == True and cannotMerge == False: # get station details print('Getting picks for', mseedfile) sta_data = return_sta_data(st[0].stats.station) rngkm, azim, baz = distance(eqla, eqlo, sta_data['stla'], sta_data['stlo']) rngdeg = km2deg(rngkm) if rngkm < 2250.: # get arrivals if eqdp < 0: arrival_dep = 0. else: arrival_dep = eqdp arrivals = model.get_travel_times( source_depth_in_km=arrival_dep, distance_in_degree=rngdeg) # find P and S p = []
print('E'+str(fe+1)) yearly_mean = [] yearly_std = [] for year in year_rng: print(' ',year) trng_dist = [] sta_dist = [] for sta in sta_dict: # get year DT yrdt = dt.datetime(year, 6, 1) if yrdt >= sta['startdate'] and yrdt <= sta['enddate']: # calc dustance dist = distance(evla[fe], evlo[fe], sta['stla'], sta['stlo'])[0] if dist <= 1500.: trng_dist.append(dist) sta_dist.append(sta['sta']) # now loop through chosen stations 100 times per year sampled_logA0diff = [] for i in range(0, 1000): sta_rate = random.uniform(low=0.65, high=0.95) # assume 50-90% stations could have recorded the event n_stas = int(round(sta_rate * len(trng_dist))) # determine N stations per sample # sample dists assuming n_stas samp_dists = random.choice(array(trng_dist), size=n_stas)
# loop through events for gad in gadat: if evdt > gad['datetime'] - timedelta(minutes=2) and \ evdt < gad['datetime'] + timedelta(minutes=2): # load mseed st = read(path.join('cwb_legacy', mseedfile)) # loop thru traces & calculate distance for tr in st: for isl in iris_sta_list: # check if in distance range if isl['sta'] == str(tr.stats.station): repi = distance(gad['lat'], gad['lon'], isl['lat'], isl['lon'])[0] if repi >= mindist and repi <= maxdist: print gad['datetime'], str(tr.stats.station) print repi # make filename filedt = datetime.strftime( (gad['datetime'] - timedelta(minutes=4)), '%Y-%m-%dT%H.%M') outmseed = path.join('cwb_legacy', '.'.join((filedt, str(tr.stats.network), \ str(tr.stats.station), 'mseed'))) tr.write(outmseed, format='MSEED')
elif filename.find('HHH') >= 0: psafile = path.join(root, filename) # get record details print(stn, psafile) sta, sps, rhyp, pga, pgv, mag_hold, dep, stlo, stla = read_psa_details(psafile) # now plot if stn != 'CDNM': i += 1 print('rhyp', rhyp) vs30, isproxy, usgsvs, asscmvs, kvs, stla, stlo = get_station_vs30(stn) #sta_dat = return_sta_data(stn) # now calculate distance on the fly repi = distance(eqlat, eqlon, stla, stlo)[0] rhyp = sqrt(repi**2 + eqdep**2) if isnan(vs30): vs30 = 760. ax = makesubplt(i, fig, plt, stn, sps, mag, eqdep, ztor, dip, rake, rhyp, vs30) if ii == 1: if prefix.startswith('201206'): if rhyp <= 100: plt.ylim([1e-4, .2]) else: plt.ylim([1e-5, 0.02]) elif prefix.startswith('201207'): if rhyp <= 20:
if len_recs > 2: ev_count += 1 cent_lonlist = array(cent_lonlist) cent_latlist = array(cent_latlist) cent_mmi = array(cent_mmi) cent_nresp = array(cent_nresp) event_ids = array(event_ids) eqlo = array(eqlo) eqla = array(eqla) eqmag = array(eqmag) # get source-site distance mmi_dist = [] for ela, elo, cla, clo in zip(eqla, eqlo, cent_latlist, cent_lonlist): mmi_dist.append(distance(ela, elo, cla, clo)[0]) mmi_dist = array(mmi_dist) ''' # get unique values unique_lons = unique(array(cent_lonlist)) unique_lats = unique(array(cent_latlist)) unique_cent = [] i = 0 for clo, cla in zip(cent_lonlist, cent_latlist): cent_match = False if i == 0: unique_cent.append([clo, cla]) else: for ucent in unique_cent:
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
def get_iris_event_data(bulk, folder, timestr, dataless, event): from obspy import UTCDateTime from obspy.clients.fdsn.client import Client #from obspy.fdsn import Client from os import path from numpy import nan, isnan from mapping_tools import distance ''' Code to extract IRIS data, one station at a time. Exports mseed file to working directory datetime tuple fmt = (Y,m,d,H,M) sta = station ''' fdsn_client = Client("IRIS") #client = Client("IRIS") sta = [] #st = client.get_waveforms_bulk(bulk) for b in bulk: try: fname = '.'.join((timestr, b[0], b[1], 'mseed')) fpath = path.join(folder, fname.replace(':', '.')) staloc = nan #first, check it site is in distance and azimuthal range for channel in ['SHZ', 'EHZ', 'BHZ', 'HHZ', 'BNZ', 'HNZ']: if b[0] == 'WRAB': locCode = '10' else: locCode = '00' seedid = '.'.join( (b[0], b[1], locCode, channel)) # e.g., 'AU.DPH.00.BNZ' try: staloc = dataless.get_coordinates(seedid, b[4]) except: a = 1 # dummy call seedid = '.'.join( (b[0], b[1], '', channel)) # e.g., 'AU.DPH..BNZ' try: staloc = dataless.get_coordinates(seedid, b[4]) except: a = 1 # dummy call # now get distance and azimuth rngkm, az, baz = distance(event['lat'], event['lon'], staloc['latitude'], staloc['longitude']) print(rngkm, az, baz) getRecord = False if rngkm <= 2000. and az > 130. and az < 230.: getRecord = True elif rngkm <= 2000. and az > 120. and az < 240. and b[1] == 'RABL': getRecord = True elif rngkm <= 2000. and az > 120. and az < 240. and b[1] == 'PMG': getRecord = True # second, check if file exists #print(path.isfile(fpath), getRecord) if not path.isfile(fpath) and getRecord == True: bulk2 = [(b[0], b[1], b[2], "*", b[4], b[5])] #, print('B2', bulk2) # ("AU", "AFI", "1?", "BHE", b[4], b[5])] client = Client("IRIS") #st = client.get_waveforms_bulk(bulk2) st = client.get_waveforms(b[0], b[1], b[2], "*", b[4], b[5]) ''' st = fdsn_client.get_waveforms(network=b[0], station=b[1], location=b[2], channel=b[3], starttime=b[4], endtime=b[5], attach_response=True) ''' #print(st[0].stats.location) st = st.merge(method=0, fill_value='interpolate') sta += st print('Writing file: ' + fpath) st.write(fpath, format="MSEED") else: print('File exists:', fpath) #return st except: print('No data for', b[0], b[1]) return sta
# prep for response spectra freq, wavfft = calc_fft(tr.data, tr.stats.sampling_rate) # prep for psa iacc = prep_psa_simple(wavfft.real, wavfft.imag, freq, 'B') # calc response spectra h = 5.0 # % minT = 0.1 maxT = 10 T, psa, pga = calc_response_spectra( iacc, tr.stats.sampling_rate, h, minT, maxT) pgv = max(abs(tr.data)) repi = distance(pickDat['eqla'], pickDat['eqlo'], staloc['latitude'], staloc['longitude'])[0] rhyp = sqrt(repi**2 + pickDat['eqdp']) azim = distance(pickDat['eqla'], pickDat['eqlo'], staloc['latitude'], staloc['longitude'])[1] psafilename = path.split( msf[:-6])[-1] + '.' + tr.stats.channel write_response_spectra(tr.stats.station, pickDat['origintime'], tr.stats.sampling_rate, \ T, psa, pga, pgv, psafilename, staloc['latitude'], staloc['longitude'], \ pickDat['eqla'], pickDat['eqlo'], pickDat['eqdp'], pickDat['mag'], rhyp, azim, lofreq, hifreq) #except: # print('Failed: ' + pickDat['mseed_path'])
arraowCol = ['k', '0.5', 'k', '0.5'] discLen = 150. # km triLen = 40. halfTriLen = triLen / 2. for fault, adirn, acol, in zip(faults2plot, arrowDirn, arraowCol): flolas = drawoneshapepoly(m, plt, sf, 'Name', fault, lw=1.5, polyline=True) discLon = [] discLat = [] discAzm = [] remainder = discLen #+ discLen/2. for poly in flolas: for i in range(1, len(poly[0])): # get dist from point 1 to point 2 rng, az, baz = distance(poly[1][i - 1], poly[0][i - 1], poly[1][i], poly[0][i]) lens = arange(discLen - remainder, rng, discLen) # get xy locs for lens if len(lens) > 0: for l in lens: discPos = reckon(poly[1][i - 1], poly[0][i - 1], l, az) discLon.append(discPos[0]) discLat.append(discPos[1]) discAzm.append(az) remainder = rng - lens[-1] else: remainder += rng
############################################################################## # loop through events ############################################################################## mindist = 0 if network == 'S1': maxdist = 1000 else: maxdist = 2200 #maxdist = 200 # already got 200 - 2200 km # loop thru events for ev in gadat: #[40:]: dt = ev['datetime'] print(dt) # allow 2 mins pre-event - subs realised "get_iris_data" already pads by 2 mins, so have 4 mins dateTuple = (dt.year, dt.month, dt.day, dt.hour, dt.minute - 2) # loop thru stations for isl in iris_sta_list: # check if station is open if isl['starttime'] <= dt and isl[ 'stoptime'] >= dt: # and dt.year >= 2014: # check if in distance range repi = distance(ev['lat'], ev['lon'], isl['lat'], isl['lon'])[0] if repi >= mindist and repi <= maxdist: # and isl['sta'].startswith('KIM'): st = get_iris_data(dateTuple, isl['sta'], network, durn=1800)
fix_bval_sig = -99 bin_width = 0.1 poly = nan ##################################################################### # loop through coords ##################################################################### for x in xrng: for y in yrng: print('\n'+str(x)+' '+str(y)) # calculate dist to all eqs epidist = [] for la, lo in zip(eqla, eqlo): epidist.append(distance(y, x, la, lo)[0]) epidist = array(epidist) # get centroid completeness singleCorner = 0 src_ycomp, src_mcomp, min_rmag = get_completeness_model_point(y, x, singleCorner) print(src_ycomp, src_mcomp, min_rmag) neqs = 0 search_rad = reskm while neqs < 50: idx = where(epidist <= search_rad)[0] neqs = len(idx) # set inputs for completeness mvect = eqmg[idx]
pt = Point(slo, sla) if pt.within(poly): shlo.append(slo) shla.append(sla) shlo = array(shlo) shla = array(shla) # plt OQ grd points x, y = m(shlo, shla) m.plot(x, y, '+', c='0.5', ms=10, mew=1.5) # get points LT dist cutoff oq_dist = [] for la, lo in zip(shla, shlo): oq_dist.append(distance(la, lo, loc_lat, loc_lon)[0]) # plt pts within cutoff oq_dist = array(oq_dist) idx = where(oq_dist <= dist_cutoff)[0] x, y = m(shlo[idx], shla[idx]) m.plot(x, y, 'r+', ms=10, mew=1.5) # draw cut-off boundary cutaz = arange(0, 360, 0.5) cutla = [] cutlo = [] for az in cutaz: cutlo.append(reckon(loc_lat, loc_lon, dist_cutoff, az)[0]) cutla.append(reckon(loc_lat, loc_lon, dist_cutoff, az)[1]) cutlo.append(cutlo[0])