예제 #1
0
def _cmi_surrogates(a):
    aa, aa_surr, aa_seas, temp, temp_surr, temp_seas, scales = a
    aa_surr.construct_fourier_surrogates_spatial()
    aa_surr.amplitude_adjust_surrogates(aa_seas[0], aa_seas[1], aa_seas[2])
    # aa_surr.construct_surrogates_with_residuals()
    # aa_surr.add_seasonality(aa_seas[0][:-1], aa_seas[1][:-1], aa_seas[2][:-1])

    cmi1 = []
    cmi2 = []

    for sc in scales:
        temp.wavelet(sc, period_unit = 'd')
        phase_temp = temp.phase.copy()

        phase_aa_surr = temp.wavelet(sc, period_unit = 'd', ts = aa_surr.surr_data)[0]

        # cmi1
        tmp = []
        for tau in range(1,30):
            x, y, z = mi.get_time_series_condition([phase_temp, phase_aa_surr], tau = tau, dim_of_condition = 1, eta = 1, phase_diff = True)
            tmp.append(mi.cond_mutual_information(x, y, z, algorithm = 'EQQ2', bins = 8, log2 = False))
        cmi1.append(np.mean(np.array(tmp)))

        # cmi2
        tmp = []
        for tau in range(1,30):
            x, y, z = mi.get_time_series_condition([phase_aa_surr, phase_temp], tau = tau, dim_of_condition = 1, eta = 1, phase_diff = True)
            tmp.append(mi.cond_mutual_information(x, y, z, algorithm = 'EQQ2', bins = 8, log2 = False))
        cmi2.append(np.mean(np.array(tmp)))

    cmi1 = np.array(cmi1)
    cmi2 = np.array(cmi2)

    return cmi1, cmi2
예제 #2
0
def _cmi_surrogates(a):
    aa, aa_surr, aa_seas, temp, temp_surr, temp_seas, scales = a
    aa_surr.construct_fourier_surrogates_spatial()
    aa_surr.amplitude_adjust_surrogates(aa_seas[0], aa_seas[1], aa_seas[2])
    # aa_surr.construct_surrogates_with_residuals()
    # aa_surr.add_seasonality(aa_seas[0][:-1], aa_seas[1][:-1], aa_seas[2][:-1])

    cmi1 = []
    cmi2 = []

    for sc in scales:
        temp.wavelet(sc, period_unit='d')
        phase_temp = temp.phase.copy()

        phase_aa_surr = temp.wavelet(sc, period_unit='d',
                                     ts=aa_surr.surr_data)[0]

        # cmi1
        tmp = []
        for tau in range(1, 30):
            x, y, z = mi.get_time_series_condition([phase_temp, phase_aa_surr],
                                                   tau=tau,
                                                   dim_of_condition=1,
                                                   eta=1,
                                                   phase_diff=True)
            tmp.append(
                mi.cond_mutual_information(x,
                                           y,
                                           z,
                                           algorithm='EQQ2',
                                           bins=8,
                                           log2=False))
        cmi1.append(np.mean(np.array(tmp)))

        # cmi2
        tmp = []
        for tau in range(1, 30):
            x, y, z = mi.get_time_series_condition([phase_aa_surr, phase_temp],
                                                   tau=tau,
                                                   dim_of_condition=1,
                                                   eta=1,
                                                   phase_diff=True)
            tmp.append(
                mi.cond_mutual_information(x,
                                           y,
                                           z,
                                           algorithm='EQQ2',
                                           bins=8,
                                           log2=False))
        cmi2.append(np.mean(np.array(tmp)))

    cmi1 = np.array(cmi1)
    cmi2 = np.array(cmi2)

    return cmi1, cmi2
