Skip to content

Instantly share code, notes, and snippets.

@maedoc
Created February 8, 2016 20:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maedoc/c02e3aafbfe8843cc479 to your computer and use it in GitHub Desktop.
Save maedoc/c02e3aafbfe8843cc479 to your computer and use it in GitHub Desktop.
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