Skip to content

Commit

Permalink
Merge pull request #2 from tomography/master
Browse files Browse the repository at this point in the history
resync
  • Loading branch information
decarlof committed Dec 1, 2016
2 parents d8b99bc + 115934f commit f689a7d
Show file tree
Hide file tree
Showing 22 changed files with 2,312 additions and 1,297 deletions.
7 changes: 4 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ python:
os:
- linux

sudo: false
sudo: required
dist: trusty

before_script:
- "export DISPLAY=:99.0"
Expand All @@ -29,8 +30,8 @@ before_install:
- conda install anaconda-client

install:
- conda install python=$TRAVIS_PYTHON_VERSION nose six numpy scipy matplotlib python-coveralls pillow cached-property
- pip install phasepack
- conda install python=$TRAVIS_PYTHON_VERSION nose six numpy scipy matplotlib python-coveralls pillow cached-property setuptools
- pip install phasepack polytope
- conda info -a
- python setup.py build_ext --inplace

Expand Down
354 changes: 354 additions & 0 deletions docs/demos/FullReferenceMetrics.ipynb

Large diffs are not rendered by default.

267 changes: 0 additions & 267 deletions docs/demos/NEQ.ipynb

This file was deleted.

439 changes: 439 additions & 0 deletions docs/demos/NoReferenceMetrics.ipynb

Large diffs are not rendered by default.

248 changes: 248 additions & 0 deletions docs/demos/Parameterized.ipynb

Large diffs are not rendered by default.

162 changes: 136 additions & 26 deletions docs/demos/Shepp.ipynb

Large diffs are not rendered by default.

335 changes: 0 additions & 335 deletions docs/demos/Soil.ipynb

This file was deleted.

57 changes: 35 additions & 22 deletions docs/demos/StandardPatterns.ipynb

Large diffs are not rendered by default.

126 changes: 29 additions & 97 deletions docs/demos/WetCircles.ipynb

Large diffs are not rendered by default.

7 changes: 4 additions & 3 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -341,9 +341,10 @@ def __getattr__(cls, name):
return Mock()

MOCK_MODULES = [
'numpy', 'scipy', 'scipy.stats', 'scipy.ndimage',
'matplotlib', 'matplotlib.pyplot', 'matplotlib.patches',
'phasepack', 'cached-property']
'numpy', 'scipy', 'scipy.stats', 'scipy.ndimage',
'matplotlib', 'matplotlib.pyplot', 'matplotlib.patches',
'phasepack', 'cached-property', 'matplotlib.path',
'matplotlib.patheffects', 'matplotlib.axis', 'scipy.spatial']

for mod_name in MOCK_MODULES:
sys.modules[mod_name] = Mock()
3 changes: 2 additions & 1 deletion meta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@ requirements:

run:
- python
- numpy
- numpy
- scipy
- six
- matplotlib
- phasepack
- cached-property
- polytope

test:
# Python imports
Expand Down
1 change: 1 addition & 0 deletions requirements-doc.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
sphinx
sphinx_rtd_theme
sphinxcontrib-bibtex
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
import setuptools
from version_hashtag import append_dev_info

version_info = (0, 1, 0)
version_info = (0, 2, 0)
version = '.'.join([str(x) for x in version_info])
version = append_dev_info(version)
with open('VERSION', 'w') as f:
Expand Down
18 changes: 18 additions & 0 deletions tests/test_acquisition.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from __future__ import (absolute_import, division, print_function,
unicode_literals)

from xdesign.acquisition import raster_scan
from numpy.testing import assert_allclose, assert_raises, assert_equal
import numpy as np


def test_raster_scan():
positions = [p.numpy.flatten() for p in raster_scan(2, 2)]
positions = np.hstack(np.hstack(positions))

correct = np.array([0.25, -10., 0.25, 10.,
0.75, -10., 0.75, 10.,
11., 0.25, -9., 0.25,
11., 0.75, -9., 0.75])

