Problem reading css format

Hi,

I’m trying to read data in CSS format, the data is stored as s3 which is one of the allowed data formats in CSS. I’m getting an error regarding the s3, with data in t4 the program work OK.

Any suggestions?

Cheers Yochai

Hi Yochai,

s3 is a weird 3-byte integer type that numpy doesn’t natively support. I’ve looked into ways to coax it into a 4-byte integer type, and found a snippet from a SciPy issue that may help (pasted below): https://github.com/scipy/scipy/issues/1930. It’s for multi-dimensional arrays, but could probably be modified for 1D arrays. If this doesn’t do what you want, the Pisces project (I’m an author) can read CSS s3 type: https://github.com/jkmacc-LANL/pisces/blob/master/pisces/io/readwaveform.py#L30.

If you’re able to do this using just the snippet, please let me know. I’d be curious how it works for you.

Best,
Jon

data = numpy.fromfile(fid, dtype='u1', count=size) # first read byte per byte
a = numpy.empty((len(data)/3, 4), dtype=`u1`)
a[:, :3] = data.reshape((-1, 3))
a[:, 3:] = (a[:, 3 - 1:3] >> 7) * 255
data = a.view('<i4').reshape(a.shape[:-1])

Dear Jon,

Thanks for your replay, I’m still in the trying to import the pisces project into my python and to operate it.

Cheers,

Yochai

Yochai,

Feel free to email me directly with any questions.

Best,
Jon

Jon Shalom,

I’m using Python 2.7.13 |Anaconda 4.3.1 (64-bit). I installed pisces using pip. However, I’m getting the following:

In [5]: from pisces import Route, AppContainer, Router

In [6]: from pisces import read_waveform

Hi Jon,

I reinstalled the piscs and now it is working!

Thanks

Yochai