pyscan-stats is a Python package for spatial scan statistics, created from a fork of the original pyscan library by Michael Matheny.
Wheels for Linux and macOS 14+ are available on PyPI. To install, run:
pip install pyscan-stats- Read the original documentation at https://michaelmathen.github.io/pyscan/
- Ready to run examples with data are available at: https://github.com/simonpedrogonzalez/pyscan-stats-resources
grid = pyscan.Grid(
unique_xs, unique_ys, # (N,) numpy arrays of sorted unique x and y coordinates
m_arr, b_arr # (N, 3) numpy arrays (x, y, weight)
)Removes the burden of instantiating in Python the pyscan.WPoint for each data point, which can be slow for larger datasets.
prec = 1e-3
disc_f = pyscan.RKULLDORF
max_area = 750 # Maximum number of pixels in the subgrid
max_subgrid = pyscan.max_subgrid_convex(grid, prec, disc_f, max_area)Allows for specifying a maximum area for the subgrid, useful when the interest is in smaller anomalies or when computational resources are limited. Usage example here. The implementation uses a sliding window version of Kadane's algorithm.
- Support for new Python versions (3.10+)
- Project dependency update and organization for easier extension and maintenance.
- Updated examples.
git clone https://github.com/simonpedrogonzalez/pyscan.- Install
uvpackage manager if not already installed (you can use other package managers, butuvis needed if you want to use the make commands provided). - Install CMake, Boost, GSL, CGAL if not already installed. For example, on Mac:
brew install cmake boost gsl cgal
- Run
make initto create a Python 3.12 venv in.venvand install dev dependencies.
You are all set to start developing! The following utility commands are available:
make cpp: compiles C++ code into thebuild/directory.make py: builds the Python package and installs it in the venv, with the last compiled cpp binaries.make test: runs the C++ tests, only works after compiling the C++ code.make clean: removesbuild/,dist/and packaging artifacts.
Notes: If an error occurs executing one of the commands, try:
- Manually activating the venv
source .venv/bin/activateand running the command again. - Running
make cleanbeforemake cppto ensure a clean build. - This setup was tested both on macOS (15.6, M2) and Linux (Ubuntu 20.04).
Pyscan is a python wrapper around a large number of anomaly detection algorithms written in c++. These algorithms are from several papers by Jeff M. Phillips, Michael Matheny, Dong Xie, Mingxuan Han, Raghvendra Singh, Liang Zhang, Kaiqiang Wang, Deepak Agarwal, Andrew McGregor, Suresh Venkatasubramanian and Zhengyuan Zhu:
- The Kernel Scan Statistic
- Scalable Spatial Scan Statistics for Trajectories
- Computing Approximate Statistical Discrepancy
- Scalable Spatial Scan Statistics through Sampling
- Spatial Scan Statistics: Approximations and Performance Studies
- The Hunting of the Bump: On Maximizing Statistical Discrepancy
Things never go as planned! Feel free to reach out: