예제 #1
0
# net = ScaleSpecificNetwork('%sair.mon.mean.levels.nc' % path_to_data, 'air', 
#                            date(1949,1,1), date(2015,1,1), None, None, 0, dataset = "NCEP", sampling = 'monthly', anom = False)

# net = ScaleSpecificNetwork('%sERA/ERAconcat.t2m.mon.means.1958-2014.bin' % path_to_data, 't2m', 
                       # date(1958,1,1), date(2015,1,1), None, None, None, 'monthly', anom = False, pickled = True)

# net_surrs = ScaleSpecificNetwork('%sERAconcat.t2m.mon.means.1958-2014.bin' % path_to_data, 't2m', 
#                        date(1958,1,1), date(2015,1,1), None, None, None, 'monthly', anom = False, pickled = True)

# net = ScaleSpecificNetwork('%s20CR/20CR.t2m.mon.nc' % path_to_data, 't2m', 
                           # date(1949,1,1), date(2011,1,1), None, None, dataset = "ERA", sampling = 'monthly', anom = False)

# net_surrs = ScaleSpecificNetwork('%sair.mon.mean.levels.nc' % path_to_data, 'air', 
                           # date(1949,1,1), date(2015,1,1), None, None, 0, dataset = "NCEP", sampling = 'monthly', anom = False)

net = ScaleSpecificNetwork('%sECAD.tg.daily.nc' % path_to_data, 'tg', date(1950, 1, 1), date(2015,1,1), None, 
    None, None, dataset = 'ECA-reanalysis', anom = False)
net.get_monthly_data()
print net.data.shape
print net.get_date_from_ndx(0), net.get_date_from_ndx(-1)


# surr_field = SurrogateField()
# a = net.get_seasonality(detrend = True)
# surr_field.copy_field(net)
# net.return_seasonality(a[0], a[1], a[2])

def _hilbert_ssa(args):
    i, j, data = args
    if not np.any(np.isnan(data)):
        ssa = ssa_class(data, M = 12)
        _, _, _, rc = ssa.run_ssa()
예제 #2
0

# 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)
예제 #3
0
from src.data_class import DataField
from src.surrogates import get_single_FT_surrogate
from scipy.stats import pearsonr
import cPickle


# path_to_data = "/Users/nikola/work-ui/data/"
path_to_data = "/home/nikola/Work/phd/data/"

NUM_SURR = 1000
NUM_WORKERS = 20




net = ScaleSpecificNetwork('%sair.mon.mean.levels.nc' % path_to_data, 'air', 
                            date(1948,1,1), date(2016,1,1), None, None, 0, dataset = "NCEP", sampling = 'monthly', anom = False)

pool = Pool(NUM_WORKERS)
net.wavelet(1, 'y', pool = pool, cut = 1)
net.get_continuous_phase(pool = pool)
net.get_phase_fluctuations(rewrite = True, pool = pool)
pool.close()
pool.join()

nao = DataField()
raw = np.loadtxt("%sNAO.station.monthly.1865-2016.txt" % (path_to_data))
raw = raw[:, 1:]
nao.data = raw.reshape(-1)
nao.create_time_array(date_from = date(1865, 1, 1), sampling = 'm')
nao.select_date(date(1949, 1, 1), date(2015, 1, 1))
nao.anomalise()
예제 #4
0
import h5py
import numpy as np
import pyclits as clt
from scale_network import ScaleSpecificNetwork
import matplotlib.pyplot as plt
from datetime import date
plt.style.use('ipython')

net = ScaleSpecificNetwork(
    '/Users/nikola/work-ui/data/NCEP/air.mon.mean.levels.nc',
    'air',
    date(1950, 1, 1),
    date(2014, 1, 1),
    None,
    None,
    level=0,
    dataset="NCEP",
    sampling='monthly',
    anom=False)

