local_character
cellseg_gsontools.character.local_character(gdf, spatial_weights, val_col, id_col=None, reductions=('sum'), weight_by_area=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 of a specified metric for each neighborhood of geometry objects 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 |
val_col |
Union[str, Tuple[str, ...]]
|
The name of the column in the gdf for which the reduction is computed. If a tuple, the reduction is computed for each column. |
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", ). |
('sum')
|
weight_by_area |
bool
|
Flag whether to weight the neighborhood values by the area of the object. 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 character column added. |
Examples:
Compute the mean of eccentricity values for each cell neighborhood
>>> from cellseg_gsontools.character import local_character
>>> from cellseg_gsontools.graphs import fit_graph
>>> w = fit_graph(gdf, type="distband", thres=75.0)
>>> local_character(
... gdf,
... spatial_weights=w,
... val_col=["eccentricity", "area"],
... reduction=["mean", "median"],
... weight_by_area=True,
... )
Source code in cellseg_gsontools/character.py
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 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 |
|