A python library for interacting with the OpenEPI data
Project description
openepi-client
A python client for accessing data from OpenEPI. Can be installed from PyPI on https://pypi.org/project/openepi-client/
Table of Contents
Weather
Sync usage
from openepi_client import GeoLocation
from openepi_client.weather import WeatherClient
# Getting the sunrise and sunset times for a location
sunrise_sunset = WeatherClient.get_sunrise(geolocation=GeoLocation(lat=51.5074, lon=0.1278))
# Getting the weather forecast for a location
forecast = WeatherClient.get_location_forecast(geolocation=GeoLocation(lat=51.5074, lon=0.1278, alt=0))
Async usage
from openepi_client import GeoLocation
from openepi_client.weather import AsyncWeatherClient
# Getting the sunrise and sunset times for a location
sunrise_sunset = await AsyncWeatherClient.get_sunrise(geolocation=GeoLocation(lat=51.5074, lon=0.1278))
# Getting the weather forecast for a location
forecast = await AsyncWeatherClient.get_location_forecast(geolocation=GeoLocation(lat=51.5074, lon=0.1278, alt=0))
Geocoding
Sync usage
from openepi_client import GeoLocation
from openepi_client.geocoding import GeocodeClient
# Searching for the coordinates to a named place
feature_collection = GeocodeClient.geocode(q="Kigali, Rwanda")
# Geocode with priority to a lat and lon
feature_collection = GeocodeClient.geocode(q="Kigali, Rwanda", geolocation=GeoLocation(lat=51.5074, lon=0.1278))
# Reverse geocode
feature_collection = GeocodeClient.reverse_geocode(geolocation=GeoLocation(lat=51.5074, lon=0.1278))
Async usage
from openepi_client import GeoLocation
from openepi_client.geocoding import AsyncGeocodeClient
# Searching for coordinates for a location
feature_collection = await AsyncGeocodeClient.geocode(q="Kigali, Rwanda")
# Geocode with priority to a lat and lon
feature_collection = await AsyncGeocodeClient.geocode(q="Kigali, Rwanda", geolocation=GeoLocation(lat=51.5074, lon=0.1278))
# Reverse geocode
feature_collection = await AsyncGeocodeClient.reverse_geocode(geolocation=GeoLocation(lat=51.5074, lon=0.1278))
Flood
Sync usage
from openepi_client import GeoLocation, BoundingBox
from openepi_client.flood import FloodClient
from datetime import date, timedelta
# Get the return period thresholds for a given geolocation
thresholds = FloodClient.get_threshold(geolocation=GeoLocation(lat=-3.422, lon=30.075))
# Get the return period thresholds for a given bounding box
thresholds = FloodClient.get_threshold(bounding_box=BoundingBox(min_lat=4.764412, min_lon=22.0, max_lat=5.015732, max_lon=23.05))
# Get a summary flood forecast for a given coordinate
summary = FloodClient.get_summary(geolocation=GeoLocation(lat=-3.422, lon=30.075))
# Get a summary flood forecast for a given coordinate and include neighboring cells
summary = FloodClient.get_summary(geolocation=GeoLocation(lat=-3.422, lon=30.075), include_neighbors=True)
# Get a summary flood forecast for a given bounding box
summary = FloodClient.get_summary(bounding_box=BoundingBox(min_lat=4.764412, min_lon=22.0, max_lat=5.015732, max_lon=23.05))
# Get a detailed flood forecast for a given coordinate
detailed = FloodClient.get_detailed(geolocation=GeoLocation(lat=-3.422, lon=30.075))
# Get a detailed flood forecast for a given coordinate and timeframe (inclusive bounds)
start_date = date.today()
end_date = start_date + timedelta(days=4)
detailed = FloodClient.get_detailed(geolocation=GeoLocation(lat=-3.422, lon=30.075), start_date=start_date, end_date=end_date)
# Get a detailed flood forecast for a given bounding box
detailed = FloodClient.get_detailed(bounding_box=BoundingBox(min_lat=4.764412, min_lon=22.0, max_lat=5.015732, max_lon=23.05))
Async usage
from openepi_client import GeoLocation, BoundingBox
from openepi_client.flood import AsyncFloodClient
from datetime import date, timedelta
# Get the return period thresholds for a given geolocation
thresholds = await AsyncFloodClient.get_threshold(geolocation=GeoLocation(lat=-3.422, lon=30.075))
# Get the return period thresholds for a given bounding box
thresholds = await AsyncFloodClient.get_threshold(bounding_box=BoundingBox(min_lat=4.764412, min_lon=22.0, max_lat=5.015732, max_lon=23.05))
# Get a summary flood forecast for a given coordinate
summary = await AsyncFloodClient.get_summary(geolocation=GeoLocation(lat=-3.422, lon=30.075))
# Get a summary flood forecast for a given coordinate and include neighboring cells
summary = await AsyncFloodClient.get_summary(geolocation=GeoLocation(lat=-3.422, lon=30.075), include_neighbors=True)
# Get a summary flood forecast for a given bounding box
summary = await AsyncFloodClient.get_summary(bounding_box=BoundingBox(min_lat=4.764412, min_lon=22.0, max_lat=5.015732, max_lon=23.05))
# Get a detailed flood forecast for a given coordinate
detailed = await AsyncFloodClient.get_detailed(geolocation=GeoLocation(lat=-3.422, lon=30.075))
# Get a detailed flood forecast for a given coordinate and timeframe (inclusive bounds)
start_date = date.today()
end_date = start_date + timedelta(days=4)
detailed = await AsyncFloodClient.get_detailed(geolocation=GeoLocation(lat=-3.422, lon=30.075), start_date=start_date, end_date=end_date)
# Get a detailed flood forecast for a given bounding box
detailed = await AsyncFloodClient.get_detailed(bounding_box=BoundingBox(min_lat=4.764412, min_lon=22.0, max_lat=5.015732, max_lon=23.05))
Deforestation
Sync usage
from openepi_client import GeoLocation, BoundingBox
from openepi_client.deforestation import DeforestationClient
# Get the yearly forest cover loss within a river basin for a given geolocation
forest_loss = DeforestationClient.get_basin(geolocation=GeoLocation(lat=5.175, lon=37.124))
# Get yearly forest cover loss for all river basins within the given bounding box
forest_loss = DeforestationClient.get_basin(bounding_box=BoundingBox(min_lat=30.909622, min_lon=28.850951, max_lat=-1.041395, max_lon=-2.840114))
Async usage
from openepi_client import GeoLocation, BoundingBox
from openepi_client.deforestation import AsyncDeforestationClient
# Get the yearly forest cover loss within a river basin for a given geolocation
forest_loss = await AsyncDeforestationClient.get_basin(geolocation=GeoLocation(lat=5.175, lon=37.124))
# Get yearly forest cover loss for all river basins within the given bounding box
forest_loss = await AsyncDeforestationClient.get_basin(bounding_box=BoundingBox(min_lat=30.909622, min_lon=28.850951, max_lat=-1.041395, max_lon=-2.840114))
Soil
Sync usage
from openepi_client import GeoLocation, BoundingBox
from openepi_client.soil import SoilClient
# Get the most probable soil type at the queried location
# and the probability of the top 4 most probable soil types
soil_type = SoilClient.get_soil_type(
geolocation=GeoLocation(lat=60.1, lon=9.58),
top_k=4
)
# Get the mean and the 0.05 quantile of the soil
# properties at the queried location and depths
properties = ["clay", "silt"]
depths = ["0-5cm", "5-15cm"]
values = ["mean", "Q0.05"]
soil_property = SoilClient.get_soil_property(
geolocation=GeoLocation(lat=60.1, lon=9.58),
depths=depths,
properties=properties,
values=values
)
# Get a summary of the soil types in the queried bounding box,
# represented by a mapping of each soil type to the number
# of occurrences in the bounding box
soil_type_summary = SoilClient.get_soil_type_summary(
bounding_box=BoundingBox(
min_lat=60.1,
max_lat=60.12,
min_lon=9.58,
max_lon=9.6,
)
)
Async usage
from openepi_client import GeoLocation, BoundingBox
from openepi_client.soil import AsyncSoilClient
# Get the most probable soil type at the queried location
# and the probability of the top 4 most probable soil types
soil_type = await AsyncSoilClient.get_soil_type(
geolocation=GeoLocation(lat=60.1, lon=9.58),
top_k=4
)
# Get the mean and the 0.05 quantile of the soil
# properties at the queried location and depths
properties = ["clay", "silt"]
depths = ["0-5cm", "5-15cm"]
values = ["mean", "Q0.05"]
soil_property = await AsyncSoilClient.get_soil_property(
geolocation=GeoLocation(lat=60.1, lon=9.58),
depths=depths,
properties=properties,
values=values
)
# Get a summary of the soil types in the queried bounding box,
# represented by a mapping of each soil type to the number
# of occurrences in the bounding box
soil_type_summary = await AsyncSoilClient.get_soil_type_summary(
bounding_box=BoundingBox(
min_lat=60.1,
max_lat=60.12,
min_lon=9.58,
max_lon=9.6,
)
)
Crop Health
Sync usage
import os
from openepi_client.crop_health import CropHealthClient
image_path = os.path.abspath("cocoa.jpg")
# Get the predicted health of the crop pictured in cocoa.jpg with the binary model.
with open(image_path, "rb") as f:
image_data = f.read()
health = CropHealthClient.get_binary_prediction(image_data)
# Get the predicted health of the crop pictured in cocoa.jpg with the single-HLT model.
with open(image_path, "rb") as f:
image_data = f.read()
health = CropHealthClient.get_singleHLT_prediction(image_data)
# Get the predicted health of the crop pictured in cocoa.jpg with the multi-HLT model.
with open(image_path, "rb") as f:
image_data = f.read()
health = CropHealthClient.get_multiHLT_prediction(image_data)
Async usage
import os
from openepi_client.crop_health import AsyncCropHealthClient
image_path = os.path.abspath("cocoa.jpg")
# Get the predicted health of the crop pictured in cocoa.jpg with the binary model.
with open(image_path, "rb") as f:
image_data = f.read()
health = await AsyncCropHealthClient.get_binary_prediction(image_data)
# Get the predicted health of the crop pictured in cocoa.jpg with the single-HLT model.
with open(image_path, "rb") as f:
image_data = f.read()
health = await AsyncCropHealthClient.get_singleHLT_prediction(image_data)
# Get the predicted health of the crop pictured in cocoa.jpg with the multi-HLT model.
with open(image_path, "rb") as f:
image_data = f.read()
health = await AsyncCropHealthClient.get_multiHLT_prediction(image_data)
Updating the client
The following commands are used to update the client types. The commands are run from the root of the project.
poetry run datamodel-codegen --url https://api.openepi.io/weather/openapi.json --output openepi_client/weather/_weather_types.py --enum-field-as-literal all --output-model-type pydantic_v2.BaseModel --input-file-type "openapi"
poetry run datamodel-codegen --url https://api.openepi.io/geocoding/openapi.json --output openepi_client/geocoding/_geocoding_types.py --enum-field-as-literal all --output-model-type pydantic_v2.BaseModel --input-file-type "openapi"
poetry run datamodel-codegen --url https://api.openepi.io/flood/openapi.json --output openepi_client/flood/_flood_types.py --enum-field-as-literal all --output-model-type pydantic_v2.BaseModel --input-file-type "openapi"
poetry run datamodel-codegen --url https://api.openepi.io/deforestation/openapi.json --output openepi_client/deforestation/_deforestation_types.py --enum-field-as-literal all --output-model-type pydantic_v2.BaseModel --input-file-type "openapi"
poetry run datamodel-codegen --url https://api.openepi.io/soil/openapi.json --output openepi_client/soil/_soil_types.py --enum-field-as-literal all --output-model-type pydantic_v2.BaseModel --input-file-type "openapi"
poetry run datamodel-codegen --url https://api.openepi.io/crop-health/openapi.json --output openepi_client/crop_health/_crop_health_types.py --enum-field-as-literal all --output-model-type pydantic_v2.BaseModel --input-file-type "openapi"
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
openepi_client-0.1.15.tar.gz
(24.6 kB
view details)
Built Distribution
File details
Details for the file openepi_client-0.1.15.tar.gz
.
File metadata
- Download URL: openepi_client-0.1.15.tar.gz
- Upload date:
- Size: 24.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4c7c956eee3aaf31e2fa6b63e611676903952b5935c22be7edea92bc261e47f8 |
|
MD5 | 0d328dffdf31560d6fbac093c1f3fd4f |
|
BLAKE2b-256 | bbe27ed3db2bca4afd578b06fd27341844f25a91b2a9ef4040a70c7afd41ff64 |
File details
Details for the file openepi_client-0.1.15-py3-none-any.whl
.
File metadata
- Download URL: openepi_client-0.1.15-py3-none-any.whl
- Upload date:
- Size: 32.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 56392f2a9ae9d0bff4b21a5d1ceb313671d794899d89cfeef929200a442ed0f1 |
|
MD5 | 8765416520e35fc7c146e84de6de3015 |
|
BLAKE2b-256 | 5af9b01b63d0828681a4d4f909f632c2670d1e7c5e6af5d1dd34c24ed9e8994b |