From 35684f2eb8028521cfc246444811180747dc6482 Mon Sep 17 00:00:00 2001 From: wabinyai Date: Mon, 3 Feb 2025 12:23:29 +0300 Subject: [PATCH 1/4] readme --- src/spatial/README.md | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/src/spatial/README.md b/src/spatial/README.md index 41a207d1fc..f9fb161018 100644 --- a/src/spatial/README.md +++ b/src/spatial/README.md @@ -42,8 +42,37 @@ http://127.0.0.1:5000/api/v2/spatial/getisord http://127.0.0.1:5000/api/v2/spatial/getisord_confidence http://127.0.0.1:5000/api/v2/spatial/localmoran + + + { "grid_id": "64b7f325d7249f0029fed743", "start_time": "2024-01-01T00:00", "end_time": "2024-01-27T00:00" } + +# Locate +Using Locate tool for site selection +http://127.0.0.1:5000/api/v2/spatial/site_location? + +the body should have; + Required polygon and number of sensors as num_sensors + Optional must_have_locations AND min_distance_km (by default min_distance_km = 0.5) + +{ + "polygon": { + "coordinates":[[[36.960411,-1.441632],[36.935005,-1.432022], [36.960411,-1.441632]]] + }, + "must_have_locations": [ + [-1.2790166, 36.816709] + ], + "min_distance_km": 2.5, + "num_sensors": 1 +} + + +# Site Category +A tool to categorize sites based on their location and properties. +http://127.0.0.1:5000/api/v2/spatial/site_category?latitude={}&longitude={} + +for a better result the latitude and longitude should have a high precision of up to 6 decimal places From 40c21868ae98f8ce45b1d457da707e02cc46ec7f Mon Sep 17 00:00:00 2001 From: wabinyai Date: Mon, 3 Feb 2025 12:40:01 +0300 Subject: [PATCH 2/4] Improve readme --- src/spatial/README.md | 140 ++++++++++++++++++++++++++++++------------ 1 file changed, 100 insertions(+), 40 deletions(-) diff --git a/src/spatial/README.md b/src/spatial/README.md index f9fb161018..07c0dbee75 100644 --- a/src/spatial/README.md +++ b/src/spatial/README.md @@ -1,78 +1,138 @@ -# REPORT. +# Air Quality Spatial Analysis API -## 1. Create venv file.. +This repository provides tools for spatial air quality analysis, including Moran's I and Getis-Ord analyses, site categorization, and sensor placement optimization. -`python -m venv venv` +## 1. Setting Up the Virtual Environment -#### Linux and MacOS +### Create a Virtual Environment -`source venv/bin/activate` +Run the following command to create a virtual environment: + +```sh +python -m venv venv +``` + +### Activate the Virtual Environment + +#### Linux and macOS +```sh +source venv/bin/activate +``` #### Windows +```sh +venv\Scripts\activate +``` + +### Install Dependencies -`venv\scripts\activate` +Ensure you have the necessary dependencies installed: -### Install the necessary dependencies +```sh +python -m pip install --upgrade pip +pip install -r requirements.txt +``` -`python.exe -m pip install --upgrade pip` -`pip install -r requirements.txt` +## 2. Identifying Your AirQloud ID -### Know your airqloud id +Different regions have specific AirQloud IDs. Below are some examples: -`Example` -`Uganda: ` -`Cameroon: 6368b31b2fa4d3001e73e9c8` -`Kampala: ` -`Kenya: 636629b22fa4d3001e739d0f` -`Fort Portal : 618b850c9326560036a453eb` +- **Uganda**: +- **Cameroon**: `6368b31b2fa4d3001e73e9c8` +- **Kampala**: +- **Kenya**: `636629b22fa4d3001e739d0f` +- **Fort Portal**: `618b850c9326560036a453eb` -### RUN local +## 3. Running the Application Locally +Start the application with the following command: + +```sh python main.py +``` + +Alternatively, you can run Flask directly: + +```sh flask run +``` -### The API token +## 4. API Authentication -Create an API token from https://platform.airqo.net/settings -The process is highlighted here: https://docs.airqo.net/airqo-rest-api-documentation +To access the API, generate an API token at [AirQo Platform](https://platform.airqo.net/settings). +For detailed instructions, refer to the [AirQo API Documentation](https://docs.airqo.net/airqo-rest-api-documentation). -#run postman -http://127.0.0.1:5000/api/v2/spatial/getisord +## 5. API Endpoints -http://127.0.0.1:5000/api/v2/spatial/getisord_confidence +### **Spatial Analysis Tools** -http://127.0.0.1:5000/api/v2/spatial/localmoran +#### Getis-Ord Hotspot Analysis +```http +GET http://127.0.0.1:5000/api/v2/spatial/getisord +``` +#### Getis-Ord Confidence Analysis +```http +GET http://127.0.0.1:5000/api/v2/spatial/getisord_confidence +``` +#### Local Moran’s I Analysis +```http +GET http://127.0.0.1:5000/api/v2/spatial/localmoran +``` +##### Example Request Body +```json { -"grid_id": "64b7f325d7249f0029fed743", -"start_time": "2024-01-01T00:00", -"end_time": "2024-01-27T00:00" + "grid_id": "64b7f325d7249f0029fed743", + "start_time": "2024-01-01T00:00", + "end_time": "2024-01-27T00:00" } +``` -# Locate -Using Locate tool for site selection -http://127.0.0.1:5000/api/v2/spatial/site_location? +### **Site Selection Using Locate Tool** -the body should have; - Required polygon and number of sensors as num_sensors - Optional must_have_locations AND min_distance_km (by default min_distance_km = 0.5) +Use this tool to select monitoring sites based on a defined area. +```http +GET http://127.0.0.1:5000/api/v2/spatial/site_location +``` + +#### Required Parameters: +- `polygon` (GeoJSON format) – Defines the area of interest. +- `num_sensors` – Number of sensors to deploy. + +#### Optional Parameters: +- `must_have_locations` – Specific coordinates that must be included. +- `min_distance_km` – Minimum distance between selected sites (default: 0.5 km). + +##### Example Request Body +```json { "polygon": { - "coordinates":[[[36.960411,-1.441632],[36.935005,-1.432022], [36.960411,-1.441632]]] + "coordinates": [ + [[36.960411, -1.441632], [36.935005, -1.432022], [36.960411, -1.441632]] + ] }, "must_have_locations": [ - [-1.2790166, 36.816709] - ], + [-1.2790166, 36.816709] + ], "min_distance_km": 2.5, "num_sensors": 1 } +``` + +### **Site Categorization Tool** + +Categorize a monitoring site based on its geographic properties. + +```http +GET http://127.0.0.1:5000/api/v2/spatial/site_category?latitude={latitude}&longitude={longitude} +``` + +Ensure latitude and longitude have high precision (up to six decimal places) for accurate categorization. +--- -# Site Category -A tool to categorize sites based on their location and properties. -http://127.0.0.1:5000/api/v2/spatial/site_category?latitude={}&longitude={} +This README provides an overview of the setup, API endpoints, and example requests. For further details, consult the official AirQo API documentation. -for a better result the latitude and longitude should have a high precision of up to 6 decimal places From ff285b3a84a0f5914f2de68a6e656115c1fba33e Mon Sep 17 00:00:00 2001 From: wabinyai Date: Mon, 3 Feb 2025 12:43:15 +0300 Subject: [PATCH 3/4] polygom --- src/spatial/README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/spatial/README.md b/src/spatial/README.md index 07c0dbee75..8375be6a96 100644 --- a/src/spatial/README.md +++ b/src/spatial/README.md @@ -111,17 +111,17 @@ GET http://127.0.0.1:5000/api/v2/spatial/site_location { "polygon": { "coordinates": [ - [[36.960411, -1.441632], [36.935005, -1.432022], [36.960411, -1.441632]] + [[32.575107,0.305577],[32.575364,0.319138],[32.597337,0.32034],[32.607894,0.312787],[32.608752,0.297509],[32.599225,0.292102],[32.580342,0.291845],[32.574334,0.296994],[32.575107,0.305577]] ] }, "must_have_locations": [ - [-1.2790166, 36.816709] + [0.324256, 32.581227] ], "min_distance_km": 2.5, "num_sensors": 1 } ``` - +Must have locations should be coordinates withinh the polygon. ### **Site Categorization Tool** Categorize a monitoring site based on its geographic properties. From edbe69fa8b79a78d36f54ee44f550c204b8b92e5 Mon Sep 17 00:00:00 2001 From: wabinyai Date: Mon, 3 Feb 2025 12:45:46 +0300 Subject: [PATCH 4/4] GRID --- src/spatial/README.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/spatial/README.md b/src/spatial/README.md index 8375be6a96..22548c0e5e 100644 --- a/src/spatial/README.md +++ b/src/spatial/README.md @@ -37,9 +37,8 @@ pip install -r requirements.txt Different regions have specific AirQloud IDs. Below are some examples: -- **Uganda**: - **Cameroon**: `6368b31b2fa4d3001e73e9c8` -- **Kampala**: +- **Kampala city**:`64b7baccf2b99f00296acd59` - **Kenya**: `636629b22fa4d3001e739d0f` - **Fort Portal**: `618b850c9326560036a453eb`