Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
calum-chamberlain committed Jul 14, 2020
2 parents 1f32a42 + a2c7e59 commit b27b198
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 12 deletions.
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
down the real-time processing.
- Templates are reshaped prior to detection use to avoid time-cost associated
with re-doing this every iteration.
- Added a hypocentral_separation parameter for declustering - this also has
a default config value set for it (30km)

# 0.0.2
- First full release. Everything is new!
1 change: 1 addition & 0 deletions rt_eqcorrscan/config/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ class RTMatchFilterConfig(_ConfigAttribDict):
"threshold": 0.3,
"threshold_type": "av_chan_corr",
"trig_int": 2.0,
"hypocentral_separation": 30.0,
"save_waveforms": True,
"plot_detections": False,
"max_correlation_cores": None,
Expand Down
2 changes: 2 additions & 0 deletions rt_eqcorrscan/reactor/spin_up.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ def run(working_dir: str, cores: int = 1, log_to_screen: bool = False):
threshold=config.rt_match_filter.threshold,
threshold_type=config.rt_match_filter.threshold_type,
trig_int=config.rt_match_filter.trig_int,
hypocentral_separation=config.rt_match_filter.hypocentral_separation,
keep_detections=86400,
detect_directory="{name}/detections",
plot_detections=config.rt_match_filter.plot_detections)
Expand All @@ -152,6 +153,7 @@ def run(working_dir: str, cores: int = 1, log_to_screen: bool = False):
threshold=config.rt_match_filter.threshold,
threshold_type=config.rt_match_filter.threshold_type,
trig_int=config.rt_match_filter.trig_int,
hypocentral_separation=config.rt_match_filter.hypocentral_separation,
min_stations=min_stations,
keep_detections=86400,
detect_directory="{name}/detections",
Expand Down
39 changes: 27 additions & 12 deletions rt_eqcorrscan/rt_match_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ def _handle_detections(
self,
new_party: Party,
trig_int: float,
hypocentral_separation: float,
endtime: UTCDateTime,
detect_directory: str,
save_waveforms: bool,
Expand All @@ -211,6 +212,9 @@ def _handle_detections(
The party of new detections
trig_int
Minimum inter-detection time in seconds.
hypocentral_separation
Maximum inter-event distance in km to consider detections as being
duplicates.
endtime
Last detection-time to be kept.
detect_directory
Expand All @@ -231,11 +235,10 @@ def _handle_detections(
d._calculate_event(template=family.template)
self.party += family
Logger.info("Removing duplicate detections")
# TODO: Decluster on pick time? Find matching picks and calc median
# pick time difference.
if len(self.party) > 0:
self.party.decluster(
trig_int=trig_int, timing="origin", metric="cor_sum")
trig_int=trig_int, timing="origin", metric="cor_sum",
hypocentral_separation=hypocentral_separation)
Logger.info("Completed decluster")
Logger.info("Writing detections to disk")
for family in self.party:
Expand Down Expand Up @@ -321,6 +324,7 @@ def run(
threshold: float,
threshold_type: str,
trig_int: float,
hypocentral_separation: float = None,
min_stations: int = None,
keep_detections: float = 86400,
detect_directory: str = "{name}/detections",
Expand Down Expand Up @@ -349,6 +353,9 @@ def run(
`eqcorrscan.core.match_filter.Tribe.detect` for options.
trig_int
Minimum inter-detection time in seconds.
hypocentral_separation
Maximum inter-event distance in km to consider detections as being
duplicates.
min_stations
Minimum number of stations required to make a detection.
keep_detections
Expand Down Expand Up @@ -478,10 +485,11 @@ def run(
for tr in self.rt_client.stream.merge()])
detection_kwargs = dict(
threshold=threshold, threshold_type=threshold_type,
trig_int=trig_int, keep_detections=keep_detections,
detect_directory=detect_directory, plot_detections=plot_detections,
save_waveforms=save_waveforms, maximum_backfill=first_data,
endtime=None, min_stations=min_stations)
trig_int=trig_int, hypocentral_separation=hypocentral_separation,
keep_detections=keep_detections, detect_directory=detect_directory,
plot_detections=plot_detections, save_waveforms=save_waveforms,
maximum_backfill=first_data, endtime=None,
min_stations=min_stations)
try:
while self.busy:
self._running = True # Lock tribe
Expand Down Expand Up @@ -543,6 +551,7 @@ def run(
if len(new_party) > 0:
self._handle_detections(
new_party, trig_int=trig_int,
hypocentral_separation=hypocentral_separation,
endtime=last_data - keep_detections,
detect_directory=detect_directory,
save_waveforms=save_waveforms,
Expand Down Expand Up @@ -727,6 +736,7 @@ def backfill(
threshold: float,
threshold_type: str,
trig_int: float,
hypocentral_separation: float = None,
keep_detections: float = 86400,
detect_directory: str = "{name}/detections",
plot_detections: bool = True,
Expand All @@ -752,6 +762,9 @@ def backfill(
`eqcorrscan.core.match_filter.Tribe.detect` for options.
trig_int
Minimum inter-detection time in seconds.
hypocentral_separation
Maximum inter-event distance in km to consider detections as being
duplicates.
keep_detections
Duration to store detection in memory for in seconds.
detect_directory
Expand All @@ -775,8 +788,8 @@ def backfill(
backfill_process = Process(
target=self._backfill,
args=(templates, threshold, threshold_type, trig_int,
keep_detections, detect_directory, plot_detections,
save_waveforms, maximum_backfill, endtime),
hypocentral_separation, keep_detections, detect_directory,
plot_detections, save_waveforms, maximum_backfill, endtime),
kwargs=kwargs, name=f"Backfiller_{self._number_of_backfillers}")
backfill_process.start()
self._backfillers.append(backfill_process)
Expand All @@ -787,6 +800,7 @@ def _backfill(
threshold: float,
threshold_type: str,
trig_int: float,
hypocentral_separation: float = None,
keep_detections: float = 86400,
detect_directory: str = "{name}/detections",
plot_detections: bool = True,
Expand Down Expand Up @@ -848,13 +862,14 @@ def _backfill(
Logger.info("Backfill detection completed - handling detections")
if len(new_party) > 0:
Logger.info(f"Lock status: {self.lock}")
with self.lock: # The only time the state of RealTimeTribe is altered
with self.lock: # The only time the state is altered
Logger.info(f"Lock status: {self.lock}")
self._handle_detections(
new_party=new_party, detect_directory=detect_directory,
endtime=endtime - keep_detections,
plot_detections=plot_detections, save_waveforms=save_waveforms,
st=st, trig_int=trig_int)
plot_detections=plot_detections,
save_waveforms=save_waveforms, st=st, trig_int=trig_int,
hypocentral_separation=hypocentral_separation)
return

def stop(self, write_stopfile: bool = False) -> None:
Expand Down

0 comments on commit b27b198

Please sign in to comment.