def make_okada_dz(fm, faultparams): mx = faultparams['mx'] my = faultparams['my'] X = linspace(faultparams['xlower'], faultparams['xupper'], mx) Y = linspace(faultparams['ylower'], faultparams['yupper'], my) dZ = zeros((my, mx)) okadaparams = {} print "Making Okada dZ for each of %s subfaults" \ % str(fm.arrayshape[0]*fm.arrayshape[1]) for i in range(fm.arrayshape[0]): for j in range(fm.arrayshape[1]): sys.stdout.write("%s.." % str(j + i * fm.arrayshape[1])) sys.stdout.flush() okadaparams["Focal_Depth"] = fm.depth[i, j] okadaparams["Fault_Length"] = fm.subfault_length okadaparams["Fault_Width"] = fm.subfault_width okadaparams["Dislocation"] = fm.slip[i, j] okadaparams["Strike_Direction"] = fm.strike[i, j] okadaparams["Dip_Angle"] = fm.dip[i, j] okadaparams["Slip_Angle"] = fm.rake[i, j] #okadaparams["Epicenter_Latitude"] = fm.latitude[i,j] #okadaparams["Epicenter_Longitude"] = fm.longitude[i,j] okadaparams["Fault_Latitude"] = fm.latitude[i, j] okadaparams["Fault_Longitude"] = fm.longitude[i, j] okadaparams["LatLong_Location"] = "centroid" # correct #okadaparams["LatLong_Location"] = "top center" # used before dZ = dZ + okadamap(okadaparams, X, Y) sys.stdout.write("\nDone\n") return X, Y, dZ
def make_okada_dz(fm, faultparams): mx = faultparams['mx'] my = faultparams['my'] X=linspace(faultparams['xlower'],faultparams['xupper'],mx) Y=linspace(faultparams['ylower'],faultparams['yupper'],my) dZ = zeros((my,mx)) okadaparams = {} print "Making Okada dZ for each of %s subfaults" \ % str(fm.arrayshape[0]*fm.arrayshape[1]) for i in range(fm.arrayshape[0]): for j in range(fm.arrayshape[1]): sys.stdout.write("%s.." % str(j+i*fm.arrayshape[1])) sys.stdout.flush() okadaparams["Focal_Depth"] = fm.depth[i,j] okadaparams["Fault_Length"] = fm.subfault_length okadaparams["Fault_Width"] = fm.subfault_width okadaparams["Dislocation"] = fm.slip[i,j] okadaparams["Strike_Direction"] = fm.strike[i,j] okadaparams["Dip_Angle"] = fm.dip[i,j] okadaparams["Slip_Angle"] = fm.rake[i,j] #okadaparams["Epicenter_Latitude"] = fm.latitude[i,j] #okadaparams["Epicenter_Longitude"] = fm.longitude[i,j] okadaparams["Fault_Latitude"] = fm.latitude[i,j] okadaparams["Fault_Longitude"] = fm.longitude[i,j] okadaparams["LatLong_Location"] = "centroid" # correct #okadaparams["LatLong_Location"] = "top center" # used before dZ = dZ + okadamap(okadaparams, X, Y) sys.stdout.write("\nDone\n") return X,Y,dZ
def make_okada_dz_witht(fm, faultparams, times, fname): mx = faultparams['mx'] my = faultparams['my'] X = linspace(faultparams['xlower'], faultparams['xupper'], mx) Y = linspace(faultparams['ylower'], faultparams['yupper'], my) mt = len(times) dZ = zeros((mt, my, mx)) first_time = -ones(fm.arrayshape) okadaparams = {} dZsubfault = [] print "Making Okada dZ for each of %s subfaults" \ % str(fm.arrayshape[0]*fm.arrayshape[1]) for i in range(fm.arrayshape[0]): dZsubi = [] for j in range(fm.arrayshape[1]): sys.stdout.write("%s.." % str(j + i * fm.arrayshape[1])) sys.stdout.flush() okadaparams["Focal_Depth"] = fm.depth[i, j] okadaparams["Fault_Length"] = fm.subfault_length okadaparams["Fault_Width"] = fm.subfault_width okadaparams["Dislocation"] = fm.slip[i, j] okadaparams["Strike_Direction"] = fm.strike[i, j] okadaparams["Dip_Angle"] = fm.dip[i, j] okadaparams["Slip_Angle"] = fm.rake[i, j] okadaparams["Fault_Latitude"] = fm.latitude[i, j] okadaparams["Fault_Longitude"] = fm.longitude[i, j] okadaparams["LatLong_Location"] = "centroid" dZij = okadamap(okadaparams, X, Y) dZsubi.append(dZij) dZsubfault.append(dZsubi) sys.stdout.write("\nDone\n") dZsubfault = array(dZsubfault) dZ = zeros((mx, my)) tprev = times.min() - 1. fid = open(fname, 'w') pngfiles = [] if 0. not in times: times = hstack(([0.], times)) print "Making time-dependent dZ for each of %s times" \ % str(len(times)) for frameno, t in enumerate(times): ruptured = [] # add to dZ any slip during time interval tprev to t: for i in range(fm.arrayshape[0]): for j in range(fm.arrayshape[1]): if (fm.rupture_initial_time[i,j] > tprev) and \ (fm.rupture_initial_time[i,j] <= t): dZ = dZ + dZsubfault[i, j] print "Adding subfault (%s,%s) at time %s... rupture_initial_time = %s" \ % (i,j,t,fm.rupture_initial_time[i,j]) ruptured.append((i, j)) # write out dZ at this time: for jj in range(len(Y)): j = -1 - jj for i in range(len(X)): fid.write('%012.6e %012.6e %012.6e %012.6e \n' \ % (t,X[i],Y[j],dZ[j,i])) print "Made dZ at time %s" % t plot_dZ = True if plot_dZ: figure(5) clf() plot(fm.fault_bdry[:, 0], fm.fault_bdry[:, 1], 'k') cmap = colormaps.blue_white_red pcolor(X, Y, dZ, cmap=cmap) for (i, j) in ruptured: # plot centroids of the fault segments that ruptured # during this time increment: plot([fm.longitude[i, j]], [fm.latitude[i, j]], 'go') clim(-10, 10) colorbar() contour(X, Y, dZ, linspace(-13, 13, 14), colors='k') title("dZ at time t = %10.2f" % t) draw() fname = "dZframe%s.png" % str(frameno).zfill(4) savefig(fname) pngfiles.append(fname) tprev = t fid.close() print "Created dtopo file ", fname if plot_dZ: html_movie.make_movie(pngfiles, "index.html") return X, Y, dZ
def make_dtopo_from_subfaults(subfaults, dtopo_params): """ Create a dtopo file named *fname* based on applying the Okada model to each of the subfaults specified in the list *subfaults*. This should be a list of dictionaries that specify the necessary Okada parameters and optionally 'rupture_time', 'rise_time', 'rise_time_ending'. The dictionary *dtopo_params* specifies the parameters for the dtopo file created. It must have entries for 'fname' : file name for dtopo file and 'mx', 'my', 'xlower', 'xupper', 'ylower', 'yupper' specifying the area over which the dz values will be output on an mx by my grid. Note that dz values are at vertices, so to output on a 1 minute grid, for example, set mx = 60*(xupper - xlower) + 1 Also dtopo_params['t0'] initial time for output dtopo_params['tfinal'] final time for output dtopo_params['ntimes'] >= 2, number of output times The seafloor deformation dz will be output at ntimes equally spaced times between t0 and tfinal. If dtopo_params['faulttype'] == 'static' then dz at t0 will be 0 and dz at tfinal will be the total dz determined by all the subfaults, ignoring the rupture_time and rise_time parameters, if any. Normally in this case it is best to specify ntimes = 2 and t0=0, tfinal=1 second, for example. If larger ntimes is specified then linear interpolation is used to determine dz at intermediate times. If dtopo_params['faulttype'] == 'kinematic' or 'dynamic' then it is assumed that the rupture_time and rise_time are set and will be used to interpolate to the specified output times. dtopo_params['dtopotype'] = 3 is assumed currently but this could be extended to allow output with other dtopotypes. """ fname = dtopo_params['fname'] faulttype = dtopo_params.get('faulttype', 'static') dtopotype = dtopo_params.get('dtopotype', 3) t0 = dtopo_params.get('t0', 0.) tfinal = dtopo_params.get('tfinal', 1.) ntimes = dtopo_params.get('ntimes', 2) mx = dtopo_params['mx'] my = dtopo_params['my'] xlower = dtopo_params['xlower'] ylower = dtopo_params['ylower'] xupper = dtopo_params['xupper'] yupper = dtopo_params['yupper'] x=linspace(xlower,xupper,mx) y=linspace(ylower,yupper,my) times = linspace(t0,tfinal,ntimes) plot_rupture = False dZ = zeros((my,mx)) dz_list = [] if dtopotype in [3]: fid = write_dtopo_header(dtopo_params) else: raise Exception("Unsupported dtopotype: %s, use dtopotype=3" \ % dtopotype) if faulttype == 'static': print "Making Okada dz for each of %s subfaults" \ % len(subfaults) for k,subfault in enumerate(subfaults): dZk = okadamap(subfault, x, y) sys.stdout.write("%s.." % k) sys.stdout.flush() dZ = dZ + dZk sys.stdout.write("\nDone\n") for t in times: alpha=(t-t0)/(tfinal-t0) dz_list.append(alpha*dZ) for j in range(my-1, -1, -1): format = mx*'%12.6e ' fid.write(format % tuple(alpha*dZ[j,:])) fid.write('\n') elif faulttype in ['kinematic','dynamic']: t_prev = -1.e99 for t in times: if plot_rupture: plt.figure(5) plt.clf() for k,subfault in enumerate(subfaults): t0 = subfault.get('rupture_time',0) t1 = subfault.get('rise_time',0.5) t2 = subfault.get('rise_time_ending',0) rf = rise_fraction(t0,t1,t2) dfrac = rf(t) - rf(t_prev) if dfrac > 0.: if subfault.get('dZ',None) is None: subfault.dZ = okadamap(subfault, x, y) print '+++ Applying Okada to subfault %s at t = %s' \ % (k,t) dZ = dZ + dfrac * subfault.dZ if plot_rupture: xc = subfault.longitude yc = subfault.latitude rise = rf(t) if rise==0: plot(xc,yc,'wo') elif rise==1: plot(xc,yc,'ko') else: plot(xc,yc,'ro') if plot_rupture: clines = list(arange(-10.5,0.,0.5)) + list(arange(0.5,11,0.5)) plt.contour(x,y,dZ,clines) plt.title('time t = %8.3f' % t) plt.draw() dz_list.append(dZ) for j in range(my-1, -1, -1): fid.write(mx*'%012.6e ' % dZ[j,:]) fid.write('\n') else: raise Exception("Unrecognized faulttype: %s" % faulttype) print "Created ",fname fid.close() dtopo = DTopo() dtopo.dtopo_params = dtopo_params dtopo.x = x dtopo.y = y dtopo.times = times dtopo.dz_list = dz_list dtopo.subfaults = subfaults return dtopo
def make_dtopo_from_subfaults(subfaults, dtopo_params): """ Create a dtopo file named *fname* based on applying the Okada model to each of the subfaults specified in the list *subfaults*. This should be a list of dictionaries that specify the necessary Okada parameters and optionally 'rupture_time', 'rise_time', 'rise_time_ending'. The dictionary *dtopo_params* specifies the parameters for the dtopo file created. It must have entries for 'fname' : file name for dtopo file and 'mx', 'my', 'xlower', 'xupper', 'ylower', 'yupper' specifying the area over which the dz values will be output on an mx by my grid. Note that dz values are at vertices, so to output on a 1 minute grid, for example, set mx = 60*(xupper - xlower) + 1 Also dtopo_params['t0'] initial time for output dtopo_params['tfinal'] final time for output dtopo_params['ntimes'] >= 2, number of output times The seafloor deformation dz will be output at ntimes equally spaced times between t0 and tfinal. If dtopo_params['faulttype'] == 'static' then dz at t0 will be 0 and dz at tfinal will be the total dz determined by all the subfaults, ignoring the rupture_time and rise_time parameters, if any. Normally in this case it is best to specify ntimes = 2 and t0=0, tfinal=1 second, for example. If larger ntimes is specified then linear interpolation is used to determine dz at intermediate times. If dtopo_params['faulttype'] == 'kinematic' or 'dynamic' then it is assumed that the rupture_time and rise_time are set and will be used to interpolate to the specified output times. dtopo_params['dtopotype'] = 3 is assumed currently but this could be extended to allow output with other dtopotypes. """ fname = dtopo_params['fname'] faulttype = dtopo_params.get('faulttype', 'static') dtopotype = dtopo_params.get('dtopotype', 3) t0 = dtopo_params.get('t0', 0.) tfinal = dtopo_params.get('tfinal', 1.) ntimes = dtopo_params.get('ntimes', 2) mx = dtopo_params['mx'] my = dtopo_params['my'] xlower = dtopo_params['xlower'] ylower = dtopo_params['ylower'] xupper = dtopo_params['xupper'] yupper = dtopo_params['yupper'] x = linspace(xlower, xupper, mx) y = linspace(ylower, yupper, my) times = linspace(t0, tfinal, ntimes) plot_rupture = False dZ = zeros((my, mx)) dz_list = [] if dtopotype in [3]: fid = write_dtopo_header(dtopo_params) else: raise Exception("Unsupported dtopotype: %s, use dtopotype=3" \ % dtopotype) if faulttype == 'static': print "Making Okada dz for each of %s subfaults" \ % len(subfaults) for k, subfault in enumerate(subfaults): dZk = okadamap(subfault, x, y) sys.stdout.write("%s.." % k) sys.stdout.flush() dZ = dZ + dZk sys.stdout.write("\nDone\n") for t in times: alpha = (t - t0) / (tfinal - t0) dz_list.append(alpha * dZ) for j in range(my - 1, -1, -1): format = mx * '%12.6e ' fid.write(format % tuple(alpha * dZ[j, :])) fid.write('\n') elif faulttype in ['kinematic', 'dynamic']: t_prev = -1.e99 for t in times: if plot_rupture: plt.figure(5) plt.clf() for k, subfault in enumerate(subfaults): t0 = subfault.get('rupture_time', 0) t1 = subfault.get('rise_time', 0.5) t2 = subfault.get('rise_time_ending', 0) rf = rise_fraction(t0, t1, t2) dfrac = rf(t) - rf(t_prev) if dfrac > 0.: if subfault.get('dZ', None) is None: subfault.dZ = okadamap(subfault, x, y) print '+++ Applying Okada to subfault %s at t = %s' \ % (k,t) dZ = dZ + dfrac * subfault.dZ if plot_rupture: xc = subfault.longitude yc = subfault.latitude rise = rf(t) if rise == 0: plot(xc, yc, 'wo') elif rise == 1: plot(xc, yc, 'ko') else: plot(xc, yc, 'ro') if plot_rupture: clines = list(arange(-10.5, 0., 0.5)) + list( arange(0.5, 11, 0.5)) plt.contour(x, y, dZ, clines) plt.title('time t = %8.3f' % t) plt.draw() dz_list.append(dZ) for j in range(my - 1, -1, -1): fid.write(mx * '%012.6e ' % dZ[j, :]) fid.write('\n') else: raise Exception("Unrecognized faulttype: %s" % faulttype) print "Created ", fname fid.close() dtopo = DTopo() dtopo.dtopo_params = dtopo_params dtopo.x = x dtopo.y = y dtopo.times = times dtopo.dz_list = dz_list dtopo.subfaults = subfaults return dtopo
def make_okada_dz_witht(fm, faultparams, times, fname): mx = faultparams['mx'] my = faultparams['my'] X=linspace(faultparams['xlower'],faultparams['xupper'],mx) Y=linspace(faultparams['ylower'],faultparams['yupper'],my) mt = len(times) dZ = zeros((mt,my,mx)) first_time = -ones(fm.arrayshape) okadaparams = {} dZsubfault = [] print "Making Okada dZ for each of %s subfaults" \ % str(fm.arrayshape[0]*fm.arrayshape[1]) for i in range(fm.arrayshape[0]): dZsubi = [] for j in range(fm.arrayshape[1]): sys.stdout.write("%s.." % str(j+i*fm.arrayshape[1])) sys.stdout.flush() okadaparams["Focal_Depth"] = fm.depth[i,j] okadaparams["Fault_Length"] = fm.subfault_length okadaparams["Fault_Width"] = fm.subfault_width okadaparams["Dislocation"] = fm.slip[i,j] okadaparams["Strike_Direction"] = fm.strike[i,j] okadaparams["Dip_Angle"] = fm.dip[i,j] okadaparams["Slip_Angle"] = fm.rake[i,j] okadaparams["Fault_Latitude"] = fm.latitude[i,j] okadaparams["Fault_Longitude"] = fm.longitude[i,j] okadaparams["LatLong_Location"] = "centroid" dZij = okadamap(okadaparams, X, Y) dZsubi.append(dZij) dZsubfault.append(dZsubi) sys.stdout.write("\nDone\n") dZsubfault = array(dZsubfault) dZ = zeros((mx,my)) tprev = times.min() - 1. fid = open(fname, 'w') pngfiles = [] if 0. not in times: times = hstack(([0.], times)) print "Making time-dependent dZ for each of %s times" \ % str(len(times)) for frameno,t in enumerate(times): ruptured = [] # add to dZ any slip during time interval tprev to t: for i in range(fm.arrayshape[0]): for j in range(fm.arrayshape[1]): if (fm.rupture_initial_time[i,j] > tprev) and \ (fm.rupture_initial_time[i,j] <= t): dZ = dZ + dZsubfault[i,j] print "Adding subfault (%s,%s) at time %s... rupture_initial_time = %s" \ % (i,j,t,fm.rupture_initial_time[i,j]) ruptured.append((i,j)) # write out dZ at this time: for jj in range(len(Y)): j=-1-jj for i in range(len(X)) : fid.write('%012.6e %012.6e %012.6e %012.6e \n' \ % (t,X[i],Y[j],dZ[j,i])) print "Made dZ at time %s" % t plot_dZ = True if plot_dZ: figure(5) clf() plot(fm.fault_bdry[:,0], fm.fault_bdry[:,1], 'k') cmap = colormaps.blue_white_red pcolor(X,Y,dZ,cmap=cmap) for (i,j) in ruptured: # plot centroids of the fault segments that ruptured # during this time increment: plot([fm.longitude[i,j]],[fm.latitude[i,j]],'go') clim(-10,10) colorbar() contour(X,Y,dZ,linspace(-13,13,14),colors='k') title("dZ at time t = %10.2f" % t) draw() fname = "dZframe%s.png" % str(frameno).zfill(4) savefig(fname) pngfiles.append(fname) tprev = t fid.close() print "Created dtopo file ", fname if plot_dZ: html_movie.make_movie(pngfiles, "index.html") return X,Y,dZ