Welcome to the PySAL Documentation Hub!
Current Version: 2.8.0
What is PySAL?
PySAL (Python Spatial Analysis Library) is an open-source cross-platform library for geospatial data science with an emphasis on geospatial vector data written in Python. It supports the development of high-level applications for spatial analysis, including detection of spatial clusters and hot-spots, construction of graphs from spatial data, spatial regression, spatial econometrics, and exploratory spatio-temporal data analysis.
As of version 2.0.0, PySAL is now a collection of affiliated geographic data science packages, focusing exclusively on Python 3 support.
PySAL Components
Lib
Foundational algorithms and data structures including I/O operations, spatial weights matrices, computational geometry, and example datasets.
- libpysal: Core functionality
- tobler: Areal interpolation and dasymetric mapping
- access: Spatial accessibility calculations
- spopt: Spatial optimization methods
Viz
Visualization tools for geospatial data, including maps and statistical plots.
- legendgram: Visualizations for distribution of observations
- mapclassify: Classification schemes for choropleth mapping
- splot: Statistical visualizations for spatial analysis
Explore
Modules for exploratory analysis of spatial and spatio-temporal data, including statistical testing.
- esda: Exploratory Spatial Data Analysis
- pointpats: Statistical analysis of point patterns
- inequality: Spatial inequality analytics
Model
Tools for modeling spatial relationships in data with various statistical frameworks.
- spreg: Spatial regression models
- spint: Spatial interaction modeling
- mgwr: Multiscale geographically weighted regression
- spglm: Spatial generalized linear models
Installation Options
PySAL can be installed using either conda (recommended) or pip:
For the full functionality, you may need to install additional dependencies. Check the official documentation for details.
System Requirements
- Python 3.6 or later
- NumPy (1.15 or later)
- SciPy (1.0 or later)
- Pandas (0.23 or later)
- GeoPandas (0.4 or later) for working with geospatial data
Quick Start Examples
Here are some examples to get you started with PySAL:
Loading Example Data
import libpysal
import geopandas as gpd
# Load example dataset
url = libpysal.examples.get_path('columbus.shp')
gdf = gpd.read_file(url)
print(gdf.head())
Calculating Spatial Weights
import libpysal
import geopandas as gpd
# Load data
url = libpysal.examples.get_path('columbus.shp')
gdf = gpd.read_file(url)
# Create queen contiguity weights
weights = libpysal.weights.Queen.from_dataframe(gdf)
# Print summary of weights
print(weights.summary())
Exploratory Spatial Data Analysis
import esda
import libpysal
import geopandas as gpd
# Load data
url = libpysal.examples.get_path('columbus.shp')
gdf = gpd.read_file(url)
y = gdf['CRIME']
# Create weights
w = libpysal.weights.Queen.from_dataframe(gdf)
w.transform = 'r'
# Calculate Moran's I
moran = esda.Moran(y, w)
print(f"Moran's I: {moran.I}")
print(f"P-value: {moran.p_sim}")
Official Resources
Academic Citation
If you use PySAL in academic work, please cite:
Rey, S.J. and L. Anselin, "PySAL: A Python Library of Spatial Analytical Methods", The Review of Regional Studies 37, 5-27 2007