예제 #3
0
    def _process_matrix_cond(self, jobq, resq):
        
        while True:
            a = jobq.get() # get queued input

            if a is None: # if it is None, we are finished, put poison pill to resq
                break # break infinity cycle
            else:
                i, j, ph1, ph2, cond_ts = a # compute stuff
                resq.put((i, j, MI.cond_mutual_information(ph1, ph2, cond_ts, algorithm = 'EQQ2', bins = 4, log2 = False)))
예제 #4
0
def _cmi_surrogates(a):
    aa, aa_surr, aa_seas, temp, temp_surr, temp_seas, scales = a
    aa_surr.construct_fourier_surrogates_spatial()
    aa_surr.add_seasonality(aa_seas[0], aa_seas[1], aa_seas[2])


    cmi1 = []
    cmi2 = []

    for sc in scales:
        period = sc # frequency of interest in months
        s0 = period / fourier_factor # get scale
        wave_temp, _, _, _ = wvlt.continous_wavelet(temp.data, 1, False, wvlt.morlet, dj = 0, s0 = s0, j1 = 0, k0 = k0) # perform wavelet
        phase_temp = np.arctan2(np.imag(wave_temp), np.real(wave_temp))[0, 12:-12] # get phases from oscillatory modes

        wave_aa, _, _, _ = wvlt.continous_wavelet(aa_surr.surr_data, 1, False, wvlt.morlet, dj = 0, s0 = s0, j1 = 0, k0 = k0) # perform wavelet
        phase_aa_surr = np.arctan2(np.imag(wave_aa), np.real(wave_aa))[0, 12:-12] # get phases from oscillatory modes

        # cmi1
        tmp = []
        for tau in range(1,30):
            x, y, z = mi.get_time_series_condition([phase_temp, phase_aa_surr], tau = tau, dim_of_condition = 1, eta = 1, phase_diff = True)
            tmp.append(mi.cond_mutual_information(x, y, z, algorithm = 'EQQ2', bins = 4, log2 = False))
        cmi1.append(np.mean(np.array(tmp)))

        # cmi2
        tmp = []
        for tau in range(1,30):
            x, y, z = mi.get_time_series_condition([phase_aa_surr, phase_temp], tau = tau, dim_of_condition = 1, eta = 1, phase_diff = True)
            tmp.append(mi.cond_mutual_information(x, y, z, algorithm = 'EQQ2', bins = 4, log2 = False))
        cmi2.append(np.mean(np.array(tmp)))

    cmi1 = np.array(cmi1)
    cmi2 = np.array(cmi2)

    return cmi1, cmi2
예제 #5
0
            wave_temp, _, _, _ = wvlt.continous_wavelet(temp.data, 1, False, wvlt.morlet, dj = 0, s0 = s0, j1 = 0, k0 = k0) # perform wavelet
            phase_temp = np.arctan2(np.imag(wave_temp), np.real(wave_temp))[0, 12:-12] # get phases from oscillatory modes

            wave_aa, _, _, _ = wvlt.continous_wavelet(aa.data, 1, False, wvlt.morlet, dj = 0, s0 = s0, j1 = 0, k0 = k0) # perform wavelet
            phase_aa = np.arctan2(np.imag(wave_aa), np.real(wave_aa))[0, 12:-12] # get phases from oscillatory modes


            # mutual information coherence
            coherence.append(mi.mutual_information(phase_aa, phase_temp, algorithm = 'EQQ2', bins = 8, log2 = False))

            # cmi1
            # plt.figure()
            tmp = []
            for tau in range(1,30):
                x, y, z = mi.get_time_series_condition([phase_temp, phase_aa], tau = tau, dim_of_condition = 1, eta = 0, phase_diff = True)
                tmp.append(mi.cond_mutual_information(x, y, z, algorithm = 'EQQ2', bins = 4, log2 = False))
            cmi1.append(np.mean(np.array(tmp)))
            # plt.plot(tmp, label = "1->2")

            # cmi2
            tmp = []
            for tau in range(1,30):
                x, y, z = mi.get_time_series_condition([phase_aa, phase_temp], tau = tau, dim_of_condition = 1, eta = 0, phase_diff = True)
                tmp.append(mi.cond_mutual_information(x, y, z, algorithm = 'EQQ2', bins = 4, log2 = False))
            cmi2.append(np.mean(np.array(tmp)))
            # plt.plot(tmp, label = "2->1")
            # plt.legend()
            # plt.savefig("CMItesting%dmon.png" % sc)
            # plt.close()

            # wavelet coherence
