Skip to content

Commit

Permalink
feat: Add draft of get_air_pollution
Browse files Browse the repository at this point in the history
  • Loading branch information
danfke committed Jan 18, 2022
1 parent 520c5f7 commit b167a08
Showing 1 changed file with 42 additions and 2 deletions.
44 changes: 42 additions & 2 deletions src/airpyllution/airpyllution.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import requests
from airpyllution.utils import *
import plotly.express as px

# import constants
OPEN_WEATHER_MAP_URL = 'http://api.openweathermap.org/data/2.5/air_pollution/'
Expand Down Expand Up @@ -106,12 +107,50 @@ def get_air_pollution(lat, lon, api_key):
OpenWeather API key
Returns
-------
altair.Chart
plotly.graph_objs._figure.Figure
Examples
--------
>>> get_air_pollution(49.2497, -123.1193, "APIKEY_example")
"""
if not isinstance(lat, float):
return "Latitude input should be a float"

if not isinstance(lon, float):
return "Longitude input should be a float"

if not isinstance(start_date, int):
return "start_date input should be an int"

if not isinstance(end_date, int):
return "end_date input should be an int"

url = 'http://api.openweathermap.org/data/2.5/air_pollution?' + 'history'
params = {
'lat': lat,
'lon': lon,
'appid': api_key
}

response = requests.get(url=url, params=params)
response_obj = response.json()

data = convert_data_to_pandas(response_obj)
data = data.melt(
id_vars=['lon', 'lat'],
value_vars = ['co', 'no', 'no2', 'o3', 'so2', 'pm2_5', 'nh3']
)

fig = px.scatter_geo(
data,
lon="lon",
lat="lat",
color="variable",
hover_name="variable",
size="value",
projection="natural earth",
)
return fig

def get_pollution_forecast(lat, lon, api_key):
"""Returns a time series plot showing predicted pollutant levels for the next 5 days.
Expand All @@ -138,4 +177,5 @@ def get_pollution_forecast(lat, lon, api_key):
Examples
--------
>>> get_pollution_forecast(50, 50, "APIKEY_example")
"""
"""

0 comments on commit b167a08

Please sign in to comment.