def init(self): if not seiscomp3.Client.Application.init(self): return False try: self.procAlertScript = self.commandline().optionString("procalert-script") except: pass try: self.minPickCount = self.commandline().optionInt("min-arr") except: pass try: self.maxAgeDays = self.commandline().optionDouble("max-age") except: pass self.bulletin = Bulletin(self.query(), "autoloc1") self.cache = seiscomp3.DataModel.PublicObjectRingBuffer( self.query(), 100) if not self.procAlertScript: seiscomp3.Logging.warning("No procalert script given") else: seiscomp3.Logging.info( "Using procalert script: %s" % self.procAlertScript) return True
def printEventProcAlert(self, evt, newEvent): now = seiscomp3.Core.Time.GMT() org = self._cache.get(seiscomp3.DataModel.Origin, evt.preferredOriginID()) prefmag = self._cache.get(seiscomp3.DataModel.Magnitude, evt.preferredMagnitudeID()) summary = self.getSummary(now, org, prefmag) # Load arrivals if org.arrivalCount() == 0: self.query().loadArrivals(org) # Load station magnitudes if org.stationMagnitudeCount() == 0: self.query().loadStationMagnitudes(org) # Load magnitudes if org.magnitudeCount() == 0: self.query().loadMagnitudes(org) picks = [] amps = [] if org: narr = org.arrivalCount() for i in range(narr): picks.append( self._cache.get(seiscomp3.DataModel.Pick, org.arrival(i).pickID())) nstamags = org.stationMagnitudeCount() for i in range(nstamags): amps.append( self._cache.get(seiscomp3.DataModel.Amplitude, org.stationMagnitude(i).amplitudeID())) netmag = {} nmag = org.magnitudeCount() bulletin = Bulletin(None, self._format) try: txt = bulletin.printEvent(evt) except: txt = "" if self._directory is None: sys.stdout.write("%s" % ("#<\n" + txt + "#>\n")) sys.stdout.flush() else: # Use created time to look up the proper directory try: arNow = evt.creationInfo().creationTime().get() # Otherwise use now (in case that event.created has not been set # which is always valid within the SC3 distribution except: arNow = now.get() seiscomp3.Logging.error("directory is " + self._directory + "/".join(["%.2d" % i for i in arNow[1:4]]) + "/" + evt.publicID() + "/") directory = self._directory + \ "/".join(["%.2d" % i for i in arNow[1:4]]) + \ "/" + evt.publicID() + "/" if directory != self._currentDirectory: if createDirectory(directory) == False: seiscomp3.Logging.error("Unable to create directory %s" % directory) return self._currentDirectory = directory self.writeLog( self._currentDirectory + self.convertID(evt.publicID()) + "." + ("%06d" % self.eventProgress(evt.publicID(), directory)), txt, "w") self.writeLog( self._currentDirectory + self.convertID(evt.publicID()) + ".last", txt, "w") self.writeLog(self._directory + "last", txt, "w") self.writeLog( self._currentDirectory + self.convertID(evt.publicID()) + ".summary", "|".join(summary), "a", "# Layout: Timestamp, +OT (minutes, decimal), Latitude, Longitude, Depth, PhaseCount, MagType, Magnitude, MagCount" ) seiscomp3.Logging.info("cache size = %d" % self._cache.size())