Created
June 9, 2022 17:35
-
-
Save sergiolucero/0c75b94e1bd85275c07dc9d9699b171a to your computer and use it in GitHub Desktop.
aire región Concón-Quintero-Puchuncaví
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import openaq | |
import pandas as pd | |
api = openaq.OpenAQ() # fuente: www.openaq.org | |
cdf = api.cities(country='CL', df=True) | |
cdf = cdf[cdf.city.isin(['Quintero','Concón','Puchuncaví'])] | |
xdf = pd.concat([api.measurements(city=city, df=True, limit=1000) | |
for city in cdf.city]) | |
xdf.index.name='fecha' | |
xdf = xdf.rename(columns={'coordinates.latitude': 'lat', | |
'coordinates.longitude': 'lon'}) | |
import seaborn as sns | |
import matplotlib.pyplot as plt | |
sns.set_theme(style="darkgrid") | |
fig, ax = plt.subplots(1, figsize=(30,10)) | |
con=xdf[xdf.parameter=='so2'].reset_index() | |
con['location'] = con.location+':'+con.city | |
con = con[con['fecha']>'2022-06-03'] | |
md = con['fecha'].median(); | |
maxima=con[con.value==con.value.max()] | |
tag='%s:%.1f ' %(maxima['location'].values[0],maxima['value'].values) | |
sns.lineplot(data=con, x='fecha', y='value', hue='location'); | |
plt.axhline(y=150, color='r', linestyle='-', linewidth=5); #24h | |
plt.axhline(y=350, color='orange', linestyle='-', linewidth=5); # 1h | |
plt.text(md, 150+10, 'norma 24h (Chile)', color='blue', size=18, weight='bold'); | |
plt.text(md, 350+10, 'norma 1h (Chile)', color='purple', size=18, weight='bold'); | |
plt.text(maxima['fecha'], maxima['value'], f"{tag}", size=18, color='r', weight='bold') | |
plt.title('Evolución reciente SO2 Concon-Quintero-Puchuncaví [µg/m3] (Fuente: OpenAQ + Quant.cl)', size=24); | |
plt.legend(loc=1,prop={'size': 18}); |
Author
sergiolucero
commented
Jun 9, 2022
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment