def info(): from msnoise.api import connect, get_config from .default import default db = connect() click.echo('') click.echo('Raw config bits: "D"efault or "M"odified (green)') for key in default.keys(): tmp = get_config(db, key, plugin='Tomo') if tmp == default[key][1]: click.secho(" D %s: %s" % (key, tmp)) else: click.secho(" M %s: %s" % (key, tmp), fg='green')
def main(per, a1, b1, l1, s1, a2, b2, l2, s2, show): # Smoothing and damping parameters db = connect() alpha1 = a1 if a1 else float(get_config(db, "alpha1", plugin="Tomo")) beta1 = b1 if b1 else float(get_config(db, "beta1", plugin="Tomo")) lambda1 = l1 if l1 else float(get_config(db, "lambda1", plugin="Tomo")) sigma1 = s1 if s1 else float(get_config(db, "sigma1", plugin="Tomo")) alpha2 = a2 if a2 else float(get_config(db, "alpha2", plugin="Tomo")) beta2 = b2 if b2 else float(get_config(db, "beta2", plugin="Tomo")) lambda2 = l2 if l2 else float(get_config(db, "lambda2", plugin="Tomo")) sigma2 = s2 if s2 else float(get_config(db, "sigma2", plugin="Tomo")) if per is None: PER = get_config(db, "ftan_periods", plugin="Tomo") periods = np.array([float(pi) for pi in PER.split(',')]) else: periods = [ float(per), ] # ANSWT inputs gridfile = 'TOMO_FILES/GLISNGrid.dat' stacoordfile = 'TOMO_FILES/GLISN_STACoord.dat' for per in periods: DCfile = 'TOMO_FILES/TestGroupVel_%.1fsGLISN.dat' % float(per) PERIOD = per paramfile = 'TOMO_FILES/ParamFile.txt' fid = open(paramfile, 'w') fid.write( '%% alpha1 \t beta1 \t lambda1 \t Lcorr1 \t alpha2 \t beta2 \t lambda2 \t Lcorr2\n' ) fid.write( '%f %f %f %f %f %f %f %f\n' % (alpha1, beta1, lambda1, sigma1, alpha2, beta2, lambda2, sigma2)) fid.close() try: ANSWT(gridfile, stacoordfile, DCfile, paramfile, PERIOD, show) except: traceback.print_exc() print("!" * 80) print("Can't compute tomo for period=", per) print("!" * 80)
def main(sta1, sta2, filterid, components, mov_stack=1, ampli=5, seismic=False, show=False, outfile=None, envelope=False, refilter=None, startdate=None, enddate=None): db = connect() maxlag = float(get_config(db, 'maxlag')) samples = get_maxlag_samples(db) cc_sampling_rate = float(get_config(db, 'cc_sampling_rate')) start, end, datelist = build_movstack_datelist(db, startdate, enddate) base = mdates.date2num(start) fig = plt.figure(figsize=(12, 9)) sta1 = sta1.replace('.', '_') sta2 = sta2.replace('.', '_') t = np.arange(samples) / cc_sampling_rate - maxlag if refilter: freqmin, freqmax = refilter.split(':') freqmin = float(freqmin) freqmax = float(freqmax) if sta2 >= sta1: pair = "%s:%s" % (sta1, sta2) print("New Data for %s-%s-%i-%i" % (pair, components, filterid, mov_stack)) nstack, stack_total = get_results(db, sta1, sta2, filterid, components, datelist, mov_stack, format="matrix") ax = fig.add_subplot(111) for i, line in enumerate(stack_total): if np.all(np.isnan(line)): continue if refilter: line = bandpass(line, freqmin, freqmax, cc_sampling_rate, zerophase=True) if envelope: line = obspy_envelope(line) line /= line.max() ax.plot(t, line * ampli + i + base, c='k') if seismic: y1 = np.ones(len(line)) * i y2 = line * ampli + i + base ax.fill_between(t, y1, y2, where=y2 >= y1, facecolor='k', interpolate=True) for filterdb in get_filters(db, all=True): if filterid == filterdb.ref: low = float(filterdb.low) high = float(filterdb.high) break ax.set_xlabel("Lag Time (s)") ax.axhline(0, lw=0.5, c='k') ax.grid() ax.scatter(0, [ start, ], alpha=0) ax.set_ylim(start - datetime.timedelta(days=ampli), end + datetime.timedelta(days=ampli)) ax.set_xlim(-maxlag, maxlag) ax.fmt_ydata = mdates.DateFormatter('%Y-%m-%d') cursor = Cursor(ax, useblit=True, color='red', linewidth=1.2) title = '%s : %s, %s, Filter %d (%.2f - %.2f Hz), Stack %d' % \ (sta1.replace('_', '.'), sta2.replace('_', '.'), components, filterid, low, high, mov_stack) if refilter: title += ", Re-filtered (%.2f - %.2f Hz)" % (freqmin, freqmax) ax.set_title(title) if outfile: if outfile.startswith("?"): pair = pair.replace(':', '-') outfile = outfile.replace( '?', '%s-%s-f%i-m%i' % (pair, components, filterid, mov_stack)) outfile = "ccftime " + outfile print("output to:", outfile) fig.savefig(outfile) if show: fig.show() else: plt.close(fig)
def main(sta1, sta2, filterid, components, mov_stack=1, ampli=5, show=False, outfile=False, refilter=None, startdate=None, enddate=None): db = connect() cc_sampling_rate = float(get_config(db, 'cc_sampling_rate')) start, end, datelist = build_movstack_datelist(db) base = mdates.date2num(start) sta1 = sta1.replace('.', '_') sta2 = sta2.replace('.', '_') # TODO: Height adjustment of the plot for large number of stacks. # Preferably interactive fig = plt.figure(figsize=(12, 9)) if refilter: freqmin, freqmax = refilter.split(':') freqmin = float(freqmin) freqmax = float(freqmax) if sta2 >= sta1: pair = "%s:%s" % (sta1, sta2) print("New Data for %s-%s-%i-%i" % (pair, components, filterid, mov_stack)) nstack, stack_total = get_results(db, sta1, sta2, filterid, components, datelist, mov_stack, format="matrix") ax = fig.add_subplot(111) for i, line in enumerate(stack_total): if np.all(np.isnan(line)): continue if refilter: line = bandpass(line, freqmin, freqmax, cc_sampling_rate, zerophase=True) freq, line = prepare_abs_postitive_fft(line, cc_sampling_rate) line /= line.max() ax.plot(freq, line * ampli + i + base, c='k') for filterdb in get_filters(db, all=True): if filterid == filterdb.ref: low = float(filterdb.low) high = float(filterdb.high) break ax.set_ylim(start-datetime.timedelta(days=ampli), end+datetime.timedelta(days=ampli)) ax.yaxis.set_major_formatter(mdates.DateFormatter('%Y-%m-%d')) ax.set_xlabel("Frequency [Hz]") ax.set_xscale('log') ax.grid() title = '%s : %s, %s, Filter %d (%.2f - %.2f Hz), Stack %d' %\ (sta1.replace('_', '.'), sta2.replace('_', '.'), components, filterid, low, high, mov_stack) if refilter: title += ", Re-filtered (%.2f - %.2f Hz)" % (freqmin, freqmax) ax.set_title(title) cursor = Cursor(ax, useblit=True, color='red', linewidth=1.2) print(outfile) if outfile: if outfile.startswith("?"): pair = pair.replace(':', '-') outfile = outfile.replace('?', '%s-%s-f%i-m%i' % (pair, components, filterid, mov_stack)) outfile = "spectime" + outfile print("output to:", outfile) plt.savefig(outfile) if show: plt.show() else: plt.close(fig)
def main(per, a1, b1, l1, s1, a2, b2, l2, s2, filterid, comp, show): verbose = False if verbose: logging.basicConfig(level=logging.INFO) # Smoothing and damping parameters db = connect() alpha1 = a1 if a1 is not None else float(get_config(db, "alpha1", plugin="Tomo")) beta1 = b1 if b1 is not None else float(get_config(db, "beta1", plugin="Tomo")) lambda1 = l1 if l1 is not None else float(get_config(db, "lambda1", plugin="Tomo")) sigma1 = s1 if s1 is not None else float(get_config(db, "sigma1", plugin="Tomo")) alpha2 = a2 if a2 is not None else float(get_config(db, "alpha2", plugin="Tomo")) beta2 = b2 if b2 is not None else float(get_config(db, "beta2", plugin="Tomo")) lambda2 = l2 if l2 is not None else float(get_config(db, "lambda2", plugin="Tomo")) sigma2 = s2 if s2 is not None else float(get_config(db, "sigma2", plugin="Tomo")) v_cmap = get_config(db, "v_cmap", plugin="Tomo") d_cmap = get_config(db, "d_cmap", plugin="Tomo") if per is None: PER = get_config(db, "ftan_periods", plugin="Tomo") periods = np.array([float(pi) for pi in PER.split(',')]) else: periods = [float(per), ] # ANSWT inputs gridfile = os.path.join("TOMO_FILES", "%02i" % filterid, comp, "Grid.dat") stacoordfile = os.path.join("TOMO_FILES", "%02i" % filterid, comp, "STACoord.dat") for per in periods: DCfile = os.path.join("TOMO_FILES", "%02i" % filterid, comp, "TestGroupVel_%.4fs.dat" % float(per)) print("Processing %s" % DCfile) logging.info("Processing %s" % DCfile) PERIOD = per logging.info("Period from db_config: %.4f" % PERIOD) paramfile = os.path.join("TOMO_FILES", "%02i" % filterid, comp, 'ParamFile.txt') print("Writing parameters to %s" % paramfile) fid = open(paramfile, 'w') fid.write('%% alpha1 \t beta1 \t lambda1 \t Lcorr1 \t alpha2 \t beta2 \t lambda2 \t Lcorr2\n') fid.write('%f %f %f %f %f %f %f %f\n' % (alpha1, beta1, lambda1, sigma1, alpha2, beta2, lambda2, sigma2)) fid.close() try: ANSWT(gridfile, stacoordfile, DCfile, paramfile, PERIOD, show, v_cmap, d_cmap) except: traceback.print_exc() print("!" * 80) print("Can't compute tomo for period=", per) print("!" * 80)
def main(sta1, sta2, filterid, components, mov_stack=1, ampli=5, show=False, outfile=False, refilter=None, startdate=None, enddate=None, **kwargs): db = connect() cc_sampling_rate = float(get_config(db, 'cc_sampling_rate')) start, end, datelist = build_movstack_datelist(db) base = mdates.date2num(start) sta1 = sta1.replace('.', '_') sta2 = sta2.replace('.', '_') # TODO: Height adjustment of the plot for large number of stacks. # Preferably interactive fig = plt.figure(figsize=(12, 9)) if refilter: freqmin, freqmax = refilter.split(':') freqmin = float(freqmin) freqmax = float(freqmax) if sta2 >= sta1: pair = "%s:%s" % (sta1, sta2) print("New Data for %s-%s-%i-%i" % (pair, components, filterid, mov_stack)) nstack, stack_total = get_results(db, sta1, sta2, filterid, components, datelist, mov_stack, format="matrix") ax = fig.add_subplot(111) for i, line in enumerate(stack_total): if np.all(np.isnan(line)): continue if refilter: line = bandpass(line, freqmin, freqmax, cc_sampling_rate, zerophase=True) freq, line = prepare_abs_postitive_fft(line, cc_sampling_rate) line /= line.max() ax.plot(freq, line * ampli + i + base, c='k') for filterdb in get_filters(db, all=True): if filterid == filterdb.ref: low = float(filterdb.low) high = float(filterdb.high) break ax.set_ylim(start-datetime.timedelta(days=ampli), end+datetime.timedelta(days=ampli)) ax.yaxis.set_major_formatter(mdates.DateFormatter('%Y-%m-%d')) if "xlim" in kwargs: plt.xlim(kwargs["xlim"][0],kwargs["xlim"][1]) ax.set_xlabel("Frequency [Hz]") ax.set_xscale('log') ax.grid() title = '%s : %s, %s, Filter %d (%.2f - %.2f Hz), Stack %d' %\ (sta1.replace('_', '.'), sta2.replace('_', '.'), components, filterid, low, high, mov_stack) if refilter: title += ", Re-filtered (%.2f - %.2f Hz)" % (freqmin, freqmax) ax.set_title(title) cursor = Cursor(ax, useblit=True, color='red', linewidth=1.2) print(outfile) if outfile: if outfile.startswith("?"): pair = pair.replace(':', '-') outfile = outfile.replace('?', '%s-%s-f%i-m%i' % (pair, components, filterid, mov_stack)) outfile = "spectime" + outfile print("output to:", outfile) plt.savefig(outfile) if show: plt.show() else: plt.close(fig)