tissue¶
tissue_simulator.tissue ¶
Core tissue section and cell classes.
Cell ¶
Cell(center: Tuple[float, float, float], radius: float, cell_type: str = 'default', is_boundary: bool = False)
Represents a single cell in the tissue section.
Attributes:
| Name | Type | Description |
|---|---|---|
center |
(x, y, z) coordinates of cell center |
|
radius |
Cell radius |
|
cell_type |
Type/classification of the cell |
|
is_boundary |
Whether cell extends beyond tissue bounds |
Source code in tissue_simulator/tissue.py
intersects ¶
Check if this cell intersects with another cell.
is_within_bounds ¶
Check if cell is completely within tissue bounds.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bounds
|
Tuple[float, float, float]
|
(height, width, thickness) of tissue section |
required |
Source code in tissue_simulator/tissue.py
intersects_bounds ¶
Check if cell center is within bounds (allowing partial overlap).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bounds
|
Tuple[float, float, float]
|
(height, width, thickness) of tissue section |
required |
Source code in tissue_simulator/tissue.py
TissueSection ¶
TissueSection(height: float, width: float, thickness: float, cell_radii: Union[Tuple[float, float], Dict[str, Tuple[float, float]]], seed: Optional[int] = None)
Represents a 3D tissue section with packed cells.
Attributes:
| Name | Type | Description |
|---|---|---|
height |
Y-dimension of tissue (micrometers) |
|
width |
X-dimension of tissue (micrometers) |
|
thickness |
Z-dimension of tissue (micrometers) |
|
cell_radii |
Dictionary mapping cell types to (min_radius, max_radius) |
|
cells |
List[Cell]
|
List of Cell objects in the tissue |
Initialize a tissue section.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
height
|
float
|
Y-dimension in micrometers |
required |
width
|
float
|
X-dimension in micrometers |
required |
thickness
|
float
|
Z-dimension in micrometers |
required |
cell_radii
|
Union[Tuple[float, float], Dict[str, Tuple[float, float]]]
|
Either a tuple (min, max) for uniform cells, or dict mapping cell types to (min, max) radii |
required |
seed
|
Optional[int]
|
Optional integer seed controlling randomness for this
tissue (both the internal sampler and the SpherePacker
created by |
None
|
Source code in tissue_simulator/tissue.py
get_bounds ¶
generate_cells ¶
generate_cells(max_attempts: int = 1000, min_spacing: float = 0.5, allow_boundary_cells: bool = True, seed: Optional[int] = None, layout=None, packing_params: Optional[Dict] = None) -> int
Generate cells using random sphere packing.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
max_attempts
|
int
|
Maximum placement attempts before stopping |
1000
|
min_spacing
|
float
|
Minimum spacing between cell surfaces |
0.5
|
allow_boundary_cells
|
bool
|
If True, allow cells that extend beyond bounds |
True
|
seed
|
Optional[int]
|
Optional integer seed that overrides |
None
|
layout
|
Optional :class: |
None
|
|
packing_params
|
Optional[Dict]
|
Extra keyword arguments for |
None
|
Returns:
| Type | Description |
|---|---|
int
|
Number of cells successfully placed |
Source code in tissue_simulator/tissue.py
get_cell_statistics ¶
Calculate statistics about the packed cells.
Source code in tissue_simulator/tissue.py
export_to_csv ¶
Export cell data to CSV file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filename
|
str
|
Output CSV file path |
required |
Source code in tissue_simulator/tissue.py
from_cells
classmethod
¶
from_cells(cells: List[Cell], height: Optional[float] = None, width: Optional[float] = None, thickness: Optional[float] = None, cell_radii: Optional[Dict[str, Tuple[float, float]]] = None) -> TissueSection
Wrap a collection of pre-positioned cells in a TissueSection.
This is the inverse complement to cell generation: instead of packing new cells into an empty tissue, it adopts cells that already have positions (e.g. imported from an external source or a CSV file) so the spatial-analysis and replicate-generation API can run on externally sourced tissue.
Dimension inference
Any dimension left as None is inferred from the bounding box of the
cell CENTERS along its axis (span = max - min): width from axis 0
(x), height from axis 1 (y), thickness from axis 2 (z). If a span is
0 -- as happens for a 2D slice where every z is equal -- the
dimension falls back to the largest cell diameter
2 * max(c.radius for c in cells) so it stays strictly positive
(this keeps get_cell_statistics()["packing_fraction"] within
(0, 1)). A dimension passed in explicitly is used as-is.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cells
|
List[Cell]
|
Non-empty list of Cell objects with positions already set. |
required |
height
|
Optional[float]
|
Optional Y-dimension; inferred from cell centers if None. |
None
|
width
|
Optional[float]
|
Optional X-dimension; inferred from cell centers if None. |
None
|
thickness
|
Optional[float]
|
Optional Z-dimension; inferred from cell centers if None. |
None
|
cell_radii
|
Optional[Dict[str, Tuple[float, float]]]
|
Optional mapping of cell type to (min, max) radius. When None, it is derived by grouping the cells on cell_type and mapping each type to its observed (min_radius, max_radius). |
None
|
Returns:
| Type | Description |
|---|---|
TissueSection
|
A TissueSection whose |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in tissue_simulator/tissue.py
visualize ¶
Create a 3D visualization of the tissue section.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
show_boundary
|
bool
|
Whether to show boundary box |
True
|
elevation
|
float
|
Viewing elevation angle |
20
|
azimuth
|
float
|
Viewing azimuth angle |
45
|
Source code in tissue_simulator/tissue.py
315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 | |
load_tissue_from_csv ¶
load_tissue_from_csv(filepath: str, height: Optional[float] = None, width: Optional[float] = None, thickness: Optional[float] = None, default_radius: float = 10.0) -> TissueSection
Load a tissue section from a CSV file.
This is the exact inverse of TissueSection.export_to_csv: it reads the
rows that export_to_csv writes back into Cell objects and wraps them in
a TissueSection (via TissueSection.from_cells), inferring any omitted
dimensions from the cell positions.
The CSV is read with csv.DictReader. The expected columns are
x, y, z, radius, cell_type and is_boundary. Only the
coordinate columns are required: radius, cell_type and
is_boundary are optional. When radius is missing or blank for a row,
default_radius is used; a missing cell_type defaults to "default";
and is_boundary is treated as True only when its value is the string
"true" (case-insensitive), otherwise False.
cell_type is the canonical column name. As a convenience, the column
type (a common alias used by tools such as PhysiCell) is also accepted
when cell_type is absent or blank. When both columns are present,
cell_type takes precedence.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filepath
|
str
|
Path to the CSV file to read. |
required |
height
|
Optional[float]
|
Optional Y-dimension; inferred from cell centers if None. |
None
|
width
|
Optional[float]
|
Optional X-dimension; inferred from cell centers if None. |
None
|
thickness
|
Optional[float]
|
Optional Z-dimension; inferred from cell centers if None. |
None
|
default_radius
|
float
|
Radius assigned to rows whose |
10.0
|
Returns:
| Type | Description |
|---|---|
TissueSection
|
A TissueSection containing the loaded cells. |