Ejemplo n.º 1
0
def data_install_msgs():
    from nipy.utils import make_datasource, DataError
    for name in ('templates', 'data'):
        try:
            make_datasource('nipy', name)
        except DataError, exception:
            log.warn('%s\n%s' % ('_'*80, exception))
def check_pkg_install(archive):
    ''' Check that source package installs so that NIPY can read it

    Parameters
    ----------
    archive : string
       filename of source archive

    Returns
    -------
    None
    '''
    # extract package name from archive
    pth, fname = os.path.split(archive)
    fname, ext = os.path.splitext(fname)
    pkg_match = pkg_re.search(fname)
    if not pkg_match:
        raise OSError('Could not get package name from %s' % archive)
    pkg_name = pkg_match.groups()[0]
    archive = os.path.abspath(archive)
    with InTemporaryDirectory() as tmpdir:
        extract_archive(archive, tmpdir)
        out_dirs = glob('*')
        if not out_dirs:
            raise OSError('No directory created by package unpack')
        if len(out_dirs) > 1:
            raise OSError('Expecting only one directory, got %s' %
                          ';'.join(out_dirs))
        os.chdir(out_dirs[0])
        caller('python setup.py install --prefix=%s' % tmpdir)
        # check that nipy finds the directory and initializes it correctly
        repo = make_datasource('share', 'nipy', 'nipy', pkg_name,
                               data_path=[tmpdir])
def check_pkg_install(archive):
    ''' Check that source package installs so that NIPY can read it

    Parameters
    ----------
    archive : string
       filename of source archive

    Returns
    -------
    None
    '''
    # extract package name from archive
    pth, fname = os.path.split(archive)
    fname, ext = os.path.splitext(fname)
    pkg_match = pkg_re.search(fname)
    if not pkg_match:
        raise OSError('Could not get package name from %s' % archive)
    pkg_name = pkg_match.groups()[0]
    archive = os.path.abspath(archive)
    with InTemporaryDirectory() as tmpdir:
        extract_archive(archive, tmpdir)
        out_dirs = glob('*')
        if not out_dirs:
            raise OSError('No directory created by package unpack')
        if len(out_dirs) > 1:
            raise OSError('Expecting only one directory, got %s' %
                          ';'.join(out_dirs))
        os.chdir(out_dirs[0])
        caller('python setup.py install --prefix=%s' % tmpdir)
        # check that nipy finds the directory and initializes it correctly
        repo = make_datasource('share',
                               'nipy',
                               'nipy',
                               pkg_name,
                               data_path=[tmpdir])
Ejemplo n.º 4
0
"""Create a nifti image from a numpy array and an affine transform."""

import os

import numpy as np

from nipy.core.api import fromarray, Affine
from nipy.io.api import save_image, load_image
from nipy.utils import make_datasource

# Make the templates datasource
templates = make_datasource('nipy', 'templates')

# Load an image to get the array and affine
filename = templates.get_filename('ICBM152', '2mm', 'T1.nii.gz')
assert os.path.exists(filename)

# Use one of our test files to get an array and affine (as numpy array) from.
img = load_image(filename)
arr = np.asarray(img)
affine_array = img.coordmap.affine.copy()

################################################################################
# START HERE
################################################################################


# 1) Create a CoordinateMap from the affine transform which specifies
# the mapping from input to output coordinates.

# Specify the axis order of the input coordinates