momepy.AverageCharacter#

class momepy.AverageCharacter(gdf, values, spatial_weights, unique_id, rng=None, mode='all', verbose=True)[source]#

Calculates the average of a character within a set neighbourhood defined in spatial_weights. Can be set to mean, median or mode. mean is defined as:

\[\frac{1}{n}\left(\sum_{i=1}^{n} value_{i}\right)\]

Adapted from [Hausleitner and Berghauser Pont, 2017].

Parameters:
gdfGeoDataFrame

A GeoDataFrame containing a morphological tessellation.

valuesstr, list, np.array, pd.Series

The name of the dataframe column, np.array, or pd.Series where character values are stored.

unique_idstr

The name of the column with unique ID used as the spatial_weights index.

spatial_weightslibpysal.weights

A spatial weights matrix.

rngtuple, list, optional (default None)

A two-element sequence containing floats between 0 and 100 (inclusive) that are the percentiles over which to compute the range. The order of the elements is not important.

modestr (default ‘all’)

The mode of average calculation. It can be set to 'all', 'mean', 'median', or 'mode' or a list of any of the options.

verbosebool (default True)

If True, shows progress bars in loops and indication of steps.

Examples

>>> sw = libpysal.weights.DistanceBand.from_dataframe(tessellation,
...                                                   threshold=100,
...                                                   silence_warnings=True,
...                                                   ids='uID')
>>> tessellation['mean_area'] = momepy.AverageCharacter(tessellation,
...                                                     values='area',
...                                                     spatial_weights=sw,
...                                                     unique_id='uID').mean
100%|██████████| 144/144 [00:00<00:00, 1433.32it/s]
>>> tessellation.mean_area[0]
4823.1334436678835
Attributes:
seriesSeries

A Series containing resulting mean values.

meanSeries

A Series containing resulting mean values.

medianSeries

A Series containing resulting median values.

modeSeries

A Series containing resulting mode values.

gdfGeoDataFrame

The original GeoDataFrame.

valuesGeoDataFrame

A Series containing used values.

swlibpysal.weights

The spatial weights matrix.

idSeries

A Series containing used unique ID.

rngtuple

The range.

modesstr

The mode.

__init__(gdf, values, spatial_weights, unique_id, rng=None, mode='all', verbose=True)[source]#

Methods

__init__(gdf, values, spatial_weights, unique_id)