events = readEvents(event_file) events = events.filter('magnitude > 7.5') elif FIT.startswith('sinus_exp_alt'): event_file = '/home/richter/Data/events/2007-2012_events_in_chile_geofon.xml' filename = path + '/data_stretching_%s.npz' #filename = path + '/data_stretching_%s_altref.npz' # nix vs _altref output = path + '/data_stretching_%s_without_sinus_exp_alt.npz' output_fit = path + '/sinus_exp_alt_%s_%ds.npz' events = readEvents(event_file) events = events.filter('magnitude > 7.5') else: assert False popts = {} for k, comb in enumerate(combs): comb = getCor(*comb) print print comb npzfile = np.load(filename % comb) tw_start, tw_width, corr, stretch, dates, sim_mat, stretch_vec = 7 * [None] vars().update(npzfile) stretch = np.ma.masked_where(corr <= 0, stretch) stretch = np.ma.masked_where(np.isnan(corr), stretch) corr = np.ma.masked_where(corr <= 0, corr) corr = np.ma.masked_where(np.isnan(corr), corr) fig = plt.figure() ax1 = fig.add_subplot(121) ax2 = fig.add_subplot(122, sharex=ax1) ax1.plot(dates, stretch)
plt.savefig(path + 'stretching_%s%s' % ('PATCX', ext.replace('.png', '.pdf'))) sys.exit() ############# 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):
print stream 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)