def PGD_basic(SA_lat, SA_lon, SA_dep, sta_lat, sta_lon, d): """ Creates basic benchmark for PGD scaling """ hypoupdate = zeros(len(sta_lat)) (x1, y1) = ll2utm(SA_lon, SA_lat, -123.0) (x2, y2) = ll2utm(sta_lon, sta_lat, -123.0) epidist = sqrt(power(x1 - x2, 2) + power(y1 - y2, 2)) runtime = 300.0 # get all events SA_time = 0.0 a1 = where(epidist / 1000.0 < (runtime - SA_time) * 3)[0] a1 = array(a1) dep = SA_dep maxD = zeros([len(a1), 1]) maxD[:, 0] = d[:] hypoupdate = zeros([len(a1), 1]) hypoupdate[:, 0] = sqrt( power(x1 - x2[a1], 2) + power(y1 - y2[a1], 2) + power(dep * 1000, 2)) [MPGD, VR_PGD] = PGD(100 * maxD, hypoupdate / 1000, epidist[a1] / 1000) print "Benchmarks for basic PGD is (MPGD,VR_PGD):", MPGD, VR_PGD
def GreenF_test(SA_lat, SA_lon, SA_dep, sta_lat, sta_lon): l1 = len(sta_lat) l2 = 1 xrs = zeros([l1, 1]) yrs = zeros([l1, 1]) zrs = zeros([l1, 1]) azi = zeros([l1, 1]) backazi = zeros([l1, 1]) for j in range(0, l1): (x1, y1) = ll2utm(sta_lon[j], sta_lat[j], -123.0) (x2, y2) = ll2utm(SA_lon, SA_lat, -123.0) azi[j, 0] = 90 - 180 / pi * atan2(x2 - x1, y2 - y1) if (azi[j, 0] < 0): azi[j, 0] = azi[j, 0] + 360 if (azi[j, 0] > 360): azi[j, 0] = azi[j, 0] - 360 if (azi[j, 0] < 180): backazi[j, 0] = azi[j, 0] + 180 if (azi[j, 0] > 180): backazi[j, 0] = azi[j, 0] - 180 if (azi[j, 0] == 180): backazi[j, 0] = 0 xrs[j, 0] = (x1 - x2) yrs[j, 0] = (y1 - y2) zrs[j, 0] = (SA_dep * 1000) G = greenF(xrs, yrs, zrs, 90 - azi + 180) #Compute Green's function print "CMT Gmat:" for l1 in xrange(len(G[:, 0])): line = '' for i in xrange(len(G[l1, :])): if (i == 3): line = line + '\n' line = line + "%14.8e," % G[l1, i] print line
def fault_CMT(lat, lon, depth, M, strikeF, dipF, nstr, ndip): [x0, y0] = ll2utm(lon, lat, -123.0) x0 = x0 / 1000 y0 = y0 / 1000 fault_alt = numpy.zeros([nstr * ndip, 1]) fault_lon = numpy.zeros([nstr * ndip, 1]) fault_lat = numpy.zeros([nstr * ndip, 1]) strike = strikeF * numpy.ones([nstr * ndip, 1]) dip = dipF * numpy.ones([nstr * ndip, 1]) AREA = math.pow(10, -3.49 + 0.91 * M) #Area of fault from Dreger and Kaverina, 2000 LEN = math.pow(10, -2.44 + 0.59 * M) #Length of fault from Dreger and Kaverina, 2000 WID = AREA / LEN #Fault width is area divided by length LEN = LEN + 0.1 * LEN #fault dimensions with 10% safety factor added WID = WID + 0.1 * WID if ( WID / 2 * math.sin(dipF * math.pi / 180) > depth ): #sets the initial top depth - either depth-width/2*sin(dip) or 0 depending on how wide and close to surface fault is z0 = 0 x0 = x0 - LEN / 2 * math.sin( strikeF * math.pi / 180) - depth * math.cos( dipF * math.pi / 180) * math.sin( (strikeF + 90) * math.pi / 180) y0 = y0 - LEN / 2 * math.cos( strikeF * math.pi / 180) - depth * math.cos( dipF * math.pi / 180) * math.cos( (strikeF + 90) * math.pi / 180) else: z0 = depth - WID / 2 * math.sin(dipF * math.pi / 180) x0 = x0 - LEN / 2 * math.sin( strikeF * math.pi / 180) - WID / 2 * math.cos( dipF * math.pi / 180) * math.sin( (strikeF + 90) * math.pi / 180) y0 = y0 - LEN / 2 * math.cos( strikeF * math.pi / 180) - WID / 2 * math.cos( dipF * math.pi / 180) * math.cos( (strikeF + 90) * math.pi / 180) DLEN = LEN / nstr DWID = WID / ndip xdoff = DWID * math.cos(dipF * math.pi / 180) * math.sin( (strikeF + 90) * math.pi / 180) ydoff = DWID * math.cos(dipF * math.pi / 180) * math.cos( (strikeF + 90) * math.pi / 180) xsoff = DLEN * math.sin(strikeF * math.pi / 180) ysoff = DLEN * math.cos(strikeF * math.pi / 180) k = 0 for j in range(0, ndip): for i in range(0, nstr): fault_X = x0 + (0.5 + i) * xsoff + (0.5 + j) * xdoff fault_Y = y0 + (0.5 + i) * ysoff + (0.5 + j) * ydoff fault_alt[k] = z0 + (0.5 + j) * DWID * math.sin( dipF * math.pi / 180) (fault_lon[k], fault_lat[k]) = utm2ll(fault_X * 1000, fault_Y * 1000, -123.0) k = k + 1 return (fault_lon, fault_lat, fault_alt, strike, dip, DLEN * numpy.ones([nstr * ndip, 1]), DWID * numpy.ones([nstr * ndip, 1]))
def data_engine_cmtff(SA_lat, SA_lon, SA_dep, SA_time, SA_mag, SA_eventid, sta_lat, sta_lon, nbuffnew, ebuffnew, ubuffnew, runtime): fname = 'events/GFAST_CMT_' + str(int(SA_eventid)) + '.txt' f = open(fname, 'a') #open gps data file to append data (x1, y1) = ll2utm(SA_lon, SA_lat, -123.0) (x2, y2) = ll2utm(sta_lon, sta_lat, -123.0) epidist = numpy.sqrt(numpy.power(x1 - x2, 2) + numpy.power(y1 - y2, 2)) a1 = numpy.where(epidist / 1000 < (runtime - SA_time) * 2 + 10)[0] a1 = numpy.array(a1) if len(a1) > 3: mcmt_vr = numpy.zeros([100, 1]) S1 = numpy.zeros([100, 1]) S2 = numpy.zeros([100, 1]) S3 = numpy.zeros([100, 1]) S4 = numpy.zeros([100, 1]) S5 = numpy.zeros([100, 1]) S6 = numpy.zeros([100, 1]) STR1 = numpy.zeros([100, 1]) STR2 = numpy.zeros([100, 1]) DIP1 = numpy.zeros([100, 1]) DIP2 = numpy.zeros([100, 1]) RAK1 = numpy.zeros([100, 1]) RAK2 = numpy.zeros([100, 1]) mcmt = numpy.zeros([100, 1]) #Depth Search dep = 1 while dep < 101: [S, VR, Mw, NP1, NP2] = moment_tensor(sta_lat[a1], sta_lon[a1], nbuffnew[a1, :], ebuffnew[a1, :], ubuffnew[a1, :], SA_lat, SA_lon, dep + 0.1, runtime, epidist) mcmt_vr[dep - 1, 0] = VR S1[dep - 1, 0] = S[0] S2[dep - 1, 0] = S[1] S3[dep - 1, 0] = S[2] S4[dep - 1, 0] = S[3] S5[dep - 1, 0] = S[4] S6[dep - 1, 0] = S[5] STR1[dep - 1, 0] = NP1['strike'] STR2[dep - 1, 0] = NP2['strike'] DIP1[dep - 1, 0] = NP1['dip'] DIP2[dep - 1, 0] = NP2['dip'] RAK1[dep - 1, 0] = NP1['rake'] RAK2[dep - 1, 0] = NP2['rake'] mcmt[dep - 1, 0] = Mw dep = dep + 1 dep_vr_cmt = numpy.argmax(mcmt_vr) mcmtstr = "{0:.2f}".format(float(mcmt[dep_vr_cmt])) vrcmtstr = "{0:.2f}".format(float(mcmt_vr[dep_vr_cmt])) str1 = "{0:.2f}".format(float(STR1[dep_vr_cmt])) str2 = "{0:.2f}".format(float(STR2[dep_vr_cmt])) dip1 = "{0:.2f}".format(float(DIP1[dep_vr_cmt])) dip2 = "{0:.2f}".format(float(DIP2[dep_vr_cmt])) rak1 = "{0:.2f}".format(float(RAK1[dep_vr_cmt])) rak2 = "{0:.2f}".format(float(RAK2[dep_vr_cmt])) print mcmtstr, dep_vr_cmt f.write( '>Event Overview (cols: lon, lat, OT (s), ElarmS mag, CMT mag, CMT variance reduction, CMT Depth, FP1 STR, FP1 DIP, FP1 RAKE, FP2 STR, FP2 DIP, FP2 RAKE,CMT no. stations, G-FAST alert time (s))' + '\n') f.write( str(SA_lon) + ' ' + str(SA_lat) + ' ' + str(SA_time) + ' ' + str(SA_mag) + ' ' + mcmtstr + ' ' + vrcmtstr + ' ' + str(dep_vr_cmt) + ' ' + str1 + ' ' + dip1 + ' ' + rak1 + ' ' + str2 + ' ' + dip2 + ' ' + rak2 + ' ' + str(len(a1)) + ' ' + str(runtime) + '\n') f.write('>' + '\n') f.close() else: mcmt_vr = numpy.zeros([100, 1]) S1 = numpy.zeros([100, 1]) S2 = numpy.zeros([100, 1]) S3 = numpy.zeros([100, 1]) S4 = numpy.zeros([100, 1]) S5 = numpy.zeros([100, 1]) S6 = numpy.zeros([100, 1]) STR1 = numpy.zeros([100, 1]) STR2 = numpy.zeros([100, 1]) DIP1 = numpy.zeros([100, 1]) DIP2 = numpy.zeros([100, 1]) RAK1 = numpy.zeros([100, 1]) RAK2 = numpy.zeros([100, 1]) mcmt = numpy.zeros([100, 1]) return (MW, S1, S2, S3, S4, S5, S6, STR1, STR2, DIP1, DIP2, RAK1, RAK2, VARRED, len(a1))
def data_engine_pgd(SA_lat, SA_lon, SA_dep, SA_time, SA_mag, SA_eventid, sta_lat, sta_lon, nbuffnew, ebuffnew, ubuffnew, runtime): fname = 'events/GFAST_PGD_' + str(int(SA_eventid)) + '.txt' f = open(fname, 'a') #open gps data file to append data (x1, y1) = ll2utm(SA_lon, SA_lat, -123.0) (x2, y2) = ll2utm(sta_lon, sta_lat, -123.0) epidist = numpy.sqrt(numpy.power(x1 - x2, 2) + numpy.power(y1 - y2, 2)) a1 = numpy.where(epidist / 1000 < (runtime - SA_time) * 3)[0] a1 = numpy.array(a1) if len(a1) > 3: dt = runtime - SA_time if (dt > 299): dt = 299 Dnew = numpy.zeros([len(a1), int(dt)]) ind = 0 while ind < len(a1): if numpy.isnan(nbuffnew[a1[ind], int(dt)]): n0 = 0 else: n0 = nbuffnew[a1[ind], int(dt)] if numpy.isnan(ebuffnew[a1[ind], int(dt)]): e0 = 0 else: e0 = ebuffnew[a1[ind], int(dt)] if numpy.isnan(ubuffnew[a1[ind], int(dt)]): u0 = 0 else: u0 = ubuffnew[a1[ind], int(dt)] nn = nbuffnew[a1[ind], 0:int(dt)] - n0 ee = ebuffnew[a1[ind], 0:int(dt)] - e0 uu = ubuffnew[a1[ind], 0:int(dt)] - u0 Dnew[ind, :] = numpy.sqrt( numpy.power(nn, 2) + numpy.power(ee, 2) + numpy.power(uu, 2)) ind = ind + 1 mpgd_vr = numpy.zeros([100, 1]) mpgd = numpy.zeros([100, 1]) maxD = numpy.zeros([len(a1), 1]) maxD = numpy.nanmax(Dnew, axis=1, out=maxD, keepdims=True) dep = 1 while dep < 101: hypoupdate = numpy.sqrt( numpy.power(x1 - x2[a1], 2) + numpy.power(y1 - y2[a1], 2) + numpy.power(dep * 1000, 2)) [MPGD, VR_PGD] = PGD(100 * maxD, hypoupdate / 1000, epidist[a1] / 1000) mpgd[dep - 1] = MPGD mpgd_vr[dep - 1] = VR_PGD dep = dep + 1 dep_vr_pgd = numpy.argmax(mpgd_vr) mpgdstr = "{0:.2f}".format(float(mpgd[dep_vr_pgd])) vrpgdstr = "{0:.2f}".format(float(mpgd_vr[dep_vr_pgd])) f.write( '>Event Overview (cols: lon, lat, OT (s), ElarmS mag, PGD mag, PGD variance reduction, PGD Depth, PGD no. stations, G-FAST alert time (s))' + '\n') f.write( str(SA_lon) + ' ' + str(SA_lat) + ' ' + str(SA_time) + ' ' + str(SA_mag) + ' ' + mpgdstr + ' ' + vrpgdstr + ' ' + str(dep_vr_pgd) + ' ' + str(len(a1)) + ' ' + str(runtime) + '\n') f.write('>PGD Records' + '\n') ind = 0 while ind < len(a1): edist = "{0:.2f}".format(float(epidist[a1[ind]]) / 1000) md = "{0:.2f}".format(float(maxD[ind]) * 100) f.write(edist + ' ' + md + '\n') ind = ind + 1 f.write('>' + '\n') f.close() #else: #mpgd_vr = numpy.zeros([100,1]) #mpgd = numpy.zeros([100,1]) else: mpgd_vr = numpy.zeros([100, 1]) mpgd = numpy.zeros([100, 1]) return (mpgd, mpgd_vr, len(a1))
def UTM_test(sta_lat, sta_lon): (x2, y2) = ll2utm(sta_lon, sta_lat, -123.0) print "xutms:", x2 print "yutms:", y2