t**s = ["NAO", "NINO3.4", "sunspot #", "PDO"]
with h5py.File("networks/phase_synch_eqq_bins=8_all_periods.h5") as hf:
    to_do_periods = np.arange(2, 15.5, 0.5)
    for period in to_do_periods:
        plt.figure(figsize=(15, 7))
        synch = hf['period_%.1fy' % (period)][:]
        for i, tit in zip(range(synch.shape[0]), t**s):
            plt.subplot(2, 2, i + 1)
            vmax, vmin = np.nanmax(synch), np.nanmin(synch)
            net.quick_render(field_to_plot=synch[i, ...],
                             tit=tit,
예제 #5
0
# import matplotlib.pyplot as plt
import src.wavelet_analysis as wvlt
import numpy as np
from src.surrogates import SurrogateField


NUM_SURR = 1000

# fname = "/Users/nikola/work-ui/data/NCEP/air.mon.mean.levels.nc"
fname = "/home/nikola/Work/phd/data/air.mon.mean.levels.nc"
net = ScaleSpecificNetwork(
    fname,
    "air",
    date(1948, 1, 1),
    date(2016, 1, 1),
    [-60, 0],
    [40, 100],
    level=0,
    dataset="NCEP",
    sampling="monthly",
    anom=False,
)

surrs = SurrogateField()
a = net.get_seasonality(detrend=True)
surrs.copy_field(net)
net.return_seasonality(a[0], a[1], a[2])

pool = Pool(20)
net.wavelet(8, "y", cut=1, pool=pool)
net.get_adjacency_matrix(net.phase, method="MIEQQ", num_workers=0, pool=pool, use_queue=False)
pool.close()
예제 #6
0
    return g.phase.copy()


WORKERS = 20
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' %
예제 #7
0
path_to_data = "/Users/nikola/work-ui/data"
# path_to_data = "/home/nikola/Work/phd/data"

# def _get_MI(args):

#     i, j, ph1, ph2 = args

#     # return i, j, MI.mutual_information(ph1, ph2, 'EQQ2', bins = 16)
#     return i, j, MI.knn_mutual_information(ph1, ph2, k = 32, dualtree = True)

net = ScaleSpecificNetwork('%s/NCEP/air.mon.mean.levels.nc' % path_to_data,
                           'air',
                           date(1950, 1, 1),
                           date(2015, 1, 1),
                           None,
                           None,
                           0,
                           dataset="NCEP",
                           sampling='monthly',
                           anom=True)

# nao = DataField()
# raw = np.loadtxt("%s/NAO.monthly.1950-2016.txt" % (path_to_data))
# nao.data = raw[:, 2]

# nao.create_time_array(date_from = date(1950, 1, 1), sampling = 'm')
# nao.select_date(date(1950, 1, 1), date(2015, 1, 1))
# nao.anomalise()

# nao.wavelet(8, 'y', cut = 1)
# pool = Pool(5)
예제 #8
0
from scale_network import ScaleSpecificNetwork
from datetime import date
from pathos.multiprocessing import Pool
import numpy as np
from src.data_class import DataField
import csv
import matplotlib.pyplot as plt
import src.wavelet_analysis as wvlt


fname = '/home/nikola/Work/phd/data/air.mon.mean.sig995.nc'
# 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..."
    # nino_s = clt.knn_mutual_information(ph, nino, k=128)
    # sunspot_s = clt.knn_mutual_information(ph, sunspots, k=128)
    # pdo_s = clt.knn_mutual_information(ph, pdo, k=128)
    nao_s = clt.mutual_information(ph, nao, algorithm='EQQ2', bins=8)
    nino_s = clt.mutual_information(ph, nino, algorithm='EQQ2', bins=8)
    sunspot_s = clt.mutual_information(ph, sunspots, algorithm='EQQ2', bins=8)
    pdo_s = clt.mutual_information(ph, pdo, algorithm='EQQ2', bins=8)

    return (i, j, nao_s, nino_s, sunspot_s, pdo_s)


WORKERS = 5
NUM_SURRS = 100
to_do_periods = np.arange(2,15.5,0.5)
net = ScaleSpecificNetwork('/Users/nikola/work-ui/data/NCEP/air.mon.mean.levels.nc', 
                                    'air', date(1950,1,1), date(2014,1,1), None, None, 
                                    level = 0, dataset="NCEP", sampling='monthly', anom=False)

synchronization = {}
for period in to_do_periods:
    print("running for %.1f period..." % (period))
    _, nao_ph, sg_nao, a_nao = load_NAOindex_wavelet_phase(date(1950,1,1), date(2014,1,1), period, anom=False)
    _, nino_ph, sg_nino, a_nino = load_nino34_wavelet_phase(date(1950,1,1), date(2014,1,1), period, anom=False)
    _, sunspots_ph, sg_sunspots, a_sunspots = load_sunspot_number_phase(date(1950,1,1), date(2014,1,1), period, anom=False)
    _, pdo_ph, sg_pdo, a_pdo = load_pdo_phase(date(1950,1,1), date(2014,1,1), period, anom=False)
    pool = Pool(WORKERS)
    net.wavelet(period, period_unit='y', cut=2, pool=pool)
    args = [(net.phase[:, i, j], i, j, nao_ph, nino_ph, sunspots_ph, pdo_ph) for i in range(net.lats.shape[0]) for j in range(net.lons.shape[0])]
    result = pool.map(_compute_MI_synch, args)
    synchs = np.zeros((4, net.lats.shape[0], net.lons.shape[0]))
    synchs_surrs = np.zeros((NUM_SURRS, 4, net.lats.shape[0], net.lons.shape[0]))
예제 #10
0
    nino_s = clt.mutual_information(ph, nino, algorithm='EQQ2', bins=8)
    sunspot_s = clt.mutual_information(ph, sunspots, algorithm='EQQ2', bins=8)
    pdo_s = clt.mutual_information(ph, pdo, algorithm='EQQ2', bins=8)

    return (i, j, nao_s, nino_s, sunspot_s, pdo_s)


WORKERS = 5
NUM_SURRS = 100
to_do_periods = np.arange(2, 15.5, 0.5)
net = ScaleSpecificNetwork(
    '/Users/nikola/work-ui/data/NCEP/air.mon.mean.levels.nc',
    'air',
    date(1950, 1, 1),
    date(2014, 1, 1),
    None,
    None,
    level=0,
    dataset="NCEP",
    sampling='monthly',
    anom=False)

synchronization = {}
for period in to_do_periods:
    print("running for %.1f period..." % (period))
    _, nao_ph, sg_nao, a_nao = load_NAOindex_wavelet_phase(date(1950, 1, 1),
                                                           date(2014, 1, 1),
                                                           period,
                                                           anom=False)
    _, nino_ph, sg_nino, a_nino = load_nino34_wavelet_phase(date(1950, 1, 1),
                                                            date(2014, 1, 1),
예제 #11
0
# date(1958,1,1), date(2015,1,1), None, None, None, 'monthly', anom = False, pickled = True)

# net_surrs = ScaleSpecificNetwork('%sERAconcat.t2m.mon.means.1958-2014.bin' % path_to_data, 't2m',
#                        date(1958,1,1), date(2015,1,1), None, None, None, 'monthly', anom = False, pickled = True)

# net = ScaleSpecificNetwork('%s20CR/20CR.t2m.mon.nc' % path_to_data, 't2m',
# date(1949,1,1), date(2011,1,1), None, None, dataset = "ERA", sampling = 'monthly', anom = False)

# net_surrs = ScaleSpecificNetwork('%sair.mon.mean.levels.nc' % path_to_data, 'air',
# date(1949,1,1), date(2015,1,1), None, None, 0, dataset = "NCEP", sampling = 'monthly', anom = False)

net = ScaleSpecificNetwork('%sECAD.tg.daily.nc' % path_to_data,
                           'tg',
                           date(1950, 1, 1),
                           date(2015, 1, 1),
                           None,
                           None,
                           None,
                           dataset='ECA-reanalysis',
                           anom=False)
net.get_monthly_data()
print net.data.shape
print net.get_date_from_ndx(0), net.get_date_from_ndx(-1)

# surr_field = SurrogateField()
# a = net.get_seasonality(detrend = True)
# surr_field.copy_field(net)
# net.return_seasonality(a[0], a[1], a[2])


def _hilbert_ssa(args):
예제 #12
0
varnorms = [True, False]
detrends = [True, False]
cos = [True, False]

for per in periods:
    for var in varnorms:
        for det in detrends:
            for c in cos:
                print(
                    "computing for %d period with %s for varnorm, %s for detrend and %s for cosweighting"
                    % (per, str(var), str(det), str(c)))
                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)
                if var:
                    net.get_seasonality(det)

                if not var and det:
                    continue

                if c:
                    net.data *= net.latitude_cos_weights()

                pool = Pool(3)
                net.wavelet(per, get_amplitude=True, pool=pool)
import numpy as np
from src.data_class import DataField
import csv
import matplotlib.pyplot as plt
import src.wavelet_analysis as wvlt
from src.surrogates import SurrogateField


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"
예제 #14
0
import h5py
import numpy as np
import pyclits as clt
from scale_network import ScaleSpecificNetwork
import matplotlib.pyplot as plt
from datetime import date
plt.style.use('ipython')

net = ScaleSpecificNetwork('/Users/nikola/work-ui/data/NCEP/air.mon.mean.levels.nc', 
                                    'air', date(1950,1,1), date(2014,1,1), None, None, 
                                    level = 0, dataset="NCEP", sampling='monthly', anom=False)

t**s = ["NAO", "NINO3.4", "sunspot #", "PDO"]
with h5py.File("networks/phase_synch_eqq_bins=8_all_periods.h5") as hf:
    to_do_periods = np.arange(2,15.5,0.5)
    for period in to_do_periods:
        plt.figure(figsize=(15,7))
        synch = hf['period_%.1fy' % (period)][:]
        for i, tit in zip(range(synch.shape[0]), t**s):
            plt.subplot(2,2,i+1)
            vmax, vmin = np.nanmax(synch), np.nanmin(synch)
            net.quick_render(field_to_plot=synch[i, ...], tit=tit, symm=False, whole_world=True, subplot=True,
                                cmap='hot', vminmax=[vmin,0.8*vmax], extend = "max")

        plt.suptitle("SYNCHRONIZATION SAT vs. X: %.1fyr phase [eqq 8]" % (period))
        plt.savefig("networks/plots-synch/SATphase_synch%.1fyr_phase_eqq8.png" % (period), bbox_inches='tight')

예제 #15
0
from scale_network import ScaleSpecificNetwork
from datetime import date
from multiprocessing import Pool
import matplotlib.pyplot as plt
import numpy as np

         
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))
예제 #16
0
#     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)
예제 #17
0
from src.data_class import DataField
from src.surrogates import get_single_FT_surrogate
from scipy.stats import pearsonr
import cPickle

