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

Add LabelVariable #832

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
19 changes: 10 additions & 9 deletions fipy/variables/cellVariable.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,23 +132,24 @@ def globalValue(self):

@property
def ndimage(self):
"""Global value as an ndarray suitable for scipy.ndimage
"""Global value as an `ndarray` suitable for `scipy.ndimage`

The cell values of a `CellVariable` are stored in a 1D ndarray.
The cell values of a `CellVariable` are stored in a 1D `ndarray.
guyer marked this conversation as resolved.
Show resolved Hide resolved
FiPy arranges its gridded cells in a right-handed Cartesian
fashion, with x increasing to the right, y increasing up, and z
increasing toward you. Conversely, NumPy arrays and ndimages are
arranged in stacks of increasing z, each consisting of rows of
increasing y, each element of which increases in x. As a result, we
reverse FiPy's (x,y,z) shape to NumPy's (z,y,x).
increasing toward you. Conversely, NumPy arrays, particularly
`scipy.ndimage` arrays, are arranged in stacks of increasing z,
each consisting of rows of increasing y, each element of which
increases in x. As a result, we reverse FiPy's (x,y,z) shape to
NumPy's (z,y,x).

>>> import fipy as fp
>>> mesh = fp.Grid2D(nx=2, ny=3)
>>> var = fp.CellVariable(mesh=mesh, value=mesh.x * mesh.y)
>>> print(var.ndimage)
[[0.25 0.75]
[0.75 2.25]
[1.25 3.75]]
[[ 0.25 0.75]
[ 0.75 2.25]
[ 1.25 3.75]]

Returns
-------
Expand Down
4 changes: 2 additions & 2 deletions fipy/variables/labelVariable.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
__all__ = [text_to_native_str(n) for n in __all__]

class LabelVariable(CellVariable):
"""Label features in `var` using scipy.ndimage.label
"""Label features in `var` using `scipy.ndimage.label`

>>> import fipy as fp

Expand Down Expand Up @@ -208,7 +208,7 @@ def __init__(self, var, name="", structure=None, dtype=int):
def _calcValue(self):
"""Label features of `var`

Side-effect: sets self._num_features
Side-effect: sets :attr:`self._num_features`.
"""
from scipy import ndimage

Expand Down