def oldmain(): from gprf.seismic.seismic_util import load_events from sigvisa.treegp.util import mkdir_p mkdir_p("scraped_events") s = load_events(basedir="/home/dmoore/mkar_stuff") outfile = open("fakescraped.txt", 'w') for i, (ev, (w, srate1)) in enumerate(s): try: #lon, lat, smaj, smin, strike, depth, depth_err = scrape_isc(ev) lon, lat, smaj, smin, strike, depth, depth_err = fakescrape(ev) except Exception as e: print e lon, lat, smaj, smin, strike, depth, depth_err = ev.lon, ev.lat, 20.0, 20.0, 0, ev.depth, 0.05 * ev.depth + 1.0 st = "%d, %d, %.4f, %.4f, %.1f, %.1f, %d, %.1f, %.1f" % ( i, ev.evid, lon, lat, smaj, smin, strike, depth, depth_err) print st outfile.write(st + "\n") outfile.flush()
def main(): from gprf.seismic.seismic_util import load_events from sigvisa.treegp.util import mkdir_p def scrape_ev(i, ev, outfile_errs, outfile_isc, outfile_idc): try: hcenter_dict = scrape_isc(ev) except Exception as e: print "error scraping event", ev.evid, e outfile_errs.write("%d %s\n" % (ev.evid, e)) outfile_errs.flush() return try: (ts, time_err, time_rms, lon, lat, smaj, smin, strike, depth, depth_err, method, source, iscid) = hcenter_dict['ISC'] st = "%d, %d, %.2f, %.3f, %.4f, %.4f, %.1f, %.1f, %d, %.1f, %.1f" % ( i, ev.evid, ts, time_err, lon, lat, smaj, smin, strike, depth, depth_err) print source, st outfile_isc.write(st + "\n") outfile_isc.flush() except Exception as e: print "ISC error", e try: (ts, time_err, time_rms, lon, lat, smaj, smin, strike, depth, depth_err, method, source, iscid) = hcenter_dict['IDC'] st = "%d, %d, %.2f, %.3f, %.4f, %.4f, %.1f, %.1f, %d, %.1f, %.1f" % ( i, ev.evid, ts, time_err, lon, lat, smaj, smin, strike, depth, depth_err) print source, st outfile_idc.write(st + "\n") outfile_idc.flush() except Exception as e: print "IDC error", e try: with open("scraped_events/full/%d.txt" % ev.evid, 'w') as f: f.write(repr(hcenter_dict)) except Exception as e: print "repr error", e mkdir_p("scraped_events") mkdir_p("scraped_events/full/") outfile_errs = open("scraped_events/scrape_errors.txt", 'a') outfile_isc = open("scraped_events/isc.txt", 'a') outfile_idc = open("scraped_events/idc.txt", 'a') basedir = "/home/dmoore/mkar_stuff" sta = "mkar" start_bin = 1 end_bin = 204 for i in range(start_bin, end_bin): fname = os.path.join(basedir, "%s_stuff_%d" % (sta, i * 1000)) with open(fname, 'rb') as f: ss = pickle.load(f) print "loaded", fname for i, (ev, (w, srate1)) in enumerate(ss): scrape_ev(i, ev, outfile_errs, outfile_isc, outfile_idc) outfile_idc.close() outfile_isc.close() outfile_errs.close()