[python-dtcwt] 03/497: add port of reflect.m
Ghislain Vaillant
ghisvail-guest at moszumanska.debian.org
Tue Jul 21 18:05:41 UTC 2015
This is an automated email from the git hooks/post-receive script.
ghisvail-guest pushed a commit to branch debian/sid
in repository python-dtcwt.
commit 9f0bd55338dc083e5313ff91a0b4513df3546d22
Author: Rich Wareham <rjw57 at cam.ac.uk>
Date: Tue Aug 6 12:35:29 2013 +0100
add port of reflect.m
---
.gitignore | 4 ++++
dtcwt/__init__.py | 1 +
dtcwt/reflect.py | 29 +++++++++++++++++++++++++++++
setup.py | 6 +++++-
tests/testreflect.py | 23 +++++++++++++++++++++++
5 files changed, 62 insertions(+), 1 deletion(-)
diff --git a/.gitignore b/.gitignore
index 0d20b64..1b1b44e 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1 +1,5 @@
*.pyc
+build/
+*.egg
+*.egg-info
+.*.swp
diff --git a/dtcwt/__init__.py b/dtcwt/__init__.py
index e69de29..d2ac8df 100644
--- a/dtcwt/__init__.py
+++ b/dtcwt/__init__.py
@@ -0,0 +1 @@
+from .reflect import reflect
diff --git a/dtcwt/reflect.py b/dtcwt/reflect.py
new file mode 100644
index 0000000..4cffa7b
--- /dev/null
+++ b/dtcwt/reflect.py
@@ -0,0 +1,29 @@
+import numpy as np
+
+def reflect(x, minx, maxx):
+ """Reflect the values in matrix x about the scalar values minx and maxx.
+ Hence a vector x containing a long linearly increasing series is converted
+ into a waveform which ramps linearly up and down between minx and maxx. If
+ x contains integers and minx and maxx are (integers + 0.5), the ramps will
+ have repeated max and min samples.
+
+ Nick Kingsbury, Cambridge University, January 1999.
+
+ """
+
+ # Copy x to avoid in-place modification
+ y = np.copy(x)
+
+ # Reflect y in maxx.
+ y[y > maxx] = 2*maxx - y[y > maxx]
+
+ while np.any(y < minx):
+ # Reflect y in minx.
+ y[y < minx] = 2*minx - y[y < minx]
+
+ # Reflect y in maxx.
+ y[y > maxx] = 2*maxx - y[y > maxx]
+
+ return y
+
+# vim:sw=4:sts=4:et
diff --git a/setup.py b/setup.py
index 837641a..ba39862 100644
--- a/setup.py
+++ b/setup.py
@@ -18,11 +18,15 @@ setup(
license = "BSD",
keywords = "example documentation tutorial",
url = "http://packages.python.org/an_example_pypi_project",
- packages=find_packages(),
+ packages=find_packages(exclude=["*.tests", "*.tests.*", "tests.*", "tests"]),
long_description=read('README.rst'),
classifiers=[
"Development Status :: 3 - Alpha",
"Topic :: Utilities",
"License :: OSI Approved :: BSD License",
],
+
+ setup_requires=['nose>=1.0',],
+
+ install_requires=['numpy',],
)
diff --git a/tests/testreflect.py b/tests/testreflect.py
new file mode 100644
index 0000000..e9c50c0
--- /dev/null
+++ b/tests/testreflect.py
@@ -0,0 +1,23 @@
+import numpy as np
+
+from dtcwt import reflect
+
+def setup():
+ global ramp, reflected
+
+ # Create a simple linear ramp and reflect it
+ ramp = np.linspace(-100, 100, 500)
+ reflected = reflect(ramp, 30, 40)
+
+def test_linear_ramp_boundaries():
+ # Check boundaries
+ assert not np.any(reflected < 30)
+ assert not np.any(reflected > 40)
+
+def test_linear_ramp_values():
+ # Check that valid region is unchanged
+ r = np.logical_and(ramp >= 30, ramp <= 40)
+ assert np.any(r)
+ assert np.all(reflected[r] == ramp[r])
+
+# vim:sw=4:sts=4:et
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/python-dtcwt.git
More information about the debian-science-commits
mailing list