cluster_cells
cellseg_gsontools.clustering.cluster_cells(cells, cell_type='inflammatory', graph_type='distband', dist_thresh=100, min_size=10, seed=42, spatial_weights=None)
¶
Cluster the cells of the given type.
Uses Local Moran analysis to find the LISA clusters of the cells.
Note
LISA is short for local indicator of spatial association. You can read more, for example, from: - https://geodacenter.github.io/workbook/6a_local_auto/lab6a.html#lisa-principle. The LISA clusters are calculated using the local Moran analysis. The cluster labels are set to HH, LL, LH, HL.
Note
In this function, the local statistic used to form the clusters is the fraction
of objects of type label
in the neighborhood times the absolute number of the
objects of type label
in the neighborhood. Due to the stochastic nature of the
LISA analysis, the clustering results may wary marginally between runs if seed is
changed. This is due to the random selection of the permutations in the
local Moran analysis.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
cells |
GeoDataFrame
|
The GeoDataFrame with the cells. |
required |
cell_type |
str
|
The class name of the cells to cluster. |
'inflammatory'
|
graph_type |
str
|
The type of graph to fit. Options are "delaunay", "knn" and "distband". |
'distband'
|
dist_thresh |
int
|
The distance threshold to use for the graph. |
100
|
min_size |
int
|
The minimum size of the cluster to assign a label. |
10
|
seed |
int
|
The random seed to use in the Moran_Local analysis. |
42
|
spatial_weights |
W
|
The spatial weights object to use in the analysis. If None, the spatial weights are calculated. |
None
|
Returns:
Name | Type | Description |
---|---|---|
clustered_cells |
GeoDataFrame
|
The GeoDataFrame with the clustered cells. |
Examples:
Cluster the inflammatory cells in a GeoDataFrame.
>>> from cellseg_gsontools.clustering import cluster_cells
>>> from cellseg_gsontools.utils import read_gdf
>>> cells = read_gdf("cells.geojson")
>>> clustered_cells = cluster_cells(cells, cell_type="inflammatory", seed=42)
class_name geometry lisa_label label
uid
0 inflammatory POLYGON ((64.00 115.020, 69.010 ... HH 0
1 inflammatory POLYGON ((65.00 15.020, 61.010 ... HH 0
2 inflammatory POLYGON ((66.00 110.020, 69.010 ... HH 2
Source code in cellseg_gsontools/clustering.py
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 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 |
|