# Getting calibration blockette information from	obspy.core read

**URL:** <https://discourse.obspy.org/t/getting-calibration-blockette-information-from-obspy-core-read/377>\
**Category:** Users Mailing List Archive\
**Tags:** archive\
**Created:** [December 3, 2014, 10:08pm UTC](https://discourse.obspy.org/t/getting-calibration-blockette-information-from-obspy-core-read/377 "2014-12-03T22:08:33Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ringler\_Adam](https://discourse.obspy.org/user_avatar/discourse.obspy.org/ringler_adam/32/231_2.png) [@Ringler\_Adam](https://discourse.obspy.org/u/Ringler_Adam)\
**Post date:** [December 3, 2014, 10:08pm UTC](https://discourse.obspy.org/t/getting-calibration-blockette-information-from-obspy-core-read/377/1 "2014-12-03T22:08:33Z")

</div>

Hello Users,

Has anyone used the obspy read routine to pull out calibration blockette information? Setting details=True seems to show when a calibration blockette exists and which type of calibration it is, but I am also trying to get the additional fields. Perhaps they are sitting somewhere else?

For example something like the following when there is the existence of a 310 blockette.

Found a Sine Calibration Blockette

Starting Time: 2014,329 16:32:57.5695

Calibration Duration: 2400 seconds

Sine Period: 250.000000

Calibration Amplitude: -36.000000

Calibration Input Channel: BC0

Reference Amplitude: 0.000000

Coupling Method: resistive

Filtering Type: 3DB@10Hz

Calibration Flags: 14

Thanks for any help anyone can give,

Adam

---

<div class="post-metadata">

**Author:** ![LionKrischer](https://discourse.obspy.org/user_avatar/discourse.obspy.org/lionkrischer/32/219_2.png) [@LionKrischer](https://discourse.obspy.org/u/LionKrischer)\
**Post date:** [December 9, 2014, 3:11pm UTC](https://discourse.obspy.org/t/getting-calibration-blockette-information-from-obspy-core-read/377/2 "2014-12-09T15:11:19Z")

</div>

Hi Adam,

sorry for the late response.

So this is not possible right now with the obspy.read function. If read with details=True, it does store the calibration type in tr.stats.mseed.calibration\_type but nothing more. If there is enough interest we might consider adding that functionality to ObsPy.

To do this right now you’ll have to do a bit of manual work. ObsPy ships with an “obspy-mseed-recordanalyzer” script:

$ obspy-mseed-recordanalyzer -n 1 CN.RES..BHE.mseed  
FILE: CN.RES..BHE.mseed  
Record Offset: 512 byte  
Header Endianness: Big Endian

FIXED SECTION OF DATA HEADER  
Sequence number: 2  
Data header/quality indicator: M  
Station identifier code: RES  
Location identifier:  
Channel identifier: BHE  
Network code: CN  
Record start time: 2013-05-24T05:40:14.625000Z  
Number of samples: 572  
Sample rate factor: 40  
Sample rate multiplier: 1  
Activity flags: 0  
I/O and clock flags: 0  
Data quality flags: 0  
Number of blockettes that follow: 1  
Time correction: 0  
Beginning of data: 64  
First blockette: 48

BLOCKETTES  
1000: Encoding Format: 11  
Word Order: 1  
Data Record Length: 9

CALCULATED VALUES  
Corrected Starttime: 2013-05-24T05:40:14.625000Z

See “$ obspy-mseed-recordanalyer -h” for more details.

You can find the source of script here: [https://github.com/obspy/obspy/blob/master/obspy/mseed/scripts/recordanalyzer.py](https://github.com/obspy/obspy/blob/master/obspy/mseed/scripts/recordanalyzer.py)

To get Blockette 310 you’ll just need to add a couple of lines to this function here:  
[https://github.com/obspy/obspy/blob/master/obspy/mseed/scripts/recordanalyzer.py#L197-220](https://github.com/obspy/obspy/blob/master/obspy/mseed/scripts/recordanalyzer.py#L197-220)

This is a bit complex so if there is broader interest in reading arbitrary MiniSEED blockettes we’ll have to think of a way to add it to ObsPy.

All the best!

Lion

---

<div class="post-metadata">

**Author:** ![Ringler\_Adam](https://discourse.obspy.org/user_avatar/discourse.obspy.org/ringler_adam/32/231_2.png) [@Ringler\_Adam](https://discourse.obspy.org/u/Ringler_Adam)\
**Post date:** [December 9, 2014, 3:29pm UTC](https://discourse.obspy.org/t/getting-calibration-blockette-information-from-obspy-core-read/377/3 "2014-12-09T15:29:44Z")

</div>

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
