anom=False) pool = Pool(20) net.wavelet(1, 'y', pool=pool, cut=1) net.get_continuous_phase(pool=pool) print "wavelet done" net.get_phase_fluctuations(rewrite=True, pool=pool) print "fluctuations done" pool.close() pool.join() net.phase_fluctuations -= np.nanmean(net.phase_fluctuations, axis=0) net.get_adjacency_matrix(net.phase_fluctuations, method="L2", pool=None, use_queue=True, num_workers=20) net.save_net('networks/NCEP-SATannual-phase-fluctuations-adjmatL2.bin', only_matrix=True) print "L2 done" ## PHASE FLUCTUATIONS NETWORK correlation print "Computing MI knn..." net = ScaleSpecificNetwork(fname, 'air', date(1950, 1, 1), date(2016, 1, 1), None, None, None, 'monthly', anom=False) pool = Pool(20) net.wavelet(1, 'y', pool=pool, cut=1)
# cPickle.dump({'mean_phase_diff' : np.mean(phase_diffs, axis = 0).flatten(), # 'std_phase_diff' : np.std(phase_diffs, axis = 0, ddof = 1).flatten(), # 'var_phase_diff' : np.var(phase_diffs, axis = 0, ddof = 1).flatten()}, f, protocol = cPickle.HIGHEST_PROTOCOL) to_do = [['MIGAU', 8], ['MIGAU', 6]] for do in to_do: METHOD = do[0] PERIOD = do[1] print("computing for %d period using %s method" % (PERIOD, METHOD)) net = ScaleSpecificNetwork('/home/nikola/Work/phd/data/air.mon.mean.levels.nc', 'air', date(1958,1,1), date(2014,1,1), None, None, 0, 'monthly', anom = True) pool = Pool(WORKERS) net.wavelet(PERIOD, get_amplitude = False, pool = pool) print "wavelet on data done" pool.close() net.get_adjacency_matrix(net.phase, method = METHOD, pool = None, use_queue = True, num_workers = WORKERS) print "estimating adjacency matrix done" net.save_net('networks/NCEP-SATAsurface-phase-span-as-ERA-adjmat%s-scale%dyears.bin' % (METHOD, PERIOD), only_matrix = True) # print phase_diffs.shape # net.get_adjacency_matrix(phase_diffs, method = METHOD, pool = None, use_queue = True, num_workers = WORKERS) # net.save_net('networks/NCEP-ERA-phase-diff-adjmat%s-scale%dyears.bin' % (METHOD, PERIOD), only_matrix = True) # net.get_adjacency_matrix(net.phase, method = METHOD, pool = None, use_queue = True, num_workers = WORKERS) # print "estimating adjacency matrix done" # net.save_net('networks/ERA-SATAsurface-phase-adjmat%s-scale%dyears.bin' % (METHOD, PERIOD), only_matrix = True)
print("Computing networks using %s method..." % (method)) # phase if method in ['MIEQQ', 'MIGAU', 'MPC']: # net = ScaleSpecificNetwork(fname, 'air', date(1948,1,1), date(2016,1,1), None, None, level = 0, dataset = "NCEP", # sampling = 'monthly', anom = False) net = ScaleSpecificNetwork(fname, 't2m', date(1958,1,1), date(2014,1,1), None, None, level=None, pickled=True, sampling='monthly', anom=False) pool = Pool(NUM_WORKERS) # net.get_hilbert_phase_amp(period = 90, width = 12, pool = pool, cut = 1) net.wavelet(scale, period_unit='m', cut=2, pool=pool) pool.close() pool.join() net.get_adjacency_matrix(net.phase, method = method, pool = None, use_queue = True, num_workers = NUM_WORKERS) net.save_net('networks/ERA-SATsurface-scale%dmonths-phase-adjmat%s.bin' % (scale, method), only_matrix = True) # amplitude if method in ['MIEQQ', 'MIGAU', 'CORR']: # net = ScaleSpecificNetwork(fname, 'air', date(1948,1,1), date(2016,1,1), None, None, level = 0, dataset = "NCEP", # sampling = 'monthly', anom = False) net = ScaleSpecificNetwork(fname, 't2m', date(1958,1,1), date(2014,1,1), None, None, level=None, pickled=True, sampling='monthly', anom=False) pool = Pool(NUM_WORKERS) # net.get_hilbert_phase_amp(period = 90, width = 12, pool = pool, cut = 1) net.wavelet(scale, period_unit='m', cut=2, pool=pool) pool.close() pool.join() net.get_adjacency_matrix(net.amplitude, method = method, pool = None, use_queue = True, num_workers = NUM_WORKERS) net.save_net('networks/ERA-SATsurface-scale%dmonths-amplitude-adjmat%s.bin' % (scale, method), only_matrix = True)
None, level=0, dataset="NCEP", sampling='monthly', anom=False) pool = Pool(WORKERS) net.wavelet(period, period_unit="y", pool=pool, cut=2) print("wavelet on data done") pool.close() pool.join() net.get_adjacency_matrix_conditioned(nao_phase, use_queue=True, num_workers=WORKERS) print("estimating adjacency matrix done") net.save_net('networks/NCEP-SAT%dy-phase-adjmatCMIEQQcondNAOphase.bin' % (period), only_matrix=True) print("computing phase conditioned on NINO") nino_phase = load_nino34_wavelet_phase(date(1950, 1, 1), date(2014, 1, 1), period, False) net.get_adjacency_matrix_conditioned(nino_phase, use_queue=True, num_workers=WORKERS) print("estimating adjacency matrix done") net.save_net('networks/NCEP-SAT%dy-phase-adjmatCMIEQQcondNINOphase.bin' % (period), only_matrix=True) print("computing phase conditioned on sunspots") sunspot_phase = load_sunspot_number_phase(date(1950, 1, 1),
# net.get_adjacency_matrix_conditioned(nino34_phase, use_queue = True, num_workers = WORKERS) # print "estimating adjacency matrix done" # net.save_net('networks/NCEP-SAT%dy-phase-adjmatCMIEQQcondNINOphase.bin' % (PERIOD), only_matrix = True) print "computing phase conditioned on NAO" to_do = [4, 6, 11, 15] for PERIOD in to_do: nao_phase = load_NAOindex_wavelet_phase(date(1948, 1, 1), date(2014, 1, 1), True) net = ScaleSpecificNetwork( '/home/nikola/Work/phd/data/air.mon.mean.levels.nc', 'air', date(1950, 1, 1), date(2014, 1, 1), None, None, 0, 'monthly', anom=False) pool = Pool(WORKERS) net.wavelet(PERIOD, get_amplitude=False, pool=pool) print "wavelet on data done" pool.close() net.get_adjacency_matrix_conditioned(nao_phase, use_queue=True, num_workers=WORKERS) print "estimating adjacency matrix done" net.save_net('networks/NCEP-SAT%dy-phase-adjmatCMIEQQcondNAOphase.bin' % (PERIOD), only_matrix=True)
# fname = "/Users/nikola/work-ui/data/air.mon.mean.sig995.nc" ## PHASE FLUCTUATIONS NETWORK L2 dist. print "Computing L2 distance..." net = ScaleSpecificNetwork(fname, 'air', date(1950,1,1), date(2016,1,1), None, None, None, 'monthly', anom = False) pool = Pool(20) net.wavelet(1, 'y', pool = pool, cut = 1) net.get_continuous_phase(pool = pool) print "wavelet done" net.get_phase_fluctuations(rewrite = True, pool = pool) print "fluctuations done" pool.close() pool.join() net.phase_fluctuations -= np.nanmean(net.phase_fluctuations, axis = 0) net.get_adjacency_matrix(net.phase_fluctuations, method = "L2", pool = None, use_queue = True, num_workers = 20) net.save_net('networks/NCEP-SATannual-phase-fluctuations-adjmatL2.bin', only_matrix = True) print "L2 done" ## PHASE FLUCTUATIONS NETWORK correlation print "Computing MI knn..." net = ScaleSpecificNetwork(fname, 'air', date(1950,1,1), date(2016,1,1), None, None, None, 'monthly', anom = False) pool = Pool(20) net.wavelet(1, 'y', pool = pool, cut = 1) net.get_continuous_phase(pool = pool) print "wavelet done" net.get_phase_fluctuations(rewrite = True, pool = pool) print "fluctuations done" pool.close() pool.join() net.get_adjacency_matrix(net.phase_fluctuations, method = "CORR", pool = None, use_queue = True, num_workers = 20) net.save_net('networks/NCEP-SATannual-phase-fluctuations-adjmatCORR.bin', only_matrix = True)
None, 0, 'monthly', anom=False) pool = Pool(WORKERS) net.wavelet(PERIOD, get_amplitude=False, save_wavelet=True, pool=pool) print "wavelet on data done" pool.close() net.get_adjacency_matrix(net.wave, method=METHOD, pool=None, use_queue=True, num_workers=WORKERS) print "estimating adjacency matrix done" net.save_net('networks/NCEP-SATsurface-wave-adjmat%s-scale%dyears.bin' % (METHOD, PERIOD), only_matrix=True) print "computing SATA wavelet coherence..." to_do = [['WCOH', 4], ['WCOH', 6], ['WCOH', 8], ['WCOH', 11], ['WCOH', 15]] for do in to_do: METHOD = do[0] PERIOD = do[1] print("computing for %d period using %s method" % (PERIOD, METHOD)) net = ScaleSpecificNetwork( '/home/nikola/Work/phd/data/air.mon.mean.levels.nc', 'air', date(1948, 1, 1), date(2014, 1, 1), None, None,
None, 'monthly', anom=False) a = net.get_seasonality(detrend=True) surrs.copy_field(net) # surrs.construct_fourier_surrogates() # surrs.add_seasonality(a[0], a[1], a[2]) for num in range(NUM_SURRS): pool = Pool(20) surrs.construct_fourier_surrogates(pool=pool) surrs.add_seasonality(a[0], a[1], a[2]) net.data = surrs.get_surr() net.wavelet(1, 'y', pool=pool, cut=1) net.get_continuous_phase(pool=pool) print "wavelet done" net.get_phase_fluctuations(rewrite=True, pool=pool) print "fluctuations done" pool.close() pool.join() net.get_adjacency_matrix(net.phase_fluctuations, method="MIEQQ", pool=None, use_queue=True, num_workers=20) net.save_net( 'networks/NCEP-SATannual-phase-fluctuations-adjmatMIEQQ-bins=4-FTsurr%d.bin' % (num), only_matrix=True)
to_do_periods = [4, 6, 8, 11, 15] for period in to_do_periods: print("computing phase conditioned on NAO") nao_phase = load_NAOindex_wavelet_phase(date(1950,1,1), date(2014,1,1), period, False) net = ScaleSpecificNetwork('/home/nikola/Work/phd/data/air.mon.mean.levels.nc', 'air', date(1950,1,1), date(2014,1,1), None, None, level = 0, dataset="NCEP", sampling='monthly', anom=False) pool = Pool(WORKERS) net.wavelet(period, period_unit="y", pool=pool, cut=2) print("wavelet on data done") pool.close() pool.join() net.get_adjacency_matrix_conditioned(nao_phase, use_queue=True, num_workers=WORKERS) print("estimating adjacency matrix done") net.save_net('networks/NCEP-SAT%dy-phase-adjmatCMIEQQcondNAOphase.bin' % (period), only_matrix=True) print("computing phase conditioned on NINO") nino_phase = load_nino34_wavelet_phase(date(1950,1,1), date(2014,1,1), period, False) net.get_adjacency_matrix_conditioned(nino_phase, use_queue=True, num_workers=WORKERS) print("estimating adjacency matrix done") net.save_net('networks/NCEP-SAT%dy-phase-adjmatCMIEQQcondNINOphase.bin' % (period), only_matrix=True) print("computing phase conditioned on sunspots") sunspot_phase = load_sunspot_number_phase(date(1950,1,1), date(2014,1,1), period, False) net.get_adjacency_matrix_conditioned(sunspot_phase, use_queue=True, num_workers=WORKERS) print("estimating adjacency matrix done") net.save_net('networks/NCEP-SAT%dy-phase-adjmatCMIEQQcondSUNSPOTphase.bin' % (period), only_matrix=True) print("computing phase conditioned on PDO") pdo_phase = load_pdo_phase(date(1950,1,1), date(2014,1,1), period, False)
'air', date(1958, 1, 1), date(2014, 1, 1), None, None, 0, 'monthly', anom=True) pool = Pool(WORKERS) net.wavelet(PERIOD, get_amplitude=False, pool=pool) print "wavelet on data done" pool.close() net.get_adjacency_matrix(net.phase, method=METHOD, pool=None, use_queue=True, num_workers=WORKERS) print "estimating adjacency matrix done" net.save_net( 'networks/NCEP-SATAsurface-phase-span-as-ERA-adjmat%s-scale%dyears.bin' % (METHOD, PERIOD), only_matrix=True) # print phase_diffs.shape # net.get_adjacency_matrix(phase_diffs, method = METHOD, pool = None, use_queue = True, num_workers = WORKERS) # net.save_net('networks/NCEP-ERA-phase-diff-adjmat%s-scale%dyears.bin' % (METHOD, PERIOD), only_matrix = True) # net.get_adjacency_matrix(net.phase, method = METHOD, pool = None, use_queue = True, num_workers = WORKERS) # print "estimating adjacency matrix done" # net.save_net('networks/ERA-SATAsurface-phase-adjmat%s-scale%dyears.bin' % (METHOD, PERIOD), only_matrix = True)
methods = ['MIEQQ', 'MPC'] periods = [15, 11] for METHOD in methods: for PERIOD in periods: net = ScaleSpecificNetwork('/home/nikola/Work/phd/data/air.mon.mean.levels.nc', 'air', date(1948,1,1), date(2014,1,1), None, None, 0, 'monthly', anom = True) pool = Pool(3) net.wavelet(PERIOD, get_amplitude = False, pool = pool) pool.close() print "wavelet on data done" net.get_adjacency_matrix(net.phase, method = METHOD, pool = None, use_queue = True, num_workers = 3) print "estimating adjacency matrix done" net.save_net('networks/NCEP-SATAsurface-adjmat%s-scale%dyears.bin' % (METHOD, PERIOD), only_matrix = True) WORKERS = 10 print "computing SAT amplitude data networks..." to_do = [['MIEQQ', 4], ['MIEQQ', 6], ['MIEQQ', 8], ['MIEQQ', 11], ['MIEQQ', 15], ['MIGAU', 4], ['MIGAU', 6], ['MIGAU', 8], ['MIGAU', 11], ['MIGAU', 15]] for do in to_do: METHOD = do[0] PERIOD = do[1] print("computing for %d period using %s method" % (PERIOD, METHOD)) net = ScaleSpecificNetwork('/home/nikola/Work/phd/data/air.mon.mean.levels.nc', 'air', date(1948,1,1), date(2014,1,1), None, None, 0, 'monthly', anom = False) pool = Pool(WORKERS) net.wavelet(PERIOD, get_amplitude = True, pool = pool) print "wavelet on data done"
None, 0, 'monthly', anom=True) pool = Pool(3) net.wavelet(PERIOD, get_amplitude=False, pool=pool) pool.close() print "wavelet on data done" net.get_adjacency_matrix(net.phase, method=METHOD, pool=None, use_queue=True, num_workers=3) print "estimating adjacency matrix done" net.save_net('networks/NCEP-SATAsurface-adjmat%s-scale%dyears.bin' % (METHOD, PERIOD), only_matrix=True) WORKERS = 10 print "computing SAT amplitude data networks..." to_do = [['MIEQQ', 4], ['MIEQQ', 6], ['MIEQQ', 8], ['MIEQQ', 11], ['MIEQQ', 15], ['MIGAU', 4], ['MIGAU', 6], ['MIGAU', 8], ['MIGAU', 11], ['MIGAU', 15]] for do in to_do: METHOD = do[0] PERIOD = do[1] print("computing for %d period using %s method" % (PERIOD, METHOD)) net = ScaleSpecificNetwork( '/home/nikola/Work/phd/data/air.mon.mean.levels.nc', 'air',
NUM_SURRS = 1 # fname = '/home/nikola/Work/phd/data/air.mon.mean.sig995.nc' fname = "/Users/nikola/work-ui/data/air.mon.mean.sig995.nc" surrs = SurrogateField() net = ScaleSpecificNetwork(fname, 'air', date(1950,1,1), date(2016,1,1), None, None, None, 'monthly', anom = False) a = net.get_seasonality(detrend = True) surrs.copy_field(net) # surrs.construct_fourier_surrogates() # surrs.add_seasonality(a[0], a[1], a[2]) for num in range(NUM_SURRS): pool = Pool(20) surrs.construct_fourier_surrogates(pool = pool) surrs.add_seasonality(a[0], a[1], a[2]) net.data = surrs.get_surr() net.wavelet(1, 'y', pool = pool, cut = 1) net.get_continuous_phase(pool = pool) print "wavelet done" net.get_phase_fluctuations(rewrite = True, pool = pool) print "fluctuations done" pool.close() pool.join() net.get_adjacency_matrix(net.phase_fluctuations, method = "MIEQQ", pool = None, use_queue = True, num_workers = 20) net.save_net('networks/NCEP-SATannual-phase-fluctuations-adjmatMIEQQ-bins=4-FTsurr%d.bin' % (num), only_matrix = True)
print "computing SAT wavelet coherence..." to_do = [['WCOH', 4], ['WCOH', 6], ['WCOH', 8], ['WCOH', 11], ['WCOH', 15]] for do in to_do: METHOD = do[0] PERIOD = do[1] print("computing for %d period using %s method" % (PERIOD, METHOD)) net = ScaleSpecificNetwork('/home/nikola/Work/phd/data/air.mon.mean.levels.nc', 'air', date(1948,1,1), date(2014,1,1), None, None, 0, 'monthly', anom = False) pool = Pool(WORKERS) net.wavelet(PERIOD, get_amplitude = False, save_wavelet = True, pool = pool) print "wavelet on data done" pool.close() net.get_adjacency_matrix(net.wave, method = METHOD, pool = None, use_queue = True, num_workers = WORKERS) print "estimating adjacency matrix done" net.save_net('networks/NCEP-SATsurface-wave-adjmat%s-scale%dyears.bin' % (METHOD, PERIOD), only_matrix = True) print "computing SATA wavelet coherence..." to_do = [['WCOH', 4], ['WCOH', 6], ['WCOH', 8], ['WCOH', 11], ['WCOH', 15]] for do in to_do: METHOD = do[0] PERIOD = do[1] print("computing for %d period using %s method" % (PERIOD, METHOD)) net = ScaleSpecificNetwork('/home/nikola/Work/phd/data/air.mon.mean.levels.nc', 'air', date(1948,1,1), date(2014,1,1), None, None, 0, 'monthly', anom = True) pool = Pool(WORKERS) net.wavelet(PERIOD, get_amplitude = False, save_wavelet = True, pool = pool) print "wavelet on data done" pool.close()
# print "computing phase conditioned on NINO3.4" # to_do = [6, 8, 11, 15] # for PERIOD in to_do: # nino34_phase = load_nino34_wavelet_phase(date(1948,1,1), date(2014,1,1), True) # net = ScaleSpecificNetwork('/home/nikola/Work/phd/data/air.mon.mean.levels.nc', 'air', # date(1948,1,1), date(2014,1,1), None, None, 0, 'monthly', anom = False) # pool = Pool(WORKERS) # net.wavelet(PERIOD, get_amplitude = False, pool = pool) # print "wavelet on data done" # pool.close() # net.get_adjacency_matrix_conditioned(nino34_phase, use_queue = True, num_workers = WORKERS) # print "estimating adjacency matrix done" # net.save_net('networks/NCEP-SAT%dy-phase-adjmatCMIEQQcondNINOphase.bin' % (PERIOD), only_matrix = True) print "computing phase conditioned on NAO" to_do = [4, 6, 11, 15] for PERIOD in to_do: nao_phase = load_NAOindex_wavelet_phase(date(1948,1,1), date(2014,1,1), True) net = ScaleSpecificNetwork('/home/nikola/Work/phd/data/air.mon.mean.levels.nc', 'air', date(1950,1,1), date(2014,1,1), None, None, 0, 'monthly', anom = False) pool = Pool(WORKERS) net.wavelet(PERIOD, get_amplitude = False, pool = pool) print "wavelet on data done" pool.close() net.get_adjacency_matrix_conditioned(nao_phase, use_queue = True, num_workers = WORKERS) print "estimating adjacency matrix done" net.save_net('networks/NCEP-SAT%dy-phase-adjmatCMIEQQcondNAOphase.bin' % (PERIOD), only_matrix = True)