Hi there
I am using obspy to read some gcf files and cut events from them and convert to sac files.
But i noticed that kstnm and kcmpnm headers of sac file are wrong.
I am using python2.7. This is part of my program.Please help me I am new with python and obspy
FID = open(“List”)
Allevents = FID.readlines()
for event in Allevents:
for stn in StnList:
try:
os.mkdir(distpath+"/"+stn)
except OSError:
print (“Creation of the directory %s failed” % stn+ “ALready exists”)
else:
print (“Successfully created the directory %s " % stn)
Evinf=event.strip().split()
year=str(Evinf[0])
moon=str(Evinf[1])
day =str(Evinf[2])
hour=str(Evinf[3])
mint=str(Evinf[4])
sec =str(0.0) #str(Evinf[5])
st=year+”-"+moon+"-"+day+“T”+hour+":"+mint+":"+sec
stime=UTCDateTime(st)
etime=UTCDateTime(st)+cutlen
print stime , stn
stfileID=INSN+str(stime.year)+"/"+stn+"/"+str(stime.month).zfill(2)+"/z/"+str(stime.year)+str(stime.month).zfill(2)+str(stime.day).zf>
enfileID=INSN+str(etime.year)+"/"+stn+"/"+str(etime.month).zfill(2)+"/z/"+str(etime.year)+str(etime.month).zfill(2)+str(etime.day).zf>
stfile=glob.glob(stfileID+"")
enfile=glob.glob(enfileID+"")
if len(stfile)==1 and len(enfile)==1:
if stfile==enfile:
try:
Bigone=obspy.read(stfile[0])
Bigone+=obspy.read(enfile[0])
Bigone.merge(method=1)
Final=Bigone.trim(stime,etime)
except:
continue
else:
try:
Bigone=obspy.read(stfile[0])
Final=Bigone.trim(stime,etime)
except:
continue
elif len(stfile)>1 or len(enfile)>1:
print “there is mor than one file for “, stime ,” or “, etime,“for station”,stn
else:
print “no file for date “,stime,“for station”,stn
outfile=distpath+”/”+stn+”/”+str(stime.year)+"."+str(stime.month).zfill(2)+"."+str(stime.day).zfill(2)+"."+str(stime.hour).zfill(2)+">
for tr in Final:
if isinstance(tr.data, np.ma.masked_array):
tr.data = tr.data.filled()
Final.write(outfile,format=‘SAC’)