def spin_up(self, triggering_event: Event) -> None: """ Run the reactors response function as a subprocess. Parameters ---------- triggering_event Event that triggered this run - needs to have at-least an origin. """ triggering_event_id = triggering_event.resource_id.id.split('/')[-1] region = estimate_region( triggering_event, multiplier=self.config.reactor.scaling_multiplier or 1.0, min_length=self.config.reactor.minimum_lookup_radius or 50.0) if region is None: return region.update( {"starttime": self.config.database_manager.lookup_starttime}) Logger.info("Getting templates within {0}".format(region)) df = self.template_database.get_event_summary(**region) event_ids = {e for e in df["event_id"]} event_ids = event_ids.difference(self.running_template_ids) Logger.debug(f"event-ids in region: {event_ids}") # Write file of event id's if len(event_ids) == 0: return tribe = self.template_database.get_templates(eventid=event_ids) Logger.info(f"Found {len(tribe)} templates") if len(tribe) == 0: Logger.info("No templates, not running") working_dir = _get_triggered_working_dir(triggering_event_id, exist_ok=True) tribe.write(os.path.join(working_dir, "tribe.tgz")) self.config.write(os.path.join(working_dir, 'rt_eqcorrscan_config.yml')) triggering_event.write(os.path.join(working_dir, 'triggering_event.xml'), format="QUAKEML") script_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), "spin_up.py") _call = [ "python", script_path, "-w", working_dir, "-n", str(min(self.available_cores, self._max_detect_cores)) ] Logger.info("Running `{call}`".format(call=" ".join(_call))) proc = subprocess.Popen(_call) self.detecting_processes.update({triggering_event_id: proc}) self._running_regions.update({triggering_event_id: region}) self._running_templates.update( {triggering_event_id: {t.event.resource_id.id for t in tribe}}) Logger.info("Started detector subprocess - continuing listening")
def test_issue_2173(self): """ Ensure events with empty origins are equal after round-trip to disk. See #2173. """ # create event and save to disk origin = Origin(time=UTCDateTime('2016-01-01')) event1 = Event(origins=[origin]) bio = io.BytesIO() event1.write(bio, 'quakeml') # read from disk event2 = read_events(bio)[0] # saved and loaded event should be equal self.assertEqual(event1, event2)