Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
subfault_folder=home+project_name+'/GFs/dynamic/'+model_name+'_'+depth+'.sub'+subfault
elif tsunami==True and static==1:
subfault_folder=home+project_name+'/GFs/tsunami/'+model_name+'_'+depth+'.sub'+subfault
elif static==1:
subfault_folder=home+project_name+'/GFs/static/'+model_name+'_'+depth+'.sub'+subfault
#Check if subfault folder exists, if not create it
if os.path.exists(subfault_folder+'/')==False:
os.makedirs(subfault_folder+'/')
#Copy velocity model file
copy(home+project_name+'/structure/'+model_name,subfault_folder+'/'+model_name)
#Move to work folder
chdir(subfault_folder)
#Get station distances to source
d,az=src2sta(station_file,source[ksource,:])
#Make distance string for system call
diststr=''
for k in range(len(d)):
diststr=diststr+' %.6f' % d[k] #Truncate distance to 6 decimal palces (meters)
# Keep the user informed, lest he get nervous
print('MPI: processor #',rank,'is now working on subfault',int(source[ksource,0]),'(',ksource+1,'/',len(source),')')
#Make the calculation
if static==0: #Compute full waveform
command=split("fk.pl -M"+model_name+"/"+depth+"/f -N"+str(NFFT)+"/"+str(dt)+'/1/'+repr(dk)+' -P'+repr(pmin)+'/'+repr(pmax)+'/'+repr(kmax)+diststr)
p=subprocess.Popen(command,stdout=subprocess.PIPE,stderr=subprocess.PIPE)
p.communicate()
# Move files up one level and delete folder created by fk
files_list=glob(subfault_folder+'/'+model_name+'_'+depth+'/*.grn*')
for f in files_list:
newf=subfault_folder+'/'+f.split('/')[-1]
copy(f,newf)
ds_length=source[9]
ss_length_in_km=ss_length/1000.
ds_length_in_km=ds_length/1000.
strdepth='%.4f' % zs
subfault=str(int(source[0])).rjust(4,'0')
if static==0 and tsunami==0: #Where to save dynamic waveforms
green_path=home+project_name+'/GFs/dynamic/'+model_name+"_"+strdepth+".sub"+subfault+"/"
if static==1 and tsunami==1: #Where to save dynamic waveforms
green_path=home+project_name+'/GFs/tsunami/'+model_name+"_"+strdepth+".sub"+subfault+"/"
if static==1 and tsunami==0: #Where to save statics
green_path=home+project_name+'/GFs/static/'+model_name+"_"+strdepth+".sub"+subfault+"/"
staname=genfromtxt(station_file,dtype="U",usecols=0)
if staname.shape==(): #Single staiton file
staname=array([staname])
#Compute distances and azimuths
d,az,lon_sta,lat_sta=src2sta(station_file,source,output_coordinates=True)
#Get moment corresponding to 1 meter of slip on subfault
mu=get_mu(structure,zs)
Mo=mu*ss_length*ds_length*1.0
Mw=(2./3)*(log10(Mo)-9.1)
#Move to output folder
os.chdir(green_path)
print('Processor '+str(rank)+' is working on subfault '+str(int(source[0]))+' and '+str(len(d))+' stations ')
for k in range(len(d)):
if static==0: #Compute full waveforms
diststr='%.6f' % d[k] #Need current distance in string form for external call
#Form the strings to be used for the system calls according to user desired options
if integrate==1: #Make displ.
#First Stike-Slip GFs
if custom_stf==None:
#Parse the soruce information
num=str(int(source[0])).rjust(4,'0')
xs=source[1]
ys=source[2]
zs=source[3]
strdepth='%.4f' % zs
subfault=str(int(source[0])).rjust(4,'0')
staname=genfromtxt(station_file,dtype="U",usecols=0)
if staname.shape==(): #Single staiton file
staname=array([staname])
#Compute distances and azimuths
d,az,lon_sta,lat_sta=src2sta(station_file,source,output_coordinates=True)
#Get moment corresponding to 1 meter of slip on subfault
Mw=5.0
M0=10**(5.0*1.5+9.1)*1e7 #to dyne-cm
#Load LOS vector for projection
los_path=home+project_name+'/data/statics/'
#Move to output folder
os.chdir(green_path)
print('Processor '+str(rank)+' is working on subfault '+str(int(source[0]))+' and '+str(len(d))+' stations ')
#Go one station at a time for that subfault
for k in range(len(d)):
#Read los vector for this subfault