if len(stream) == 0: continue if USE_TWS_AFTER_SW: dist = data.stations.dist(correlation[0][:-1], correlation[1][:-1]) if dist > 550: continue direct = int(round(dist / 3.)) tws = (((-direct - 30 - 80, direct + 30), 80),) stream.trim2(-trim_stream, trim_stream, 'middle') stretches = None if reftr: stretches = [] for tw in tws[i][0]: if tw <= border_time: npzfile = np.load(fit_file % (getCor(*correlation), tw)) stretches.append(-npzfile['sinus_exp']) result = stream.stretch(reftr=reftr, stretch=stretches, str_range=str_range, nstr=nstr, time_windows=tws[i], sides='right') if period == 24 * 3600: dates = [(time + 12 * 3600).toordinal() for time in stream.getHI('starttime')] else: def get_ord(time): day = (time + period / 2) day = day.toordinal() + 1.*day.hour / 24 + 1.*day.minute / 24 / 60 + 1.*day.second / 24 / 3600 return day dates = [get_ord(time) for time in stream.getHI('starttime')] dates = _correct_dates(dates) print np.array([dates[j + 1] - dates[j] for j in range(len(dates) - 1)]) checkDir(path + 'bla') np.savez(path + 'data_stretching_%s%s%s%s' % (getCor(*correlation), getFilter(filters[i]), getStack(None, period, stack), add_to_file), tw_start=tws[i][0], tw_width=tws[i][1], dates=dates, **result) #corr=corr, stretch=stretch)
############# script starts here print 'Use method %s' % METHOD if alternative_npzfile: print 'Alternative npz file: ON' fff = 5 for filter_, correlation in itertools.product(filters, correlations): # labels = ['%s_%d' % (getCor(*correlation), year) for year in range(2007, 2012)] # labels.append(st) XCORR = correlation[0] != correlation[1] if alternative_npzfile: npzfile = np.load(alternative_npzfile) l = '%s' % (getCor(*correlation),) else: l = '%s%s%s%s' % (getCor(*correlation), getFilter(filter_), getStack(None, period, stack), add_to_file) try: #print path + 'data_stretching_%s.npz' % l npzfile = np.load(path + 'data_stretching_%s.npz' % l) except Exception as ex: print ex print 'Error for %s-%s' % correlation continue tw_start, tw_width, corr, stretch, dates, sim_mat, stretch_vec = 7 * [None] vars().update(npzfile) sum_to_one_day = False if sum_to_one_day: sim_mat_new = np.empty((sim_mat.shape[0], 24, sim_mat.shape[2])) for i in range(24): sim_mat_new[:, i, :] = np.average(sim_mat[:, i::24, :], axis=1) sim_mat = sim_mat_new