Problem with CSS file

Hello.
I’m using Obspy 0.9.2 on Windows 7 amd64.

The problem is, when I try to open CSS-file, for example, from CSS/tests/data directory of obspy, or any other CSS-file, I got error message:

when I run just “read(css_filename)” I got: TypeError: Unknown format for file 201101311155.10.w

when “data = read(‘201101311155.10.w’, format=‘CSS’)”, the error is: ValueError: invalid literal for int() with base 10: ‘’

Any help appreciated.

Hi,

I'm not too familiar with CSS but as far as I understood you always need
the corresponding header file along with the binary waveform file. The
file you mentioned in the ObsPy directory for example is read via
"test.wfdisc" which points at the respective byte offsets for the single
traces stored in '201101311155.10.w'.

best,
Tobias

Hello. As Tobias said, you just have to read the wfdisc file. I am
working here with some CSS data and I have had no problem until now. A
couple of advices: if you don't see the signal when trying to plot the
seismogram, check that the calib factor is not 0.00000. As I said
this, I have another kind of problem. I want to save some of this data
in mseed format, but when I try it... well, have a look.

In [1]: from obspy.core import read, Trace, Stream, UTCDateTime

In [2]: st=read("STAT-20140902-230311.wfdisc","css")

In [3]: print st[0].stats
         network:
         station: STAT
        location:
         channel: 0
       starttime: 2014-09-02T23:03:12.438000Z
         endtime: 2014-09-03T00:03:06.676000Z
   sampling_rate: 500.0
           delta: 0.002
            npts: 1797120
           calib: 0.953674
         _format: CSS
          calper: 0.0

In [4]: st.write('dan.mseed', format='MSEED', reclen=512, encoding='INT16')

Hi Daniel,

it looks like your data can not be written as int16 and that's what
you're forcing on the write method. Just try leaving away the "encoding"
kwarg (you also probably do not need the "reclen" kwarg) or try to
specify an appropriate encoding (I suspect you're facing float data.. so
probably "FLOAT32" or "FLOAT64").
Also beware, not all miniseed readers support float encodings..

best,
Tobias

Thanks Tobias. Well... The data is stored each sample as short integer
(16 bits) in the binary files. But leaving out the reclen and encoding
parameters, I still have some errors. Is it that there's a limit in
the size of the data to save in a single mseed file? My file has
1797120 samples...

In [6]: st.write('dan.mseed', format='MSEED')

It appears you end up with a stream with 8byte integer values..? That
should not happen according to the CSS manual..

I think we should continue this as an issue at github.. can you open one
please?

best,
Tobias

Hi all,

I have some error whe opening some CSS files, when data dtype is “i4” in data header of waveform data file.

I have installed obspy version 0.9.2 on Windows 7 64-bit.

First of all, error raises KeyError:
KeyError Traceback (most recent call last)
in ()
----> 1 readCSS(filename)

C:\Anaconda\lib\site-packages\obspy-0.9.2-py2.7-win32.egg\obspy\css\core.py in readCSS(filename, **kwargs)
95 filename = os.path.join(basedir, dirname, filename)
96 offset = int(line[246:256])
—> 97 dtype = DTYPE[line[143:145]]
98 fmt = “>” + dtype * npts
99 with open(filename, “rb”) as fh:

KeyError: ‘i4’

Looked at core.py file, and changed DTYPE to
DTYPE = {

Big-endian integers

b’s4’: b’>i’,
b’s2’: b’>h’,

Little-endian integers

b’i4’: b’<i’,
b’i2’: b’<h’,

ASCII integers

b’c0’: (b’S12’, np.int),
b’c#’: (b’S12’, np.int),

Big-endian floating point

b’t4’: b’>f’,
b’t8’: b’>d’,

Little-endian floating point

b’f4’: b’<f’,
b’f8’: b’<d’,

ASCII floating point

b’a0’: (b’S15’, np.float32),
b’a#’: (b’S15’, np.float32),
b’b0’: (b’S24’, np.float64),
b’b#’: (b’S24’, np.float64),
}

(from dev-version of obspy?)

raises error:
error Traceback (most recent call last)
in ()
----> 1 readCSS(filename)

C:\Anaconda\lib\site-packages\obspy-0.9.2-py2.7-win32.egg\obspy\css\core.py in readCSS(filename, **kwargs)
99 with open(filename, “rb”) as fh:
100 fh.seek(offset)
–> 101 size = struct.calcsize(fmt)
102 data = fh.read(size)
103 data = struct.unpack(fmt, data)

error: bad char in struct format

Dont’ know what to do, hoping for response.

Hi there,

only adjusting the DTYPE dictionary is not enough, there are changes in
the reading logic as well (I'm attaching a diff of css/core.py between
0.9.2 and master).

Either you hack those changes into the css/core.py of your installation
(this will need adaptions, because master is adapted to python-future
for Python3 support), or you simply move on to using the master branch
in your anaconda installation.. (although I don't have any experience on
how well that works with the compilation on Windows).

best,
Tobias

diff (3.71 KB)