Skip to content

Commit

Permalink
Merge pull request #26 from MDAnalysis/issue/25
Browse files Browse the repository at this point in the history
make scipy import optional (issue #25)
  • Loading branch information
orbeckst committed Dec 12, 2015
2 parents 003e5d1 + 19da4d4 commit 75ae094
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 25 deletions.
27 changes: 15 additions & 12 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
env:
global:
- secure: "BzLdQUSTs6dsngJfNGjLtG++Gmi4KzYv7FEwVqUB6pXKnpMIpv+/md2zkH/Lo3UtdioR2SKytXk3/40tCbpUVD2Yjb+yc5WyyeFLQF9KeF2k9gZkmC35iSbTWt9hK+mnkdJidCK5xbfrXEbZx4FpqyDGFl8GCCjJlPOQ/KEcRVQ="
- GH_DOC_BRANCH: master
- GH_REPOSITORY: github.com/MDAnalysis/GridDataFormats.git
- GIT_CI_USER: TravisCI
- GIT_CI_EMAIL: TravisCI@mdanalysis.org
- MDA_DOCDIR: doc/html
matrix:
- SETUP=full
- SETUP=minimal
language: python
python:
- "2.7"
Expand All @@ -17,11 +28,12 @@ before_install:
- export PATH=/home/travis/miniconda/bin:$PATH
- conda update --yes conda
install:
- conda create --yes -q -n pyenv python=$TRAVIS_PYTHON_VERSION numpy=1.9.2 scipy=0.16.0 nose=1.3.7 six sphinx=1.3
- if [[ $SETUP == 'full' ]]; then conda create --yes -q -n pyenv python=$TRAVIS_PYTHON_VERSION numpy=1.9.2 scipy=0.16.0 nose=1.3.7 sphinx=1.3; fi
- if [[ $SETUP == 'minimal' ]]; then conda create --yes -q -n pyenv python=$TRAVIS_PYTHON_VERSION numpy=1.9.2 nose=1.3.7 sphinx=1.3; fi
- source activate pyenv
- case "$TRAVIS_PYTHON_VERSION" in 2.*) SPECIAL_PACKAGES="mock";; 3.*) SPECIAL_PACKAGES="";; esac
- pip install coveralls tempdir $SPECIAL_PACKAGES

