blobmodel package

Submodules

blobmodel.blob_shape module

This module defines classes for blob pulse shapes used in two-dimensional simulations.

class blobmodel.blob_shape.AbstractBlobShape

Bases: ABC

Abstract class containing the blob pulse shapes. Two-dimensional blob pulse shapes are written in the form:

phi(theta_x, theta_y) = phi_x(theta_x) * phi_y(theta_y)

abstract get_blob_shape_perp(theta: ndarray, **kwargs) ndarray
abstract get_blob_shape_prop(theta: ndarray, **kwargs) ndarray
class blobmodel.blob_shape.BlobShapeImpl(pulse_shape_prop='gauss', pulse_shape_perp='gauss')

Bases: AbstractBlobShape

Implementation of the AbstractPulseShape class.

get_blob_shape_perp(theta: ndarray, **kwargs) ndarray

Compute the pulse shape perpendicular to the propagation direction.

Parameters:
  • theta (np.ndarray) – Array of theta values.

  • kwargs – Additional keyword arguments.

Returns:

Array representing the pulse shape perpendicular to the propagation direction.

Return type:

np.ndarray

get_blob_shape_prop(theta: ndarray, **kwargs) ndarray

Compute the pulse shape in the propagation direction.

Parameters:
  • theta (np.ndarray) – Array of theta values.

  • kwargs – Additional keyword arguments.

Returns:

Array representing the pulse shape in the propagation direction.

Return type:

np.ndarray

blobmodel.blobs module

This module defines a Blob class and related functions for discretizing and manipulating blobs.

class blobmodel.blobs.Blob(blob_id: int, blob_shape: AbstractBlobShape, amplitude: float, width_prop: float, width_perp: float, v_x: float, v_y: float, pos_x: float, pos_y: float, t_init: float, t_drain: float | NDArray[Any, Any], prop_shape_parameters: dict | None = None, perp_shape_parameters: dict | None = None, blob_alignment: bool = True)

Bases: object

Define a single blob.

discretize_blob(x: NDArray[Any, Any], y: NDArray[Any, Any], t: NDArray[Any, Any], Ly: float, periodic_y: bool = False, one_dimensional: bool = False) NDArray[Any, Any]

Discretize blob on grid. If one_dimensional the perpendicular pulse shape is ignored.

Parameters:
  • x (NDArray) – Grid coordinates in the x-direction.

  • y (NDArray) – Grid coordinates in the y-direction.

  • t (NDArray) – Time coordinates.

  • Ly (float) – Length of domain in the y-direction.

  • periodic_y (bool, optional) – Flag indicating periodicity in the y-direction (default: False).

  • one_dimensional (bool, optional) – Flag indicating a one-dimensional blob (default: False).

Returns:

discretized_blob – Discretized blob on a 3D array with dimensions (x, y, t).

Return type:

NDArray

blobmodel.geometry module

This module defines the Geometry class for creating a grid for the Model.

class blobmodel.geometry.Geometry(Nx: int, Ny: int, Lx: float, Ly: float, dt: float, T: float, periodic_y: bool)

Bases: object

Define grid for Model.

blobmodel.model module

This module defines a 2D model of propagating blobs.

class blobmodel.model.Model(Nx: int = 100, Ny: int = 100, Lx: float = 10, Ly: float = 10, dt: float = 0.1, T: float = 10, periodic_y: bool = False, blob_shape: ~blobmodel.blob_shape.AbstractBlobShape | str = <blobmodel.blob_shape.BlobShapeImpl object>, num_blobs: int = 1000, t_drain: float | ~nptyping.ndarray.NDArray[~typing.Any, ~typing.Any] | int = 10, blob_factory: ~blobmodel.stochasticality.BlobFactory = <blobmodel.stochasticality.DefaultBlobFactory object>, labels: str = 'off', label_border: float = 0.75, one_dimensional: bool = False)

Bases: object

2D Model of propagating blobs.

get_blobs() List[Blob]

Return the list of blobs.

Returns:

List of Blob objects.

Return type:

List[Blob]

Notes

  • Note that if Model.sample_blobs has not been called, the list will be empty

make_realization(file_name: str | None = None, speed_up: bool = False, error: float = 1e-10) Dataset

Integrate the Model over time and write out data as an xarray dataset.

Parameters:
  • file_name (str, optional) – File name for the .nc file containing data as an xarray dataset.

  • speed_up (bool, optional) – Flag for speeding up the code by discretizing each single blob at smaller time window when blob values fall under given error value the blob gets discarded

  • error (float, optional) – Numerical error at x = Lx when the blob gets truncated.

Returns:

xarray dataset with the resulting data.

Return type:

xr.Dataset

Notes

  • speed_up is only a good approximation for blob_shape=”exp”

blobmodel.plotting module

This module provides functions to create and display animations of model output.

blobmodel.plotting.show_model(dataset: Dataset, variable: str = 'n', interval: int = 100, gif_name: str | None = None, fps: int = 10) None

Creates an animation that shows the evolution of a specific variable over time.

Parameters:
  • dataset (xr.Dataset) – Model data.

  • variable (str, optional) – Variable to be animated (default: “n”).

  • interval (int, optional) – Time interval between frames in milliseconds (default: 100).

  • gif_name (str, optional) – If not None, save the animation as a GIF and name it acoridingly.

  • fps (int, optional) – Set the frames per second for the saved GIF (default: 10).

Return type:

None

Notes

  • This function chooses between a 1D and 2D visualizations based on the dimensionality of the dataset.

blobmodel.stochasticality module

This module defines a class for generating blob parameters.

class blobmodel.stochasticality.BlobFactory

Bases: ABC

Abstract class used by 2d propagating blob model to specify blob parameters.

abstract is_one_dimensional() bool

returns True if the BlobFactory is compatible with a one_dimensional model.

abstract sample_blobs(Ly: float, T: float, num_blobs: int, blob_shape: AbstractBlobShape, t_drain: float | NDArray[Any, Any]) List[Blob]

creates list of Blobs used in Model.

class blobmodel.stochasticality.DefaultBlobFactory(A_dist: str = 'exp', wx_dist: str = 'deg', wy_dist: str = 'deg', vx_dist: str = 'deg', vy_dist: str = 'normal', spx_dist: str = 'deg', spy_dist: str = 'deg', A_parameter: float = 1.0, wx_parameter: float = 1.0, wy_parameter: float = 1.0, vx_parameter: float = 1.0, vy_parameter: float = 1.0, shape_param_x_parameter: float = 0.5, shape_param_y_parameter: float = 0.5, blob_alignment: bool = True)

Bases: BlobFactory

Default implementation of BlobFactory.

Generates blob parameters for different possible random distributions. All random variables are independent from each other

is_one_dimensional() bool

Returns True if the BlobFactory is compatible with a one-dimensional model.

Returns:

True if the BlobFactory is compatible with a one-dimensional model, False otherwise.

Return type:

bool

Notes

  • Perpendicular width parameters are irrelevant since perp shape should be ignored by the Bolb class.

sample_blobs(Ly: float, T: float, num_blobs: int, blob_shape: AbstractBlobShape, t_drain: float | NDArray[Any, Any]) List[Blob]

Creates a list of Blobs used in the Model.

Parameters:
  • Ly (float) – Size of the domain in the y-direction.

  • T (float) – Total time duration.

  • num_blobs (int) – Number of blobs to generate.

  • blob_shape (AbstractBlobShape) – Object representing the shape of the blobs.

  • t_drain (float) – Time at which the blobs start draining.

Returns:

List of Blob objects generated for the Model.

Return type:

List[Blob]

Module contents