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 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 xrange(narr): picks.append(self._cache.get(seiscomp3.DataModel.Pick, org.arrival(i).pickID())) nstamags = org.stationMagnitudeCount() for i in xrange(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())
class ProcAlert(seiscomp3.Client.Application): def __init__(self, argc, argv): seiscomp3.Client.Application.__init__(self, argc, argv) self.setMessagingEnabled(True) self.setDatabaseEnabled(True, True) self.setAutoApplyNotifierEnabled(True) self.setInterpretNotifierEnabled(True) self.setPrimaryMessagingGroup("LISTENER_GROUP") self.addMessagingSubscription("EVENT") self.addMessagingSubscription("LOCATION") self.addMessagingSubscription("MAGNITUDE") self.maxAgeDays = 1. self.minPickCount = 25 self.procAlertScript = "" ep = seiscomp3.DataModel.EventParameters() def createCommandLineDescription(self): try: self.commandline().addGroup("Publishing") self.commandline().addIntOption("Publishing", "min-arr", "Minimum arrival count of a published origin", self.minPickCount) self.commandline().addDoubleOption("Publishing", "max-age", "Maximum age in days of published origins", self.maxAgeDays) self.commandline().addStringOption("Publishing", "procalert-script", "Specify the script to publish an event. The ProcAlert file and the event id are passed as parameter $1 and $2") self.commandline().addOption("Publishing", "test", "Test mode, no messages are sent") except: seiscomp3.Logging.warning( "caught unexpected error %s" % sys.exc_info()) def initConfiguration(self): if not seiscomp3.Client.Application.initConfiguration(self): return False try: self.procAlertScript = self.configGetString("scripts.procAlert") except: pass try: self.minPickCount = self.configGetInt("minArrivals") except: pass try: self.maxAgeDays = self.configGetDouble("maxAgeDays") except: pass return True 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 addObject(self, parentID, obj): org = seiscomp3.DataModel.Origin.Cast(obj) if org: self.cache.feed(org) seiscomp3.Logging.info("Received origin %s" % org.publicID()) return self.updateObject(parentID, obj) def updateObject(self, parentID, obj): try: evt = seiscomp3.DataModel.Event.Cast(obj) if evt: orid = evt.preferredOriginID() org = self.cache.get(seiscomp3.DataModel.Origin, orid) if not org: seiscomp3.Logging.error("Unable to fetch origin %s" % orid) return if org.arrivalCount() == 0: self.query().loadArrivals(org) if org.stationMagnitudeCount() == 0: self.query().loadStationMagnitudes(org) if org.magnitudeCount() == 0: self.query().loadMagnitudes(org) if not self.originMeetsCriteria(org, evt): seiscomp3.Logging.warning("Origin %s not published" % orid) return txt = self.bulletin.printEvent(evt) for line in txt.split("\n"): line = line.rstrip() seiscomp3.Logging.info(line) seiscomp3.Logging.info("") if not self.commandline().hasOption("test"): self.send_procalert(txt, evt.publicID()) return except: sys.stderr.write("%s\n" % sys.exc_info()) def hasValidNetworkMagnitude(self, org, evt): nmag = org.magnitudeCount() for imag in range(nmag): mag = org.magnitude(imag) if mag.publicID() == evt.preferredMagnitudeID(): return True return False def send_procalert(self, txt, evid): if self.procAlertScript: tmp = "/tmp/yyy%s" % evid.replace("/", "_").replace(":", "-") f = file(tmp, "w") f.write("%s" % txt) f.close() os.system(self.procAlertScript + " " + tmp + " " + evid) def coordinates(self, org): return org.latitude().value(), org.longitude().value(), org.depth().value() def originMeetsCriteria(self, org, evt): publish = True lat, lon, dep = self.coordinates(org) if 43 < lat < 70 and -10 < lon < 60 and dep > 200: seiscomp3.Logging.error("suspicious region/depth - ignored") publish = False if stationCount(org) < self.minPickCount: seiscomp3.Logging.error("too few picks - ignored") publish = False now = seiscomp3.Core.Time.GMT() if (now - org.time().value()).seconds()/86400. > self.maxAgeDays: seiscomp3.Logging.error("origin too old - ignored") publish = False try: if org.evaluationMode() == seiscomp3.DataModel.MANUAL: publish = True except: pass try: if org.evaluationStatus() == seiscomp3.DataModel.CONFIRMED: publish = True except: pass if not self.hasValidNetworkMagnitude(org, evt): seiscomp3.Logging.error("no network magnitude - ignored") publish = False return publish
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())
class ProcAlert(seiscomp3.Client.Application): def __init__(self, argc, argv): seiscomp3.Client.Application.__init__(self, argc, argv) self.setMessagingEnabled(True) self.setDatabaseEnabled(True, True) self.setAutoApplyNotifierEnabled(True) self.setInterpretNotifierEnabled(True) self.setPrimaryMessagingGroup("LISTENER_GROUP") self.addMessagingSubscription("EVENT") self.addMessagingSubscription("LOCATION") self.addMessagingSubscription("MAGNITUDE") self.maxAgeDays = 1. self.minPickCount = 25 self.procAlertScript = "" ep = seiscomp3.DataModel.EventParameters() def createCommandLineDescription(self): try: self.commandline().addGroup("Publishing") self.commandline().addIntOption("Publishing", "min-arr", "Minimum arrival count of a published origin", self.minPickCount) self.commandline().addDoubleOption("Publishing", "max-age", "Maximum age in days of published origins", self.maxAgeDays) self.commandline().addStringOption("Publishing", "procalert-script", "Specify the script to publish an event. The ProcAlert file and the event id are passed as parameter $1 and $2") self.commandline().addOption("Publishing", "test", "Test mode, no messages are sent") except: seiscomp3.Logging.warning("caught unexpected error %s" % sys.exc_info()) def initConfiguration(self): if not seiscomp3.Client.Application.initConfiguration(self): return False try: self.procAlertScript = self.configGetString("scripts.procAlert") except: pass try: self.minPickCount = self.configGetInt("minArrivals") except: pass try: self.maxAgeDays = self.configGetDouble("maxAgeDays") except: pass return True 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 addObject(self, parentID, obj): org = seiscomp3.DataModel.Origin.Cast(obj) if org: self.cache.feed(org) seiscomp3.Logging.info("Received origin %s" % org.publicID()) return self.updateObject(parentID, obj) def updateObject(self, parentID, obj): try: evt = seiscomp3.DataModel.Event.Cast(obj) if evt: orid = evt.preferredOriginID() org = self.cache.get(seiscomp3.DataModel.Origin, orid) if not org: seiscomp3.Logging.error("Unable to fetch origin %s" % orid) return if org.arrivalCount() == 0: self.query().loadArrivals(org) if org.stationMagnitudeCount() == 0: self.query().loadStationMagnitudes(org) if org.magnitudeCount() == 0: self.query().loadMagnitudes(org) if not self.originMeetsCriteria(org, evt): seiscomp3.Logging.warning("Origin %s not published" % orid) return txt = self.bulletin.printEvent(evt) for line in txt.split("\n"): line = line.rstrip() seiscomp3.Logging.info(line) seiscomp3.Logging.info("") if not self.commandline().hasOption("test"): self.send_procalert(txt, evt.publicID()) return except: print >> sys.stderr, sys.exc_info() def hasValidNetworkMagnitude(self, org, evt): nmag = org.magnitudeCount() for imag in xrange(nmag): mag = org.magnitude(imag) if mag.publicID() == evt.preferredMagnitudeID(): return True return False def send_procalert(self, txt, evid): if self.procAlertScript: tmp = "/tmp/yyy%s" % evid.replace("/","_").replace(":","-") f = file(tmp, "w") f.write("%s" % txt) f.close() os.system(self.procAlertScript + " " + tmp + " " + evid) def coordinates(self, org): return org.latitude().value(), org.longitude().value(), org.depth().value() def originMeetsCriteria(self, org, evt): publish = True lat, lon, dep = self.coordinates(org) if 43 < lat < 70 and -10 < lon < 60 and dep > 200: seiscomp3.Logging.error("suspicious region/depth - ignored") publish = False if stationCount(org) < self.minPickCount: seiscomp3.Logging.error("too few picks - ignored") publish = False now = seiscomp3.Core.Time.GMT() if (now - org.time().value()).seconds()/86400. > self.maxAgeDays: seiscomp3.Logging.error("origin too old - ignored") publish = False try: if org.evaluationMode() == seiscomp3.DataModel.MANUAL: publish = True except: pass try: if org.evaluationStatus() == seiscomp3.DataModel.CONFIRMED: publish = True except: pass if not self.hasValidNetworkMagnitude(org, evt): seiscomp3.Logging.error("no network magnitude - ignored") publish = False return publish