Skip to main content

airqolocate

airqolocate creates recommended AirQo sensor locations for a named place. It resolves the OpenStreetMap administrative boundary with OSMnx and submits the resulting polygon to the AirQo Spatial site_location API.

Requirements

  • Python 3.9 or newer
  • An AirQo API token

Installation

Install the package:

pip install airqolocate

From this repository:

cd packages/airqo-site-location
python -m pip install -e .

Authentication

Pass a token directly or set AIRQO_PLATFORM_TOKEN or AIRQO_API_TOKEN.

$env:AIRQO_API_TOKEN = "your-airqo-api-token"

Quick start

from airqolocate import locate_sites

result = locate_sites(
    "Kampala, Uganda",
    num_sensors=5,
    min_distance_km=2.5,
)

print(result["site_location"])

The library resolves Kampala, Uganda into an OpenStreetMap polygon before calling:

POST https://platform.airqo.net/api/v2/spatial/site_location?token=...

Required locations

must_have_locations is optional. Use it when specific coordinates must be included in the result.

result = locate_sites(
    "Nairobi, Kenya",
    num_sensors=5,
    min_distance_km=2.5,
    must_have_locations=[
        [-1.2790166, 36.816709],
    ],
)

Required locations use [latitude, longitude] order. num_sensors is the total number of returned locations, including required locations.

Client usage

from airqolocate import LocateClient

client = LocateClient(
    token="your-airqo-api-token",
    timeout=60,
)

result = client.locate(
    polygon="Kampala, Uganda",
    num_sensors=5,
    min_distance_km=2.5,
)

Explicit polygon coordinates

Applications that already have a boundary can provide it directly. Polygon positions use GeoJSON [longitude, latitude] order.

polygon = {
    "coordinates": [
        [
            [32.575107, 0.305577],
            [32.607894, 0.312787],
            [32.580342, 0.291845],
            [32.575107, 0.305577],
        ]
    ]
}

result = locate_sites(polygon, num_sensors=3)

Additional API options

Additional supported API fields can be passed through options:

result = client.locate(
    polygon="Kampala, Uganda",
    num_sensors=5,
    options={
        "include_source_metadata": True,
        "include_satellite": False,
        "water_buffer_m": 100,
        "require_water_data": True,
    },
)

Validation and errors

The library validates sensor counts, minimum distance, coordinates, and required-location counts before making the API request. Explicit polygon rings are closed automatically.

Place lookup and request validation errors raise ValueError. Missing OSMnx support raises ImportError. HTTP, network, timeout, invalid JSON, and malformed response errors raise LocateClientError.

from airqolocate import LocateClientError, locate_sites

try:
    result = locate_sites("Kampala, Uganda", num_sensors=5)
except LocateClientError as error:
    print(error.status_code)
    print(error.payload)

Development

Test and build

From the repository root:

cd packages/airqo-site-location
python -m pip install --upgrade build twine
python -m unittest discover -s tests -v
python -m build
python -m twine check dist/*
python -m twine upload dist/*        

Remove old build artifacts before creating a release. In PowerShell:

Remove-Item -Recurse -Force build, dist -ErrorAction SilentlyContinue
python -m build
python -m twine check (Get-ChildItem dist -File).FullName

Publish to PyPI

Confirm the version in pyproject.toml has not already been published, then upload the validated distributions:

python -m twine upload (Get-ChildItem dist -File).FullName

Use __token__ as the username and your PyPI API token as the password. Verify the release in a clean environment:

python -m pip install airqolocate
python -c "import airqolocate; print(airqolocate.__version__)"

License

MIT

Metadata

Release files for airqolocate 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for airqolocate 0.1.1
File Size Uploaded
airqolocate-0.1.1.tar.gz 9.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for airqolocate 0.1.1
File Interpreter ABI Platform
airqolocate-0.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 18.1 kB

Release files / airqolocate-0.1.1.tar.gz

Download URL airqolocate-0.1.1.tar.gz
Size 9.9 kB
Tags Source
SHA-256 checksum
How to use checksums
ebc3db79d0f431cf45f313b9f78c615b6b823d4aa371ce0d6a2cac3c010d1cbc
BLAKE2b-256 checksum
How to use checksums
be75c75de238851a5d2956b00fbdfa8b74d4c4832c51217a1e5fcbaaf93b77c9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.10.11

Release files / airqolocate-0.1.1-py3-none-any.whl

Download URL airqolocate-0.1.1-py3-none-any.whl
Size 8.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
01c4e24084f4ca97a8d24cf83d2933a0b870217c76942ce9192b896d957d1d5a
BLAKE2b-256 checksum
How to use checksums
17b3a442cf7a323d6ed869797be3eae771e89a4515064f364bd870ef3e73cd7f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.10.11

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page