how to convert 3 byte to float

marek.rocki at wp.pl marek.rocki at wp.pl
Sun Dec 9 11:40:22 EST 2007


Mario M. Mueller napisał(a):
> Personally I would expect simple counts (since other seismic formats don't
> even think of using floats because most digitizers deliver counts). But I
> was told that there are floats inside.
>
> But if I assume counts I get some reasonable numbers out of the file.

I looked at the data and it seems to be 24-bit big-endian integers. I
even plotted it and the graph looks quite reasonable (though I have no
expertise in seismic data at all).

> But I'm experiencing some strange jumps in the data (seismic data is mostly
> quite smooth at 40 Hz sampling rate). I think I did some mistake in the
> byte order...

Probably. In your code sample, when you pad it to 32-bits, why are you
inserting every third byte, instead of the most significant one? Maybe
the following will work:

if sign:
    s = struct.unpack('>i','%c%c%c%c' % (chr(0xFF),s0,s1,s2))[0]
else:
    s = struct.unpack('>i','%c%c%c%c' % (chr(0x00),s0,s1,s2))[0]

Regards,
Marek



More information about the Python-list mailing list