Wrong headers when extracting sac files from gcf files

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’)

Hi

The gcf format does not contain station information unless you have set the unitID to be the station code (streamID which is the unitID appended by orientation - e.g. z, and output tap is contained in the header of a gcf data block).

A quick look in the source code gives that the gcf reader implemented in obspy currently sets the station code to be the streamID striped of the last two characters (i.e. the unitID) where as the channel is set to the second last character of the streamID prepended by default by HH (can be changed by setting argument channel_prefix to desired value, e.g channel_prefix=“BL”, in call to read(). Thus if streamID is guralp streamID orientation code should be correct but possibly not channel or band code and station code will be guralp unitID. Whereas if streamID is set to station code station and orientation code should be ok but channel or band code may be wrong (unless actually HH or set in call to read as described).

To fix the issue simply set the channel and station proper in your script after having read the file.

\p