Metadata-Version: 2.2
Name: pyscan-stats
Version: 1.0.0
Summary: C++ spatial scan wrapper for Python
Author: Michael Matheny
License: MIT License
         
         Copyright (c) 2018 michaelmathen
         
         Permission is hereby granted, free of charge, to any person obtaining a copy
         of this software and associated documentation files (the "Software"), to deal
         in the Software without restriction, including without limitation the rights
         to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
         copies of the Software, and to permit persons to whom the Software is
         furnished to do so, subject to the following conditions:
         
         The above copyright notice and this permission notice shall be included in all
         copies or substantial portions of the Software.
         
         THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
         IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
         FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
         AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
         LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
         OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
         SOFTWARE.
         
Requires-Python: >=3.8
Provides-Extra: dev
Requires-Dist: scikit-build-core; extra == "dev"
Requires-Dist: cmake; extra == "dev"
Requires-Dist: ninja; extra == "dev"
Requires-Dist: pybind11; extra == "dev"
Requires-Dist: pybind11-global; extra == "dev"
Requires-Dist: twine; extra == "dev"
Requires-Dist: build; extra == "dev"
Requires-Dist: cibuildwheel; extra == "dev"
Provides-Extra: utils
Requires-Dist: geopandas>=0.13.2; extra == "utils"
Requires-Dist: matplotlib>=3.7.5; extra == "utils"
Requires-Dist: pandas>=2.0.3; extra == "utils"
Requires-Dist: pyqt6>=6.7.1; extra == "utils"
Requires-Dist: shapely>=2.0.7; extra == "utils"
Requires-Dist: seaborn>=0.13.2; extra == "utils"
Requires-Dist: tqdm>=4.67.1; extra == "utils"
Requires-Dist: xarray>=2025.1.1; extra == "utils"
Requires-Dist: h5netcdf>=1.6.3; extra == "utils"
Description-Content-Type: text/markdown

# pyscan-stats

**[pyscan-stats](https://pypi.org/project/pyscan-stats/)** is a Python package for spatial scan statistics, created from a fork of the original **[pyscan](https://github.com/michaelmathen/pyscan)** library by Michael Matheny.

## User Installation

```bash
pip install pyscan-stats
```

## Documentation

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

# New Features

## Faster Numpy-based Net Grid Constructor

```python
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 in larger datasets.

## Area-Limited Max Convex Subgrid Scan

```python
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](https://github.com/simonpedrogonzalez/pyscan-stats-resources/blob/master/examples_with_data/AreaLimitedGridScanning.py). 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`.
1. [Install `uv` package manager](https://docs.astral.sh/uv/getting-started/installation/#standalone-installer) if not already installed.
2. Install CMake, Boost, GSL, CGAL if not already installed. For example, on Mac:
    ```bash
    brew install cmake boost gsl cgal
    ```
3. 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 and Linux.

# 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:

- [The Kernel Scan Statistic](https://arxiv.org/abs/1906.09381)
- [Scalable Spatial Scan Statistics for Trajectories](https://arxiv.org/abs/1906.01693)
- [Computing Approximate Statistical Discrepancy](https://arxiv.org/abs/1804.11287)
- [Scalable Spatial Scan Statistics through Sampling](https://dl.acm.org/citation.cfm?id=2996939)
- [Spatial Scan Statistics: Approximations and Performance Studies](http://www.cs.utah.edu/~jeffp/papers/stat-disc-KDD06.pdf)
- [The Hunting of the Bump: On Maximizing Statistical Discrepancy](http://www.cs.utah.edu/~jeffp/papers/stat-disc-SODA06.pdf)
