Skip to content
 
 

Repository files navigation

pyscan-stats

pyscan-stats is a Python package for spatial scan statistics, created from a fork of the original pyscan library by Michael Matheny.

User Installation

Wheels for Linux and macOS 14+ are available on PyPI. To install, run:

pip install pyscan-stats

Documentation

  1. Read the original documentation at https://michaelmathen.github.io/pyscan/
  2. Ready to run examples with data are available at: https://github.com/simonpedrogonzalez/pyscan-stats-resources

New Features

Faster Numpy-based Net Grid Constructor

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.

Area-Limited Max Convex Subgrid Scan

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.

Improvements

  • Support for new Python versions (3.10+)
  • Project dependency update and organization for easier extension and maintenance.
  • Updated examples.

Dev installation

  1. git clone https://github.com/simonpedrogonzalez/pyscan.
  2. Install uv package manager if not already installed (you can use other package managers, but uv is needed if you want to use the make commands provided).
  3. Install CMake, Boost, GSL, CGAL if not already installed. For example, on Mac:
    brew install cmake boost gsl cgal
  4. Run make init to create a Python 3.12 venv in .venv and install dev dependencies.

You are all set to start developing! The following utility commands are available:

  • make cpp: compiles C++ code into the build/ 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: removes build/, dist/ and packaging artifacts.

Notes: If an error occurs executing one of the commands, try:

  • Manually activating the venv source .venv/bin/activate and running the command again.
  • Running make clean before make cpp to ensure a clean build.
  • This setup was tested both on macOS (15.6, M2) and Linux (Ubuntu 20.04).

About pyscan

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:

🛠️ Need Help?

Things never go as planned! Feel free to reach out:

📧 simon.pedro.g@gmail.com
🐙 GitHub Issues

About

An anomaly detection framework for large data sets.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages