cassiopeia.sim.BrownianSpatialDataSimulator#

class cassiopeia.sim.BrownianSpatialDataSimulator(dim, diffusion_coefficient, scale_unit_area=True, random_seed=None)[source]#

Simulate spatial data with a Brownian motion process.

This subclass of SpatialDataSimulator simulates the spatial coordinates of each cell in the provided CassiopeiaTree through a Brownian motion process.

The simulation procedure is as follows. The tree is traversed from the root to the leaves. The the root cell is placed at the origin. At each split (i.e. when a cell divides), two new cells are placed at new coordinate X relative to the position of the parent X’ (so, the absolute coordinate is X’ + X). X is a n-dimensional vector with x_i ~ Normal(0, 2*D*t), where D is the diffusion coefficient and t is the time since the last cell division. X is sampled independently for each dimension for each cell, so the two new cells will be placed at different coordinates. Note that this process is dependent on the scale of the branch lengths.

Parameters:
dim int

Number of spatial dimensions. For instance, a value of 2 indicates a 2D slice.

diffusion_coeficient

The diffusion coefficient to use in the Brownian motion process. Specifically, 2 * diffusion_coefficient * (branch length) is the variance of the Normal distribution.

scale_unit_area bool (default: True)

Whether or not the space should be scaled to have unit length in all dimensions. Defaults to True.

random_seed Optional[int] (default: None)

A seed for reproducibility

Raises:

DataSimulatorError if dim is less than equal to zero, or the diffusion – coefficient is negative.

Methods

overlay_data(tree, attribute_key='spatial')[source]#

Overlays spatial data onto the CassiopeiaTree via Brownian motion.

Parameters:
tree CassiopeiaTree

The CassiopeiaTree to overlay spatial data on to.

attribute_key str (default: 'spatial')

The name of the attribute to save the coordinates as. This also serves as the prefix of the coordinates saved into the cell_meta attribute as {attribute_key}_i where i is an integer from 0…`dim-1`.