Did I find the right examples for you? yes no

All Samples(98)  |  Call(81)  |  Derive(0)  |  Import(17)

src/n/i/nibabel-1.3.0/nibabel/spm99analyze.py   nibabel(Download)
import numpy as np
from .py3k import BytesIO
from .spatialimages import HeaderDataError, HeaderTypeError
            return ret
        import scipy.io as sio
        mats = sio.loadmat(BytesIO(contents))
        if 'mat' in mats: # this overrides a 'M', and includes any flip
            mat = mats['mat']

src/n/i/nibabel-1.3.0/nibabel/benchmarks/bench_load_save.py   nibabel(Download)
import numpy as np
from ..py3k import BytesIO
from .. import Nifti1Image
    arr = rng.normal(size=img_shape)
    img = Nifti1Image(arr, np.eye(4))
    sio = BytesIO()
    img.file_map['image'].fileobj = sio
    hdr = img.get_header()
    arr = arr.astype(np.int16)
    img = Nifti1Image(arr, np.eye(4))
    sio = BytesIO()
    img.file_map['image'].fileobj = sio
    hdr = img.get_header()

src/n/i/nibabel-1.3.0/nibabel/dft.py   nibabel(Download)
import numpy
from .py3k import BytesIO
from .nifti1 import Nifti1Header
        data = data.astype(numpy.uint8)
        im = PIL.Image.fromstring('L', (self.rows, self.columns), data.tostring())
        s = BytesIO()
        im.save(s, 'PNG')
        return s.getvalue()
        hdr.set_data_shape((self.columns, self.rows, len(self.storage_instances)))
        s = BytesIO()

src/n/i/nibabel-1.3.0/nibabel/externals/tests/test_netcdf.py   nibabel(Download)
import numpy as np
from ...py3k import BytesIO, asbytes
from ..netcdf import netcdf_file
def test_read_write_sio():
    eg_sio1 = BytesIO()
    f1 = make_simple(eg_sio1, 'w')
    str_val = eg_sio1.getvalue()
    eg_sio2 = BytesIO(str_val)
    # Test that error is raised if attempting mmap for sio
    eg_sio3 = BytesIO(str_val)
    yield assert_raises, ValueError, netcdf_file, eg_sio3, 'r', True
    # Test 64-bit offset write / read
    eg_sio_64 = BytesIO()

src/n/i/nibabel-1.3.0/nibabel/tests/test_analyze.py   nibabel(Download)
import numpy as np
from ..py3k import BytesIO, StringIO, asbytes
from ..volumeutils import array_to_file
from ..spatialimages import (HeaderDataError, HeaderTypeError)
    def test_read_write_data(self):
        # Check reading and writing of data
        hdr = self.header_class()
        # Trying to read data from an empty header gives no data
        bytes = hdr.data_from_fileobj(BytesIO())
        assert_equal(len(bytes), 0)
        # Setting no data into an empty header results in - no data
        str_io = BytesIO()
        S = BytesIO()
        data = np.arange(6, dtype=np.float64)
        # data have to be the right shape
        assert_raises(HeaderDataError, hdr.data_to_fileobj, data, S)

src/n/i/nibabel-1.3.0/nibabel/tests/test_wrapstruct.py   nibabel(Download)
from ..batteryrunners import Report
from ..py3k import BytesIO, StringIO, asbytes, ZEROB
from ..volumeutils import swapped_code, native_code, Recoder
from ..spatialimages import HeaderDataError
    def test_to_from_fileobj(self):
        # Successful write using write_to
        hdr = self.header_class()
        str_io = BytesIO()
        # override this test
        hdr = self.header_class()
        str_io = BytesIO()
        assert_equal(str_io.getvalue(), hdr.binaryblock)

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
    # Check on string buffers
    offset = 0
    assert_true(buf_chk(in_arr, BytesIO(), None, offset))
    offset = 10
    assert_true(buf_chk(in_arr, BytesIO(), None, offset))
        del out_buf, in_buf
    # Make sure empty shape, and zero length, give empty arrays
    arr = array_from_file((), np.dtype('f8'), BytesIO())
    assert_equal(len(arr), 0)
    arr = array_from_file((0,), np.dtype('f8'), BytesIO())

src/n/i/nibabel-1.3.0/nibabel/tests/test_trackvis.py   nibabel(Download)
import numpy as np
from ..py3k import BytesIO, asbytes
from .. import trackvis as tv
from ..orientations import aff2axcodes
def test_write():
    streams = []
    out_f = BytesIO()
    tv.write(out_f, [], {})
    assert_equal(out_f.getvalue(), tv.empty_header().tostring())
    props = np.arange(P) + 1000
    # If scalars not same size for each point, error
    out_f = BytesIO()
    streams = [(points, None, None),
               (points, scalars, None)]
def test_round_trip():
    out_f = BytesIO()
    xyz0 = np.tile(np.arange(5).reshape(5,1), (1, 3))
    xyz1 = np.tile(np.arange(5).reshape(5,1) + 10, (1, 3))
    streams = [(xyz0, None, None), (xyz1, None, None)]
    # Now we need a new file object, because we're still using the old one for
    # our generator
    out_f_write = BytesIO()
    tv.write(out_f_write, streams3, {})
    # and re-read just to check

src/n/i/nibabel-1.3.0/nibabel/tests/test_spm99analyze.py   nibabel(Download)
import numpy as np
from ..py3k import BytesIO
from numpy.testing import assert_array_equal, assert_array_almost_equal, dec
    def test_scaling(self):
        hdr = self.header_class()
        S3 = BytesIO()
        data = np.arange(6, dtype=np.float64).reshape((1,2,3))
        # This uses scaling
        hdr.data_to_fileobj(data, S3)
        data_back = hdr.data_from_fileobj(S3)
        assert_array_almost_equal(data, data_back, 4)
        # This is exactly the same call, just testing it works twice
        data_back2 = hdr.data_from_fileobj(S3)
        assert_array_equal(data_back, data_back2, 4)

src/n/i/nibabel-1.3.0/nibabel/tests/test_spatialimages.py   nibabel(Download)
from ..py3k import BytesIO
import numpy as np
def test_read_data():
    hdr = Header(np.int32, shape=(1,2,3), zooms=(3.0, 2.0, 1.0))
    fobj = BytesIO()
    data = np.arange(6).reshape((1,2,3))
    hdr.data_to_fileobj(data, fobj)

  1 | 2  Next