assert_allclose(positions, correct)
173 changes: 128 additions & 45 deletions tests/test_geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
unicode_literals)

from xdesign.geometry import *
from xdesign.geometry import beamcirc
from xdesign.geometry import beamcirc, beampoly
from xdesign.acquisition import *
from numpy.testing import assert_allclose, assert_raises, assert_equal
import numpy as np
Expand All @@ -61,125 +61,208 @@
__docformat__ = 'restructuredtext en'


# Transformations

def rotate_around_self():
P0 = Point([0, 0])
origin = P0
P1 = rotate(P0, np.pi/2, origin)
assert_allclose([P1.x, P1.y], [0, 0])


def rotate_around_other():
P0 = Point([0, 0])
origin = Point([1, 0])
P1 = rotate(P0, np.pi/2, origin)
assert_allclose([P1.x, P1.y], [1, -1])


def test_Point_rotate_around_self():
P0 = Point([0, 0])
origin = P0
P0.rotate(np.pi/2, origin)
assert_allclose([P0.x, P0.y], [0, 0])


def test_Point_rotate_around_other():
P0 = Point([0, 0])
origin = Point([1, 0])
P0.rotate(np.pi/2, origin)
assert_allclose([P0.x, P0.y], [1, -1])

P0 = Point([0, 0])
origin = Point([0, 1])
P0.rotate(np.pi/2, origin)
assert_allclose([P0.x, P0.y], [1, 1])

P0 = Point([0, 0])
origin = Point([-1, 0])
P0.rotate(np.pi/2, origin)
assert_allclose([P0.x, P0.y], [-1, 1])

P0 = Point([0, 0])
origin = Point([-1, -1])
P0.rotate(np.pi/2, origin)
assert_allclose([P0.x, P0.y], [-2, 0])


def test_translate():
P0 = Point([0, 0])
P0.translate([2.3, 4.5])
assert_equal([P0.x, P0.y], [2.3, 4.5])


# Nonintersecting beams

def test_beamcirc_nonintersecting_top():
circ = Circle(Point(0, 3), 1)
beam = Beam(Point(-2, 0), Point(2, 0), 2)
circ = Circle(Point([0, 3]), 1)
beam = Beam(Point([-2, 0]), Point([2, 0]), 2)
assert_allclose(beamcirc(beam, circ), 0., rtol=1e-6)


def test_beamcirc_nonintersecting_bottom():
circ = Circle(Point(0, -3), 1)
beam = Beam(Point(-2, 0), Point(2, 0), 2)
circ = Circle(Point([0, -3]), 1)
beam = Beam(Point([-2, 0]), Point([2, 0]), 2)
assert_allclose(beamcirc(beam, circ), 0., rtol=1e-6)


def test_beampoly_nonintersecting_top():
tri = Triangle(Point([0, 1]), Point([1, -1]), Point([-1, -1]))
beam = Beam(Point([-2, 2]), Point([2, 2]), 2)
assert_allclose(beampoly(beam, tri), 0., rtol=1e-6)


def test_beampoly_nonintersecting_bottom():
tri = Triangle(Point([0, 1]), Point([1, -1]), Point([-1, -1]))
beam = Beam(Point([-2, -2]), Point([2, -2]), 2)
assert_allclose(beampoly(beam, tri), 0., rtol=1e-6)


# Partial intersections

def test_beamcirc_intersecting_partially_from_top_outside_center():
circ = Circle(Point(0, 1.5), 1)
beam = Beam(Point(-2, 0), Point(2, 0), 2)
circ = Circle(Point([0, 1.5]), 1)
beam = Beam(Point([-2, 0]), Point([2, 0]), 2)
assert_allclose(beamcirc(beam, circ), 0.614184849304, rtol=1e-6)


