Skip to content

Commit 1bc9cae

Browse files
committed
Add schematic figure engine and shapefile loading utilities
- Implemented `schematic_figure.py` to provide a generic nested three-panel figure engine with layers for raster, polygon, and point data, along with a convenience wrapper for creating schematic figures. - Introduced `shapefile_functions.py` for loading admin shapefiles, including functions to load global admin boundaries and rasterize admin codes into a pixel grid. - Added detailed docstrings for public API and internal functions to enhance code readability and usability.
1 parent 31cfa98 commit 1bc9cae

20 files changed

+5586
-213
lines changed

README.md

Lines changed: 93 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,69 +1,133 @@
11
# IDD Spatial Analysis
22

3-
[![Python](https://img.shields.io/badge/python-3.10+-blue.svg)](https://www.python.org/downloads/)
3+
[![Python](https://img.shields.io/badge/python-3.13+-blue.svg)](https://www.python.org/downloads/)
44
[![Poetry](https://img.shields.io/badge/poetry-managed-blue.svg)](https://python-poetry.org/)
55

6-
Repository for IDD geospatial analysis tools and utilities in Python.
6+
Geospatial analysis tools for IDD research, focusing on clinic proximity analysis and population coverage estimation.
77

8-
## 🚀 Quick Start
8+
## 🚀 Features
99

10-
### Local Installation
10+
- **Clinic Proximity Analysis**: Calculate population within X km of each clinic
11+
- **Coverage Analysis**: Estimate population with access to at least Y clinics within X km
12+
- **Administrative Summaries**: Aggregate results by admin boundaries (Admin 0, 1, 2)
13+
- **Raster Operations**: Work with 100m resolution population rasters in equal area projections
1114

12-
#### Option 1: Using Conda (Recommended)
15+
## 📦 Environment Setup
16+
17+
This project uses conda for environment management with Python 3.13 and all necessary geospatial libraries.
18+
19+
### Create and Activate Environment
1320

1421
```bash
15-
# Clone the repository
22+
# Clone the repository (if not already cloned)
1623
git clone https://github.com/ihmeuw/idd-spatial-analysis.git
1724
cd idd-spatial-analysis
1825

19-
# Create and activate the conda environment
26+
# Create the conda environment
2027
conda env create -f environment.yml
21-
conda activate idd-spatial-analysis
22-
```
23-
24-
#### Option 2: Using Poetry
2528

26-
```bash
27-
# Clone the repository
28-
git clone https://github.com/ihmeuw/idd-spatial-analysis.git
29-
cd idd-spatial-analysis
29+
# Activate the environment
30+
conda activate idd-spatial-analysis
3031

31-
# Install dependencies with poetry
32+
# Install the package in development mode
3233
poetry install
33-
poetry shell
34+
35+
# Create Jupyter kernel (for notebooks)
36+
python -m ipykernel install --user --name=idd-spatial-analysis --display-name="Python 3.13 (idd-spatial-analysis)"
3437
```
3538

36-
#### Option 3: Install as a Python package (from GitHub)
39+
## 💡 Usage
3740

38-
You can install and use `idd_spatial_analysis` in other projects/environments:
41+
### Basic Example
3942

40-
```bash
41-
pip install git+https://github.com/ihmeuw/idd-spatial-analysis.git
43+
```python
44+
from idd_spatial_analysis.clinic_proximity import (
45+
load_clinic_data,
46+
population_within_distance,
47+
population_coverage_multiple_clinics
48+
)
49+
50+
# Load clinic GPS coordinates
51+
clinics = load_clinic_data("path/to/clinics.csv")
52+
53+
# Calculate population within 5 km of each clinic
54+
results = population_within_distance(
55+
clinics_gdf=clinics,
56+
population_raster_path="path/to/population_100m.tif",
57+
distance_km=5.0
58+
)
59+
60+
# Calculate population with access to at least 1 clinic within 5 km
61+
coverage = population_coverage_multiple_clinics(
62+
clinics_gdf=clinics,
63+
population_raster_path="path/to/population_100m.tif",
64+
distance_km=5.0,
65+
min_clinics=1
66+
)
67+
68+
print(f"Coverage: {coverage['coverage_percentage']:.2f}%")
4269
```
4370

44-
Then, in your Python code:
71+
### Data Requirements
4572

46-
```python
47-
from idd_spatial_analysis import spatial_utils
73+
1. **Clinic Data**: GPS coordinates in CSV, shapefile, or GeoJSON format
74+
- Expected columns: `longitude`/`latitude` or `lon`/`lat` or `x`/`y`
75+
76+
2. **Population Raster**: High-resolution population data
77+
- Format: GeoTIFF
78+
- Projection: Equal area projection (e.g., Mollweide, Albers Equal Area)
79+
- Resolution: 100m (or as available)
80+
81+
3. **Administrative Boundaries**: Shapefiles for Admin 0, 1, and 2 levels
82+
- Format: Shapefile, GeoJSON, or other vector format
83+
- Must have a name field for labeling
4884

49-
# Your geospatial analysis code here
50-
```
85+
### Example Notebook
5186

52-
## 📦 Package Structure
87+
See [notebooks/example_usage.ipynb](notebooks/example_usage.ipynb) for a complete working example.
88+
89+
## � Project Structure
5390

5491
```
5592
idd-spatial-analysis/
5693
├── src/
5794
│ └── idd_spatial_analysis/ # Main package
5895
│ ├── __init__.py
59-
│ └── spatial_utils.py # Core spatial utilities
96+
│ ├── spatial_utils.py # Core spatial utilities
97+
│ └── clinic_proximity.py # Clinic proximity analysis functions
6098
├── notebooks/ # Example notebooks
99+
│ └── example_usage.ipynb # Complete usage example
61100
├── tests/ # Unit tests
101+
│ ├── __init__.py
102+
│ └── test_spatial_utils.py
62103
├── pyproject.toml # Poetry configuration
63-
├── environment.yml # Conda environment
104+
├── environment.yml # Conda environment (Python 3.13)
64105
└── README.md
65106
```
66107

108+
## 🔑 Key Functions
109+
110+
### `load_clinic_data(filepath, crs="EPSG:4326")`
111+
Load clinic GPS coordinates from various file formats.
112+
113+
### `population_within_distance(...)`
114+
Calculate population within specified distance of each individual clinic.
115+
116+
**Returns**: DataFrame with clinic IDs and population counts.
117+
118+
### `population_coverage_multiple_clinics(...)`
119+
Calculate population with access to at least `min_clinics` within `distance_km`.
120+
121+
**Returns**:
122+
- Total population
123+
- Population with access
124+
- Coverage percentage
125+
- Coverage raster (number of clinics within distance per pixel)
126+
- Admin-level summaries (if boundaries provided)
127+
128+
### `export_coverage_raster(...)`
129+
Export coverage raster to GeoTIFF file.
130+
67131
## 🛠️ Development
68132

69133
### Running Tests

environment.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ channels:
33
- conda-forge
44
- defaults
55
dependencies:
6-
- python=3.10
6+
- python=3.13
77
- geopandas>=0.14.0
88
- rasterio>=1.3.0
99
- xarray>=2023.0.0
@@ -13,6 +13,8 @@ dependencies:
1313
- numpy>=1.24.0
1414
- matplotlib>=3.7.0
1515
- cartopy>=0.22.0
16+
- scipy>=1.10.0
17+
- rtree>=1.0.0
1618
- dask
1719
- netcdf4
1820
- zarr

0 commit comments

Comments
 (0)