From 883fb0cb5b56a6c0270f5684b184dc0f2bc08850 Mon Sep 17 00:00:00 2001 From: Kyle Sunden Date: Tue, 15 Jan 2019 16:05:00 -0600 Subject: [PATCH 1/6] Move to service instead of involking xvfb directly --- .travis.yml | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index 21484ddc0..1d3093462 100644 --- a/.travis.yml +++ b/.travis.yml @@ -16,8 +16,6 @@ install: - pip install cython - pip install . - pip install -U pytest "coverage<5" -before_script: -- "export DISPLAY=:99.0" -- "sh -e /etc/init.d/xvfb start" -- sleep 3 # give xvfb some time to start +services: + - xvfb script: python setup.py test From 2722e0ffab4c4026b3c26fa1d9cde86399331c28 Mon Sep 17 00:00:00 2001 From: Kyle Sunden Date: Wed, 16 Jan 2019 11:54:21 -0600 Subject: [PATCH 2/6] MAINT: Use scipy.signal instead of skimage for downscale Removes dependency scikit-image --- WrightTools/data/_data.py | 32 ++++++++++++++++++-------------- setup.py | 1 - tests/data/downscale.py | 5 +++++ 3 files changed, 23 insertions(+), 15 deletions(-) diff --git a/WrightTools/data/_data.py b/WrightTools/data/_data.py index 9a224f51b..a3a9e07bf 100644 --- a/WrightTools/data/_data.py +++ b/WrightTools/data/_data.py @@ -15,7 +15,7 @@ import scipy from scipy.interpolate import griddata, interp1d -from skimage.transform import downscale_local_mean +from scipy.signal import decimate from .._group import Group from .. import collection as wt_collection @@ -897,10 +897,9 @@ def create_variable( def downscale(self, tup, name=None, parent=None) -> "Data": """Down sample the data array using local averaging. - See `skimage.transform.downscale_local_mean`__ for more info. + See `scipy.signal.decimate`__ for more info. - __ http://scikit-image.org/docs/0.12.x/api/ - skimage.transform.html#skimage.transform.downscale_local_mean + __ https://docs.scipy.org/doc/scipy/reference/generated/scipy.signal.decimate.html Parameters ---------- @@ -931,21 +930,26 @@ def downscale(self, tup, name=None, parent=None) -> "Data": else: parent.create_data(name=name) + def _nd_decimate(arr, factor): + if isinstance(factor, (int, type(None))): + factor = [factor] * arr.ndim + factor = [1 if f is None else f for f in factor] + for axis, f in enumerate(factor): + if arr.shape[axis] >= f: + arr = decimate(arr, f, axis=axis) + return arr + for channel in self.channels: name = channel.natural_name newdata.create_channel( - name=name, values=downscale_local_mean(channel[:], tup), units=channel.units + name=name, values=_nd_decimate(channel[:], tup), units=channel.units ) - args = [] - for i, axis in enumerate(self.axes): - if len(axis.variables) > 1: - raise NotImplementedError("downscale only works with simple axes currently") - variable = axis.variables[0] + for variable in self.variables: name = variable.natural_name - args.append(name) - slices = [slice(None, None, step) for step in tup] - newdata.create_variable(name=name, values=variable[slices], units=variable.units) - newdata.transform(*args) + newdata.create_variable( + name=name, values=_nd_decimate(variable[:], tup), units=variable.units + ) + newdata.transform(*self.axis_names) return newdata def get_nadir(self, channel=0) -> tuple: diff --git a/setup.py b/setup.py index bfd16a895..ea05b580e 100755 --- a/setup.py +++ b/setup.py @@ -35,7 +35,6 @@ def read(fname): setup_requires=["pytest-runner"], tests_require=["pytest", "pytest-cov", "sphinx", "sphinx-gallery==0.1.12", "sphinx-rtd-theme"], install_requires=[ - "scikit-image", "h5py", "imageio", "matplotlib>=3.0", diff --git a/tests/data/downscale.py b/tests/data/downscale.py index befeb12f3..629c192bb 100644 --- a/tests/data/downscale.py +++ b/tests/data/downscale.py @@ -18,6 +18,11 @@ def test_downscale(): b = a.downscale((3, 10)) assert b.shape == (854, 216) assert b.axis_expressions == a.axis_expressions + # wt.artists.quick2D(a) + wt.artists.quick2D(b) + import matplotlib.pyplot as plt + + plt.show() if __name__ == "__main__": From eaaacbf284ffcdccbae0f0c1d66efaa1123bbeb7 Mon Sep 17 00:00:00 2001 From: Kyle Sunden Date: Wed, 16 Jan 2019 13:33:13 -0600 Subject: [PATCH 3/6] TST: remove plt.show() --- tests/data/downscale.py | 5 ----- 1 file changed, 5 deletions(-) diff --git a/tests/data/downscale.py b/tests/data/downscale.py index 629c192bb..befeb12f3 100644 --- a/tests/data/downscale.py +++ b/tests/data/downscale.py @@ -18,11 +18,6 @@ def test_downscale(): b = a.downscale((3, 10)) assert b.shape == (854, 216) assert b.axis_expressions == a.axis_expressions - # wt.artists.quick2D(a) - wt.artists.quick2D(b) - import matplotlib.pyplot as plt - - plt.show() if __name__ == "__main__": From dfa8c3c8ddb89d5139b8070ec1cc40c6c304df7f Mon Sep 17 00:00:00 2001 From: Kyle Sunden Date: Wed, 16 Jan 2019 14:28:13 -0600 Subject: [PATCH 4/6] Update .travis.yml --- .travis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 1d3093462..25c7cc071 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,11 +2,11 @@ language: python matrix: include: - python: 3.6 - dist: trusty + dist: xenial sudo: false - python: 3.7 dist: xenial - sudo: true + sudo: false addons: apt: packages: From 3bc09ce87aeaefbf932d72a5b9b7f9df01ade0a9 Mon Sep 17 00:00:00 2001 From: Kyle Sunden Date: Wed, 16 Jan 2019 14:33:53 -0600 Subject: [PATCH 5/6] remove sudo=false https://blog.travis-ci.com/2018-10-04-combining-linux-infrastructures --- .travis.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 25c7cc071..9b09ac95d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,10 +3,8 @@ matrix: include: - python: 3.6 dist: xenial - sudo: false - python: 3.7 dist: xenial - sudo: false addons: apt: packages: From d7d9e2eef76cd37f15e41710e40dc825edff1c9a Mon Sep 17 00:00:00 2001 From: Kyle Sunden Date: Wed, 16 Jan 2019 17:03:42 -0600 Subject: [PATCH 6/6] MAINT: use convolve instead of skimage for downscale Alternative implementation to #862 --- WrightTools/data/_data.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/WrightTools/data/_data.py b/WrightTools/data/_data.py index a3a9e07bf..2a2dcd2e6 100644 --- a/WrightTools/data/_data.py +++ b/WrightTools/data/_data.py @@ -934,9 +934,11 @@ def _nd_decimate(arr, factor): if isinstance(factor, (int, type(None))): factor = [factor] * arr.ndim factor = [1 if f is None else f for f in factor] - for axis, f in enumerate(factor): - if arr.shape[axis] >= f: - arr = decimate(arr, f, axis=axis) + factor = [1 if s == 1 else f for s, f in zip(arr.shape, factor)] + m = np.ones(factor) + sl = tuple(slice(None, None, f) for f in factor) + arr = np.ascontiguousarray(scipy.ndimage.convolve(arr, m)[sl]) + arr = arr / m.size return arr for channel in self.channels: