예제 #1
0
def read_brik(brikname):
	h = afni_header_read(brikname)

	hn = h['HISTORY_NOTE']
	tfdim = hn.find('tfdim:')
	if tfdim < 0:
		printerror("Brik %s doesn't contain TF data." % brikname)
		sys.exit(1)
	tfdim = hn[tfdim:]
	title = hn.find('tftitle:')
	if title < 0:
		tftitle = brikname
	else:
		tftitle = hn[title + 9:].split('\n')[0]

	dim = h['DATASET_DIMENSIONS']

	isstat = hn.find('3dWilcoxon') >= 0 or hn.find('3dMannWhitney') >= 0

	# Format is 'tfdim: start end srate lo hi'
	# Also return xdim and ydim.
	s = tfdim.split()
	return [tftitle, float(s[1]), float(s[2]), float(s[3]), float(s[4]),
		float(s[5]), int(dim[0]), int(dim[1]), isstat]
예제 #2
0
            if s[0] == 'c_ras':
                c_ras = list(map(float, s[1:]))
                break
        if c_ras is None:
            raise
except:
    print("Reading", name)
    print("Can't find c_ras origin offset!")
    sys.exit(1)

c_ras = np.array(c_ras) * .001  # mm to m

# Read the AFNI header, get the tags.

pathname = op.expanduser(brikname)
h = afni_header_read(pathname)
if not h.get('TAGSET_NUM'):
    print("{} has no tags!".format(pathname))
    sys.exit(1)

ntags, pertag = h['TAGSET_NUM']
f = h['TAGSET_FLOATS']
lab = h['TAGSET_LABELS']
d = {}
for i in range(ntags):
    tl = f[i * pertag : (i+1) * pertag] # get this tag's coordinate list
    x = np.array(tl[0:3]) * .001        # convert from mm to m
    x = np.array((-x[0], -x[1], x[2]))  # convert from RAI to LPI (aka ras)
    d[lab[i]] = x - c_ras               # shift to ras origin

# AFNI tag name to MNE tag ident
예제 #3
0
# If the argument is a .ds directory, get the corresponding .hc or .hdm file.
s = filename.split('.')
ext = s[-1]
if ext == 'ds' or ext == 'ds/':
    base = s[0].split('/')[-1]
    if type == HDM:
        msg("using default.hdm\n")
        filename += '/' + 'default.hdm'
    elif type == HC:
        msg("using %s.hc\n" % base)
        filename += '/' + base + '.hc'

# If it's a BRIK, read the header, otherwise just open the file.

if type == BRIK:
    h = afni_header_read(filename)
    if not h.has_key('TAGSET_NUM'):
        printerror("%s has no tags!" % filename)
        sys.exit(1)
else:
    x = open(filename)

def get_coord(f):
    l = f.next()
    return float(l.split()[2])

# HC
def coord(f):
    x = get_coord(f)
    y = get_coord(f)
    z = get_coord(f)