def test_average(ind=0): R1phi = [] R1cc = [] R2phi = [] R2cc = [] for ind in range(4): meta = test_calc(ind) if meta is None: continue R1phi.append(meta.R1phi) R2phi.append(meta.R2phi) R1cc.append(meta.R1cc) R2cc.append(meta.R2cc) R1phi = np.array(R1phi).flatten() R1cc = np.array(R1cc).flatten() R2phi = np.array(R2phi).flatten() R2cc = np.array(R2cc).flatten() stkey = '' phi = np.concatenate((R1phi, R2phi), axis=None) cc = np.concatenate((R1cc, R2cc), axis=None) ind = cc > 0.5 val, err = utils.estimate(phi, ind) plot = plotting.plot_dl_results(stkey, R1phi, R1cc, R2phi, R2cc, ind, val, err, phi, cc, 0.5)
def test_average(): phi = [] cc = [] snr = [] TR = [] RZ = [] baz = [] mag = [] for ind in range(20): meta = test_calc(ind) if meta is None: continue phi.append(meta.phi) snr.append(meta.snr) cc.append(np.abs(meta.cc)) TR.append(meta.TR) RZ.append(meta.RZ) baz.append(meta.baz) mag.append(meta.mag) phi = np.array(phi) cc = np.array(cc) snr = np.array(snr) TR = np.array(TR) RZ = np.array(RZ) baz = np.array(baz) mag = np.array(mag) stkey = '' # Set conditions for good result snrp = snr > -1. ccp = cc > -1. TRp = TR > -1. RZp = RZ > -1. # Indices where conditions are met ind = snrp * ccp * TRp * RZp # Get estimate and uncertainty val, err = utils.estimate(phi, ind) plot = plotting.plot_bng_conditions(stkey, snr, cc, TR, RZ, ind) plot = plotting.plot_bng_results(stkey, phi, snr, cc, TR, RZ, baz, mag, ind, val, err)
def main(): # Run the Input Parser args = arguments.get_dl_average_arguments() # Load Database db, stkeys = stdb.io.load_db(fname=args.indb, keys=args.stkeys) # Loop over station keys for stkey in list(stkeys): sta = db[stkey] # Input directory indir = Path(args.loadloc) / stkey.upper() if not indir.exists(): raise (Exception("Directory does not exist: ", indir, ", aborting")) # Temporary print locations tlocs = sta.location if len(tlocs) == 0: tlocs = [''] for il in range(0, len(tlocs)): if len(tlocs[il]) == 0: tlocs[il] = "--" sta.location = tlocs # Update Display if args.verb > 1: print("|==============================================|") print("| {0:>8s} |".format( sta.station)) print("|==============================================|") print("| Station: {0:>2s}.{1:5s} |". format(sta.network, sta.station)) print("| Channel: {0:2s}; Locations: {1:15s} |".format( sta.channel, ",".join(tlocs))) print("| Lon: {0:7.2f}; Lat: {1:6.2f} |".format( sta.longitude, sta.latitude)) print("| Input Directory: ", args.loadloc) print("| Plot Results: ", args.showplot) print("|") R1phi = [] R1cc = [] R2phi = [] R2cc = [] for folder in os.listdir(indir): # Load meta data filename = indir / folder / "Meta_Data.pkl" if not filename.is_file(): continue meta = pickle.load(open(filename, 'rb')) R1phi.append(meta.R1phi) R2phi.append(meta.R2phi) R1cc.append(meta.R1cc) R2cc.append(meta.R2cc) R1phi = np.array(R1phi).flatten() R1cc = np.array(R1cc).flatten() R2phi = np.array(R2phi).flatten() R2cc = np.array(R2cc).flatten() phi = np.concatenate((R1phi, R2phi), axis=None) cc = np.concatenate((R1cc, R2cc), axis=None) ind = cc > args.cc val, err = utils.estimate(phi, ind) # output results to termianl print("| D-L mean, error, data included: " + "{0:.2f}, {1:.2f}, {2}".format(val, err, np.sum(ind))) print("| D-L CC level: {0:.1f}".format(args.cc)) print() if np.sum(np.isnan(np.array([val, err]))) > 0: continue if args.showplot or args.saveplot: plot = plotting.plot_dl_results(stkey, R1phi, R1cc, R2phi, R2cc, ind, val, err, phi, cc, args.cc) # save figure if args.saveplot: figname = indir / ('results.' + args.fmt) plot.savefig(figname, fmt=args.fmt) if args.showplot: plot.show()
def main(): # Run the Input Parser args = arguments.get_bng_average_arguments() # Load Database db, stkeys = stdb.io.load_db(fname=args.indb, keys=args.stkeys) # Loop over station keys for stkey in list(stkeys): sta = db[stkey] # Input directory indir = Path(args.loadloc) / stkey.upper() if not indir.exists(): raise (Exception("Directory does not exist: ", indir, ", aborting")) # Temporary print locations tlocs = sta.location if len(tlocs) == 0: tlocs = [''] for il in range(0, len(tlocs)): if len(tlocs[il]) == 0: tlocs[il] = "--" sta.location = tlocs # Update Display if args.verb > 1: print("|==============================================|") print("| {0:>8s} |".format( sta.station)) print("|==============================================|") print("| Station: {0:>2s}.{1:5s} |". format(sta.network, sta.station)) print("| Channel: {0:2s}; Locations: {1:15s} |".format( sta.channel, ",".join(tlocs))) print("| Lon: {0:7.2f}; Lat: {1:6.2f} |".format( sta.longitude, sta.latitude)) print("| Input Directory: ", args.loadloc) print("| Plot Results: ", args.showplot) print("|") phi = [] cc = [] snr = [] TR = [] RZ = [] baz = [] mag = [] for folder in os.listdir(indir): # Load meta data filename = indir / folder / "Meta_Data.pkl" if not filename.is_file(): continue meta = pickle.load(open(filename, 'rb')) phi.append(meta.phi) snr.append(meta.snr) cc.append(np.abs(meta.cc)) TR.append(meta.TR) RZ.append(meta.RZ) baz.append(meta.baz) mag.append(meta.mag) phi = np.array(phi) cc = np.array(cc) snr = np.array(snr) TR = np.array(TR) RZ = np.array(RZ) baz = np.array(baz) mag = np.array(mag) # Set conditions for good result snrp = snr > args.snr ccp = cc > args.cc TRp = TR > args.TR RZp = RZ > args.RZ # Indices where conditions are met ind = snrp * ccp * TRp * RZp # Get estimate and uncertainty val, err = utils.estimate(phi, ind) # output results to termianl print("| B-N-G mean, error, data included: " + "{0:.1f}, {1:.1f}, {2}".format(val, err, np.sum(ind))) print() if np.sum(np.isnan(np.array([val, err]))) > 0: continue if args.showplot or args.saveplot: plot = plotting.plot_bng_conditions(stkey, snr, cc, TR, RZ, ind) # save figure if args.saveplot: figname = indir / ('conditions.' + args.fmt) plot.savefig(figname, fmt=args.fmt) if args.showplot: plot.show() plot = plotting.plot_bng_results(stkey, phi, snr, cc, TR, RZ, baz, mag, ind, val, err) # save figure if args.saveplot: figname = indir / ('results.' + args.fmt) plot.savefig(figname, fmt=args.fmt) if args.showplot: plot.show()