momepy.Shannon#
- momepy.Shannon(gdf, values, spatial_weights, unique_id, binning='HeadTailBreaks', categorical=False, categories=None, verbose=True, **classification_kwds)[source]#
Calculates the Shannon index of values within neighbours defined in
spatial_weights
. Usesmapclassify.classifiers
under the hood for binning. Requiresmapclassify>=.2.1.0
dependency.\[H^{\prime}=-\sum_{i=1}^{R} p_{i} \ln p_{i}\]- Parameters:
- gdfGeoDataFrame
A GeoDataFrame containing morphological tessellation.
- valuesstr, list, np.array, pd.Series
The name of the dataframe column,
np.array
, orpd.Series
where character values are stored.- spatial_weightslibpysal.weights, optional
A spatial weights matrix. If
None
, Queen contiguity matrix of set order will be calculated based on objects.- unique_idstr
The name of the column with unique IDs used as the
spatial_weights
index.- binningstr
One of mapclassify classification schemes. For details see mapclassify API documentation.
- categoricalbool (default False)
Treat values as categories (will not use binning).
- categorieslist-like (default None)
A list of categories. If
None
,values.unique()
is used.- verbosebool (default True)
If
True
, shows progress bars in loops and indication of steps.- **classification_kwdsdict
Keyword arguments for classification scheme For details see mapclassify documentation.
- Attributes:
- seriesSeries
A Series containing resulting values.
- gdfGeoDataFrame
The original GeoDataFrame.
- valuesSeries
A Series containing used values.
- swlibpysal.weights
The spatial weights matrix.
- idSeries
A Series containing used unique ID.
- binningstr
The binning method used.
- binsmapclassify.classifiers.Classifier
The generated bins.
- classification_kwdsdict
Keyword arguments for classification scheme For details see mapclassify documentation.
Examples
>>> sw = momepy.sw_high(k=3, gdf=tessellation_df, ids='uID') >>> tessellation_df['area_Shannon'] = mm.Shannon(tessellation_df, ... 'area', ... sw, ... 'uID').series 100%|██████████| 144/144 [00:00<00:00, 455.83it/s]