# path_to_data = "/Users/nikola/work-ui/data/"
path_to_data = "/home/nikola/Work/phd/data/"

NUM_SURR = 1000
NUM_WORKERS = 20

net = ScaleSpecificNetwork('%sair.mon.mean.levels.nc' % path_to_data,
                           'air',
                           date(1948, 1, 1),
                           date(2015, 1, 1),
                           None,
                           None,
                           0,
                           dataset="NCEP",
                           sampling='monthly',
                           anom=False)

pool = Pool(NUM_WORKERS)
net.wavelet(1, 'y', pool=pool, cut=1)
net.get_continuous_phase(pool=pool)
net.get_phase_fluctuations(rewrite=True, pool=pool)
pool.close()
pool.join()

nao = DataField()
raw = np.loadtxt("%sWeMO.monthly.1821-2013.txt" % (path_to_data))
raw = raw[:, 1:]
예제 #18
0
#         pool.close()
#         for i, j, res in job_result:
#             autocoherence[i, j] = res
#         del job_result

#         with open("networks/NCEP-SATAsurface-autocoherence-phase-scale%dyears-avg-to-%.1f.bin" % (PERIOD, AVG), "wb") as f:
#             cPickle.dump({'autocoherence' : autocoherence, 'lats' : net.lats, 'lons' : net.lons}, f, protocol = cPickle.HIGHEST_PROTOCOL)


