Пример #1
0
def _hdr_from_mapping(hdr=None, mapping=None, endianness=native_code):
    ''' Fill `hdr` from mapping `mapping`, with given endianness '''
    if hdr is None:
        # passed a valid mapping as header?  Copy and return
        if isinstance(mapping, np.ndarray):
            test_dtype = mapping.dtype.newbyteorder('=')
            if test_dtype in (header_1_dtype, header_2_dtype):
                return mapping.copy()
        # otherwise make a new empty header.   If no version specified,
        # go for default (2)
        if mapping is None:
            version = 2
        else:
            version =  mapping.get('version', 2)
        hdr = empty_header(endianness, version)
    if mapping is None:
        return hdr
    if isinstance(mapping, np.ndarray):
        mapping = rec2dict(mapping)
    for key, value in mapping.items():
        hdr[key] = value
    # check header values
    if np.asscalar(hdr['id_string'])[:5] != asbytes('TRACK'):
        raise HeaderError('Expecting TRACK as first '
                          '5 characaters of id_string')
    if hdr['version'] not in (1, 2):
        raise HeaderError('Reader only supports version 1')
    if hdr['hdr_size'] != 1000:
        raise HeaderError('hdr_size should be 1000')
    return hdr
Пример #2
0
def _hdr_from_mapping(hdr=None, mapping=None, endianness=native_code):
    ''' Fill `hdr` from mapping `mapping`, with given endianness '''
    if hdr is None:
        # passed a valid mapping as header?  Copy and return
        if isinstance(mapping, np.ndarray):
            test_dtype = mapping.dtype.newbyteorder('=')
            if test_dtype in (header_1_dtype, header_2_dtype):
                return mapping.copy()
        # otherwise make a new empty header.   If no version specified,
        # go for default (2)
        if mapping is None:
            version = 2
        else:
            version = mapping.get('version', 2)
        hdr = empty_header(endianness, version)
    if mapping is None:
        return hdr
    if isinstance(mapping, np.ndarray):
        mapping = rec2dict(mapping)
    for key, value in mapping.items():
        hdr[key] = value
    # check header values
    if np.asscalar(hdr['id_string'])[:5] != asbytes('TRACK'):
        raise HeaderError('Expecting TRACK as first '
                          '5 characaters of id_string')
    if hdr['version'] not in (1, 2):
        raise HeaderError('Reader only supports version 1')
    if hdr['hdr_size'] != 1000:
        raise HeaderError('hdr_size should be 1000')
    return hdr
Пример #3
0
def transform_to_trackvis_voxmm(streams, header):
    from nibabel.volumeutils import rec2dict
    from nibabel.streamlines.trk import get_affine_rasmm_to_trackvis
    from dipy.tracking.utils import move_streamlines
    header = rec2dict(header)
    header['voxel_sizes'] = header['voxel_size']
    header['voxel_to_rasmm'] = header['vox_to_ras']
    header['dimensions'] = header['dim']
    affine = get_affine_rasmm_to_trackvis(header)
    streams = move_streamlines(streams, affine)
    return streams
Пример #4
0
def transform_to_trackvis_voxmm(streams, header):
    from nibabel.volumeutils import rec2dict
    from nibabel.streamlines.trk import get_affine_rasmm_to_trackvis
    from dipy.tracking.utils import move_streamlines
    header = rec2dict(header)
    header['voxel_sizes'] = header['voxel_size']
    header['voxel_to_rasmm'] = header['vox_to_ras']
    header['dimensions'] = header['dim']
    affine = get_affine_rasmm_to_trackvis(header)
    streams = move_streamlines(streams, affine)
    return streams