From 32e367514deb3a4e46e81be45ea861c824267f7b Mon Sep 17 00:00:00 2001 From: Calum Chamberlain Date: Wed, 7 Feb 2024 17:10:27 +1300 Subject: [PATCH] Catch no matching data in the right places --- eqcorrscan/core/match_filter/helpers/processes.py | 11 +++++++++-- eqcorrscan/core/match_filter/helpers/tribe.py | 2 +- eqcorrscan/core/match_filter/template.py | 2 +- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/eqcorrscan/core/match_filter/helpers/processes.py b/eqcorrscan/core/match_filter/helpers/processes.py index 60c44631..885384da 100644 --- a/eqcorrscan/core/match_filter/helpers/processes.py +++ b/eqcorrscan/core/match_filter/helpers/processes.py @@ -388,14 +388,17 @@ def _pre_processor( break Logger.debug("Getting stream from queue") st = _get_and_check(input_stream_queue, poison_queue) + Logger.warning(st) if st is None: Logger.info("Ran out of streams, stopping processing") break elif isinstance(st, Poison): Logger.error("Killed") break - if len(st) == 0: - break + # if len(st) == 0: + # Logger.error("Empty stream provided") + # poison_queue.put_nowait(Poison(IndexError("No matching channels between stream and "))) + # break Logger.info(f"Processing stream:\n{st}") # Process stream @@ -528,6 +531,10 @@ def _prepper( f"Multiple channels in continuous data for " f"{', '.join(_duplicate_sids)}"))) break + template_sids = {tr.id for template in templates for tr in template.st} + if len(template_sids.intersection(st_sids)) == 0: + poison_queue.put_nowait(Poison( + IndexError("No matching channels between templates and data"))) # Do the grouping for this stream Logger.info(f"Grouping {len(templates)} templates into groups " f"of {group_size} templates") diff --git a/eqcorrscan/core/match_filter/helpers/tribe.py b/eqcorrscan/core/match_filter/helpers/tribe.py index fcaa29fe..2b6ff2a1 100644 --- a/eqcorrscan/core/match_filter/helpers/tribe.py +++ b/eqcorrscan/core/match_filter/helpers/tribe.py @@ -287,7 +287,7 @@ def _group( if t_name in t_dict.keys() and len({tr.stats.station for tr in t_dict.get(t_name).st}.intersection(stations) - ) >= min_stations] + ) >= max(1, min_stations)] Logger.info(f"Dropping {len(grp) - len(template_group)} templates " f"due to fewer than {min_stations} matched channels") if len(template_group): diff --git a/eqcorrscan/core/match_filter/template.py b/eqcorrscan/core/match_filter/template.py index 96c7735f..6bdf5c4e 100644 --- a/eqcorrscan/core/match_filter/template.py +++ b/eqcorrscan/core/match_filter/template.py @@ -792,7 +792,7 @@ def group_templates_by_seedid( # Don't use templates that don't have any overlap with the stream template_seed_ids = tuple( (t_name, t_chans) for t_name, t_chans in template_seed_ids - if len({sid.split('.')[1] for sid in t_chans}) >= min_stations) + if len({sid.split('.')[1] for sid in t_chans}) >= max(1, min_stations)) Logger.info(f"Dropping {len(templates) - len(template_seed_ids)} " f"templates due to fewer than {min_stations} matched channels") # We will need this dictionary at the end for getting the templates by id