def load(**kwargs): """ Load data and compute some features **kwargs can be used to pass arguments to atddm.load """ dd = atddm.load(**kwargs) for df in dd.values(): df['national'] = (df['START'].apply(lambda x: x[:2]) == df['END'].apply(lambda x: x[:2])).astype(int) df['continental'] = df['START'].apply(lambda x: x[0]).isin(['E', 'L'])\ * abs(1-df['national']) df['intercontinental'] = 1 - df['national'] - df['continental'] onedayinsecs = 24 * 3600 for df in dd.values(): # df['day_part'] = df['M1_FL240'].dt.time.apply(categorize_time) m1_time = to_seconds(df['M1_FL240'].dt) df['time_cos'] = np.cos(m1_time * 2 * np.pi / onedayinsecs) df['time_sin'] = np.sin(m1_time * 2 * np.pi / onedayinsecs) weekday = df['M1_FL240'].dt.weekday df['weekday_cos'] = np.cos(weekday * 2 * np.pi / 7) df['weekday_sin'] = np.sin(weekday * 2 * np.pi / 7) df['week'] = df['M1_FL240'].dt.week df['dayno'] = df['M1_FL240'].dt.dayofyear df['delay_sec'] = df['delay'] / pd.Timedelta(1, unit='s') return dd
PRFIX = './../publications/talk_plots/' else: sns.set(style="whitegrid", context='paper') PRFIX = './../plots/' def rgbfy(code): return list(map(lambda x: x / 255, COLORS[code])) BEGDT = pd.Timestamp(BEGDT) ENDDT = pd.Timestamp(ENDDT) # ENDDT = BEGDT + pd.Timedelta(21, 'D') INTERVAL = 10 dd = atddm.load(subset=CODES) m3_bin = {} nairp = len(CODES) CODES.sort() for code in CODES: indx = pd.date_range(start=BEGDT, end=ENDDT, freq=str(INTERVAL) + 'min', tz=TZONES[code]) m3_bin[code] = atddm.binarrivals(dd[code].M3_FL240, interval=INTERVAL, tz=TZONES[code])[indx].fillna(0) if TRGT == 'talk': f, axes = plt.subplots(2, nairp // 2, sharey=False)