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]