|
1 | 1 | # IDD Spatial Analysis |
2 | 2 |
|
3 | | -[](https://www.python.org/downloads/) |
| 3 | +[](https://www.python.org/downloads/) |
4 | 4 | [](https://python-poetry.org/) |
5 | 5 |
|
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. |
7 | 7 |
|
8 | | -## 🚀 Quick Start |
| 8 | +## 🚀 Features |
9 | 9 |
|
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 |
11 | 14 |
|
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 |
13 | 20 |
|
14 | 21 | ```bash |
15 | | -# Clone the repository |
| 22 | +# Clone the repository (if not already cloned) |
16 | 23 | git clone https://github.com/ihmeuw/idd-spatial-analysis.git |
17 | 24 | cd idd-spatial-analysis |
18 | 25 |
|
19 | | -# Create and activate the conda environment |
| 26 | +# Create the conda environment |
20 | 27 | conda env create -f environment.yml |
21 | | -conda activate idd-spatial-analysis |
22 | | -``` |
23 | | - |
24 | | -#### Option 2: Using Poetry |
25 | 28 |
|
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 |
30 | 31 |
|
31 | | -# Install dependencies with poetry |
| 32 | +# Install the package in development mode |
32 | 33 | 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)" |
34 | 37 | ``` |
35 | 38 |
|
36 | | -#### Option 3: Install as a Python package (from GitHub) |
| 39 | +## 💡 Usage |
37 | 40 |
|
38 | | -You can install and use `idd_spatial_analysis` in other projects/environments: |
| 41 | +### Basic Example |
39 | 42 |
|
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}%") |
42 | 69 | ``` |
43 | 70 |
|
44 | | -Then, in your Python code: |
| 71 | +### Data Requirements |
45 | 72 |
|
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 |
48 | 84 |
|
49 | | -# Your geospatial analysis code here |
50 | | -``` |
| 85 | +### Example Notebook |
51 | 86 |
|
52 | | -## 📦 Package Structure |
| 87 | +See [notebooks/example_usage.ipynb](notebooks/example_usage.ipynb) for a complete working example. |
| 88 | + |
| 89 | +## � Project Structure |
53 | 90 |
|
54 | 91 | ``` |
55 | 92 | idd-spatial-analysis/ |
56 | 93 | ├── src/ |
57 | 94 | │ └── idd_spatial_analysis/ # Main package |
58 | 95 | │ ├── __init__.py |
59 | | -│ └── spatial_utils.py # Core spatial utilities |
| 96 | +│ ├── spatial_utils.py # Core spatial utilities |
| 97 | +│ └── clinic_proximity.py # Clinic proximity analysis functions |
60 | 98 | ├── notebooks/ # Example notebooks |
| 99 | +│ └── example_usage.ipynb # Complete usage example |
61 | 100 | ├── tests/ # Unit tests |
| 101 | +│ ├── __init__.py |
| 102 | +│ └── test_spatial_utils.py |
62 | 103 | ├── pyproject.toml # Poetry configuration |
63 | | -├── environment.yml # Conda environment |
| 104 | +├── environment.yml # Conda environment (Python 3.13) |
64 | 105 | └── README.md |
65 | 106 | ``` |
66 | 107 |
|
| 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 | + |
67 | 131 | ## 🛠️ Development |
68 | 132 |
|
69 | 133 | ### Running Tests |
|
0 commit comments