Skip to content

Commit c12cb5b

Browse files
committed
idw | centroid_poisson_kriging docs examples
1 parent 9e7d982 commit c12cb5b

File tree

4 files changed

+88
-1
lines changed

4 files changed

+88
-1
lines changed

CHANGELOG.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ Changes - from version >= 1.x
4343
* [docs] corrected broken links to `CONTRIBUTING.md` file in readme and docs
4444
* [setup] links to documentation have been added to `pyproject.toml`
4545
* [docs] docstring examples - all user-facing API endpoints has examples in docstrings, using new input types (values | geometries)
46-
* [docs] updated docstrings (examples) in: `PointSupportDistance`, `core.block_filter`, `pipelines.interpolate`, `pyinterpolate.distance.block.calc_block_to_block_distance`, `validate_kriging`, `metrics` module functions,
46+
* [docs] updated docstrings (examples) in: `PointSupportDistance`, `core.block_filter`, `pipelines.interpolate`, `pyinterpolate.distance.block.calc_block_to_block_distance`, `validate_kriging`, `metrics` module functions, `inverse_distance_weighting`, `centroid_poisson_kriging`,
4747

4848
2025-10-11
4949
----------

src/pyinterpolate/idw/idw.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,27 @@ def inverse_distance_weighting(unknown_location: ArrayLike,
7272
ValueError
7373
Less than 2 neighbours or more than the number of ``known_points``
7474
neighbours are given in the ``number_of_neighbours`` parameter.
75+
76+
Examples
77+
--------
78+
>>> unknown_pos = (10, 10)
79+
>>> locs = np.array([
80+
... [11, 1, 1],
81+
... [23, 2, 2],
82+
... [33, 3, 3],
83+
... [14, 44, 4],
84+
... [13, 10, 9],
85+
... [12, 55, 35],
86+
... [11, 9, 7]
87+
... ])
88+
>>> pred = inverse_distance_weighting(
89+
... unknown_locations=unknown_pos,
90+
... known_values=locs[:, -1],
91+
... known_geometries=locs[:, :-1],
92+
... no_neighbors=2
93+
... )
94+
>>> print(pred)
95+
7.286311587314138
7596
"""
7697

7798
# Check power parameter

src/pyinterpolate/kriging/block/centroid_based_poisson_kriging.py

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,71 @@ def centroid_poisson_kriging(semivariogram_model: TheoreticalVariogram,
7373
------
7474
ValueError
7575
Raised when prediction or prediction error are negative.
76+
77+
Examples
78+
--------
79+
>>> import os
80+
>>> import geopandas as gpd
81+
>>> from pyinterpolate import (
82+
... centroid_poisson_kriging,
83+
... Blocks,
84+
... ExperimentalVariogram,
85+
... PointSupport,
86+
... TheoreticalVariogram
87+
... )
88+
>>>
89+
>>>
90+
>>> FILENAME = 'cancer_data.gpkg'
91+
>>> LAYER_NAME = 'areas'
92+
>>> DS = gpd.read_file(FILENAME, layer=LAYER_NAME)
93+
>>> AREA_VALUES = 'rate'
94+
>>> AREA_INDEX = 'FIPS'
95+
>>> AREA_GEOMETRY = 'geometry'
96+
>>> PS_LAYER_NAME = 'points'
97+
>>> PS_VALUES = 'POP10'
98+
>>> PS_GEOMETRY = 'geometry'
99+
>>> PS = gpd.read_file(FILENAME, layer=PS_LAYER_NAME)
100+
>>>
101+
>>> CANCER_DATA = {
102+
... 'ds': DS,
103+
... 'index_column_name': AREA_INDEX,
104+
... 'value_column_name': AREA_VALUES,
105+
... 'geometry_column_name': AREA_GEOMETRY
106+
... }
107+
>>> POINT_SUPPORT_DATA = {
108+
... 'ps': PS,
109+
... 'value_column_name': PS_VALUES,
110+
... 'geometry_column_name': PS_GEOMETRY
111+
... }
112+
>>> BLOCKS = Blocks(**CANCER_DATA)
113+
>>> indexes = BLOCKS.block_indexes
114+
>>>
115+
>>> PS = PointSupport(
116+
... points=POINT_SUPPORT_DATA['ps'],
117+
... ps_blocks=BLOCKS,
118+
... points_value_column=POINT_SUPPORT_DATA['value_column_name'],
119+
... points_geometry_column=POINT_SUPPORT_DATA['geometry_column_name']
120+
... )
121+
>>>
122+
>>> EXPERIMENTAL = ExperimentalVariogram(
123+
... ds=BLOCKS.representative_points_array(),
124+
... step_size=40000,
125+
... max_range=300001
126+
... )
127+
>>>
128+
>>> THEO = TheoreticalVariogram()
129+
>>> THEO.autofit(
130+
... experimental_variogram=EXPERIMENTAL,
131+
... sill=150
132+
... )
133+
>>> centroid_pk = centroid_poisson_kriging(
134+
... semivariogram_model=THEO,
135+
... point_support=PS,
136+
... unknown_block_index=34017,
137+
... number_of_neighbors=8
138+
... )
139+
>>> print(centroid_pk)
140+
{'block_id': 34017, 'zhat': 134.13113195517153, 'sig': 11.795520367595483}
76141
"""
77142
# Kriging data
78143
kriging_data = select_centroid_poisson_kriging_data(

tests/test_kriging/test_centroid_pk.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ def test_cpk():
6666
unknown_block_index=indexes[-1],
6767
number_of_neighbors=8
6868
)
69+
print(cpk)
6970
assert isinstance(cpk, dict)
7071
assert cpk['block_id'] == indexes[-1]
7172
assert cpk['zhat'] > 0

0 commit comments

Comments
 (0)