local_distances
cellseg_gsontools.character.local_distances(gdf, spatial_weights, id_col=None, reductions=('mean'), weight_by_area=False, invert=False, parallel=True, num_processes=-1, rm_nhood_cols=True, col_prefix=None, create_copy=True)
¶
Compute the local sum/mean/median/min/max/std distance of the neighborhood distances for each geometry object in a gdf.
Note
Option to weight the nhood values by their area before reductions.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
gdf |
GeoDataFrame
|
The input GeoDataFrame. |
required |
spatial_weights |
W
|
Libpysal spatial weights object. |
required |
id_col |
str
|
The unique id column in the gdf. If None, this uses |
None
|
reductions |
Tuple[str, ...]
|
A list of reduction methods for the neighborhood. One of "sum", "mean", "median", "min", "max", "std". Defaults to ("sum", ). |
('mean')
|
weight_by_area |
bool
|
Flag whether to weight the neighborhood values by the area of the object. Defaults to False. |
False
|
invert |
bool
|
Flag whether to invert the distances. Defaults to False. |
False
|
parallel |
bool
|
Flag whether to use parallel apply operations when computing the character. Defaults to True. |
True
|
num_processes |
int, default=-1
|
The number of processes to use when parallel=True. If -1, this will use all available cores. |
-1
|
rm_nhood_cols |
bool
|
Flag, whether to remove the extra neighborhood columns from the result gdf. Defaults to True. |
True
|
col_prefix |
str
|
Prefix for the new column names. |
None
|
create_copy |
bool
|
Flag whether to create a copy of the input gdf and return that. Defaults to True. |
True
|
Returns:
Type | Description |
---|---|
GeoDataFrame
|
gpd.GeoDataFrame: The input geodataframe with computed distances column added. |
Examples:
Compute the mean of eccentricity values for each neighborhood
>>> from cellseg_gsontools.character import local_distances
>>> from cellseg_gsontools.graphs import fit_graph
>>> w = fit_graph(gdf, type="distband", thres=75.0)
>>> local_distances(gdf, spatial_weights=w, reduction=["mean"], weight_by_area=True)
Source code in cellseg_gsontools/character.py
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 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 |
|