def setUpClass(cls): cls.detect_dir = os.path.join( os.path.abspath(os.path.dirname(__file__)), ".test_detections") client = Client('GEONET') cls.t1 = UTCDateTime(2016, 9, 4, 18) cls.t2 = UTCDateTime(2016, 9, 5) catalog = client.get_events(starttime=cls.t1, endtime=cls.t2, minmagnitude=4, minlatitude=-49, maxlatitude=-35, minlongitude=175.0, maxlongitude=180.0) catalog = catalog_utils.filter_picks(catalog, channels=['EHZ'], top_n_picks=2) cls.tribe = Tribe().construct(method='from_client', catalog=catalog, client_id='GEONET', lowcut=2.0, highcut=9.0, samp_rate=100.0, filt_order=4, length=3.0, prepick=0.15, swin='all', process_len=300) cls.client = "GEONET" cls.inventory = get_inventory(client=client, tribe=cls.tribe, location=dict(latitude=-42, longitude=177.5), starttime=cls.t1)
def test_no_origin(self): event = self.trigger_event.copy() event.preferred_origin_id = None event.origins = [] inventory = get_inventory(client=self.client, tribe=self.tribe, triggering_event=event) self.assertEqual(len(inventory), 0)
def test_get_inventory_no_trigger(self): inventory = get_inventory( client=self.client, tribe=self.tribe, location=dict(latitude=self.trigger_event.origins[0].latitude, longitude=self.trigger_event.origins[0].longitude), starttime=self.trigger_event.origins[0].time) self.assertEqual(len(inventory), 10)
def run_real_time_matched_filter(**kwargs): config = read_config(config_file=kwargs.get("config_file", None)) debug = kwargs.get("debug", False) if debug: config.log_level = "DEBUG" print("Using the following configuration:\n{0}".format(config)) config.setup_logging() Logger.debug("Running in debug mode - expect lots of output!") client = config.rt_match_filter.get_client() if kwargs.get("local_archive"): local_wave_bank = WaveBank( base_path=config.rt_match_filter.local_wave_bank) client = ClientBank(wave_bank=local_wave_bank, event_bank=client, station_bank=client) triggering_eventid = kwargs.get("eventid", None) if triggering_eventid: triggering_event = client.get_events(eventid=triggering_eventid)[0] region = estimate_region(triggering_event) tribe_name = triggering_eventid else: triggering_event = None region = { "latitude": kwargs.get("latitude", None), "longitude": kwargs.get("longitude", None), "maxradius": kwargs.get("maxradius", None) } tribe_name = "{0}_{1}_{2}".format(kwargs.get("latitude", "lat"), kwargs.get("longitude", "long"), kwargs.get("maxradius", "rad")) starttime = kwargs.get("starttime", None) endtime = kwargs.get("endtime", None) rt_client_starttime = kwargs.get("rt_client_starttime", None) if starttime is not None: region.update({"starttime": starttime}) if endtime is not None: region.update({"endtime": endtime}) elif rt_client_starttime is not None: region.update({"endtime": rt_client_starttime}) bank = TemplateBank(base_path=config.database_manager.event_path, name_structure=config.database_manager.name_structure, event_format=config.database_manager.event_format, path_structure=config.database_manager.path_structure, event_ext=config.database_manager.event_ext) Logger.info("Region: {0}".format(region)) df = bank.get_event_summary(**region) Logger.info("{0} events within region".format(len(df))) if len(df) == 0: return Party() Logger.info("Reading in Tribe") tribe = bank.get_templates(**region) Logger.info("Read in tribe of {0} templates".format(len(tribe))) _detection_starttime = rt_client_starttime or UTCDateTime.now() inventory = get_inventory(client, tribe, triggering_event=triggering_event, location=region, starttime=_detection_starttime, max_distance=1000, n_stations=10) used_channels = { "{net}.{sta}.{loc}.{chan}".format(net=net.code, sta=sta.code, loc=chan.location_code, chan=chan.code) for net in inventory for sta in net for chan in sta } tribe = check_tribe_quality( tribe=tribe, seed_ids=used_channels, min_stations=config.database_manager.min_stations, **config.template) Logger.info("After some QC there are {0} templates in the Tribe".format( len(tribe))) if rt_client_starttime is not None: config.streaming.starttime = rt_client_starttime config.streaming.speed_up = kwargs.get("speed_up", 1.0) config.plot.offline = True rt_client = config.streaming.get_streaming_client() real_time_tribe = RealTimeTribe( tribe=tribe, inventory=inventory, rt_client=rt_client, detect_interval=config.rt_match_filter.detect_interval, plot=config.rt_match_filter.plot, name=tribe_name, plot_options=config.plot, wavebank=config.rt_match_filter.local_wave_bank) try: real_time_tribe._speed_up = config.streaming.speed_up except AttributeError: real_time_tribe._speed_up = 1 party = None try: party = real_time_tribe.run(**config.rt_match_filter) except KeyboardInterrupt as e: Logger.error(e) finally: real_time_tribe.stop() return party
def test_small_region(self): inventory = get_inventory(client=self.client, tribe=self.tribe, triggering_event=self.trigger_event, max_distance=50.) self.assertLess(len(inventory), 10)
def test_get_inventory_using_event(self): inventory = get_inventory(client=self.client, tribe=self.tribe, triggering_event=self.trigger_event) self.assertEqual(len(inventory), 10)