Skip to main content

Air pollution source metadata client, inference engine, and optional API

Project description

airqosm

airqosm is a lightweight Python package for:

  • fetching source metadata from the AirQo Platform spatial API
  • normalizing the platform response into a stable {message, data} shape
  • inferring likely air pollution source metadata locally from features when needed

The local inference engine works from:

  • site context (category, landuse, natural, highway)
  • satellite pollutant summary means (SO2, HCHO, CO, NO2, O3, AOD)

It can run as:

  • a Python client (SourceMetadataClient)
  • a Python library (SourceMetadataEngine)
  • an optional Flask API (airqosm-api)

Requirements

  • Python >=3.9
  • Dependencies are managed in pyproject.toml

Do I need a requirements.txt?

No, not for this package.

This package is already standards-based and pip-installable using pyproject.toml (PEP 517/518/621).
Use requirements.txt only if you specifically want a separate pinned file for CI/runtime environments.

Install

From PyPI:

pip install airqosm

Install with API server support:

pip install "airqosm[api]"

From this monorepo (editable mode):

cd packages/airqo-source-metadata
pip install -e .

Library Quick Start

Simple import style:

import airqosm

result = airqosm.source_metadata(
    latitude=5.798044,
    longitude=-0.8212,
    token="your-platform-token",
)

print(result["data"]["primary_source"])

Direct helper imports:

from airqosm import candidate_sources, primary_source

print(primary_source(5.798044, -0.8212, token="your-platform-token"))
print(candidate_sources(5.798044, -0.8212, token="your-platform-token"))

Fetch from AirQo Platform:

from airqosm import SourceMetadataClient

client = SourceMetadataClient(token="your-platform-token")

response = client.fetch(
    latitude=5.798044,
    longitude=-0.8212,
    include_satellite=True,
)

print(response["data"]["primary_source"])

The client automatically unwraps singleton list wrappers such as [[{...}]] and returns:

{
    "message": "Operation successful",
    "data": {
        "primary_source": {...},
        "candidate_sources": [...],
        ...
    },
}

Run local inference from features:

from airqosm import SourceMetadataEngine

engine = SourceMetadataEngine()

result = engine.build_from_features(
    latitude=0.322502,
    longitude=32.584726,
    site_category={
        "category": "Urban Background",
        "landuse": "commercial",
        "natural": "unknown",
        "highway": "primary",
        "area_name": "Kampala",
        "search_radius": 100,
        "waterway": "unknown",
    },
    satellite_pollutants_mean={
        "SO2": 0.00007,
        "HCHO": 0.00012,
        "CO": 0.05,
        "NO2": 0.00009,
        "O3": 0.14,
        "AOD": 1.2,
    },
    include_satellite=True,
)

print(result["primary_source"])

Run API

airqosm-api --host 0.0.0.0 --port 8010 --platform-token your-platform-token

The API command requires the optional API extra:

pip install "airqosm[api]"

Base URL: http://127.0.0.1:8010

Endpoints

  • GET /healthz
  • GET /api/v2/spatial/source_metadata
  • POST /api/v1/source-metadata/from-features
  • POST /api/v1/source-metadata/batch-from-features

API Examples

Coordinate lookup through the platform client:

curl "http://127.0.0.1:8010/api/v2/spatial/source_metadata?latitude=5.798044&longitude=-0.8212&include_satellite=true&token=your-platform-token"

Single request:

curl -X POST "http://127.0.0.1:8010/api/v1/source-metadata/from-features" \
  -H "Content-Type: application/json" \
  -d '{
    "latitude": 0.322502,
    "longitude": 32.584726,
    "site_category": {
      "category": "Urban Background",
      "landuse": "commercial",
      "natural": "unknown",
      "highway": "primary"
    },
    "satellite_pollutants_mean": {
      "SO2": 0.00007,
      "HCHO": 0.00012,
      "CO": 0.05,
      "NO2": 0.00009,
      "O3": 0.14,
      "AOD": 1.2
    }
  }'

Batch request:

curl -X POST "http://127.0.0.1:8010/api/v1/source-metadata/batch-from-features" \
  -H "Content-Type: application/json" \
  -d '{
    "include_satellite": true,
    "items": [
      {
        "id": "site-1",
        "latitude": 0.322502,
        "longitude": 32.584726,
        "site_category": {"category": "Urban Background", "landuse": "commercial", "natural": "unknown", "highway": "primary"},
        "satellite_pollutants_mean": {"SO2": 0.00007, "HCHO": 0.00012, "CO": 0.05, "NO2": 0.00009, "O3": 0.14, "AOD": 1.2}
      },
      {
        "id": "site-2",
        "latitude": 0.347596,
        "longitude": 32.582520,
        "site_category": {"category": "Major Highway", "landuse": "industrial", "natural": "unknown", "highway": "trunk"},
        "satellite_pollutants_mean": {"SO2": 0.0001, "HCHO": 0.00011, "CO": 0.06, "NO2": 0.00012, "O3": 0.13, "AOD": 1.0}
      }
    ]
  }'

Build and Publish (PyPI)

cd packages/airqo-source-metadata
python -m pip install --upgrade build twine
python -m build
python -m twine check dist/*
python -m twine upload dist/*

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

airqosm-0.2.0.tar.gz (11.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

airqosm-0.2.0-py3-none-any.whl (11.7 kB view details)

Uploaded Python 3

File details

Details for the file airqosm-0.2.0.tar.gz.

File metadata

  • Download URL: airqosm-0.2.0.tar.gz
  • Upload date:
  • Size: 11.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.11

File hashes

Hashes for airqosm-0.2.0.tar.gz
Algorithm Hash digest
SHA256 9b247aab8b43a2a1088d07714877cc10928d1c21026fd3181f76db88deb48e2d
MD5 5dcf42e5432f00371f5f906f6ead6d03
BLAKE2b-256 1606898a5400a31d6cef3c6e3cbbed1527ba7c09c3c37921bf12e167b399a399

See more details on using hashes here.

File details

Details for the file airqosm-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: airqosm-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 11.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.11

File hashes

Hashes for airqosm-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 59242a33e781893a1ce5fa1b1c5548313b97d01a99e6c220d22f23b7e44b192a
MD5 5daf252904afb8efe58735a30a2dd207
BLAKE2b-256 107b14eb16fb062dc9020119f22455cf9c903cd3ed598a72805d88bb6d978ff9

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page