momepy.percentile#
- momepy.percentile(y, graph, q=[25, 50, 75])[source]#
Calculates linearly weighted percentiles of
y
values using the neighbourhoods and weights defined ingraph
.The specific interpolation method implemented is “hazen”.
- Parameters:
- ySeries
A Series containing the values to be analysed.
- graphlibpysal.graph.Graph
A spatial weights matrix for the data.
- qarray-like (default [25, 50, 75])
The percentiles to return.
- Returns:
- Dataframe
A Dataframe with columns as the results for each percentile
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, ...]>
Percentiles of building area within 5 nearest neighbors:
>>> momepy.percentile(buildings.area, knn5).head() 25 50 75 focal 0 347.252959 427.819360 605.909188 1 621.834862 641.629131 735.825691 2 622.262074 903.746689 3501.073660 3 621.834862 641.629131 713.840496 4 621.834862 641.987211 709.472695
Optionally, you can specify which percentile values shall be computed.
>>> momepy.percentile(buildings.area, knn5, q=[10, 90]).head() 10 90 focal 0 123.769329 683.514930 1 564.160901 1009.158671 2 564.160901 11216.093578 3 564.160901 929.400353 4 564.160901 903.746689