if not PLOT:
    ## autocoherence filtered data - SATA
    print "computing autocoherence for SATA filtered data"
    for PERIOD in periods:
        for AVG in avg_to:
            print("computing for %d year period and averaging up to %d" % (PERIOD, 12*AVG*PERIOD))
            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 = True, pool = pool)
            print "wavelet on data done"
            net.get_filtered_data(pool = pool)
            print "filtered data acquired"
            autocoherence = np.zeros(net.get_spatial_dims())
            job_args = [ (i, j, int(AVG*12*PERIOD), net.filtered_data[:, i, j]) for i in range(net.lats.shape[0]) for j in range(net.lons.shape[0]) ]
            job_result = pool.map(_get_autocoherence, job_args)
            del job_args
            pool.close()
            for i, j, res in job_result:
                autocoherence[i, j] = res
            del job_result

            with open("networks/NCEP-SATAsurface-autocoherence-filtered-scale%dyears-avg-to-%.1f.bin" % (PERIOD, AVG), "wb") as f:
예제 #19
0
    if anom:
        g.anomalise()

    g.wavelet(period, period_unit="y", cut=2)

    return g.phase.copy()


WORKERS = 20
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)
예제 #20
0
# pool.join()
# net.get_adjacency_matrix(net.phase, method = 'MPC', pool = None, use_queue = True, num_workers = NUM_WORKERS)
# net.save_net('networks/NCEP-SATsurface-7-8yrs-Hilb-phase-adjmat%s.bin' % ('MPC'), only_matrix = True)