def test_beamcirc_intersecting_partially_from_bottom_outside_center():
circ = Circle(Point(0, -1.5), 1)
beam = Beam(Point(-2, 0), Point(2, 0), 2)
circ = Circle(Point([0, -1.5]), 1)
beam = Beam(Point([-2, 0]), Point([2, 0]), 2)
assert_allclose(beamcirc(beam, circ), 0.614184849304, rtol=1e-6)


def test_beamcirc_intersecting_partially_from_top_inside_center():
circ = Circle(Point(0, 0.5), 1)
beam = Beam(Point(-2, 0), Point(2, 0), 2)
circ = Circle(Point([0, 0.5]), 1)
beam = Beam(Point([-2, 0]), Point([2, 0]), 2)
assert_allclose(beamcirc(beam, circ), 2.52740780429, rtol=1e-6)


def test_beamcirc_intersecting_partially_from_bottom_inside_center():
circ = Circle(Point(0, -0.5), 1)
beam = Beam(Point(-2, 0), Point(2, 0), 2)
circ = Circle(Point([0, -0.5]), 1)
beam = Beam(Point([-2, 0]), Point([2, 0]), 2)
assert_allclose(beamcirc(beam, circ), 2.52740780429, rtol=1e-6)


def test_beampoly_intersecting_partially_from_top():
tri = Rectangle(Point([0, 0]), Point([1, 0]), Point([1, 1]), Point([0, 1]))
beam = Beam(Point([-2, 1]), Point([2, 1]), 1)
assert_allclose(beampoly(beam, tri), 1/2, rtol=1e-6)


def test_beampoly_intersecting_partially_from_bottom():
tri = Rectangle(Point([0, 0]), Point([1, 0]), Point([1, 1]), Point([0, 1]))
beam = Beam(Point([-2, 0]), Point([2, 0]), 1)
assert_allclose(beampoly(beam, tri), 1/2, rtol=1e-6)


# Full intersections

def test_beamcirc_intersecting_fully_from_top_outside_center():
circ = Circle(Point(0, 1.5), 3)
beam = Beam(Point(-2, 0), Point(2, 0), 2)
circ = Circle(Point([0, 1.5]), 3)
beam = Beam(Point([-2, 0]), Point([2, 0]), 2)
assert_allclose(beamcirc(beam, circ), 10.0257253792, rtol=1e-6)


def test_beamcirc_intersecting_fully_from_bottom_outside_center():
circ = Circle(Point(0, -1.5), 3)
beam = Beam(Point(-2, 0), Point(2, 0), 2)
circ = Circle(Point([0, -1.5]), 3)
beam = Beam(Point([-2, 0]), Point([2, 0]), 2)
assert_allclose(beamcirc(beam, circ), 10.0257253792, rtol=1e-6)


def test_beamcirc_intersecting_fully_from_top_inside_center():
circ = Circle(Point(0, 0.5), 3)
beam = Beam(Point(-2, 0), Point(2, 0), 2)
circ = Circle(Point([0, 0.5]), 3)
beam = Beam(Point([-2, 0]), Point([2, 0]), 2)
assert_allclose(beamcirc(beam, circ), 11.5955559562, rtol=1e-6)


def test_beamcirc_intersecting_fully_from_bottom_inside_center():
circ = Circle(Point(0, -0.5), 3)
beam = Beam(Point(-2, 0), Point(2, 0), 2)
circ = Circle(Point([0, -0.5]), 3)
beam = Beam(Point([-2, 0]), Point([2, 0]), 2)
assert_allclose(beamcirc(beam, circ), 11.5955559562, rtol=1e-6)


def test_beamcirc_intersecting_fully():
circ = Circle(Point(0, 0), 1)
beam = Beam(Point(-2, 0), Point(2, 0), 2)
circ = Circle(Point([0, 0]), 1)
beam = Beam(Point([-2, 0]), Point([2, 0]), 2)
assert_allclose(beamcirc(beam, circ), 3.14159265359, rtol=1e-6)

