Skip to content

Commit

Permalink
0.01 mag precision
Browse files Browse the repository at this point in the history
  • Loading branch information
YijianZhou committed Mar 28, 2024
1 parent 1761e40 commit 97aae04
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
2 changes: 0 additions & 2 deletions hypodd/mk_event.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]):
Expand All @@ -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()
Expand Down
14 changes: 11 additions & 3 deletions hypodd/run_hypoDD.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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)

0 comments on commit 97aae04

Please sign in to comment.