Pressures¶
Cell pressures inferred from a multimaterial mesh and its interface tensions.
The pressures are solved from the tensions (foambryo.tension_inference), by the variational
method (the default) or by Laplace's law (PressureComputationMethod). They are in the unit of the
tensions divided by the mesh's length unit: the tensions being relative (normalised to
mean_tension), so are the pressures, which scale with the tensions. The exterior medium, label 0,
has the pressure base_pressure; a cell whose pressure the mesh does not determine, or a cell the
crop cuts, is nan, never a number.
Sacha Ichbiah 2021 Matthieu Perez 2024
UndeterminedTensionError ¶
UndeterminedTensionError(interfaces: tuple[tuple[int, int], ...])
Bases: ValueError
A pressure inference was handed an interface tension that is not a finite number.
Every pressure method solves for the cell pressures from the interface tensions, and the default variational method couples every cell to every tension, so a single non-finite tension makes nearly every inferred pressure non-finite: measured on five real embryo timepoints with one to four closed interfaces, all but one cell's pressure came back non-finite each time (54 of 55 cells up to 71 of 72). Such a field carries no usable value, so the pressure inference refuses it rather than returning it.
The usual cause is not a numerical failure. An interface with no triple line at all -- a closed
surface, such as an engulfed cell or a sealed lumen, or a fragment that a segmentation left
inside another cell -- has no angle from which its tension could be measured, and
foambryo.infer_tensions reports it as float("nan") by design. The other tensions of such a
mesh remain valid; use foambryo.infer_tensions_by_junction_component to see which interfaces
are undetermined and which component each determined tension belongs to.
Subclasses ValueError, so code that already caught the generic error the least-squares
solve raised on a non-finite input keeps working.
Attributes:
| Name | Type | Description |
|---|---|---|
interfaces |
the interfaces whose tension is not finite, sorted. |
Build the error and its message from the offending interfaces.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
interfaces
|
tuple[tuple[int, int], ...]
|
the interfaces whose tension is not finite. |
required |
UndeterminedPressureWarning ¶
Bases: UserWarning
Emitted when the Laplace pressure leaves cells undetermined; their pressure is nan.
Also emitted by the variational method on a cropped mesh, for a cell that the crop does not cut but whose every vertex lies on a crop face or on an interface without a tension.
The Laplace methods write one equation per interface, P_a - P_b = -2 H_ab T_ab, which
needs the interface's mean curvature H_ab. The curvature is read at the vertices of the
interface that are not on a junction line, so an interface all of whose vertices lie on
junctions has no curvature (nan), and its equation is left out. When the equations that
remain do not connect a cell to the exterior, through a chain of interfaces, nothing fixes
that cell's pressure: it is reported as nan, never as a number. This is common on coarse
meshes of small cells, where up to about a third of the interfaces can have no curvature and a
few cells per hundred can be left undetermined.
The variational method (the default) does not use curvatures and is not affected.
PressureComputationMethod ¶
Bases: Enum
The pressure inference methods.
- Variational (the default): the least-squares solution of the vertex force balance at the given tensions (see our article). It reads no curvature, gives a number for every cell of an uncropped mesh, and is the only method with a formulation for crop faces.
- Laplace: Laplace's law,
P_a - P_b = -2 H_ab T_ab, on each interface, with the interface's mean curvatureH_abaveraged over its vertices off the junction lines. - WeightedLaplace: the same, with the curvature averaged with area weights.
The two Laplace methods need each interface's mean curvature. An interface with no
measurable curvature contributes no equation, and a cell that the remaining equations do
not connect to the exterior gets the pressure nan (see UndeterminedPressureWarning).
They refuse a cropped mesh (ValueError); has_crop_face_formulation says which methods
accept one.
has_crop_face_formulation
property
¶
has_crop_face_formulation: bool
Whether the method infers pressures on a cropped mesh (one with crop faces, foambryo.crop_faces).
Only Variational does: the two Laplace methods read each interface's curvature, which on an interface the
crop cuts is read partly on the crop, and infer_pressures refuses them on a cropped mesh. A front end can
offer only the methods that have the formulation instead of failing after the tensions.
warn_on_undetermined_pressures ¶
warn_on_undetermined_pressures(cells: tuple[int, ...], stacklevel: int = 4) -> None
Emit UndeterminedPressureWarning naming the cells whose Laplace pressure is nan.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cells
|
tuple[int, ...]
|
Labels of the undetermined cells (nothing is emitted if empty). |
required |
stacklevel
|
int
|
passed through to |
4
|
infer_pressures ¶
infer_pressures(mesh: DcelData, dict_tensions: dict[tuple[int, int], float], mode: PressureComputationMethod = PressureComputationMethod.Variational, base_pressure: float = 0, *, solver: str = 'auto', sparse_threshold: int | None = None, diagnostics: bool | str = False) -> dict[int, float] | tuple[dict[int, float], linear_solves.SolveDiagnostics]
Infer the pressure of every cell of a mesh from its interface tensions.
The pressures are in the unit of the tensions divided by the mesh's length unit, and scale with the tensions: tensions normalised to a mean of 1 give pressures relative to that scale.
Cropped meshes (foambryo.crop_faces, variational method only): the pressure of every
cut cell is solved for and returned as nan, with a CutCellPressureWarning naming the
cells; the force balances of the vertices on crop faces, and of the vertices of interfaces
whose tension is nan, are left out, so nan tensions are accepted there; a cell those
balances leave undetermined is nan too (UndeterminedPressureWarning). The crop interfaces
need no entry in dict_tensions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mesh
|
DcelData
|
Mesh to analyze, in any length unit. |
required |
dict_tensions
|
dict[tuple[int, int], float]
|
interface |
required |
mode
|
PressureComputationMethod
|
Computation method. Defaults to
|
Variational
|
base_pressure
|
float
|
Pressure of the exterior medium (label 0), returned as its pressure. Defaults to 0. |
0
|
solver
|
str
|
|
'auto'
|
sparse_threshold
|
int | None
|
unknowns at which |
None
|
diagnostics
|
bool | str
|
|
False
|
Returns:
| Type | Description |
|---|---|
dict[int, float] | tuple[dict[int, float], SolveDiagnostics]
|
dict[int, float]: map cell label (0 = exterior, at |
Raises:
| Type | Description |
|---|---|
UndeterminedTensionError
|
on an uncropped mesh, if any tension in |
ValueError
|
on a cropped mesh with a Laplace method, which has no formulation for crop
faces ( |
KeyError
|
with a Laplace method, when |
LinAlgError
|
if the variational system is singular. |
Warns:
| Type | Description |
|---|---|
UndeterminedPressureWarning
|
when a cell's pressure is undetermined and reported |
CutCellPressureWarning
|
on a cropped mesh, naming the cut cells reported |
SparseSolveFallbackWarning
|
when |
DenseSolveMemoryWarning
|
when |
infer_pressures_and_residuals ¶
infer_pressures_and_residuals(mesh: DcelData, dict_tensions: dict[tuple[int, int], float], mode: PressureComputationMethod = PressureComputationMethod.Variational, base_pressure: float = 0, *, solver: str = 'auto', sparse_threshold: int | None = None, diagnostics: bool | str = False) -> tuple
Infer the pressure of every cell of a mesh from its interface tensions, with the residuals.
infer_pressures returns this function's second value; see it for the units and for cropped
meshes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mesh
|
DcelData
|
Mesh to analyze, in any length unit. |
required |
dict_tensions
|
dict[tuple[int, int], float]
|
interface |
required |
mode
|
PressureComputationMethod
|
Computation method. Defaults to
|
Variational
|
base_pressure
|
float
|
Pressure of the exterior medium (label 0), returned as its pressure. Defaults to 0. |
0
|
solver
|
str
|
|
'auto'
|
sparse_threshold
|
int | None
|
unknowns at which |
None
|
diagnostics
|
bool | str
|
|
False
|
Returns:
| Type | Description |
|---|---|
tuple
|
tuple[NDArray[np.float64], dict[int, float], NDArray[np.float64] | int]:
- with a Laplace method, one value per material in |
Raises:
| Type | Description |
|---|---|
UndeterminedTensionError
|
on an uncropped mesh, if any tension in |
ValueError
|
on a cropped mesh with a Laplace method, which has no formulation for crop
faces ( |
KeyError
|
with a Laplace method, when |
LinAlgError
|
if the variational system is singular. |
Warns:
| Type | Description |
|---|---|
UndeterminedPressureWarning
|
when a cell's pressure is undetermined and reported |
CutCellPressureWarning
|
on a cropped mesh, naming the cut cells reported |
SparseSolveFallbackWarning
|
when |
DenseSolveMemoryWarning
|
when |