Did I find the right examples for you? yes no

All Samples(84)  |  Call(67)  |  Derive(0)  |  Import(17)

src/n/i/nibabel-1.3.0/nibabel/externals/netcdf.py   nibabel(Download)
 
import numpy as np
from ..py3k import asbytes, asstr
from numpy import fromstring, ndarray, dtype, empty, array, asarray
from numpy import little_endian as LITTLE_ENDIAN
 
 
ABSENT       = asbytes('\x00\x00\x00\x00\x00\x00\x00\x00')
ZERO         = asbytes('\x00\x00\x00\x00')
NC_BYTE      = asbytes('\x00\x00\x00\x01')
ZERO         = asbytes('\x00\x00\x00\x00')
NC_BYTE      = asbytes('\x00\x00\x00\x01')
NC_CHAR      = asbytes('\x00\x00\x00\x02')
NC_SHORT     = asbytes('\x00\x00\x00\x03')
NC_INT       = asbytes('\x00\x00\x00\x04')

src/n/i/nibabel-1.3.0/nibabel/nifti1.py   nibabel(Download)
import numpy.linalg as npl
 
from .py3k import ZEROB, ints2bytes, asbytes, asstr
from .volumeutils import Recoder, make_dt_codes, endian_codes
from .spatialimages import HeaderDataError, ImageFileError
        magic = np.asscalar(hdr['magic'])
        offset = hdr['vox_offset']
        if magic == asbytes('n+1'): # one file
            if offset >= 352:
                if not offset % 16:
                hdr['vox_offset'] = 352
                rep.fix_msg = 'setting to minimum value of 352'
        elif magic != asbytes('ni1'): # two files
            # unrecognized nii magic string, oh dear
            rep.problem_msg = ('magic string "%s" is not valid' %

src/n/i/nibabel-1.3.0/nibabel/minc.py   nibabel(Download)
from .externals.netcdf import netcdf_file
 
from .py3k import asbytes, asstr
from .spatialimages import SpatialImage
 
        # http://www.bic.mni.mcgill.ca/software/minc/minc1_format/node15.html
        for dim in self._dims:
            if dim.spacing != asbytes('regular__'):
                raise ValueError('Irregular spacing not supported')
        self._spatial_dims = [name for name in self._dim_names

src/n/i/nibabel-1.3.0/nibabel/nicom/csareader.py   nibabel(Download)
import numpy as np
 
from ..py3k import ZEROB, asbytes, asstr
from .structreader import Unpacker
 
    hdr_id = csa_str[:4]
    up_str = Unpacker(csa_str, endian='<')
    if hdr_id == asbytes('SV10'): # CSA2
        hdr_type = 2
        up_str.ptr = 4 # omit the SV10

src/n/i/nibabel-1.3.0/nibabel/loadsave.py   nibabel(Download)
### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ##
# module imports
from .py3k import asbytes
from .filename_parser import types_filenames, splitext_addext
from . import volumeutils as vu
            vu.allopen(filenames['header']),
            check=False)
        if hdr['magic'] in (asbytes('ni1'), asbytes('n+1')):
            # allow goofy nifti single magic for pair
            klass = nifti1.Nifti1Pair

src/n/i/nibabel-1.3.0/nibabel/trackvis.py   nibabel(Download)
import numpy.linalg as npl
 
from .py3k import asbytes, asstr
from .volumeutils import (native_code, swapped_code, endian_codes,
                          allopen, rec2dict)
                     dtype=header_2_dtype,
                     buffer=hdr_str)
    if np.asscalar(hdr['id_string'])[:5] != asbytes('TRACK'):
        raise HeaderError('Expecting TRACK as first '
                          '5 characters of id_string')
        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')

src/n/i/nibabel-HEAD/nibabel/externals/netcdf.py   nibabel(Download)
 
import numpy as np
from ..py3k import asbytes, asstr
from numpy import fromstring, ndarray, dtype, empty, array, asarray
from numpy import little_endian as LITTLE_ENDIAN
 
        nc_type = REVERSE[var.typecode(), var.itemsize()]
        self.fp.write(asbytes(nc_type))
 
        if not var.isrec:
        values = asarray(values, dtype=dtype_)
 
        self.fp.write(asbytes(nc_type))
 
        if values.dtype.char == 'S':
    def _pack_string(self, s):
        count = len(s)
        self._pack_int(count)
        self.fp.write(asbytes(s))
        self.fp.write(b'0' * (-count % 4))  # pad

src/n/i/nibabel-1.3.0/nibabel/nicom/tests/test_structreader.py   nibabel(Download)
import struct
 
from ...py3k import asbytes
from ..structreader import Unpacker
 
def test_unpacker():
    s = asbytes('1234\x00\x01')
    le_int, = struct.unpack('<h', asbytes('\x00\x01'))
    be_int, = struct.unpack('>h', asbytes('\x00\x01'))
    if sys.byteorder == 'little':
        swapped_code = '<'
    up_str = Unpacker(s, endian='<')
    assert_equal(up_str.read(4), asbytes('1234'))
    up_str.ptr = 0
    assert_equal(up_str.unpack('4s'), (asbytes('1234'),))

src/n/i/nibabel-1.3.0/nibabel/tests/test_nifti1.py   nibabel(Download)
import os
 
from ..py3k import BytesIO, ZEROB, asbytes
 
import numpy as np
    def test_empty(self):
        tana.TestAnalyzeHeader.test_empty(self)
        hdr = self.header_class()
        assert_equal(hdr['magic'], asbytes('ni1'))
        assert_equal(hdr['scl_slope'], 1)
    def test_from_eg_file(self):
        hdr = Nifti1Header.from_fileobj(open(self.example_file, 'rb'))
        assert_equal(hdr.endianness, '<')
        assert_equal(hdr['magic'], asbytes('ni1'))
        assert_equal(hdr['sizeof_hdr'], 348)
        hdr['magic'] = 'ooh'
        fhdr, message, raiser = self.log_chk(hdr, 45)
        assert_equal(fhdr['magic'], asbytes('ooh'))
        assert_equal(message, 'magic string "ooh" is not valid; '
                           'leaving as is, but future errors are likely')
    def test_empty(self):
        tana.TestAnalyzeHeader.test_empty(self)
        hdr = self.header_class()
        assert_equal(hdr['magic'], asbytes('n+1'))
        assert_equal(hdr['scl_slope'], 1)

src/n/i/nibabel-1.3.0/nibabel/tests/test_utils.py   nibabel(Download)
''' Test for volumeutils module '''
from __future__ import with_statement
from ..py3k import BytesIO, asbytes, ZEROB
import tempfile
 
    fd, fname = tempfile.mkstemp()
    with InTemporaryDirectory():
        open(fname, 'wb').write(asbytes('1'))
        in_buf = open(fname, 'rb')
        # For windows this will raise a WindowsError from mmap, Unices
def buf_chk(in_arr, out_buf, in_buf, offset):
    ''' Write contents of in_arr into fileobj, read back, check same '''
    instr = asbytes(' ') * offset + in_arr.tostring(order='F')
    out_buf.write(instr)
    out_buf.flush()
def test_a2f_offset():
    # check that non-zero file offset works
    arr = np.array([[0.0, 1.0],[2.0, 3.0]])
    str_io = BytesIO()
    str_io.write(asbytes('a') * 42)
def test_rec2dict():
    r = np.zeros((), dtype = [('x', 'i4'), ('s', 'S10')])
    d = rec2dict(r)
    assert_equal(d, {'x': 0, 's': asbytes('')})
 

  1 | 2  Next