Skip to content

v.ppa: Point Pattern Analysis - #3826

Merged
cwhite911 merged 40 commits into
OSGeo:mainfrom
cwhite911:v.ppa
Aug 25, 2026
Merged

cwhite911 merged 40 commits into
OSGeo:mainfrom
cwhite911:v.ppa

Conversation

@cwhite911

Copy link
Copy Markdown
Contributor

I'm adding vector point pattern analysis functionality for F, G, L, K, and Bivariate Ripley's K.

@github-actions github-actions Bot added vector Related to vector data processing Python Related code is in Python C Related code is in C HTML Related code is in HTML module docs tests Related to Test Suite labels Jun 15, 2024
Comment thread vector/v.ppa/main.c Resolved
@cwhite911

Copy link
Copy Markdown
Contributor Author

The G and K functions are complete, but I'm still working on the functions.

Comment thread vector/v.ppa/main.c Resolved
Comment thread vector/v.ppa/main.c Resolved
Comment thread vector/v.ppa/main.c Resolved
Comment thread vector/v.ppa/main.c Resolved
Comment thread vector/v.ppa/main.c Resolved
Comment thread vector/v.ppa/main.c Resolved
Comment thread vector/v.ppa/main.c Resolved
Comment thread vector/v.ppa/main.c Resolved
cwhite911 and others added 17 commits June 18, 2024 15:16
Co-authored-by: Loïc Bartoletti <lbartoletti@users.noreply.github.com>
Co-authored-by: Loïc Bartoletti <lbartoletti@users.noreply.github.com>
Co-authored-by: Loïc Bartoletti <lbartoletti@users.noreply.github.com>
Co-authored-by: Loïc Bartoletti <lbartoletti@users.noreply.github.com>
Co-authored-by: Loïc Bartoletti <lbartoletti@users.noreply.github.com>
Co-authored-by: Loïc Bartoletti <lbartoletti@users.noreply.github.com>
Comment thread vector/v.ppa/testsuite/test_v_ppa.py Resolved
@github-actions github-actions Bot added the markdown Related to markdown, markdown files label May 23, 2025
cwhite911 added 3 commits May 24, 2025 11:06
Restructure the tool for core inclusion and fix correctness problems
found in review:

- Split main.c into per-function files (g_function.c, f_function.c,
  k_function.c, result.c) sharing local_proto.h.
- Use the computational region as the observation window for the
  intensity estimate, F function sampling, edge correction geometry,
  and default distance range. Points outside the region are ignored
  with a warning.
- Add Ripley's isotropic edge correction for the K and L functions
  (correction=isotropic|none, default isotropic), using the closed
  form for rectangular windows.
- Evaluate K and L up to max_distance (default one quarter of the
  shorter region side) instead of the O(n^2) pattern diameter, and
  estimate K with one radius query per point.
- Print results to standard output by default with
  format=plain|csv|json; JSON output is a records array with method,
  point count, intensity, window, and correction metadata. The output
  option optionally writes to a file for all methods.
- Fix correctness bugs: intensity truncated to int made the G CSR
  reference always zero, kdtree_knn was called with k=2 writing into
  scalars, duplicate coordinates were dropped from the k-d tree,
  omitting output crashed on fopen(NULL), and num_distances was
  ignored by the G and F functions.
- Remove the unfinished Monte Carlo envelope code and the simulations
  option; simulation envelopes are planned as a follow-up (see TODO
  in the manual).
- Add the nprocs and seed standard options; report all functions
  together with their theoretical values under CSR.
- Replace the gunittest testsuite and committed test data with pytest
  tests on seeded synthetic patterns that assert agreement with CSR
  theory, clustering detection, and edge correction behavior.
- Register the tool in vector/CMakeLists.txt and use grass/gjson.h
  instead of the removed grass/parson.h.
- Rewrite the manual pages.

The restructured estimators and the isotropic correction were
implemented with AI assistance; the correction was validated
numerically against a brute-force estimate of the circle fraction
inside the window, and the estimators against CSR theory on seeded
random patterns.
@cwhite911 cwhite911 self-assigned this Jul 13, 2026
@github-actions github-actions Bot added the CMake label Jul 13, 2026
Add a pattern map figure (clustered, random, dispersed) rendered with
d.vect and one plot per function comparing the three patterns against
the CSR expectation. The figures are generated by the included
doc_figures.py script from seeded synthetic patterns, so they are
reproducible. Created with AI assistance.
@cwhite911
cwhite911 marked this pull request as ready for review July 14, 2026 10:41
@cwhite911

Copy link
Copy Markdown
Contributor Author

Any opinions on having the functions in a library like rst and making the tool a "thin tool" like v.surf.rst (interpfl has 2 usages in core)? Other examples of libraries like that would be stats (7 usages in core) and arraystats (2 usages in core).

@wenzeslaus see how the code is broken out now.

@cwhite911
cwhite911 requested a review from metzm July 14, 2026 16:08
@cwhite911

Copy link
Copy Markdown
Contributor Author

I cross-validated v.ppa against spatstat 3.0-7 (Kest, Lest, Gest, Fest) on identical coordinates and r values: K/L agree to machine precision, G exactly, and F within the Monte Carlo noise of its random test points.

Validation run with Claude Code.

@petrasovaa

Copy link
Copy Markdown
Contributor

Maybe to expose this little bit more, consider adding it somewhere to GUI menu. Also check whether the topology needs to be built for this to run. Not sure about the CodeQL CI, looks unrelated.

@github-actions github-actions Bot added the GUI wxGUI related label Aug 25, 2026
@cwhite911

cwhite911 commented Aug 25, 2026 •

Copy link
Copy Markdown
Contributor Author

@petrasovaa

Maybe to expose this little bit more, consider adding it somewhere to GUI menu.

I exposed v.ppa in the Point Analysis and Vector Reports And Statistics toolboxes.

Also check whether the topology needs to be built for this to run.

Topology is not needed for the tool to run.

Not sure about the CodeQL CI, looks unrelated.

Agreed

@cwhite911
cwhite911 merged commit f5ebd74 into OSGeo:main Aug 25, 2026
25 of 26 checks passed
@github-actions github-actions Bot added this to the 8.6.0 milestone Aug 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

C Related code is in C CMake docs GUI wxGUI related HTML Related code is in HTML markdown Related to markdown, markdown files module Python Related code is in Python tests Related to Test Suite vector Related to vector data processing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants