Writing into SEG2/H5

Hi everyone,

Currently, I am working on a dataset with SEG2 format that has important headers within each waveform’s stats. Obspy reads them and I can correct the faulty traces but , as it is said in the documentation, I cannot write the filtered data into the SEG2 format.

I tried saving in different formats but I am missing important headers like: Channel number, source location, receiver location, …! Any Idea how I can get around this issue?

Another option for me is writing as H5 files but again, Obspy is not supporting it. I would appreciate it if somebody can guide me



to guarantee persistence of waveform metadata I personally use obspyh5:

For a more standardized writing to HDF5 format, see the asdf file format. I did not use it and I do not know if it supports arbitrary metadata (stats attributes) as obspyh5.


1 Like

Thank you for your response. Actually, I have tried it before, but I get the following error:

  1. no matter what the name is! I get the error " name already exists". However, it creates the H5 file in the directory.

  2. The created file is still not readable by obspy. Am I missing something?

Interesting. Can you post the full error traceback (preferable as text inside triple back ticks ```)? Can you also post the output of print(st)?

The file cannot be read, because it is corrupted due to the error upon writing.

1 Like

This is the print(st) result:

Here is the full error:



As a fast work-around, call

import obspyh5

before writing the files.

Back-ground: HDF5 uses indices for writing data. The index is created by using seed id, starttime and endtime. In your case the empty seed id appears to trigger a bug.

I’ll try to push a fix to obspyh5 soonish.


Thank you, Tom, for your time.

It works right now. However, I noticed that the stats of the SEG2 file are not preserved. Is there anyway I can import those attributes to the created H5?

Here is what I get:

Yes, the format specific header is ignored by default. One way to write seg2 header anyway is to trick obspyh5 with

for tr in stream:
    del tr.stats._format

In this way, obspyh5 does not know anymore that seg2 is the format specific header.
Alternatively, you can simply copy the header to another entry:

for tr in stream:
    tr.stats.seg = tr.stats.seg2

By the way, writing traces with empty SEED id is working with the freshly published obspyh5 version 0.6.0.


Thanks, Tom, I really appreciate your support.