for method in METHODS:

    for scale in SCALES:

        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)
예제 #21
0

for per in periods:
    for var in varnorms:
        for det in detrends:
            for c in cos:
                print(
                    "computing for %d period with %s for varnorm, %s for detrend and %s for cosweighting"
                    % (per, str(var), str(det), str(c))
                )
                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,
                )
                if var:
                    net.get_seasonality(det)

                if not var and det:
                    continue

                if c:
                    net.data *= net.latitude_cos_weights()

                pool = Pool(3)
import numpy as np
from src.data_class import DataField
import csv
import matplotlib.pyplot as plt
import src.wavelet_analysis as wvlt

fname = '/home/nikola/Work/phd/data/air.mon.mean.sig995.nc'
# 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",
예제 #23
0
import matplotlib.pyplot as plt
import numpy as np

WORKERS = 10

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' %
예제 #24
0
#         with open("networks/NCEP-SATAsurface-autocoherence-phase-scale%dyears-avg-to-%.1f.bin" % (PERIOD, AVG), "wb") as f:
#             cPickle.dump({'autocoherence' : autocoherence, 'lats' : net.lats, 'lons' : net.lons}, f, protocol = cPickle.HIGHEST_PROTOCOL)

if not PLOT:
    ## autocoherence filtered data - SATA
    print "computing autocoherence for SATA filtered data"
    for PERIOD in periods:
        for AVG in avg_to:
            print("computing for %d year period and averaging up to %d" %
                  (PERIOD, 12 * AVG * PERIOD))
            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=True, pool=pool)
            print "wavelet on data done"
            net.get_filtered_data(pool=pool)
            print "filtered data acquired"
            autocoherence = np.zeros(net.get_spatial_dims())
            job_args = [(i, j, int(AVG * 12 * PERIOD), net.filtered_data[:, i,
                                                                         j])
                        for i in range(net.lats.shape[0])
                        for j in range(net.lons.shape[0])]
            job_result = pool.map(_get_autocoherence, job_args)
예제 #25
0
from pathos.multiprocessing import Pool
# import matplotlib.pyplot as plt
import src.wavelet_analysis as wvlt
import numpy as np
from src.surrogates import SurrogateField

