Hi guys,
I'm trying to change headers of gse2 files inplace, i.e. without having to read in the files themselves (necessary for runtime reasons...). For SAC, this is conveniently possible using obspy.sac.SacIO().SetHvalueInFile. In gse2, this seems to be not so easy...this is as far as I got:
{{{ file = open('test','rwb') #get file pointer, test is a GSE2 file h = obspy.gse2.libgse2.readHead(file) #this gives me a dictionary of the header entries h['calper'] = 2*pi #change whatever I want to change h['vang'] = 90.0 h1 = obspy.gse2.libgse2.HEADER() #create empty gse2-header for i in h.keys(): setattr(h1,i,h[i]) #fill it with values from the dictionary h1.calper #test if it worked Out[72]: 6.2831854820251465 h1.vang Out[74]: 90.0
In [70]: obspy.gse2.libgse2.writeHeader(file,h1)
IOError Traceback (most recent call last)
/home/sippl/sandbox/spicker/data/ in ()
/home/sippl/programs/obspy/obspy.gse2/obspy/gse2/libgse2.pyc in writeHeader(f, head) 199 head.instype, 200 head.hang, --> 201 head.vang)) 202 203
IOError: [Errno 9] Bad file descriptor }}}
That's as far as I get. Not entirely sure what's going wrong here... I know these are low-level routines that shouldn't be used directly, but for the amount of data I have it would be a huge advantage not having to read in the files for header changes.
Another problem: The format I have to have my gse2-data in are volumes of many gse2-traces stored in one file (one gse2 volume per event). In this case, obspy.gse2.libgse2.readHead only returns the header of the very first trace inside my volume.
And a suggestion: how about setting the default values for 'vang' and 'hang' according to the header entry in 'channel'? I.e. if there is a discernible information there about the sensor orientation (E,N,Z), then set the these two angles of sensor orientation accordingly (90.0 and 90.0, 90.0 and 0.0 and 0.0 and -1.0, respectively). At the moment, all traces are by default given the values for vertical records.
Cheers, Christian
该提问来源于开源项目:obspy/obspy