momepy.values_range#
- momepy.values_range(y, graph, q=(0, 100))[source]#
Calculates the range of values within neighbours defined in
graph
.Adapted from [Dibble et al., 2017].
- Parameters:
- ySeries
A DataFrame or Series containing the values to be analysed.
- graphlibpysal.graph.Graph
A spatial weights matrix for the data.
- qtuple, list, optional (default (0,100)))
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.
- Returns:
- Series
A Series containing resulting values.
Notes
The index of
y
must match the index along which thegraph
is built.Examples
>>> from libpysal import graph >>> path = momepy.datasets.get_path("bubenec") >>> buildings = geopandas.read_file(path, layer="buildings") >>> buildings.head() uID geometry 0 1 POLYGON ((1603599.221 6464369.816, 1603602.984... 1 2 POLYGON ((1603042.88 6464261.498, 1603038.961 ... 2 3 POLYGON ((1603044.65 6464178.035, 1603049.192 ... 3 4 POLYGON ((1603036.557 6464141.467, 1603036.969... 4 5 POLYGON ((1603082.387 6464142.022, 1603081.574...
Define spatial graph:
>>> knn5 = graph.Graph.build_knn(buildings.centroid, k=5) >>> knn5 <Graph of 144 nodes and 720 nonzero edges indexed by [0, 1, 2, 3, 4, ...]>
Range of building area within 5 nearest neighbors:
>>> momepy.values_range(buildings.area, knn5) focal 0 559.745602 1 444.997770 2 10651.932677 3 365.239452 4 339.585788 ... 139 769.179096 140 721.444718 141 996.921755 142 119.708607 143 798.344284 Length: 144, dtype: float64
To eliminate the effect of outliers, you can take into account only values within a specified percentile range (
q
).>>> momepy.values_range(buildings.area, knn5, q=(25, 75)) focal 0 258.656230 1 113.990829 2 2878.811586 3 92.005635 4 87.637833 ... 139 587.139513 140 325.726611 141 621.315615 142 34.446110 143 488.967863 Length: 144, dtype: float64