momepy.Shannon

class momepy.Shannon(gdf, values, spatial_weights, unique_id, binning='HeadTailBreaks', categorical=False, categories=None, **classification_kwds)[source]

Calculates the Shannon index of values within neighbours defined in spatial_weights.

Uses mapclassify.classifiers under the hood for binning. Requires mapclassify>=.2.1.0 dependency.

\[H^{\prime}=-\sum_{i=1}^{R} p_{i} \ln p_{i}\]
Parameters
objectsGeoDataFrame

GeoDataFrame containing morphological tessellation

valuesstr, list, np.array, pd.Series

the name of the dataframe column, np.array, or pd.Series where is stored character value.

spatial_weightslibpysal.weights, optional

spatial weights matrix - If None, Queen contiguity matrix of set order will be calculated based on objects.

orderint

order of Queen contiguity

binningstr

One of mapclassify classification schemes Options are BoxPlot, EqualInterval, FisherJenks, FisherJenksSampled, HeadTailBreaks, JenksCaspall, JenksCaspallForced, JenksCaspallSampled, MaxPClassifier, MaximumBreaks, NaturalBreaks, Quantiles, Percentiles, StdMean, UserDefined

categoricalbool (default False)

treat values as categories (will not use binning)

categorieslist-like (default None)

list of categories. If None values.unique() is used.

**classification_kwdsdict

Keyword arguments for classification scheme For details see mapclassify documentation: https://pysal.org/mapclassify

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]
Attributes
seriesSeries

Series containing resulting values

gdfGeoDataFrame

original GeoDataFrame

valuesSeries

Series containing used values

swlibpysal.weights

spatial weights matrix

idSeries

Series containing used unique ID

binningstr

binning method

binsmapclassify.classifiers.Classifier

generated bins

classification_kwdsdict

classification_kwds

__init__(self, gdf, values, spatial_weights, unique_id, binning='HeadTailBreaks', categorical=False, categories=None, \*\*classification_kwds)[source]

Initialize self. See help(type(self)) for accurate signature.

Methods

__init__(self, gdf, values, spatial_weights, …)

Initialize self.