Ripley's K Function (Second order intensity function) Python
Asked Answered
C

2

7

I am looking for Ripley's k function implementation in Python. But so far haven't been able to find any spatial modules implementing this in scipy or elsewhere.

I have created Voronoi tessellation of a fibre composite and need to perform analysis using Ripley's K and pair distribution functions compared to a Poisson distribution.

Cannot upload images-not enough rep.

Catalano answered 23/4, 2015 at 16:8 Comment(2)
Would it be an option for you to simply call an R function via RPy? In that case you can use the spatstat package for R.Veto
Thanks! Didn't know about RPy before but that sounds feasible.Catalano
C
4

Solved my problem, this is for others looking to do same analysis.

Definitely recommend using R for spatial analysis. A transfer from python is simple because all you need is coordinates of your point pattern.

  1. Write a csv of x,y and z coordinates of your points using python

  2. R has good functionality of reading csv using command read.csv("filename"). Make sure the directory is set properly using setwd command.

  3. Convert the csv you just read to a ppp(point pattern which R understands) using as.ppp command.
  4. Continue to use Kest, Gest etc for required spatial analysis.

Cheers.

Catalano answered 9/9, 2015 at 16:29 Comment(0)
H
2

Now (2021) there is a Ripley's K implementation for Python, easy to install

https://pypi.org/project/ripleyk/

And also a more comprehensive package that includes Ripley's K, G, F and includes MC simulations for p-values, very nice.

https://github.com/pysal/pointpats/blob/master/notebooks/distance_statistics-numpy-oriented.ipynb

Hakodate answered 6/9, 2021 at 9:55 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.