find_lisa_clusters
cellseg_gsontools.clustering.find_lisa_clusters(gdf, label, graph_type='distband', dist_thresh=100, permutations=100, seed=42, spatial_weights=None)
¶
Calculate LISA clusters of objects with class_name=label
.
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 |
---|---|---|---|
gdf |
GeoDataFrame
|
The GeoDataFrame with the objects to calculate the LISA clusters of. |
required |
label |
str
|
The class name to calculate the LISA clusters of. |
required |
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
|
permutations |
int
|
The number of permutations to use in the Moran_Local analysis. |
100
|
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 |
---|---|---|
labels |
List[int]
|
The cluster labels of the objects. |
w |
W
|
The spatial weights object used in the analysis. |
Examples:
Find the LISA clusters of inflammatory cells in a GeoDataFrame.
>>> from cellseg_gsontools.clustering import find_lisa_clusters
>>> from cellseg_gsontools.utils import read_gdf
>>> cells = read_gdf("cells.geojson")
>>> labels, w = find_lisa_clusters(cells, label="inflammatory", seed=42)
Source code in cellseg_gsontools/clustering.py
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 |
|