|
1 | 1 | # Weather Service |
2 | 2 |
|
3 | | -🇪🇺 *This service was created in the context of OpenAgri project (https://horizon-openagri.eu/). OpenAgri has received funding from the EU’s Horizon Europe research and innovation programme under Grant Agreement no. 101134083.* |
| 3 | +[](./LICENSE) |
| 4 | + |
| 5 | + |
4 | 6 |
|
5 | | -## Description |
6 | | -Fast, reliable weather API providing 5-day forecasts, agricultural indicators like |
7 | | -[Temperature-Humidity Index](https://www.pericoli.com/en/temperature-humidity-index-what-you-need-to-know-about-it/), |
8 | | -UAV flight condition predictions, and spray condition forecasts. Built with FastAPI for high performance. |
9 | | -Easy to integrate, deploy, and scale. |
| 7 | +Fast, reliable weather API with 5-day forecasts, agricultural indicators, UAV flight condition predictions, and spray condition forecasts. |
| 8 | +Built with [FastAPI](https://fastapi.tiangolo.com/) for high performance and easy integration. |
10 | 9 |
|
| 10 | +**IMPORTANT**: This project is in an early stage. Some parts are stable, others need refactoring. We welcome contributors who want to help improve tests, documentation, and code quality. |
11 | 11 |
|
12 | | -Project is fully functional, compatible with Python 3.12. |
13 | | -Is built using [FastAPI](https://fastapi.tiangolo.com/) framework and served with [Uvicorn](https://www.uvicorn.org). |
| 12 | +--- |
14 | 13 |
|
15 | | -The application is containerized using Docker. To install it please firstly install `docker` |
| 14 | +## About |
16 | 15 |
|
17 | | -You can follow [this guide](https://docs.docker.com/engine/install/ubuntu/) to install `docker` on Ubuntu. |
| 16 | +This service was created in the context of the [OpenAgri project](https://horizon-openagri.eu/), funded by the EU’s Horizon Europe research and innovation programme (Grant Agreement no. 101134083). |
18 | 17 |
|
19 | | -## Requirements |
20 | | -- git |
21 | | -- docker |
22 | | -- docker-compose |
| 18 | +The Weather Service provides: |
23 | 19 |
|
24 | | -## Installation |
25 | | -After installing `docker` you can simply run |
| 20 | +- **Forecasts** – 5-day forecasts in JSON and JSON-LD (OCSM) formats |
| 21 | +- **Current weather conditions** – temperature, humidity, wind, sky conditions |
| 22 | +- **Agricultural indicators** – Temperature-Humidity Index (THI) |
| 23 | +- **UAV flight forecasts** – 5-day predictions for UAV flight conditions (by model, filterable) |
| 24 | +- **Spray condition forecasts** – support for agricultural spraying planning |
| 25 | +- **Historical weather API** – daily and hourly values |
| 26 | +- **Offline support** – cache last month’s history for specific locations |
| 27 | +- **Containerized builds** – multi-arch Docker images (AMD64 and ARM64) |
26 | 28 |
|
27 | | -``` |
28 | | -docker compose up --build |
29 | | -``` |
| 29 | +--- |
30 | 30 |
|
31 | | -to run the application. |
| 31 | +## Roadmap |
32 | 32 |
|
33 | | -The application is served by default on `http://127.0.0.1:8000` |
| 33 | +High-level next steps for the Weather Service: |
34 | 34 |
|
35 | | -## Documentation |
| 35 | +- [ ] Connect with local weather stations for improved ground-truth data |
| 36 | +- [ ] Integrate with additional 3rd party weather APIs |
| 37 | +- [ ] Enhance accuracy of weather, UAV, and spray forecasts by combining multiple data sources |
36 | 38 |
|
37 | | -**GET** |
38 | | -``` |
39 | | -/api/data/forecast5?lat={latitude}&lon={longitude} |
40 | | -``` |
41 | | -Retrieves a 5-day weather forecast with 3-hour intervals for a specific location. Response is in standard JSON format |
| 39 | +--- |
42 | 40 |
|
43 | | -**GET** |
44 | | -``` |
45 | | -/api/linkeddata/forecast5?lat={latitude}&lon={longitude} |
46 | | -``` |
47 | | -Retrieves the same 5-day weather forecast with 3-hour intervals, but returns data in OCSM JSON-LD format |
| 41 | +## Quickstart |
| 42 | + |
| 43 | +### Requirements |
| 44 | + |
| 45 | +- `git` |
| 46 | +- `docker` |
| 47 | +- `docker-compose` |
| 48 | + |
| 49 | +### Installation |
| 50 | + |
| 51 | +## Clone repository: |
48 | 52 |
|
49 | | -**GET** |
| 53 | +```bash |
| 54 | +git clone https://github.com/openagri-eu/OpenAgri-WeatherService.git |
| 55 | +cd OpenAgri-WeatherService |
| 56 | +cp env.example .env |
50 | 57 | ``` |
51 | | -/api/data/thi?lat={latitude}&lon={longitude} |
| 58 | +You will then need to grab an api key for OpenWeatherMap API |
| 59 | + |
| 60 | +## Getting an OpenWeather API Key |
| 61 | + |
| 62 | +Some features of Weather Service use the [OpenWeather API](https://openweathermap.org/api). |
| 63 | +You’ll need your own API key to enable those calls. |
| 64 | + |
| 65 | +1. Create a free account at [openweathermap.org](https://home.openweathermap.org/users/sign_up). |
| 66 | +2. After signing up, go to your [API keys page](https://home.openweathermap.org/api_keys). |
| 67 | +3. Copy the **default key** or generate a new one. |
| 68 | +4. Add it to your `.env` file: |
| 69 | + ```env |
| 70 | + WEATHER_SRV_OPENWEATHERMAP_API_KEY=your-api-key-here |
| 71 | + ``` |
| 72 | +## Build & Run the service |
| 73 | + |
| 74 | +```bash |
| 75 | +docker compose up |
52 | 76 | ``` |
53 | | -Provides the Temperature Humidity Index for a specific location in standard JSON format |
54 | 77 |
|
55 | | -**GET** |
| 78 | +By default, the API documentation is available at: |
| 79 | + |
| 80 | +http://127.0.0.1:8010/docs |
| 81 | + |
| 82 | +To build local docker image: |
| 83 | +```bash |
| 84 | +docker compose up --build |
56 | 85 | ``` |
57 | | -/api/linkeddata/thi?lat={latitude}&lon={longitude} |
| 86 | + |
| 87 | +## Authentication |
| 88 | + |
| 89 | +All API endpoints require a JWT. |
| 90 | + |
| 91 | +### Get a token |
| 92 | +Request a token using the dev credentials: |
| 93 | + |
| 94 | +```bash |
| 95 | +curl -X 'POST' \ |
| 96 | + 'http://localhost:8010/api/v1/auth/token' \ |
| 97 | + -H 'Content-Type: application/x-www-form-urlencoded' \ |
| 98 | + -d 'grant_type=&username=test&password=test&scope=&client_id=&client_secret=' |
58 | 99 | ``` |
59 | | -Provides the Temperature Humidity Index for a specific location in OCSM JSON-LD format |
60 | 100 |
|
61 | | -**GET** |
| 101 | +**Response:** |
| 102 | +```bash |
| 103 | +{"jwt_token": "<JWT>"} |
62 | 104 | ``` |
63 | | -/api/data/flight_forecast5/{uavmodel}?lat={latitude}&lon={longitude} |
| 105 | + |
| 106 | +**Use the token** |
| 107 | + |
| 108 | +Pass the token as a Bearer header: |
| 109 | +```bash |
| 110 | +TOKEN="<paste JWT here>" |
| 111 | +curl -s "http://127.0.0.1:8010/api/data/weather/?lat=35.0&lon=33.23/?lat=35.0&lon=33.23" \ |
| 112 | + -H "Authorization: Bearer $TOKEN" |
64 | 113 | ``` |
65 | | -Retrieves a 5-day flight forecast with 3-hour intervals for a specific UAV model at the given location. |
66 | | -Response is in standard JSON format |
67 | 114 |
|
68 | | -**GET** |
| 115 | +Tip: In Swagger UI (/docs), click Authorize and paste `Bearer <JWT>`. |
| 116 | + |
| 117 | +## API Overview |
| 118 | + |
| 119 | +### Forecasts |
| 120 | + |
| 121 | +- `GET /api/data/forecast5/?lat={lat}&lon={lon}` – 5-day forecast (3-hour intervals, JSON) |
| 122 | +- `GET /api/linkeddata/forecast5/?lat={lat}&lon={lon}` – 5-day forecast (JSON-LD/OCSM) |
| 123 | + |
| 124 | +### Temperature-Humidity Index (THI) |
| 125 | + |
| 126 | +- `GET /api/data/thi/?lat={lat}&lon={lon}` – THI (JSON) |
| 127 | +- `GET /api/linkeddata/thi/?lat={lat}&lon={lon}` – THI (JSON-LD/OCSM) |
| 128 | + |
| 129 | +### UAV Flight Forecast |
| 130 | + |
| 131 | +- `GET /api/data/flight_forecast5/{uavmodel}/?lat={lat}&lon={lon}` – 5-day UAV forecast (by model) |
| 132 | +- `GET /api/data/flight_forecast5/?lat={lat}&lon={lon}&uavmodels={model}&status_filter={status}` – 5-day UAV forecast (filterable) |
| 133 | + |
| 134 | +### Current Weather |
| 135 | + |
| 136 | +- `GET /api/data/weather/?lat={lat}&lon={lon}` – Current conditions (JSON) |
| 137 | + |
| 138 | +### Historical weather data |
| 139 | + |
| 140 | +- `POST /api/v1/history/hourly/` - Hourly history |
| 141 | +- `POST /api/v1/history/daily/` - Daily history |
| 142 | + |
| 143 | +--- |
| 144 | + |
| 145 | +## Documentation |
| 146 | + |
| 147 | +- Interactive API docs: [http://127.0.0.1:8010/docs](http://127.0.0.1:8010/docs) (Swagger UI) |
| 148 | +- Full OpenAPI specification (JSON + OCSM JSON-LD) available via endpoints |
| 149 | +- Use [Swagger Editor](https://editor.swagger.io/) to explore the API specification |
| 150 | + |
| 151 | +--- |
| 152 | + |
| 153 | +## Example Requests |
| 154 | + |
| 155 | +### Current Weather |
| 156 | + |
| 157 | +```bash |
| 158 | +curl "http://127.0.0.1:8010/api/data/weather?lat=35.2&lon=33.3" |
69 | 159 | ``` |
70 | | -/api/data/flight_forecast5?lat={latitude}&lon={longitude}&uavmodels={model}&status_filter={status} |
| 160 | +**Sample response:** |
| 161 | + |
| 162 | +```json |
| 163 | +{ |
| 164 | + "temperature": 28.5, |
| 165 | + "humidity": 62, |
| 166 | + "wind_speed": 4.2, |
| 167 | + "conditions": "Clear sky", |
| 168 | + "timestamp": "2025-09-18T12:00:00Z" |
| 169 | +} |
71 | 170 | ``` |
72 | | -Retrieves a 5-day flight forecast with 3-hour intervals for UAVs at a specific location. |
73 | | -You can filter results by UAV model types and status conditions. Response is in standard JSON format |
74 | 171 |
|
| 172 | +### 5-Day Forecast |
75 | 173 |
|
76 | | -**GET** |
| 174 | +```bash |
| 175 | +curl "http://127.0.0.1:8010/api/data/forecast5?lat=35.2&lon=33.3" |
77 | 176 | ``` |
78 | | -/api/data/weather?lat={latitude}&lon={longitude} |
| 177 | + |
| 178 | +### Daily history |
| 179 | +```bash |
| 180 | +curl -X POST "http://127.0.0.1:8010/api/v1/history/daily" \ |
| 181 | + -H "Content-Type: application/json" \ |
| 182 | + -d '{ |
| 183 | + "lat": 35.0, |
| 184 | + "lon": 33.2, |
| 185 | + "start": "2025-07-01", |
| 186 | + "end": "2025-07-03", |
| 187 | + "variables": ["temperature_2m_max", "temperature_2m_min"], |
| 188 | + "radius_km": 10 |
| 189 | + }' |
79 | 190 | ``` |
80 | | -Returns current weather conditions for a specific location in standard JSON format |
81 | 191 |
|
82 | | -Get a complete list of the OpenApi specification compatible with [OCSM](OCSM.md) and [JSON](API.md) |
| 192 | +## Contributing |
| 193 | + |
| 194 | +We welcome first-time contributions! |
83 | 195 |
|
84 | | -## Swagger Live Docs |
85 | | -Use the [Online Swagger Editor](https://editor-next.swagger.io/?url=https://raw.githubusercontent.com/agstack/openagri-weather-service/refs/heads/main/openapi.yml) to visualise the current API specification and documentation. |
| 196 | +See our [Contributing Guide](CONTRIBUTE.md) |
86 | 197 |
|
87 | | -## Contribute |
| 198 | +You can also open an issue to discuss ideas. |
88 | 199 |
|
89 | | -Please contanct the repository maintainer. |
| 200 | +Weather Service is part of OpenAgri project, building tools for agriculture & climate data. Your contribution helps farmers and researchers. |
90 | 201 |
|
91 | 202 | ## License |
92 | 203 |
|
93 | | -[European Union Public Licence](LICENSE) |
| 204 | +This project is licensed under the European Union Public Licence (EUPL) v1.2. |
| 205 | +See the [European Union Public Licence](LICENSE) file for details. |
94 | 206 |
|
95 | 207 |
|
96 | 208 |
|
|
0 commit comments