def main(): n_samples = 1024 # Ruido vermelho S3 = powernoise(2, n_samples) # Caos, usado para gerar o sinal S7 rho = 3.85 a0 = 0.001 S4 = logistic(rho, a0, n_samples) # Soma os sinais e normalizae modo que <A>=0 e std=1 S7 = pre.standardize(S3 + S4) # Sinal gerado pelo pmodel S8 = pmodel(noValues=n_samples, p=0.52, slope=-1.66) data = S8 z = np.linspace(0, 1024, 1024) data_norm = waipy.normalize(data) result = waipy.cwt(data_norm, 1, 1, 0.125, 2, 4 / 0.125, 0.72, 6, mother='h', name='S8') waipy.wavelet_plot('S8', z, data_norm, 0.03125, result)
def main(): ''' d = np.genfromtxt(INFILE).T time, data = d ''' fs, data = wavfile.read(INFILE) plt.plot(data) # plt.show() data = data[10000:11000] # data = scipy.signal.resample(data, len(data)//4) # time = np.arange(0, len(data), 1./fs) time = np.arange(len(data)) data = waipy.normalize(data) result = waipy.cwt(data, 1, 1, 0.25, 2, 4 / 0.25, alpha, 6, mother='Morlet') waipy.wavelet_plot() wavelet(time, data, True) raw_input('')
def plot_wavelet(self): d_obs = self.d_obs d_mod = self.d_mod d_t_obs = self.d_t_obs """ plot data wavelet """ scores = [] for j, site in enumerate(self.sitename): print('Process on Wavelet_' + ''.join(site) + '_No.' + str(j) + '!') fig3 = plt.figure(figsize=(8, 8)) # ax3 = fig6.add_subplot(1, 2, 1) # fig3, ax3 = plt.subplots() data = d_obs[j, :].compressed() time_data = d_t_obs[~d_obs[j, :].mask] # time_data = d_t_obs result = waipy.cwt(data, 1, 1, 0.125, 2, 4 / 0.125, 0.72, 6, mother='Morlet', name='Data') waipy.wavelet_plot('Data', time_data, data, 0.03125, result, fig3) fig3.savefig(self.filedir + self.variable + '/' + ''.join(site) + '_Wavelet_' + self.variable + '.png') for m in range(len(d_mod)): fig4 = plt.figure(figsize=(8, 8)) data = d_mod[m][j, :][~d_obs[j, :].mask] - d_obs[ j, :].compressed() # time_data = d_mod[m][j, :] result = waipy.cwt(data, 1, 1, 0.125, 2, 4 / 0.125, 0.72, 6, mother='Morlet', name='Data') waipy.wavelet_plot('Data', time_data, data, 0.03125, result, fig4) fig4.savefig(self.filedir + self.variable + '/' + ''.join(site) + 'model' + str(m) + '_wavelet_' + self.variable + '.png') plt.close('all') return scores
def Plot_Wavelet(obs, mod, site_id): print('Process on Wavelet ' + 'No.' + str(site_id) + '!') time_data = mod.time data = (obs.extractDatasites(lat=obs.lat, lon=obs.lat)).data[:, site_id] y = (mod.extractDatasites(lat=obs.lat, lon=obs.lat)).data[:, site_id] fig3 = plt.figure(figsize=(8, 8)) result = waipy.cwt(data, 1, 1, 0.125, 2, 4 / 0.125, 0.72, 6, mother='Morlet', name='Obs') ax1, ax2, ax3, ax5 = waipy.wavelet_plot('Obs', time_data, data, 0.03125, result, fig3, unit=obs.unit) change_x_tick(mod, site_id, ax2)
from scipy import signal import numpy as np import matplotlib.pyplot as plt import waipy datasets = (['data1.dat', 'SAR', 1800], ['data2.dat', 'BIK', 1864], ['data3.dat', 'VUS', 1609]) dt = 1 units = 'mm' for d, name, t0 in datasets: data = np.loadtxt(d) N = data.size time = np.arange(0, N) * dt + t0 label = 'Precipitation data {}'.format(name) data_norm = waipy.normalize(data) alpha = abs(np.corrcoef(data_norm[0:-1], data_norm[1:])[0, 1]) result = waipy.cwt(data_norm, 1, 1, 0.25, 2, 7 / 0.25, alpha, 6, mother='Morlet', name=name) waipy.wavelet_plot(label, time, data_norm, 1.0e-6, result)
def plot_wavelet(self): d_obs = self.d_obs d_mod = self.d_mod d_t_obs = self.d_t_obs """ plot data wavelet """ scores = [] for j, site in enumerate(self.sitename): if self.sitename.mask[j]: continue print('Process on Wavelet_' + site + '_No.' + str(j) + '!') data = d_obs[j, :].compressed() fig3 = plt.figure(figsize=(8, 8)) if len(data) > 0: time_data = d_t_obs[~d_obs[j, :].mask] # time_data = d_t_obs result = waipy.cwt(data, 1, 1, 0.125, 2, 4 / 0.125, 0.72, 6, mother='Morlet', name='Obs') waipy.wavelet_plot('Obs', time_data, data, 0.03125, result, fig3, unit=self.d_unit_obs) # plt.tight_layout() for m in range(len(d_mod)): fig4 = plt.figure(figsize=(8, 8)) data2 = d_mod[m][j, :][~d_obs[j, :].mask] data = data2.compressed() - d_obs[ j, :].compressed()[~data2.mask] if len(data) > 0: result = waipy.cwt(data, 1, 1, 0.125, 2, 4 / 0.125, 0.72, 6, mother='Morlet', name='Obs - Mod' + str(m + 1)) waipy.wavelet_plot('Obs - Mod' + str(m + 1), time_data[~data2.mask], data, 0.03125, result, fig4, unit=self.d_unit_obs, m=m) # plt.tight_layout() fig4.savefig(self.filedir + self.variable + '/' + site + 'model' + str(m) + '_wavelet_' + self.variable + '.png', bbox_inches='tight') fig3.savefig(self.filedir + self.variable + '/' + site + '_Wavelet_' + self.variable + '.png', bbox_inches='tight') plt.close('all') return scores
import waipy import numpy as np z = np.linspace(0,2048,2048) x = np.sin(50*np.pi*z) y = np.cos(50*np.pi*z) data_norm = waipy.normalize(x) result = waipy.cwt(data_norm, 1, 1, 0.125, 2, 4/0.125, 0.72, 6, mother='Morlet',name='x') waipy.wavelet_plot('Sine', z, data_norm, 0.03125, result) data_norm1 = waipy.normalize(y) result1 = waipy.cwt(data_norm1, 1, 1, 0.125, 2, 4/0.125, 0.72, 6, mother='Morlet',name='y') waipy.wavelet_plot('Cosine', z, data_norm1, 0.03125, result1) cross_power, coherence, phase_angle = waipy.cross_wavelet(result['wave'], result1['wave']) waipy.plot_cross('Crosspower sine and cosine', cross_power, phase_angle, z, result, result1)
import waipy import numpy as np x = np.linspace(0, 100, 100) y1 = np.random.rand(100) # Generation of the Random Signal 1 y2 = np.random.rand(100) # Generation of the Random Signal 2 data_norm = waipy.normalize(y1) data_norm1 = waipy.normalize(y2) result = waipy.cwt(data_norm, 1, 1, 0.25, 2, 4/0.25, 0.72, 6, mother='Morlet', name='x') result1 = waipy.cwt(data_norm1, 1, 1, 0.25, 2, 4/0.25, 0.72, 6, mother='Morlet', name='y') waipy.wavelet_plot('y1-random-signal', x, data_norm, 0.03125, result) waipy.wavelet_plot('y2-random-signal', x, data_norm1, 0.03125, result1) cross_power, coherence, phase_angle = waipy.cross_wavelet(result['wave'], result1['wave']) waipy.plot_cross('Crosspower of y1 and y2', cross_power, phase_angle, x, result, result1)
############################################################################## ################################### MAIN ##################################### ############################################################################## namefile = "daily-cases-covid-19.csv" l = pd.read_csv(namefile) codes = list(set(l["Entity"])) codes = codes[1:] l = l.set_index("Entity") values = [] countries = ["Brazil", "India", "Iran", "South Africa", "Egypt"] for i in codes: y = list(l.filter(like=i, axis=0)["Daily confirmed cases (cases)"]) if i in countries: result = waipy.cwt(y, 1, 1, 0.125, 2, 4 / 0.125, 0.72, 6, 'DOG', "x") waipy.wavelet_plot(i, range(len(y)), y, 0.03125, result, savefig=True) if len(y) > 50: alfa, xdfa, ydfa, reta = funcs.dfa1d(y, 1) freqs, power, xdata, ydata, amp, index, powerlaw, INICIO, FIM = funcs.psd( y) values.append([ funcs.variance(y), funcs.skewness(y), funcs.kurtosis(y), alfa, index, mfdfa.makemfdfa(y), i ]) skew2 = [] alfa = [] kurt = [] index = []
p = p[np.nonzero(p)] c = counts[np.nonzero(counts)] log_p = np.log10(p) a = (log_p[np.argmax(c)] - log_p[np.argmin(c)]) / (np.max(c) - np.min(c)) b = log_Prob[0] y = b * np.power(10, (a*counts)) """ Plotagem """ plt.clf() plt.scatter(np.log10(counts), y, marker=".", color="blue") plt.title('SOC', fontsize = 16) plt.xlabel('log(ni)') plt.ylabel('log(Yi)') plt.grid() plt.show() for i in range(1): x,p=pmodel("Endogenous") SOC(p) result=waipy.cwt(p, 1, 1, 0.125, 2, 4/0.125, 0.72, 6, 'DOG', "x") waipy.wavelet_plot("Endogenous series", x, p, 0.03125, result, True) for i in range(1): x,p=pmodel("Exogenous") SOC(p) result=waipy.cwt(p, 1, 1, 0.125, 2, 4/0.125, 0.72, 6, 'DOG', "x") waipy.wavelet_plot("Exogenous series", x, p, 0.03125, result, True)
from waipy import wavelet_plot tick_spacing = 4 data = np.genfromtxt("data/batch_4.txt", delimiter=",")[20000:30000] time = (data[:, 0])#/1000 x = 9.8*(data[:, 1])/2048 y = 9.8*(data[:, 2])/2048 z = 9.8*((data[:, 3]))/2048 # -- factory offset of this particular accelerometer! var = z dt = 5 data_norm = waipy.normalize(var) alpha = np.corrcoef(data_norm[0:-1], data_norm[1:])[0,1]; result = waipy.cwt(data_norm, dt, 0, 0.0625, 1, 36, alpha, 6, mother='Morlet', name="name") waipy.wavelet_plot("img/batch_4_z_start_osc", time, data_norm, 0.03125, result); """ CONTINUOUS WAVELET TRANSFORM pad = 1 # pad the time series with zeroes (recommended) dj = 0.25 # this will do 4 sub-octaves per octave s0 = 2*dt # this says start at a scale of 6 months j1 = 7/dj # this says do 7 powers-of-two with dj sub-octaves each lag1 = 0.72 # lag-1 autocorrelation for red noise background param = 6 mother = 'Morlet' """
Yticks = 2 ** np.arange(np.ceil(np.log2(period.min())), np.ceil(np.log2(period.max()))) ax.set_yticks(np.log2(Yticks)) ax.set_yticklabels(Yticks) ax.invert_yaxis() ylim = ax.get_ylim() ax.set_ylim(ylim[0], -1) cbar = plt.colorbar(cf) plt.show() #%% data_norm = waipy.normalize(arsi.NDVI) result = waipy.cwt(data_norm, 1, 1, 0.125, 2, 4/0.125, 0.72, 6,mother='Morlet',name='X') waipy.wavelet_plot('Wavelet Signal', arsi.index.values, data_norm, 0.03125, result) #%% #Augmented Dickey-Fuller test #conclusion: all data are stationary result = adfuller(arsi.NDVI) print('ADF Statistic: %f' % result[0]) print('p-value: %f' % result[1]) print('Critical Values:') for key, value in result[4].items(): print('\t%s: %.3f' % (key, value)) result = adfuller(arsi.ET) print('ADF Statistic: %f' % result[0])
data_norm1 = waipy.normalize(y2) result = waipy.cwt(data_norm, 1, 1, 0.25, 2, 4 / 0.25, 0.72, 6, mother='Morlet', name='x') result1 = waipy.cwt(data_norm1, 1, 1, 0.25, 2, 4 / 0.25, 0.72, 6, mother='Morlet', name='y') waipy.wavelet_plot('y1-random-signal', x, data_norm, 0.03125, result) waipy.wavelet_plot('y2-random-signal', x, data_norm1, 0.03125, result1) cross_power, coherence, phase_angle = waipy.cross_wavelet( result['wave'], result1['wave']) waipy.plot_cross('Crosspower of y1 and y2', cross_power, phase_angle, x, result, result1)