uniform_partition¶
-
odl.discr.partition.
uniform_partition
(min_pt=None, max_pt=None, shape=None, cell_sides=None, nodes_on_bdry=False)[source]¶ Return a partition with equally sized cells.
- Parameters
- min_pt, max_ptfloat or sequence of float, optional
Vectors defining the lower/upper limits of the intervals in an
IntervalProd
(a rectangular box).None
entries mean “compute the value”.- shapeint or sequence of ints, optional
Number of nodes per axis.
None
entries mean “compute the value”.- cell_sidesfloat or sequence of floats, optional
Side length of the partition cells per axis.
None
entries mean “compute the value”.- nodes_on_bdrybool or sequence, optional
If a sequence is provided, it determines per axis whether to place the last grid point on the boundary (
True
) or shift it by half a cell size into the interior (False
). In each axis, an entry may consist in a single bool or a 2-tuple of bool. In the latter case, the first tuple entry decides for the left, the second for the right boundary. The length of the sequence must bearray.ndim
.A single boolean is interpreted as a global choice for all boundaries.
See also
uniform_partition_fromintv
partition an existing set
uniform_partition_fromgrid
use an existing grid as basis
Notes
In each axis, 3 of the 4 possible parameters
min_pt
,max_pt
,shape
andcell_sides
must be given. If all four are provided, they are checked for consistency.Examples
Any combination of three of the four parameters can be used for creation of a partition:
>>> part = odl.uniform_partition(min_pt=0, max_pt=2, shape=4) >>> part.cell_boundary_vecs (array([ 0. , 0.5, 1. , 1.5, 2. ]),) >>> part = odl.uniform_partition(min_pt=0, shape=4, cell_sides=0.5) >>> part.cell_boundary_vecs (array([ 0. , 0.5, 1. , 1.5, 2. ]),) >>> part = odl.uniform_partition(max_pt=2, shape=4, cell_sides=0.5) >>> part.cell_boundary_vecs (array([ 0. , 0.5, 1. , 1.5, 2. ]),) >>> part = odl.uniform_partition(min_pt=0, max_pt=2, cell_sides=0.5) >>> part.cell_boundary_vecs (array([ 0. , 0.5, 1. , 1.5, 2. ]),)
In higher dimensions, the parameters can be given differently in each axis. Where
None
is given, the value will be computed:>>> part = odl.uniform_partition(min_pt=[0, 0], max_pt=[1, 2], ... shape=[4, 2]) >>> part.cell_boundary_vecs (array([ 0. , 0.25, 0.5 , 0.75, 1. ]), array([ 0., 1., 2.])) >>> part = odl.uniform_partition(min_pt=[0, 0], max_pt=[1, 2], ... shape=[None, 2], cell_sides=[0.25, None]) >>> part.cell_boundary_vecs (array([ 0. , 0.25, 0.5 , 0.75, 1. ]), array([ 0., 1., 2.])) >>> part = odl.uniform_partition(min_pt=[0, None], max_pt=[None, 2], ... shape=[4, 2], cell_sides=[0.25, 1]) >>> part.cell_boundary_vecs (array([ 0. , 0.25, 0.5 , 0.75, 1. ]), array([ 0., 1., 2.]))
By default, no grid points are placed on the boundary:
>>> part = odl.uniform_partition(0, 1, 4) >>> part.nodes_on_bdry False >>> part.cell_boundary_vecs (array([ 0. , 0.25, 0.5 , 0.75, 1. ]),) >>> part.grid.coord_vectors (array([ 0.125, 0.375, 0.625, 0.875]),)
This can be changed with the nodes_on_bdry parameter:
>>> part = odl.uniform_partition(0, 1, 3, nodes_on_bdry=True) >>> part.nodes_on_bdry True >>> part.cell_boundary_vecs (array([ 0. , 0.25, 0.75, 1. ]),) >>> part.grid.coord_vectors (array([ 0. , 0.5, 1. ]),)
We can specify this per axis, too. In this case we choose both in the first axis and only the rightmost in the second:
>>> part = odl.uniform_partition([0, 0], [1, 1], (3, 3), ... nodes_on_bdry=(True, (False, True))) ... >>> part.cell_boundary_vecs[0] # first axis, as above array([ 0. , 0.25, 0.75, 1. ]) >>> part.grid.coord_vectors[0] array([ 0. , 0.5, 1. ]) >>> part.cell_boundary_vecs[1] # second, asymmetric axis array([ 0. , 0.4, 0.8, 1. ]) >>> part.grid.coord_vectors[1] array([ 0.2, 0.6, 1. ])