Created
February 8, 2016 20:51
-
-
Save maedoc/c02e3aafbfe8843cc479 to your computer and use it in GitHub Desktop.
read dfc files from BrainSuite
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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