예제 #6
0
def _cmi_surrogates(a):
    aa, aa_surr, aa_seas, temp, temp_surr, temp_seas, scales = a
    aa_surr.construct_fourier_surrogates_spatial()
    aa_surr.add_seasonality(aa_seas[0], aa_seas[1], aa_seas[2])

    cmi1 = []
    cmi2 = []

    for sc in scales:
        period = sc  # frequency of interest in months
        s0 = period / fourier_factor  # get scale
        wave_temp, _, _, _ = wvlt.continous_wavelet(temp.data,
                                                    1,
                                                    False,
                                                    wvlt.morlet,
                                                    dj=0,
                                                    s0=s0,
                                                    j1=0,
                                                    k0=k0)  # perform wavelet
        phase_temp = np.arctan2(
            np.imag(wave_temp),
            np.real(wave_temp))[0, 12:-12]  # get phases from oscillatory modes

        wave_aa, _, _, _ = wvlt.continous_wavelet(aa_surr.surr_data,
                                                  1,
                                                  False,
                                                  wvlt.morlet,
                                                  dj=0,
                                                  s0=s0,
                                                  j1=0,
                                                  k0=k0)  # perform wavelet
        phase_aa_surr = np.arctan2(
            np.imag(wave_aa),
            np.real(wave_aa))[0, 12:-12]  # get phases from oscillatory modes

        # cmi1
        tmp = []
        for tau in range(1, 30):
            x, y, z = mi.get_time_series_condition([phase_temp, phase_aa_surr],
                                                   tau=tau,
                                                   dim_of_condition=1,
                                                   eta=1,
                                                   phase_diff=True)
            tmp.append(
                mi.cond_mutual_information(x,
                                           y,
                                           z,
                                           algorithm='EQQ2',
                                           bins=4,
                                           log2=False))
        cmi1.append(np.mean(np.array(tmp)))

        # cmi2
        tmp = []
        for tau in range(1, 30):
            x, y, z = mi.get_time_series_condition([phase_aa_surr, phase_temp],
                                                   tau=tau,
                                                   dim_of_condition=1,
                                                   eta=1,
                                                   phase_diff=True)
            tmp.append(
                mi.cond_mutual_information(x,
                                           y,
                                           z,
                                           algorithm='EQQ2',
                                           bins=4,
                                           log2=False))
        cmi2.append(np.mean(np.array(tmp)))

    cmi1 = np.array(cmi1)
    cmi2 = np.array(cmi2)

    return cmi1, cmi2
예제 #7
0
                                  bins=8,
                                  log2=False))

        # cmi1
        # plt.figure()
        tmp = []
        for tau in range(1, 30):
            x, y, z = mi.get_time_series_condition([phase_temp, phase_aa],
                                                   tau=tau,
                                                   dim_of_condition=1,
                                                   eta=0,
                                                   phase_diff=True)
            tmp.append(
                mi.cond_mutual_information(x,
                                           y,
                                           z,
                                           algorithm='EQQ2',
                                           bins=4,
                                           log2=False))
        cmi1.append(np.mean(np.array(tmp)))
        # plt.plot(tmp, label = "1->2")

        # cmi2
        tmp = []
        for tau in range(1, 30):
            x, y, z = mi.get_time_series_condition([phase_aa, phase_temp],
                                                   tau=tau,
                                                   dim_of_condition=1,
                                                   eta=0,
                                                   phase_diff=True)
            tmp.append(
                mi.cond_mutual_information(x,