Closed mikaelhg closed 1 year ago
Since the Wiki went away, I'm adding a full Python example of the use of the FMI opendata timeseries endpoint as an issue.
import requests import datetime import pandas as pd import numpy as np end_time = datetime.datetime.utcnow() start_time = end_time - datetime.timedelta(days=1) aq_fields = { 'fmisid': np.int32, 'time': np.datetime64, 'AQINDEX_PT1H_avg': np.float64, 'PM10_PT1H_avg': np.float64, 'PM25_PT1H_avg': np.float64, 'O3_PT1H_avg': np.float64, 'CO_PT1H_avg': np.float64, 'SO2_PT1H_avg': np.float64, 'NO2_PT1H_avg': np.float64, 'TRSC_PT1H_avg': np.float64, } url = 'https://opendata.fmi.fi/timeseries' params = { 'format': 'json', 'precision': 'double', 'groupareas': '0', 'producer': 'airquality_urban', 'area': 'Uusimaa', 'param': ','.join(aq_fields.keys()), 'starttime': start_time.isoformat(timespec="seconds"), 'endtime': end_time.isoformat(timespec="seconds"), 'tz': 'UTC', } data = requests.get(url, params=params).json() df = pd.DataFrame(data).astype(aq_fields) #df = df.set_index(['fmisid', 'time'])
Merged elsewhere.
Since the Wiki went away, I'm adding a full Python example of the use of the FMI opendata timeseries endpoint as an issue.