NUM_SURR = 1000

# fname = "/Users/nikola/work-ui/data/NCEP/air.mon.mean.levels.nc"
fname = "/home/nikola/Work/phd/data/air.mon.mean.levels.nc"

net = ScaleSpecificNetwork(fname,
                           'air',
                           date(1948, 1, 1),
                           date(2016, 1, 1),
                           None,
                           None,
                           level=0,
                           dataset="NCEP",
                           sampling='monthly',
                           anom=False)

surrs = SurrogateField()
a = net.get_seasonality(detrend=True)
surrs.copy_field(net)
net.return_seasonality(a[0], a[1], a[2])

pool = Pool(20)
net.wavelet(8, 'y', cut=1, pool=pool)
net.get_adjacency_matrix(net.phase,
                         method="MIEQQ",
                         num_workers=20,
예제 #26
0
#     import cPickle
#     with open("networks/NCEPxERA-phase-diffs%d.bin" % (PERIOD), "wb") as f:
#         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)
예제 #27
0
import matplotlib.pyplot as plt
import src.wavelet_analysis as wvlt
from src.surrogates import SurrogateField

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()
예제 #28
0
import matplotlib.pyplot as plt


path_to_data = "/Users/nikola/work-ui/data"
# path_to_data = "/home/nikola/Work/phd/data"


# def _get_MI(args):

#     i, j, ph1, ph2 = args

#     # return i, j, MI.mutual_information(ph1, ph2, 'EQQ2', bins = 16)
#     return i, j, MI.knn_mutual_information(ph1, ph2, k = 32, dualtree = True)


net = ScaleSpecificNetwork('%s/NCEP/air.mon.mean.levels.nc' % path_to_data, 'air', 
                           date(1950,1,1), date(2015,1,1), None, None, 0, dataset = "NCEP", sampling = 'monthly', anom = True)


# nao = DataField()
# raw = np.loadtxt("%s/NAO.monthly.1950-2016.txt" % (path_to_data))
# nao.data = raw[:, 2]

# nao.create_time_array(date_from = date(1950, 1, 1), sampling = 'm')
# nao.select_date(date(1950, 1, 1), date(2015, 1, 1))
# nao.anomalise()

# nao.wavelet(8, 'y', cut = 1)
# pool = Pool(5)
# net.wavelet(8, 'y', pool = pool, cut = 1)

# print nao.phase.shape, net.phase.shape
예제 #29
0
from scale_network import ScaleSpecificNetwork
from datetime import date
import numpy as np
import cPickle
from src.surrogates import get_p_vals


net = ScaleSpecificNetwork('/Users/nikola/work-ui/data/NCEP/air.mon.mean.levels.nc', 'air', 
                           date(1949,1,1), date(2015,1,1), None, None, 0, sampling = 'monthly', anom = False)

# net.quick_render(t = 0)

# net = ScaleSpecificNetwork('/Users/nikola/work-ui/data/ERA/ERAconcat.t2m.mon.means.1958-2014.bin', 't2m', 
                       # date(1958,1,1), date(2015,1,1), None, None, None, 'monthly', anom = False, pickled = True)

# net = ScaleSpecificNetwork('/Users/nikola/work-ui/data/ECAD.tg.daily.nc', 'tg', date(1950, 1, 1), date(2015,1,1), None, 
#         None, None, dataset = 'ECA-reanalysis', anom = False)
# net.get_monthly_data()
print net.data.shape
print net.get_date_from_ndx(0), net.get_date_from_ndx(-1)


with open("../scale-nets/bins/WeMO-JFM_ann_means-NCEP-phase-fluc-1000FTsurrs-from-indices.bin", "rb") as f:
    surr_res = cPickle.load(f)

# INDICES = ['TNA', 'SOI', 'SCAND', 'PNA', 'PDO', 'EA', 'AMO', 'NAO', 'NINO3.4', 'TPI', 'SAM']
P_VAL = 0.05

data_corrs = surr_res['data']
surr_corrs = surr_res['surrs']