Skip to content

Commit 75ae094

Browse files
committed
Merge pull request #26 from MDAnalysis/issue/25
make scipy import optional (issue #25)
2 parents 003e5d1 + 19da4d4 commit 75ae094

File tree

8 files changed

+60
-25
lines changed

8 files changed

+60
-25
lines changed

.travis.yml

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
env:
2+
global:
3+
- secure: "BzLdQUSTs6dsngJfNGjLtG++Gmi4KzYv7FEwVqUB6pXKnpMIpv+/md2zkH/Lo3UtdioR2SKytXk3/40tCbpUVD2Yjb+yc5WyyeFLQF9KeF2k9gZkmC35iSbTWt9hK+mnkdJidCK5xbfrXEbZx4FpqyDGFl8GCCjJlPOQ/KEcRVQ="
4+
- GH_DOC_BRANCH: master
5+
- GH_REPOSITORY: github.com/MDAnalysis/GridDataFormats.git
6+
- GIT_CI_USER: TravisCI
7+
- GIT_CI_EMAIL: [email protected]
8+
- MDA_DOCDIR: doc/html
9+
matrix:
10+
- SETUP=full
11+
- SETUP=minimal
112
language: python
213
python:
314
- "2.7"
@@ -17,11 +28,12 @@ before_install:
1728
- export PATH=/home/travis/miniconda/bin:$PATH
1829
- conda update --yes conda
1930
install:
20-
- 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
31+
- 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
32+
- 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
2133
- source activate pyenv
2234
- case "$TRAVIS_PYTHON_VERSION" in 2.*) SPECIAL_PACKAGES="mock";; 3.*) SPECIAL_PACKAGES="";; esac
23-
- pip install coveralls tempdir $SPECIAL_PACKAGES
24-
35+
- pip install coveralls tempdir $SPECIAL_PACKAGES
36+
- pip install -v ./
2537
script:
2638
- nosetests -v --with-coverage --cover-package gridData --process-timeout=120 --processes=2 gridData
2739
- |
@@ -37,12 +49,3 @@ after_success:
3749
test ${TRAVIS_BRANCH} == ${GH_DOC_BRANCH} && \
3850
test "${TRAVIS_BUILD_NUMBER}.1" == "${TRAVIS_JOB_NUMBER}" && \
3951
bash ./ci/deploy_docs.sh
40-
41-
env:
42-
global:
43-
- secure: "BzLdQUSTs6dsngJfNGjLtG++Gmi4KzYv7FEwVqUB6pXKnpMIpv+/md2zkH/Lo3UtdioR2SKytXk3/40tCbpUVD2Yjb+yc5WyyeFLQF9KeF2k9gZkmC35iSbTWt9hK+mnkdJidCK5xbfrXEbZx4FpqyDGFl8GCCjJlPOQ/KEcRVQ="
44-
- GH_DOC_BRANCH: master
45-
- GH_REPOSITORY: github.com/MDAnalysis/GridDataFormats.git
46-
- GIT_CI_USER: TravisCI
47-
- GIT_CI_EMAIL: [email protected]
48-
- MDA_DOCDIR: doc/html

CHANGELOG

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,20 @@ The rules for this file:
1212
* accompany each entry with github issue/PR number (Issue #xyz)
1313

1414
------------------------------------------------------------------------------
15+
12/11/2015 orbeckst
16+
17+
* 0.3.2
18+
19+
Enhancements
20+
21+
Changes
22+
23+
* can import without scipy present (scipy.ndimage will only be used
24+
on demand when interpolation of a Grid is requested) (issue #25)
25+
26+
Fixes
27+
28+
1529
12/07/2015 orbeckst, richardjgowers
1630

1731
* 0.3.1

MANIFEST.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
include README README.rst INSTALL CHANGELOG COPYING COPYING.LESSER AUTHORS
2-
include ez_setup.py setup.py
2+
include setup.py
33

44

gridData/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,4 +194,4 @@
194194
from . import CCP4
195195

196196
__all__ = ['Grid', 'OpenDX', 'gOpenMol', 'CCP4']
197-
__version__ = '0.3.1'
197+
__version__ = '0.3.2'

gridData/core.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@
2727
import os
2828
from six.moves import cPickle, range, zip
2929
import numpy
30-
from scipy import ndimage
30+
31+
# For interpolated grids: need scipy.ndimage but we import it only when needed:
32+
# import scipy
3133

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

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

466-
coeffs = ndimage.spline_filter(_data, order=spline_order)
469+
coeffs = scipy.ndimage.spline_filter(_data, order=spline_order)
467470
x0 = self.origin
468471
dx = self.delta
469472

@@ -482,12 +485,12 @@ def interpolatedF(*coordinates):
482485
_coordinates = numpy.array(
483486
[_transform(coordinates[i], x0[i], dx[i]) for i in range(len(
484487
coordinates))])
485-
return ndimage.map_coordinates(coeffs,
486-
_coordinates,
487-
prefilter=False,
488-
mode='nearest',
489-
cval=cval)
490-
# mode='wrap' would be ideal but is broken: http://projects.scipy.org/scipy/ticket/796
488+
return scipy.ndimage.map_coordinates(coeffs,
489+
_coordinates,
490+
prefilter=False,
491+
mode='nearest',
492+
cval=cval)
493+
# mode='wrap' would be ideal but is broken: https://github.com/scipy/scipy/issues/1323
491494
return interpolatedF
492495

493496
def __eq__(self, other):

gridData/tests/__init__.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# utilities for running the tests
2+
3+
import importlib
4+
5+
def module_not_found(module):
6+
try:
7+
importlib.import_module(module)
8+
except ImportError:
9+
return True
10+
else:
11+
return False

gridData/tests/test_grid.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import numpy as np
2-
from numpy.testing import assert_array_equal, assert_array_almost_equal
2+
from numpy.testing import assert_array_equal, assert_array_almost_equal, dec
33
from nose.tools import raises
44

55
from gridData import Grid
66

7+
from ..tests import module_not_found
78

89
class TestGrid:
910

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

103+
104+
@dec.skipif(module_not_found('scipy'),
105+
"Test skipped because scipy is not available.")
102106
def test_resample_factor(self):
103107
g = self.grid.resample_factor(2)
104108
assert_array_equal(g.delta, np.ones(3) * .5)

setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
long_description = f.read()
99

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

0 commit comments

Comments
 (0)