WINDOW_LENGTH = 16384 WINDOW_SHIFT = 1 # years, delta in the sliding window analysis MEANS = True # if True, compute conditional means, if False, compute conditional variance WORKERS = 16 NUM_SURR = 100 # how many surrs will be used to evaluate SURR_TYPE = 'AR' # MF, FT, AR diff_ax = (0, 2) # means -> 0, 2, var -> 1, 8 mean_ax = (18, 22) # means -> -1, 1.5, var -> 9, 18 PLOT_PHASE = False PHASE_ANALYSIS_YEAR = None # year of detailed analysis - phase and bins, or None AMPLITUDE = True ## loading data g = load_station_data('TG_STAID000027.txt', date(1834, 7, 28), date(2014, 1, 1), ANOMALISE) sg = SurrogateField() if AMPLITUDE: g_amp = load_station_data('TG_STAID000027.txt', date(1834, 7, 28), date(2014, 1, 1), False) sg_amp = SurrogateField() print( "[%s] Wavelet analysis in progress with %d year window shifted by %d year(s)..." % (str(datetime.now()), WINDOW_LENGTH, WINDOW_SHIFT)) k0 = 6. # wavenumber of Morlet wavelet used in analysis y = 365.25 # year in days fourier_factor = (4 * np.pi) / (k0 + np.sqrt(2 + np.power(k0, 2))) period = PERIOD * y # frequency of interest s0 = period / fourier_factor # get scale cond_means = np.zeros((8, ))
if NUM_SURR != 0: surr_completed = 0 diffs = np.zeros((NUM_SURR, )) mean_vars = np.zeros_like(diffs) g_surrs.data = g.data[start_idx:end_idx].copy() g_surrs.time = g.time[start_idx:end_idx].copy() if np.all(np.isnan(g_surrs.data) == False): # construct the job queue jobQ = Queue() resQ = Queue() for i in range(NUM_SURR): jobQ.put(1) for i in range(WORKERS): jobQ.put(None) a = g_surrs.get_seasonality(DETREND=True) sg = SurrogateField() sg.copy_field(g_surrs) if SURR_TYPE == 'AR': sg.prepare_AR_surrogates() workers = [ Process(target=_cond_difference_surrogates, args=(sg, g_surrs, a, start_cut, jobQ, resQ)) for iota in range(WORKERS) ] for w in workers: w.start() while surr_completed < NUM_SURR: # get result diff, meanVar = resQ.get() diffs[surr_completed] = diff mean_vars[surr_completed] = meanVar