Reading Raw Data in Python

In a similar vein to reading raw data into Matlab, I created a similar type of function in Python:

[cc lang="python"]
def readraw(filename, shape, intype=’int16′, byteSwap=False):
“”" readraw – To read in a raw file and reformat it to the right shape “”"

# Read in the file
if filename.endswith(‘gz’):
fp = gzip.open(filename, ‘rb’)
else:
fp = open(filename, ‘rb’)

d = fromfile(file=fp, dtype=intype).reshape(shape)

d.byteswap(byteSwap)

return d
[/cc]

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>