Skip to content

Commit 9bc792b

Browse files
committed
version of SoCal paper
1 parent bf6aeef commit 9bc792b

File tree

1 file changed

+37
-20
lines changed

1 file changed

+37
-20
lines changed

pyvorotomo/_iterator.py

Lines changed: 37 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -687,8 +687,10 @@ def _sample_arrivals(self, phase):
687687
arrivals = remove_outliers(arrivals, tukey_k, "residual")
688688

689689
# Sample arrivals.
690-
narrival = min(len(arrivals), narrival)
691-
arrivals = arrivals.sample(n=narrival, weights="weight")
690+
#narrival = min(len(arrivals), narrival)
691+
narrival = int(len(arrivals)*0.8)
692+
#arrivals = arrivals.sample(n=narrival, weights="weight")
693+
arrivals = arrivals.sample(n=narrival)
692694

693695
self.sampled_arrivals = arrivals
694696

@@ -796,7 +798,7 @@ def _trace_rays(self, phase):
796798
return (True)
797799

798800
@_utilities.log_errors(logger)
799-
def _update_arrival_weights_random(
801+
def _update_events_weights_random(
800802
self,
801803
phase: str,
802804
npts: int=5000,
@@ -837,22 +839,35 @@ def _update_arrival_weights_random(
837839
events_count = events_count.groupby(by='cell_id').count()
838840
events_count = events_count.reset_index()
839841
events_weight = events[['event_id','cell_id']].merge(events_count,on='cell_id')
840-
events_weight['weight'] = 1.0/events_weight['latitude']
842+
#print('sth is wrong 1')
843+
#logger.info('sth is wrong 1')
844+
#events_weight['weight'] = 1.0/events_weight['latitude']
845+
events['weight'] = 1.0/events_weight['latitude']
846+
847+
848+
#arrivals = arrivals.merge(events_weight,on = 'event_id')
849+
#arrivals = arrivals.drop(columns=['latitude','cell_id'])
850+
851+
## Update the self.arrivals attribute with weights.
852+
#index_columns = ["network", "station", "event_id", "phase"]
853+
#arrivals = arrivals.set_index(index_columns)
854+
#_arrivals = self.arrivals.set_index(index_columns)
855+
#_arrivals = _arrivals.sort_index()
856+
#idx = arrivals.index
857+
#print('sth is wrong 2')
858+
#logger.info('sth is wrong 2')
859+
#_arrivals.loc[idx, "weight"] = arrivals["weight"]
860+
#_arrivals = _arrivals.reset_index()
861+
#self.arrivals = _arrivals
862+
863+
#events["weight"] = 1.0
864+
self.events = events
841865

842-
arrivals = arrivals.merge(events_weight,on = 'event_id')
843-
arrivals = arrivals.drop(columns=['latitude','cell_id'])
866+
self.synchronize(attrs=["events"])
844867

845-
# Update the self.arrivals attribute with weights.
846-
index_columns = ["network", "station", "event_id", "phase"]
847-
arrivals = arrivals.set_index(index_columns)
848-
_arrivals = self.arrivals.set_index(index_columns)
849-
_arrivals = _arrivals.sort_index()
850-
idx = arrivals.index
851-
_arrivals.loc[idx, "weight"] = arrivals["weight"]
852-
_arrivals = _arrivals.reset_index()
853-
self.arrivals = _arrivals
854868

855-
self.synchronize(attrs=["arrivals"])
869+
870+
#self.synchronize(attrs=["arrivals"])
856871

857872
return (True)
858873

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

11611176
for phase in self.phases:
1162-
self._update_arrival_weights(phase)
1163-
self._update_events_weights()
1177+
#self._update_arrival_weights_random(phase)
1178+
self._update_events_weights_random(phase)
11641179
for hvr in hvrs:
11651180
self._reset_realization_stack(phase)
11661181
for phase in self.phases:
@@ -1600,7 +1615,8 @@ def sanitize_data(self):
16001615
arrivals = self.arrivals.set_index(["network", "station"])
16011616
idx_keep = arrivals.index.unique()
16021617
stations = self.stations.set_index(["network", "station"])
1603-
stations = stations.loc[idx_keep]
1618+
stations = stations[stations.index.isin(idx_keep)]
1619+
#stations = stations.loc[idx_keep]
16041620
stations = stations.reset_index()
16051621
self.stations = stations
16061622
dn = n0 - len(self.stations)
@@ -1615,7 +1631,8 @@ def sanitize_data(self):
16151631
stations = self.stations.set_index(["network", "station"])
16161632
idx_keep = stations.index.unique()
16171633
arrivals = self.arrivals.set_index(["network", "station"])
1618-
arrivals = arrivals.loc[idx_keep]
1634+
#arrivals = arrivals.loc[idx_keep]
1635+
arrivals = arrivals[arrivals.index.isin(idx_keep)]
16191636
arrivals = arrivals.reset_index()
16201637
self.arrivals = arrivals
16211638
dn = n0 - len(self.arrivals)

0 commit comments

Comments
 (0)