From 97aae042f6f59f93ceed7ddfd9ce406f7eef68a3 Mon Sep 17 00:00:00 2001 From: Yijian ZHOU <34815814+YijianZhou@users.noreply.github.com> Date: Thu, 28 Mar 2024 09:56:10 -0700 Subject: [PATCH] 0.01 mag precision --- hypodd/mk_event.py | 2 -- hypodd/run_hypoDD.py | 14 +++++++++++--- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/hypodd/mk_event.py b/hypodd/mk_event.py index f6c02b7..982b419 100644 --- a/hypodd/mk_event.py +++ b/hypodd/mk_event.py @@ -25,7 +25,6 @@ evid_lists[i].append([]) fouts.append(open('input/event_%s-%s.dat'%(i,j),'w')) - def get_fout_idx(lat, lon): evid_idx, fout_idx = [], [] for i in range(num_grids[0]): @@ -40,7 +39,6 @@ def get_fout_idx(lat, lon): evid_idx = [i,j] return evid_idx, fout_idx - f=open(fevent); lines=f.readlines(); f.close() for line in lines: codes = line.split() diff --git a/hypodd/run_hypoDD.py b/hypodd/run_hypoDD.py index d70693e..e3ea30c 100644 --- a/hypodd/run_hypoDD.py +++ b/hypodd/run_hypoDD.py @@ -14,7 +14,6 @@ keep_grids = cfg.keep_grids hypo_root = cfg.hypo_root - # write hypoDD input file def write_fin(i,j): fout = open('input/hypoDD_%s-%s.inp'%(i,j),'w') @@ -25,6 +24,15 @@ def write_fin(i,j): fout.write(line) fout.close() +def get_mag_dict(): + mag_dict = {} + f=open('input/event.dat'); lines=f.readlines(); f.close() + for line in lines: + codes = line.split() + evid = str(int(codes[-1])) + mag = float(codes[4]) + mag_dict[evid] = mag + return mag_dict class Run_HypoDD(Dataset): """ Dataset for running HypoDD @@ -52,7 +60,7 @@ def __getitem__(self, index): # get loc info lat, lon, dep = codes[1:4] dep = round(float(dep) - dep_corr, 2) - mag = float(codes[16]) + mag = mag_dict[evid] # get time info year, mon, day, hour, mnt, sec = codes[10:16] sec = '59.999' if sec=='60.000' else sec @@ -71,6 +79,7 @@ def __len__(self): os.system('python mk_dt.py') os.system('python mk_event.py') evid_lists = np.load('input/evid_lists.npy', allow_pickle=True) + mag_dict = get_mag_dict() # 2. run hypoDD idx_list = [(i,j) for i in range(num_grids[0]) for j in range(num_grids[1])] dataset = Run_HypoDD(idx_list) @@ -89,4 +98,3 @@ def __len__(self): for reloc_grid in reloc_grids: os.unlink(reloc_grid) for ctlg_grid in ctlg_grids: os.unlink(ctlg_grid) for input_file in input_files: os.unlink(input_file) -