h0 = f.root.dh_mean_xcal[:] h = f.root.dh_mean_xcal_interp_short_const[:] #h = f.root.dh_mean_short_const_xcal[:] h2 = f.root.dh_mean_xcal_short_const[:] #h2 = f.root.dh_mean_short_const_xcal[:] g = f.root.dg_mean_xcal[:] g2 = f.root.dg_mean_xcal[:] dt = ap.year2date(time) # add interpolated grid-cells ind = np.where(~np.isnan(h2)) h[ind] = h2[ind] # gaussian filter (in space) print 'smoothing seasonal fields...' h = ap.gfilter2d(h, .5) # array -> panel -> dataframe data = pd.Panel(h, items=dt, major_axis=lat, minor_axis=lon).to_frame(filter_observations=False).T # HP filter (in time) print 'applying HP filter...' #hpfilt = data.apply(hpfilter, lamb=7) hpfilt = data # split data n = int(len(hpfilt) / 4.) hpfilt1 = hpfilt.T.to_panel().values[0 * n:1 * n, ...] hpfilt2 = hpfilt.T.to_panel().values[1 * n:2 * n, ...] hpfilt3 = hpfilt.T.to_panel().values[2 * n:3 * n, ...]
h = f.root.dh_mean_xcal_interp_short_const[:] #h = f.root.dh_mean_short_const_xcal[:] h2 = f.root.dh_mean_xcal_short_const[:] #h2 = f.root.dh_mean_short_const_xcal[:] g = f.root.dg_mean_xcal[:] g2 = f.root.dg_mean_xcal[:] dt = ap.year2date(time) # add interpolated grid-cells ind = np.where(~np.isnan(h2)) h[ind] = h2[ind] # gaussian filter (in space) print 'smoothing seasonal fields...' h = ap.gfilter2d(h, .5) # array -> panel -> dataframe data = pd.Panel(h, items=dt, major_axis=lat, minor_axis=lon ).to_frame(filter_observations=False).T # annual averages (forward-backward) ''' print 'calculating annual averages...' ann1 = pd.rolling_mean(data, 5, min_periods=3, center=True) ann2 = pd.rolling_mean(data[::-1], 5, min_periods=3, center=True)[::-1] annual = ann1.combine_first(ann2).T.to_panel().values del ann1, ann2 ''' # HP filter (in time)
h = f.root.dh_mean_xcal_interp_short_const[:] # h = f.root.dh_mean_short_const_xcal[:] h2 = f.root.dh_mean_xcal_short_const[:] # h2 = f.root.dh_mean_short_const_xcal[:] g = f.root.dg_mean_xcal[:] g2 = f.root.dg_mean_xcal[:] dt = ap.year2date(time) # add interpolated grid-cells ind = np.where(~np.isnan(h2)) h[ind] = h2[ind] # gaussian filter (in space) print "smoothing seasonal fields..." h = ap.gfilter2d(h, 0.5) # array -> panel -> dataframe data = pd.Panel(h, items=dt, major_axis=lat, minor_axis=lon).to_frame(filter_observations=False).T # HP filter (in time) print "applying HP filter..." # hpfilt = data.apply(hpfilter, lamb=7) hpfilt = data # split data n = int(len(hpfilt) / 4.0) hpfilt1 = hpfilt.T.to_panel().values[0 * n : 1 * n, ...] hpfilt2 = hpfilt.T.to_panel().values[1 * n : 2 * n, ...] hpfilt3 = hpfilt.T.to_panel().values[2 * n : 3 * n, ...] hpfilt4 = hpfilt.T.to_panel().values[3 * n : -1, ...]
h0 = f.root.dh_mean_xcal[:] h = f.root.dh_mean_xcal_interp_short_const[:] #h = f.root.dh_mean_short_const_xcal[:] h2 = f.root.dh_mean_xcal_short_const[:] #h2 = f.root.dh_mean_short_const_xcal[:] g = f.root.dg_mean_xcal[:] g2 = f.root.dg_mean_xcal[:] dt = ap.year2date(time) # add interpolated grid-cells ind = np.where(~np.isnan(h2)) h[ind] = h2[ind] # gaussian filter (in space) print 'smoothing seasonal fields...' h = ap.gfilter2d(h, .5) # array -> panel -> dataframe data = pd.Panel(h, items=dt, major_axis=lat, minor_axis=lon).to_frame(filter_observations=False).T # annual averages (forward-backward) ''' print 'calculating annual averages...' ann1 = pd.rolling_mean(data, 5, min_periods=3, center=True) ann2 = pd.rolling_mean(data[::-1], 5, min_periods=3, center=True)[::-1] annual = ann1.combine_first(ann2).T.to_panel().values del ann1, ann2 ''' # HP filter (in time)