def test_beampoly_intersecting_fully():
tri = Rectangle(Point([-1, -1]), Point([1, -1]), Point([1, 1]), Point([-1, 1]))
beam = Beam(Point([-2, 0]), Point([2, 0]), 3)
assert_allclose(beampoly(beam, tri), 4, rtol=1e-6)

# Vertical intersection.

def test_beamcirc_vertical_intersection():
circ = Circle(Point(0, 0), 1)
beam = Beam(Point(-1, -1), Point(1, 1), 1)
circ = Circle(Point([0, 0]), 1)
beam = Beam(Point([-1, -1]), Point([1, 1]), 1)
assert_allclose(beamcirc(beam, circ), 1.91322295498, rtol=1e-6)

def test_beampoly_vertical_intersection():
tri = Rectangle(Point([-5, 0]), Point([5, 0]), Point([5, 1]), Point([-5, 1]))
beam = Beam(Point([0, -1]), Point([0, 1]), 1)
assert_allclose(beampoly(beam, tri), 1, rtol=1e-6)

# Line

def test_Line_slope_vertical():
line = Line(Point(0, -1), Point(0, 1))
line = Line(Point([0, -1]), Point([0, 1]))
assert_allclose(line.slope, np.inf, rtol=1e-6)


def test_Line_yintercept_vertical():
line = Line(Point(0, -1), Point(0, 1))
assert_allclose(line.yintercept, 0, rtol=1e-6)
line = Line(Point([0, -1]), Point([0, 1]))
assert_allclose(line.yintercept, np.inf, rtol=1e-6)


def test_Line_slope():
line = Line(Point(-1, 0), Point(1, 2))
line = Line(Point([-1, 0]), Point([1, 2]))
assert_allclose(line.slope, 1, rtol=1e-6)


def test_Line_yintercept():
line = Line(Point(-1, 0), Point(1, 2))
line = Line(Point([-1, 0]), Point([1, 2]))
assert_allclose(line.yintercept, 1, rtol=1e-6)


def test_Line_same_points():
assert_raises(ValueError, Line, Point(1, 2), Point(1, 2))
assert_raises(ValueError, Line, Point([1, 2]), Point([1, 2]))


# Circle

def test_Circle_area():
circle = Circle(Point(0, 0), 1)
circle = Circle(Point([0, 0]), 1)
assert_allclose(circle.area, 3.14159265359, rtol=1e-6)


def test_Mesh_area():
p5 = Point(0, 0)
p1 = Point(1, 1)
p4 = Point(1, -1)
p3 = Point(-1, -1)
p2 = Point(-1, 1)
p5 = Point([0, 0])
p1 = Point([1, 1])
p4 = Point([1, -1])
p3 = Point([-1, -1])
p2 = Point([-1, 1])
m = Mesh()
assert_equal(m.area, 0)
m.append(Triangle(p5, p1, p2))
Expand All @@ -190,25 +273,25 @@ def test_Mesh_area():


def test_Mesh_center():
p5 = Point(0, 0)
p1 = Point(1, 1)
p4 = Point(1, -1)
p3 = Point(-1, -1)
p2 = Point(-1, 1)
p5 = Point([0, 0])
p1 = Point([1, 1])
p4 = Point([1, -1])
p3 = Point([-1, -1])
p2 = Point([-1, 1])
m = Mesh()
assert_equal(m.center, Point(0, 0))
assert_equal(m.center, Point([0, 0]))

m.append(Triangle(p5, p1, p2))
m.append(Triangle(p5, p2, p3))
m.append(Triangle(p5, p3, p4))
m.append(Triangle(p5, p4, p1))
assert_equal(m.center, Point(0, 0))
assert_equal(m.center, Point([0, 0]))

m.pop()
m.pop()
m.pop()
m.pop()
assert_equal(m.center, Point(0, 0))
assert_equal(m.center, Point([0, 0]))


if __name__ == '__main__':
Expand Down

0 comments on commit f689a7d

Please sign in to comment.