From 61a29db528fbb8f2d9f1f6bf754589611bbf7d7a Mon Sep 17 00:00:00 2001 From: Holger Kohr Date: Sat, 21 Jan 2017 20:42:37 +0100 Subject: [PATCH] MAINT: minor fixes --- odl/discr/grid.py | 21 +++++++++++++-------- odl/discr/partition.py | 11 +++-------- odl/test/discr/grid_test.py | 2 ++ odl/test/discr/partition_test.py | 2 ++ odl/test/tomo/backends/astra_setup_test.py | 7 +++++++ 5 files changed, 27 insertions(+), 16 deletions(-) diff --git a/odl/discr/grid.py b/odl/discr/grid.py index e7036fc3bf8..3f3d6488244 100644 --- a/odl/discr/grid.py +++ b/odl/discr/grid.py @@ -106,8 +106,6 @@ def __init__(self, *coord_vectors): [1.0, 2.0, 5.0], [-2.0, 1.5, 2.0] ) - >>> print(g) - grid [1.0, 2.0, 5.0] x [-2.0, 1.5, 2.0] >>> g.ndim # number of axes 2 >>> g.shape # points per axis @@ -392,11 +390,17 @@ def mid_pt(self): def stride(self): """Step per axis between neighboring points of a uniform grid. + Raises + ------ + NotImplementedError + if the grid is not uniform + Examples -------- >>> rg = uniform_grid([-1.5, -1], [-0.5, 3], (2, 3)) >>> rg.stride array([ 1., 2.]) + """ if not self.is_uniform: raise NotImplementedError('`stride` not defined for non-uniform ' @@ -570,10 +574,11 @@ def is_subgrid(self, other, atol=0.0): # Optimization for some common cases if other is self: return True - if not (isinstance(other, RectGrid) and - np.all(self.shape <= other.shape) and - np.all(self.min_pt >= other.min_pt - atol) and - np.all(self.max_pt <= other.max_pt + atol)): + if not isinstance(other, RectGrid): + return False + if not(np.all(self.shape <= other.shape) and + np.all(self.min_pt >= other.min_pt - atol) and + np.all(self.max_pt <= other.max_pt + atol)): return False if self.is_uniform and other.is_uniform: @@ -599,7 +604,7 @@ def is_subgrid(self, other, atol=0.0): # vec_s. If there is no almost zero entry in each row, # return False. vec_o_mg, vec_s_mg = sparse_meshgrid(vec_o, vec_s) - if not np.all(np.any(np.abs(vec_s_mg - vec_o_mg) <= atol, + if not np.all(np.any(np.isclose(vec_s_mg, vec_o_mg, atol=atol), axis=0)): return False return True @@ -701,7 +706,7 @@ def squeeze(self): ) """ - nondegen_indcs = np.where(self.nondegen_byaxis)[0] + nondegen_indcs = np.flatnonzero(self.nondegen_byaxis) coord_vecs = [self.coord_vectors[axis] for axis in nondegen_indcs] return RectGrid(*coord_vecs) diff --git a/odl/discr/partition.py b/odl/discr/partition.py index edc50ce8adf..1270d983e33 100644 --- a/odl/discr/partition.py +++ b/odl/discr/partition.py @@ -771,10 +771,6 @@ def __repr__(self): return RectPartitionByAxis() - def __str__(self): - """Return ``str(self)``.""" - return 'partition of {} using {}'.format(self.set, self.grid) - def __repr__(self): """Return ``repr(self)``.""" bdry_fracs = np.vstack(self.boundary_cell_fractions) @@ -835,6 +831,8 @@ def __repr__(self): sep=[',\n', ', ', ',\n']) return '{}(\n{}\n)'.format(constructor, indent_rows(sig_str)) + __str__ = __repr__ + def uniform_partition_fromintv(intv_prod, shape, nodes_on_bdry=False): """Return a partition of an interval product into equally sized cells. @@ -898,10 +896,7 @@ def uniform_partition_fromintv(intv_prod, shape, nodes_on_bdry=False): >>> part.grid.coord_vectors[1] array([ 0.2, 0.6, 1. ]) """ - - grid = uniform_grid_fromintv(intv_prod, shape, - nodes_on_bdry=nodes_on_bdry) - + grid = uniform_grid_fromintv(intv_prod, shape, nodes_on_bdry=nodes_on_bdry) return RectPartition(intv_prod, grid) diff --git a/odl/test/discr/grid_test.py b/odl/test/discr/grid_test.py index f8eef18049e..7a2fc5c032c 100644 --- a/odl/test/discr/grid_test.py +++ b/odl/test/discr/grid_test.py @@ -15,6 +15,8 @@ # You should have received a copy of the GNU General Public License # along with ODL. If not, see . +from __future__ import division + import pytest import numpy as np diff --git a/odl/test/discr/partition_test.py b/odl/test/discr/partition_test.py index c6690261ba5..44c9927856a 100644 --- a/odl/test/discr/partition_test.py +++ b/odl/test/discr/partition_test.py @@ -15,6 +15,8 @@ # You should have received a copy of the GNU General Public License # along with ODL. If not, see . +from __future__ import division + import pytest import numpy as np diff --git a/odl/test/tomo/backends/astra_setup_test.py b/odl/test/tomo/backends/astra_setup_test.py index 38db51a9612..58592706aed 100644 --- a/odl/test/tomo/backends/astra_setup_test.py +++ b/odl/test/tomo/backends/astra_setup_test.py @@ -168,6 +168,13 @@ def test_astra_projection_geometry(): apart = odl.uniform_partition(0, 2 * np.pi, 5) dpart = odl.uniform_partition(-40, 40, 10) + # motion sampling grid, detector sampling grid but not uniform + dpart_0 = odl.RectPartition(odl.IntervalProd(0, 3), + odl.RectGrid([0, 1, 3])) + geom_p2d = odl.tomo.Parallel2dGeometry(apart, dpart=dpart_0) + with pytest.raises(ValueError): + odl.tomo.astra_projection_geometry(geom_p2d) + # detector sampling grid, motion sampling grid geom_p2d = odl.tomo.Parallel2dGeometry(apart, dpart) odl.tomo.astra_projection_geometry(geom_p2d)