sg.copy_field(g_for_avg) sg.prepare_AR_surrogates() year = 365.25 k0 = 6. # wavenumber of Morlet wavelet used in analysis fourier_factor = (4 * np.pi) / (k0 + np.sqrt(2 + np.power(k0, 2))) period = PERIOD * year # frequency of interest s0 = period / fourier_factor # get scale avg_bins_surr = np.zeros( (NUM_SURR, 8, 2)) # num surr x bin no. x result no. (hot / cold extremes) phase_bins = get_equidistant_bins() for surr in range(NUM_SURR): sg.construct_surrogates_with_residuals() sg.add_seasonality(mean[:-1], var[:-1], trend[:-1]) # so SAT data g_for_avg.data = sg.surr_data.copy() g_for_avg.time = g_for_avg.time[:-1] tg_temp = g_for_avg.copy_data() g_for_avg.anomalise() # SATA data for phase wave, _, _, _ = wvlt.continous_wavelet(g_for_avg.data, 1, False, wvlt.morlet, dj=0, s0=s0, j1=0, k0=k0) # perform wavelet phase = np.arctan2(np.imag(wave), np.real(wave)) # get phases from oscillatory modes
bins_surrogates = np.zeros((SU, NUM_SURR / NUM_FILES, sg.data.shape[1], sg.data.shape[2], 8)) bins_surrogates_var = np.zeros_like(bins_surrogates) for surr_completed in range(NUM_SURR / NUM_FILES): # create surrogates field if (SURR_TYPE == 'MF') or (SURR_TYPE == 'ALL' and su_type == 0): sg.construct_multifractal_surrogates(pool=pool) sg.add_seasonality(0, var, trend) elif (SURR_TYPE == 'FT') or (SURR_TYPE == 'ALL' and su_type == 1): sg.construct_fourier_surrogates_spatial(pool=pool) sg.add_seasonality(0, var, trend) elif (SURR_TYPE == 'AR') or (SURR_TYPE == 'ALL' and su_type == 2): sg.construct_surrogates_with_residuals(pool=pool) sg.add_seasonality(0, var[:-1, ...], trend[:-1, ...]) # oscillatory modes phase_surrs = np.zeros_like(sg.surr_data) job_args = [(i, j, s0, sg.surr_data[:, i, j]) for i in range(sg.lats.shape[0]) for j in range(sg.lons.shape[0])] job_result = map_func(_get_oscillatory_modes, job_args) del job_args # map results for i, j, ph in job_result: phase_surrs[:, i, j] = ph del job_result if AMPLITUDE:
# g_for_avg are SAT data mean, var, trend = g_for_avg.get_seasonality(detrend = True) sg.copy_field(g_for_avg) sg.prepare_AR_surrogates() year = 365.25 k0 = 6. # wavenumber of Morlet wavelet used in analysis fourier_factor = (4 * np.pi) / (k0 + np.sqrt(2 + np.power(k0,2))) period = PERIOD * year # frequency of interest s0 = period / fourier_factor # get scale avg_bins_surr = np.zeros((NUM_SURR, 8, 2)) # num surr x bin no. x result no. (hot / cold extremes) phase_bins = get_equidistant_bins() for surr in range(NUM_SURR): sg.construct_surrogates_with_residuals() sg.add_seasonality(mean[:-1], var[:-1], trend[:-1]) # so SAT data g_for_avg.data = sg.surr_data.copy() g_for_avg.time = g_for_avg.time[:-1] tg_temp = g_for_avg.copy_data() g_for_avg.anomalise() # SATA data for phase wave, _, _, _ = wvlt.continous_wavelet(g_for_avg.data, 1, False, wvlt.morlet, dj = 0, s0 = s0, j1 = 0, k0 = k0) # perform wavelet phase = np.arctan2(np.imag(wave), np.real(wave)) # get phases from oscillatory modes avg_ndx = g_for_avg.select_date(date(1844, 4, 14), date(1926,1,1)) phase = phase[0, avg_ndx] tg_temp = tg_temp[avg_ndx] sigma = np.std(tg_temp, axis = 0, ddof = 1) for i in range(phase_bins.shape[0] - 1):
map_func = map for su_type in range(SU): for file_num in range(NUM_FILES): bins_surrogates = np.zeros((SU, NUM_SURR/NUM_FILES, sg.data.shape[1], sg.data.shape[2], 8)) bins_surrogates_var = np.zeros_like(bins_surrogates) for surr_completed in range(NUM_SURR/NUM_FILES): # create surrogates field if (SURR_TYPE == 'MF') or (SURR_TYPE == 'ALL' and su_type == 0): sg.construct_multifractal_surrogates(pool = pool) sg.add_seasonality(0, var, trend) elif (SURR_TYPE == 'FT') or (SURR_TYPE == 'ALL' and su_type == 1): sg.construct_fourier_surrogates_spatial(pool = pool) sg.add_seasonality(0, var, trend) elif (SURR_TYPE == 'AR') or (SURR_TYPE == 'ALL' and su_type == 2): sg.construct_surrogates_with_residuals(pool = pool) sg.add_seasonality(0, var[:-1, ...], trend[:-1, ...]) # oscillatory modes phase_surrs = np.zeros_like(sg.surr_data) job_args = [ (i, j, s0, sg.surr_data[:, i, j]) for i in range(sg.lats.shape[0]) for j in range(sg.lons.shape[0]) ] job_result = map_func(_get_oscillatory_modes, job_args) del job_args # map results for i, j, ph in job_result: phase_surrs[:, i, j] = ph del job_result if AMPLITUDE: # surrogates are now SATA, for amplitude we need SAT so plus mean, times 1 var, plus 0 trend if SURR_TYPE == 'MF' or SURR_TYPE == 'FT':