Skip to content

Commit

Permalink
version of SoCal paper
Browse files Browse the repository at this point in the history
  • Loading branch information
HongjianFang committed Jun 15, 2021
1 parent bf6aeef commit 9bc792b
Showing 1 changed file with 37 additions and 20 deletions.
57 changes: 37 additions & 20 deletions pyvorotomo/_iterator.py
Original file line number Diff line number Diff line change
Expand Up @@ -687,8 +687,10 @@ def _sample_arrivals(self, phase):
arrivals = remove_outliers(arrivals, tukey_k, "residual")

# Sample arrivals.
narrival = min(len(arrivals), narrival)
arrivals = arrivals.sample(n=narrival, weights="weight")
#narrival = min(len(arrivals), narrival)
narrival = int(len(arrivals)*0.8)
#arrivals = arrivals.sample(n=narrival, weights="weight")
arrivals = arrivals.sample(n=narrival)

self.sampled_arrivals = arrivals

Expand Down Expand Up @@ -796,7 +798,7 @@ def _trace_rays(self, phase):
return (True)

@_utilities.log_errors(logger)
def _update_arrival_weights_random(
def _update_events_weights_random(
self,
phase: str,
npts: int=5000,
Expand Down Expand Up @@ -837,22 +839,35 @@ def _update_arrival_weights_random(
events_count = events_count.groupby(by='cell_id').count()
events_count = events_count.reset_index()
events_weight = events[['event_id','cell_id']].merge(events_count,on='cell_id')
events_weight['weight'] = 1.0/events_weight['latitude']
#print('sth is wrong 1')
#logger.info('sth is wrong 1')
#events_weight['weight'] = 1.0/events_weight['latitude']
events['weight'] = 1.0/events_weight['latitude']


#arrivals = arrivals.merge(events_weight,on = 'event_id')
#arrivals = arrivals.drop(columns=['latitude','cell_id'])

## Update the self.arrivals attribute with weights.
#index_columns = ["network", "station", "event_id", "phase"]
#arrivals = arrivals.set_index(index_columns)
#_arrivals = self.arrivals.set_index(index_columns)
#_arrivals = _arrivals.sort_index()
#idx = arrivals.index
#print('sth is wrong 2')
#logger.info('sth is wrong 2')
#_arrivals.loc[idx, "weight"] = arrivals["weight"]
#_arrivals = _arrivals.reset_index()
#self.arrivals = _arrivals

#events["weight"] = 1.0
self.events = events

arrivals = arrivals.merge(events_weight,on = 'event_id')
arrivals = arrivals.drop(columns=['latitude','cell_id'])
self.synchronize(attrs=["events"])

# Update the self.arrivals attribute with weights.
index_columns = ["network", "station", "event_id", "phase"]
arrivals = arrivals.set_index(index_columns)
_arrivals = self.arrivals.set_index(index_columns)
_arrivals = _arrivals.sort_index()
idx = arrivals.index
_arrivals.loc[idx, "weight"] = arrivals["weight"]
_arrivals = _arrivals.reset_index()
self.arrivals = _arrivals

self.synchronize(attrs=["arrivals"])

#self.synchronize(attrs=["arrivals"])

return (True)

Expand Down Expand Up @@ -1159,8 +1174,8 @@ def iterate(self):
logger.info(f"Iteration #{self.iiter} (/{niter}).")

for phase in self.phases:
self._update_arrival_weights(phase)
self._update_events_weights()
#self._update_arrival_weights_random(phase)
self._update_events_weights_random(phase)
for hvr in hvrs:
self._reset_realization_stack(phase)
for phase in self.phases:
Expand Down Expand Up @@ -1600,7 +1615,8 @@ def sanitize_data(self):
arrivals = self.arrivals.set_index(["network", "station"])
idx_keep = arrivals.index.unique()
stations = self.stations.set_index(["network", "station"])
stations = stations.loc[idx_keep]
stations = stations[stations.index.isin(idx_keep)]
#stations = stations.loc[idx_keep]
stations = stations.reset_index()
self.stations = stations
dn = n0 - len(self.stations)
Expand All @@ -1615,7 +1631,8 @@ def sanitize_data(self):
stations = self.stations.set_index(["network", "station"])
idx_keep = stations.index.unique()
arrivals = self.arrivals.set_index(["network", "station"])
arrivals = arrivals.loc[idx_keep]
#arrivals = arrivals.loc[idx_keep]
arrivals = arrivals[arrivals.index.isin(idx_keep)]
arrivals = arrivals.reset_index()
self.arrivals = arrivals
dn = n0 - len(self.arrivals)
Expand Down

0 comments on commit 9bc792b

Please sign in to comment.