def make_green(home, project_name, station_file, fault_name, model_name, dt, NFFT, static, tsunami, hot_start, dk, pmin, pmax, kmax, okada=False): ''' This routine set's up the computation of GFs for each subfault to all stations. The GFs are impulse sources, they don't yet depend on strike and dip. IN: home: Home directory project_name: Name fo the problem station_file: File with coordinates of stations fault_name: Name of fault file model_Name: Name of Earth structure model file dt: Desired sampling itnerval for waveforms NFFT: No. of samples requested in waveform (must be power of 2) static: =0 if computing full waveforms, =1 if computing only the static field hot_start: =k if you want to start computations at k-th subfault, =0 to compute all OUT: Nothing ''' import time, glob from mudpy import green from numpy import loadtxt from shutil import rmtree, copy from os import chdir, path, makedirs, remove from string import rjust import datetime import gc if okada == False: tic = time.time() model_path = home + project_name + '/structure/' green_path = home + project_name + '/GFs/' station_file = home + project_name + '/data/station_info/' + station_file fault_file = home + project_name + '/data/model_info/' + fault_name logpath = home + project_name + '/logs/' #log time now = datetime.datetime.now() now = now.strftime('%b-%d-%H%M') chdir(model_path) #Load source model for station-event distance computations source = loadtxt(fault_file, ndmin=2) for k in range(hot_start, source.shape[0]): #Run comptuation for 1 subfault log = green.run_green(source[k, :], station_file, model_name, dt, NFFT, static, dk, pmin, pmax, kmax) #Write log f = open(logpath + 'make_green.' + now + '.log', 'a') f.write(log) f.close() #Move to correct directory strdepth = '%.4f' % source[k, 3] subfault = rjust(str(int(source[k, 0])), 4, '0') if static == 0 and tsunami == False: #Move results to dynamic GF dir dirs = glob.glob('*.mod_' + strdepth) #Where am I writting this junk too? outgreen = green_path + '/dynamic/' + path.split( dirs[0])[1] + '.sub' + subfault #Check if GF subdir already exists if path.exists(outgreen) == False: #It doesn't, make it, don't be lazy makedirs(outgreen) #Now copy GFs in, this will OVERWRITE EXISTING GFs of the same name flist = glob.glob(dirs[0] + '/*') for k in range(len(flist)): copy(flist[k], outgreen) #Cleanup rmtree(dirs[0]) gc.collect() elif static == 0 and tsunami == True: #Tsunami GFs #Move results to tsunami GF dir dirs = glob.glob('*.mod_' + strdepth) #Where am I writting this junk too? outgreen = green_path + '/tsunami/' + path.split( dirs[0])[1] + '.sub' + subfault #Check if GF subdir already exists if path.exists(outgreen) == False: #It doesn't, make it, don't be lazy makedirs(outgreen) #Now copy GFs in, this will OVERWRITE EXISTING GFs of the same name flist = glob.glob(dirs[0] + '/*') for k in range(len(flist)): copy(flist[k], outgreen) #Cleanup rmtree(dirs[0]) gc.collect() else: #Static GFs copy( 'staticgf', green_path + 'static/' + model_name + '.static.' + strdepth + '.sub' + subfault) #Cleanup remove('staticgf') #How long was I working for? toc = time.time() print 'GFs computed in ' + str((toc - tic) / 60) + ' minutes...' else: print 'GFs not necessary when using an elastic halfspace, exiting make_green'
def make_green(home,project_name,station_file,fault_name,model_name,dt,NFFT,static,tsunami, hot_start,coord_type,dk,pmin,pmax,kmax): ''' This routine set's up the computation of GFs for each subfault to all stations. The GFs are impulse sources, they don't yet depend on strike and dip. IN: home: Home directory project_name: Name fo the problem station_file: File with coordinates of stations fault_name: Name of fault file model_Name: Name of Earth structure model file dt: Desired sampling itnerval for waveforms NFFT: No. of samples requested in waveform (must be power of 2) static: =0 if computing full waveforms, =1 if computing only the static field hot_start: =k if you want to start computations at k-th subfault, =0 to compute all coord_type: =0 if problem is in cartesian coordinates, =1 if problem is in lat/lon OUT: Nothing ''' import time,glob from mudpy import green from numpy import loadtxt from shutil import rmtree,copy from os import chdir,path,makedirs,remove from string import rjust import datetime import gc tic=time.time() model_path=home+project_name+'/structure/' green_path=home+project_name+'/GFs/' station_file=home+project_name+'/data/station_info/'+station_file fault_file=home+project_name+'/data/model_info/'+fault_name logpath=home+project_name+'/logs/' #log time now=datetime.datetime.now() now=now.strftime('%b-%d-%H%M') chdir(model_path) #Load source model for station-event distance computations source=loadtxt(fault_file,ndmin=2) for k in range(hot_start,source.shape[0]): #Run comptuation for 1 subfault log=green.run_green(source[k,:],station_file,model_name,dt,NFFT,static,coord_type,dk,pmin,pmax,kmax) #Write log f=open(logpath+'make_green.'+now+'.log','a') f.write(log) f.close() #Move to correct directory strdepth='%.4f' % source[k,3] subfault=rjust(str(k+1),4,'0') if static==0 and tsunami==0: #Move results to dynamic GF dir dirs=glob.glob('*.mod_'+strdepth) #Where am I writting this junk too? outgreen=green_path+'/dynamic/'+path.split(dirs[0])[1]+'.sub'+subfault #Check if GF subdir already exists if path.exists(outgreen)==False: #It doesn't, make it, don't be lazy makedirs(outgreen) #Now copy GFs in, this will OVERWRITE EXISTING GFs of the same name flist=glob.glob(dirs[0]+'/*') for k in range(len(flist)): copy(flist[k],outgreen) #Cleanup rmtree(dirs[0]) gc.collect() elif static==0 and tsunami==1: #Tsunami GFs #Move results to tsunami GF dir dirs=glob.glob('*.mod_'+strdepth) #Where am I writting this junk too? outgreen=green_path+'/tsunami/'+path.split(dirs[0])[1]+'.sub'+subfault #Check if GF subdir already exists if path.exists(outgreen)==False: #It doesn't, make it, don't be lazy makedirs(outgreen) #Now copy GFs in, this will OVERWRITE EXISTING GFs of the same name flist=glob.glob(dirs[0]+'/*') for k in range(len(flist)): copy(flist[k],outgreen) #Cleanup rmtree(dirs[0]) gc.collect() else: #Static GFs copy('staticgf',green_path+'static/'+model_name+'.static.'+strdepth+'.sub'+subfault) #Cleanup remove('staticgf') #How long was I working for? toc=time.time() print 'GFs computed in '+str((toc-tic)/60)+' minutes...'