link_counts
cellseg_gsontools.links.link_counts(gdf, w, classes)
¶
Get the link-type counts of a geodataframe given a spatial weights object w
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
gdf |
GeoDataFrame
|
Input geodataframe. Has to have a |
required |
w |
W
|
Libpysal spatial weights object of the gdf. |
required |
classes |
Tuple[str, ...]
|
A list/tuple containing the classes of your dataset. |
required |
Returns:
Type | Description |
---|---|
Dict[str, int]
|
Dict[str, int]: A contigency dictionary. |
Examples:
Get the link types of the tumor-stroma interfaces.
>>> from cellseg_gsontools.spatial_context import InterfaceContext
>>> from cellseg_gsontools.links import link_counts
>>> iface_context = InterfaceContext(
... area_gdf=areas,
... cell_gdf=cells,
... top_labels="area_cin",
... bottom_labels="areastroma",
... silence_warnings=True,
... min_area_size=100000.0,
... )
>>> classes = [
... "inflammatory",
... "connective",
... "glandular_epithel",
... "squamous_epithel",
... "neoplastic",
... ]
>>> iface_context.fit(verbose=False)
>>> w = iface_context.context2weights("border_network")
>>> link_counts(cells, w, classes)
{'inflammatory-inflammatory': 31,
'inflammatory-connective': 89,
'inflammatory-glandular_epithel': 0,
'inflammatory-squamous_epithel': 0,
'inflammatory-neoplastic': 86,
'connective-connective': 131,
'connective-glandular_epithel': 0,
'connective-squamous_epithel': 0,
'connective-neoplastic': 284,
'glandular_epithel-glandular_epithel': 0,
'glandular_epithel-squamous_epithel': 0,
'glandular_epithel-neoplastic': 0,
'squamous_epithel-squamous_epithel': 0,
'squamous_epithel-neoplastic': 0,
'neoplastic-neoplastic': 236}
Source code in cellseg_gsontools/links.py
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 221 222 223 |
|