amep.continuum.cluster_properties#
- amep.continuum.cluster_properties(dfield: ndarray, X: ndarray, Y: ndarray, ids: ndarray, labels: ndarray, pbc: bool = True) tuple[ndarray, ndarray, ndarray, ndarray, ndarray, ndarray, ndarray] #
Calculates the size, geometric center, center of mass, radius of gyration and linear extension of each cluster in a continuum field.
- Parameters:
dfield (np.ndarray of shape (N,M)) – Two dimensional density field.
X (np.ndarray of shape (N,M)) – x coordinates of grid cells in form of a meshgrid with same shape as dfield.
Y (np.ndarray of shape (N,M)) – y coordinates of grid cells in form of a meshgrid with same shape as dfield.
ids (np.ndarray) – An array of the cluster IDs, starting from 0.
labels (np.ndarray of shape (N,M)) – Array of the same shape as the input field, where each pixel or grid point is labeled with the cluster ID it belongs to.
pbc (bool, optional) – Whether to use periodic boundary conditions. Default is True.
- Returns:
sizes (np.ndarray) – The respective size of each cluster. Size in this context means field value integrated over the cluster.
geometric_centers (np.ndarray) – The geometric centers of the clusters.
mass_centers (np.ndarray) – The centers of masses of the clusters.
radii_of_gyration (np.ndarray) – The radii of gyration of the clusters.
linear_extensions (np.ndarray) – The linear extensions of the clusters.
gyration_tensors (np.ndarray) – The gyration tensor of each cluster.
inertia_tensors (np.ndarray) – The inertia tensor of each cluster.
Examples
>>> import amep >>> import numpy as np >>> X, Y = np.meshgrid( ... np.linspace(0, np.pi, 101), np.linspace(0, np.pi, 101) ... ) >>> dfield = np.cos(2*np.pi*X)*np.cos(2*np.pi*Y) >>> ids, labels = amep.continuum.identify_clusters( ... dfield, scale=1.0, cutoff=0.8, threshold=0.2, ... method="threshold", pbc=True ... ) >>> sizes, gmcs, coms, rgs, les, gts, its = amep.continuum.cluster_properties( ... dfield, X, Y, ids, labels, pbc=True ... ) >>> fig, axs = amep.plot.new(figsize=(3.75, 3)) >>> mp = amep.plot.field(axs, dfield, X, Y, cmap="gray") >>> cax = amep.plot.add_colorbar(fig, axs, mp, label=r"$\rho$") >>> axs.scatter( ... gmcs[1:,0], gmcs[1:,1], marker="o", c="blue", ... label="geometric center", s=20 ... ) >>> axs.scatter( ... coms[1:,0], coms[1:,1], marker="+", c="red", ... label="center of mass", s=40 ... ) >>> angle = np.linspace(0, 2*np.pi, 50) >>> x = rgs[4]*np.cos(angle)+coms[4,0] >>> y = rgs[4]*np.sin(angle)+coms[4,1] >>> axs.plot(x, y, c="orange", ls="-", lw=1, label="radius of gyration", marker="") >>> x = 0.5*les[4]*np.cos(angle)+coms[4,0] >>> y = 0.5*les[4]*np.sin(angle)+coms[4,1] >>> axs.plot(x, y, c="orange", ls='--', lw=1, label="linear extension", marker="") >>> axs.legend(frameon=True, loc="upper left") >>> axs.set_xlabel(r"$x$") >>> axs.set_ylabel(r"$y$") >>> fig.savefig("./figures/continuum/continuum-cluster_properties.png")