Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP/MAINT: Use scipy.signal instead of skimage for downscale #862

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 3 additions & 7 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@ language: python
matrix:
include:
- python: 3.6
dist: trusty
sudo: false
dist: xenial
- python: 3.7
dist: xenial
sudo: true
addons:
apt:
packages:
Expand All @@ -16,8 +14,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
32 changes: 18 additions & 14 deletions WrightTools/data/_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
----------
Expand Down Expand Up @@ -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:
Expand Down
1 change: 0 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down