Beispiel #1
0
from London import *
import datetime

#API Key comes from your account on the opensensors platform
API_KEY = ''
#the days to look back
lookback = 2
#the first date we try and get data 
start_date = (datetime.datetime.now() + datetime.timedelta(days=-lookback)).strftime("%Y%m%d")
#the last date defaults to today
end_date =datetime.datetime.now().strftime("%Y%m%d")

#create instance of Air Quality Object
opensensor = London(API_KEY)

AQ_mtx = opensensor.getAirQuality(start=start_date,end=end_date)

Bike_mtx, Bike_meta_data = opensensor.getTFLBikes(start_date,end_date)

Roads_mtx, Roads_meta_data = opensensor.getTFLRoads(start_date,end_date)

Tubes_mtx = opensensor.getTFLTube(start_date,end_date)
Beispiel #2
0
with open(LAQN_file) as f:
    reader = csv.reader(f)
    LAQN_locations = dict((rows[0],[float(rows[1]),float(rows[2])]) for rows in reader)

def moving_average_convergence(x, nslow=8, nfast=4):
    """
    wrap the method in the London object so we can use apply
    """
    NO2_emafast,NO2_emaslow,NO2_macd = opensensor.getMovingAverageConvergence(x, nslow, nfast)
    return pandas.Series(NO2_macd)

#get the list of LAQN measures
LAQN_mtx = opensensor.getAirQuality(start=start_date,end=end_date)

#get bike data
bikes_mtx, bikes_metadata = opensensor.getTFLBikes((datetime.datetime.now() + datetime.timedelta(days=-1)).strftime("%Y%m%d"),end_date)


coverage_day = LAQN_mtx['NO2'].transpose().apply(np.isnan).sum()/LAQN_mtx['NO2'].transpose().apply(np.isnan).count() 
NO2 = LAQN_mtx['NO2'][coverage_day < 0.2]

coverage_sensor = NO2.apply(np.isnan).sum()/NO2.apply(np.isnan).count() 

NO2 = NO2.transpose()[coverage_sensor < 0.2].transpose()

mean_daily_variance = NO2.groupby(lambda x: (x.date)).std()

for row in mean_daily_variance.index:
    if mean_daily_variance.mean(1)[row] < 1:
        valid_dates = NO2.index[NO2.index.date != row]
        NO2 = NO2.transpose()[valid_dates].transpose()
Beispiel #3
0
import pandas 
import datetime

lookback = 2

#API Key comes from your account on the opensensors platform
API_KEY = ''
#the first date we try and get data 
start_date = (datetime.datetime.now() + datetime.timedelta(days=-lookback)).strftime("%Y%m%d")
#the last date defaults to today
end_date =datetime.datetime.now().strftime("%Y%m%d")

#create instance of Air Quality Object
opensensor = London(API_KEY)

#initiated the list of days for which well have a list of measures
BikeData = pandas.DataFrame(columns = ['name', 'level_1', 'value'])
BikeMetaData = {}

todays_matrix, todays_metadata = opensensor.getTFLBikes(start_date,end_date)

#lose dupes
todays_matrix = todays_matrix[~todays_matrix.duplicated(['name', 'level_1', 'value'])]
#lose NA
todays_matrix = todays_matrix.dropna(subset=['name', 'level_1', 'value'], how='any')
#reset the index
todays_matrix = todays_matrix.reset_index(drop=True)
#pivot into all the locations
bike_mtx = todays_matrix.pivot(index='level_1', columns='name', values='value')