Hello Lion,
Thanks so much. I ended up taking a similar approach (see below). I would guess there aren’t many people using this type of information.
However, it is good to know there is a recordanalyzer in obspy!
Thanks for all of your help,
Adam
def get_calibrations(file_name):
calibrations = []
#Read the first file and get the record length from blockette 1000
fh = open(file_name, ‘rb’)
record = fh.read(256)
index = struct.unpack(’>H’, record[46:48])[0]
file_stats = os.stat(file_name)
record_length = 2 ** struct.unpack(’>B’, record[index+6:index+7])[0]
#Get the total number of records
total_records = file_stats[stat.ST_SIZE] / record_length
#Now loop through the records and look for calibration blockettes
for rec_idx in xrange(0,total_records):
fh.seek(rec_idx * record_length,0)
record = fh.read(record_length)
next_blockette = struct.unpack(’>H’, record[46:48])[0]
while next_blockette != 0:
index = next_blockette
blockette_type, next_blockette = struct.unpack(’>HH’, record[index:index+4])
if blockette_type in (300, 310, 320, 390):
if debug:
print ‘We have a calibration blockette’
year,jday,hour,minute,sec,,tmsec,,cal_flags,duration = tuple(struct.unpack(’>HHBBBBHBBL’, record[index+4:index+20]))
stime = UTCDateTime(year=year,julday=jday,hour=hour,minute=minute,second=sec)
if debug:
print(stime.ctime())
if blockette_type == 300:
step_count,,,ntrvl_duration,amplitude,cal_input = struct.unpack(’>BBLLf3s’, record[index+14:index+31])
calibrations.append({‘type’:‘step’,‘amplitude’: amplitude,‘number’:step_count,‘start_time’:stime,‘duration’:duration/10000,‘inteveral_duration’:ntrvl_duration})
if blockette_type == 310:
signal_period,amplitude,cal_input = struct.unpack(’>ff3s’, record[index+20:index+31])
calibrations.append({‘type’:‘sine’,‘amplitude’: amplitude, ‘period’: signal_period,‘start_time’:stime,‘duration’:duration/10000})
if blockette_type in (320, 390):
amplitude,cal_input = struct.unpack(’>f3s’, record[index+20:index+27])
calibrations.append({‘type’:‘random’,‘amplitude’: amplitude,‘start_time’:stime,‘duration’:duration/10000})
fh.close()
return calibrations