~matthew-brett/nipy/binaryformats

« back to all changes in this revision

Viewing changes to binaryformats/spmanalyze.py

  • Committer: Matthew Brett
  • Date: 2008-10-11 08:14:56 UTC
  • Revision ID: matthew.brett@gmail.com-20081011081456-54ih7h1682b4rt0p
Cleaned up headers utility functions, added tests for qform, sform get / set

Show diffs side-by-side

added added

removed removed

Lines of Context:
3
3
import numpy as np
4
4
 
5
5
import binaryformats.endiancodes as ecodes
 
6
from binaryformats.headers import pretty_print
6
7
 
7
8
# Sub-parts of standard analyze header from 
8
9
# Mayo dbh.h file
78
79
    return hdr.sizeof_hdr != 348
79
80
 
80
81
def endian_code(hdr):
81
 
    endiancode_label = 'swapped' if byteswapped(hdr) else 'native'
82
 
    return ecodes.to_numpy(endiancode_label)
 
82
    endian_label = 'swapped' if byteswapped(hdr) else 'native'
 
83
    return ecodes.to_numpy(endian_label)
83
84
 
84
 
def read(fileobj, endiancode=None):
 
85
def read(fileobj, endian=None):
85
86
    hdr = raw_read(fileobj)
86
 
    if endiancode is None:
87
 
        endiancode = endian_code(hdr)
88
 
    if not endiancode == ecodes.native:
 
87
    if endian is None:
 
88
        endian = endian_code(hdr)
 
89
    if not endian == ecodes.native:
89
90
        hdr = hdr.newbyteorder(ecodes.swapped)
90
 
    return hdr, endiancode
 
91
    return hdr, endian
91
92
 
92
 
def write(hdr, fileobj, endiancode=None):
93
 
    if endiancode is None:
 
93
def write(hdr, fileobj, endian=None):
 
94
    if endian is None:
94
95
        return raw_write(hdr, fileobj)
95
 
    if not endiancode == ecodes.native:
 
96
    if not endian == ecodes.native:
96
97
        pass
97
98
 
98
99