Skip to content

Instantly share code, notes, and snippets.

@maedoc maedoc/dfcread.py
Created Feb 8, 2016

Embed
What would you like to do?
read dfc files from BrainSuite
import struct
import numpy
class DFC(object):
def __init__(self, fname):
self.fname = fname
# http://brainsuite.org/formats/dfc/
with open(fn, 'rb') as fd:
self.magic = fd.read(8)
self.version = struct.unpack('B' * 4, fd.read(4))
(self.header_size,
self.data_start,
self.metadata_offset,
self.subject_data_offset,
self.n_curves) = struct.unpack('IIIIi', fd.read(20))
self.curves = list()
fd.seek(data_start)
for i in range(self.n_curves):
n_points, = struct.unpack('I', fd.read(4))
curve = fd.read(4 * 3 * n_points)
self.curves.append(
numpy.fromstring(curve, dtype=numpy.float32)
.reshape((n_points, 3))
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.