- pip install coveralls tempdir $SPECIAL_PACKAGES
- pip install -v ./
script:
- nosetests -v --with-coverage --cover-package gridData --process-timeout=120 --processes=2 gridData
- |
Expand All @@ -37,12 +49,3 @@ after_success:
test ${TRAVIS_BRANCH} == ${GH_DOC_BRANCH} && \
test "${TRAVIS_BUILD_NUMBER}.1" == "${TRAVIS_JOB_NUMBER}" && \
bash ./ci/deploy_docs.sh
env:
global:
- secure: "BzLdQUSTs6dsngJfNGjLtG++Gmi4KzYv7FEwVqUB6pXKnpMIpv+/md2zkH/Lo3UtdioR2SKytXk3/40tCbpUVD2Yjb+yc5WyyeFLQF9KeF2k9gZkmC35iSbTWt9hK+mnkdJidCK5xbfrXEbZx4FpqyDGFl8GCCjJlPOQ/KEcRVQ="
- GH_DOC_BRANCH: master
- GH_REPOSITORY: github.com/MDAnalysis/GridDataFormats.git
- GIT_CI_USER: TravisCI
- GIT_CI_EMAIL: TravisCI@mdanalysis.org
- MDA_DOCDIR: doc/html
14 changes: 14 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,20 @@ The rules for this file:
* accompany each entry with github issue/PR number (Issue #xyz)

------------------------------------------------------------------------------
12/11/2015 orbeckst

* 0.3.2

Enhancements

Changes

* can import without scipy present (scipy.ndimage will only be used
on demand when interpolation of a Grid is requested) (issue #25)

Fixes


12/07/2015 orbeckst, richardjgowers

* 0.3.1
Expand Down
2 changes: 1 addition & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
include README README.rst INSTALL CHANGELOG COPYING COPYING.LESSER AUTHORS
include ez_setup.py setup.py
include setup.py


2 changes: 1 addition & 1 deletion gridData/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,4 +194,4 @@
from . import CCP4

__all__ = ['Grid', 'OpenDX', 'gOpenMol', 'CCP4']
__version__ = '0.3.1'
__version__ = '0.3.2'
19 changes: 11 additions & 8 deletions gridData/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@
import os
from six.moves import cPickle, range, zip
import numpy
from scipy import ndimage

# For interpolated grids: need scipy.ndimage but we import it only when needed:
# import scipy

from . import OpenDX
from . import gOpenMol
Expand Down Expand Up @@ -447,6 +449,7 @@ def _interpolationFunctionFactory(self, spline_order=None, cval=None):
# for scipy >=0.9: should use scipy.interpolate.griddata
# http://docs.scipy.org/doc/scipy/reference/generated/scipy.interpolate.griddata.html#scipy.interpolate.griddata
# (does it work for nD?)
import scipy.ndimage

if spline_order is None:
# must be compatible with whatever :func:`scipy.ndimage.spline_filter` takes.
Expand All @@ -463,7 +466,7 @@ def _interpolationFunctionFactory(self, spline_order=None, cval=None):
except AttributeError:
_data = data

coeffs = ndimage.spline_filter(_data, order=spline_order)
coeffs = scipy.ndimage.spline_filter(_data, order=spline_order)
x0 = self.origin
dx = self.delta

Expand All @@ -482,12 +485,12 @@ def interpolatedF(*coordinates):
_coordinates = numpy.array(
[_transform(coordinates[i], x0[i], dx[i]) for i in range(len(
coordinates))])
return ndimage.map_coordinates(coeffs,
_coordinates,
prefilter=False,
mode='nearest',
cval=cval)
# mode='wrap' would be ideal but is broken: http://projects.scipy.org/scipy/ticket/796
return scipy.ndimage.map_coordinates(coeffs,
_coordinates,
prefilter=False,
mode='nearest',
cval=cval)
# mode='wrap' would be ideal but is broken: https://github.com/scipy/scipy/issues/1323
return interpolatedF

def __eq__(self, other):
Expand Down
11 changes: 11 additions & 0 deletions gridData/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# utilities for running the tests

import importlib

def module_not_found(module):
try:
importlib.import_module(module)
except ImportError:
return True
else:
return False
6 changes: 5 additions & 1 deletion gridData/tests/test_grid.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import numpy as np
from numpy.testing import assert_array_equal, assert_array_almost_equal
from numpy.testing import assert_array_equal, assert_array_almost_equal, dec
from nose.tools import raises

from gridData import Grid

from ..tests import module_not_found

class TestGrid:

Expand Down Expand Up @@ -99,6 +100,9 @@ def test_centers(self):
assert_array_equal(centers[-1] - g.origin,
(np.array(g.grid.shape) - 1) * self.delta)


@dec.skipif(module_not_found('scipy'),
"Test skipped because scipy is not available.")
def test_resample_factor(self):
g = self.grid.resample_factor(2)
assert_array_equal(g.delta, np.ones(3) * .5)
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
long_description = f.read()

setup(name="GridDataFormats",
version="0.3.1",
version="0.3.2",
description="Reading and writing of data on regular grids in Python",
long_description=long_description,
author="Oliver Beckstein",
Expand All @@ -26,7 +26,7 @@
'Topic :: Software Development :: Libraries :: Python Modules',
],
packages=find_packages(exclude=[]),
package_data={},
package_data={'gridData': ['tests/*.dx', 'tests/*.ccp4']},
install_requires=['numpy>=1.0.3', 'six'],
tests_require=['nose', 'tempdir', 'numpy'],
# extras can be difficult to install through setuptools and/or
Expand Down

0 comments on commit 75ae094

Please sign in to comment.