# Problems reading CSS waveform files - Is there a	trick that I need to know?

**URL:** <https://discourse.obspy.org/t/problems-reading-css-waveform-files-is-there-a-trick-that-i-need-to-know/390>\
**Category:** Users Mailing List Archive\
**Tags:** archive\
**Created:** [February 27, 2015, 3:29am UTC](https://discourse.obspy.org/t/problems-reading-css-waveform-files-is-there-a-trick-that-i-need-to-know/390 "2015-02-27T03:29:55Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tychoaussie](https://discourse.obspy.org/user_avatar/discourse.obspy.org/tychoaussie/32/405_2.png) [@Tychoaussie](https://discourse.obspy.org/u/Tychoaussie)\
**Post date:** [February 27, 2015, 3:29am UTC](https://discourse.obspy.org/t/problems-reading-css-waveform-files-is-there-a-trick-that-i-need-to-know/390/1 "2015-02-27T03:29:55Z")

</div>

Good morning,  
I am working on an Obspy / python based instrument calibration package for whole-system instrument response calibrations. The network that I’m working with is using the CSS3.0 waveform format, but I cannot for the life of me get Obspy to import it. I have been given four sample files:

43090920.bhe  
43090920.bhn  
43090920.bhz  
DGS14309.wfd

I can supply these files if someone can help me figure out how to import the data?  
In the mean time, I have placed them over at github at this location:

[https://github.com/tychoaussie/sample\_data](https://github.com/tychoaussie/sample_data)

I need to be able to bring in the sensor data for doing some FFT signal analysis but up until now, I have totally struck out in getting the data open in Obspy. Is the CSS in Obspy something different than CSSS2.0 or CSS3.0? If so, is there a way of reading in the 3.0 waveform format ?

I’m at the Kazakhstan KNDC at the moment, in case any of you happen to be driving through Almaty and want to give me a hand with this!

- Thanks for reading, and bigger thanks if you happen to have any insights,

-Dan Burk  
Michigan State University

---

<div class="post-metadata">

**Author:** ![megies](https://discourse.obspy.org/user_avatar/discourse.obspy.org/megies/32/9_2.png) [@megies](https://discourse.obspy.org/u/megies)\
**Post date:** [February 27, 2015, 9:35am UTC](https://discourse.obspy.org/t/problems-reading-css-waveform-files-is-there-a-trick-that-i-need-to-know/390/2 "2015-02-27T09:35:26Z")

</div>

The wdf header file (which you need to feed to read()) points to some  
waveform files that are missing. If you remove the lines referring to  
files 43090919.bh\* you can read it with

read("DGS14309.wfd", format="CSS")

(Not sure why file type detection is not working..)

cheers,  
Tobias

---

<div class="post-metadata">

**Author:** ![Tychoaussie](https://discourse.obspy.org/user_avatar/discourse.obspy.org/tychoaussie/32/405_2.png) [@Tychoaussie](https://discourse.obspy.org/u/Tychoaussie)\
**Post date:** [February 27, 2015, 4:10pm UTC](https://discourse.obspy.org/t/problems-reading-css-waveform-files-is-there-a-trick-that-i-need-to-know/390/3 "2015-02-27T16:10:15Z")

</div>

Thanks for the tips, Tobias, but I still cannot open the files.  
Here’s what I have thus far, in order to validate the .wdf file:

---

<div class="post-metadata">

**Author:** ![megies](https://discourse.obspy.org/user_avatar/discourse.obspy.org/megies/32/9_2.png) [@megies](https://discourse.obspy.org/u/megies)\
**Post date:** [February 27, 2015, 6:19pm UTC](https://discourse.obspy.org/t/problems-reading-css-waveform-files-is-there-a-trick-that-i-need-to-know/390/4 "2015-02-27T18:19:14Z")

</div>

Hi Dan,

there's a few problems in your code, mainly you didn't close the  
outfile, and it ended up empty. I \*strongly\* recommend using the with  
construct for file handling.  
Also, reading those lines with indexing by character position is pretty  
dangerous, I would recommend .split() on the single lines (you ended up  
trying to read your output file with some spaces at the end of the  
filename, note the quick and dirty .strip() for fixing).

The following works, hope you're good now. All the best for the field  
work. 😉

cheers,  
T

import sys,os  
from obspy import read

infile = "DGS14309.wfd"  
dir = "."  
with open(infile,'r') as f:  
&nbsp;&nbsp;&nbsp;&nbsp;lines = f.readlines()

outfile=infile[:-4]+'\_bak'+infile[-4:]  
with open(outfile,'w') as fout:

&nbsp;&nbsp;&nbsp;&nbsp;for i in range(0,len(lines)):  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;candidate=os.path.join(dir, lines[i][213:255]).strip()  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if os.path.isfile(candidate):  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;print "{} is a real file.".format(candidate)  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fout.writelines(lines[i])  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;else:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;print "{} does not exist.".format(candidate)

&nbsp;&nbsp;&nbsp;&nbsp;if os.path.isfile(outfile):  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;print outfile+" has been created."  
&nbsp;&nbsp;&nbsp;&nbsp;else:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;print outfile + "does not yet exist."

st = read(outfile,format="css")  
print st  
st.plot()
