Skip to content

Commit

Permalink
Change to network code finding function in seismic/catalogue/merge_ca…
Browse files Browse the repository at this point in the history
…talogues_python_new/ (#237)

* Modification to seismic/catalogue/merge_catalogues/python_new/Convert_Catalogues_To_CSV.py network code matching function.
Correction to seismic/ssst_relocation/relocation/Relocation.py hypocentre updating function.

* Update Convert_Catalogues_To_CSV.py

Co-authored-by: Lachlan Adams <la8536@gadi-login-07.gadi.nci.org.au>
  • Loading branch information
Lachlan-Adams and Lachlan Adams committed Feb 3, 2022
1 parent 7fec82b commit fa41875
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,37 @@ def find_station_information(stat, net, lon, lat, ot, station_dict,
slon, slat, selev, _, _ = station_dict[key]
dist = ang_dist(lon, lat, slon, slat)
return slon, slat, selev, net, dist
else:
key = str('IR.' + stat)
if key in IR_station_dict.keys():
slon, slat, selev, _, _ = IR_station_dict[key]
dist = ang_dist(lon, lat, slon, slat)
keys = [key for key in station_dict.keys() \
if key.split('.')[1] == stat]
if len(keys) == 0:
return slon, slat, selev, 'IR', dist
else:
rows = [station_dict[key] for key in keys]
slons = np.array([row[0] for row in rows])
slats = np.array([row[1] for row in rows])
dists = ang_dist(slon, slat, slons, slats)
if np.nanmin(dists) < 0.01:
ind = np.argwhere(dists == np.nanmin(dists))[0][0]
slon, slat, selev, _, _ = rows[ind]
net = keys[ind].split('.')[0]
dist = ang_dist(lon, lat, slon, slat)
return slon, slat, selev, net, dist
else:
return slon, slat, selev, 'IR', dist
#end if
#end if
else:
slon = slat = selev = None
dist = 999.0
return slon, slat, selev, net, dist
#end if
#end if
"""
else:
keys = [key for key in station_dict.keys() \
if key.split('.')[1] == stat]
Expand Down Expand Up @@ -471,6 +502,7 @@ def find_station_information(stat, net, lon, lat, ot, station_dict,
#end if
#end if
#end if
"""
#end func

def write_list_to_csv(lst, path, rank, nproc):
Expand Down Expand Up @@ -637,4 +669,4 @@ def process():

if __name__ == "__main__":
process()
#end if
#end if
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def azimuth(lon1, lat1, lon2, lat2, units='degrees'):
a = lon1
b = np.pi/2.0 - lat1
x = lon2
y = mp.pi/2.0 - lat2
y = np.pi/2.0 - lat2
#end if
azim = np.arctan(np.sin(x - a)/(np.sin(b)/np.tan(y) - \
np.cos(b)*np.cos(x - a)))
Expand Down
16 changes: 7 additions & 9 deletions seismic/ssst_relocation/relocation/Relocation.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,11 @@ def update_hypocentres_from_database(events, picks, hypo_dict, config,
lat1 = 90.0 - picks_temp['ecolat'][0]
time1 = picks_temp['origin_time'][0]

lon2, lat2, depth2, time2 = hypo_dict[event]
try:
lon2, lat2, depth2, time2 = hypo_dict[event]
except:
continue
#end try

if np.abs(lon1 - lon2) > thr_dist or np.abs(lat1 - lat2) > thr_dist \
or np.abs(time1 - time2) > thr_time:
Expand All @@ -262,18 +266,12 @@ def update_hypocentres_from_database(events, picks, hypo_dict, config,
return picks, unstable_events
#end func

def extract_hypocentres_from_database(events):
def extract_hypocentres_from_database():
"""
Retrieves updated hypocentres from SeisComp3 database after relocation has
been performed.
Parameters
----------
events : list
List of event IDs for which to retrieve updated hypocentres.
Returns
-------
hypo_dict : dictionary
Expand All @@ -296,7 +294,7 @@ def extract_hypocentres_from_database(events):
rows = c.fetchall()
hypo_dict = {row[0]: (float(row[1]), float(row[2]), float(row[3])*1e3,
UTCDateTime(row[4]).timestamp + int(row[5])/1e6) \
for row in rows if row[0] in events}
for row in rows}
c.close()
db.close()

Expand Down
6 changes: 3 additions & 3 deletions seismic/ssst_relocation/relocation/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -470,18 +470,18 @@ def process():
rank)
comm.barrier()

hypo_dict = None
if rank == 0:
from Relocation import extract_hypocentres_from_database
events = list(np.unique(picks['event_id']))
hypo_dict = extract_hypocentres_from_database(events)
hypo_dict = extract_hypocentres_from_database()
#end if

hypo_dict = comm.bcast(hypo_dict, root=0)
picks_split = np.load(os.path.join(output_path,
'%s.npy'%str(rank).zfill(3)))

picks_split, unstable_events = \
update_hypocentres_from_database(events, picks_split,
update_hypocentres_from_database(events_split, picks_split,
hypo_dict, config,
unstable_events=\
unstable_events)
Expand Down

0 comments on commit fa41875

Please sign in to comment.