def getDate(value): if isinstance(value, datetime.datetime): return Core.Time(*(value.timetuple()[:6])) elif isinstance(value, str): value = parsers.parseDate(value) return Core.Time(*(value.timetuple()[:6])) return value
def parse(self, line): # parses a line of input and returns a Pick object line = line.strip().split() pickID, time, net, sta = line[0], line[1], line[2], line[3] # this will become the creation time now = Core.Time.GMT() time = Core.Time() time.fromString("2015-09-25T10:33:42", "%Y-%m-%dT%H:%M:%S") pick = DataModel.Pick.Create(pickID) wfid = DataModel.WaveformStreamID() wfid.setNetworkCode(net) wfid.setStationCode(sta) pick.setWaveformID(wfid) crea = DataModel.CreationInfo() crea.setAuthor("pick import script") crea.setAgencyID("TEST") crea.setCreationTime(now) crea.setModificationTime(now) pick.setCreationInfo(crea) pick.setEvaluationStatus(DataModel.REVIEWED) pick.setEvaluationMode(DataModel.MANUAL) pick.setTime(DataModel.TimeQuantity(time)) pick.setCreationInfo(crea) return pick
def init(self): if not Client.Application.init(self): return False try: cstr = self.commandline().optionString("coord") tstr = self.commandline().optionString("time") except: sys.stderr.write( "must specify origin using '--coord lat,lon,dep --time time'\n" ) return False self.origin = DataModel.Origin.Create() ci = DataModel.CreationInfo() ci.setAgencyID(self.agencyID()) ci.setCreationTime(Core.Time.GMT()) self.origin.setCreationInfo(ci) lat, lon, dep = map(float, cstr.split(",")) self.origin.setLongitude(DataModel.RealQuantity(lon)) self.origin.setLatitude(DataModel.RealQuantity(lat)) self.origin.setDepth(DataModel.RealQuantity(dep)) time = Core.Time() time.fromString(tstr.replace("/", "-") + ":0:0", "%F %T") self.origin.setTime(DataModel.TimeQuantity(time)) return True
def _parseTime(timestring): t = Core.Time() if t.fromString(timestring, "%F %T"): return t if t.fromString(timestring, "%FT%T"): return t if t.fromString(timestring, "%FT%TZ"): return t return None
def _overlaps(self, pstart, pend, cstart, cend): if cstart is None and cend is None: return True if cstart is None: cstart = Core.Time() if pend is not None: if pend > cstart: if cend is None or pstart < cend: return True else: if cend is None or pstart < cend: return True return False
def parseTime(self, timeStr): time = Core.Time() for fmt in TimeFormats: if time.fromString(timeStr, fmt): break return time
def datetime_to_seiscomp(dt): """Convert a python or obspy UTC datetime to a seiscomp Time.""" if isinstance(dt, UTCDateTime): dt = dt.datetime return Core.Time(dt.year, dt.month, dt.day, dt.hour, dt.minute, dt.second, dt.microsecond)
def parseLogLine(self, line): 'convert log lines to sc3 objects' if 'E:I: ' in line or 'E:I:F' in line: # origin parameters #E:I:H: eventid ver evlat evlon dep mag time latu lonu depu magu timeu lk nTb nSb nT nS ave rms fitok splitok near statrig active inact nsta percnt prcntok mindist maxdist distok azspan Mok nSok Lok Tdif Tok Aok Ast alert_time timeStamp, Eid, ver, lat, lon, depth, mag, otTxt, latu, lonu, depu, magu, timeu, lk, nTb, nSb, nT, nS, ave, rms, fitok, splitok, near, statrig, active, inact, nsta, percnt, prcntok, mindist, maxdist, distok, azspan, Mok, nSok, Lok, Tdif, Tok, Aok, Ast, atimeTxt = line.strip( ).split() # parse line creationTime = sccore.Time() # creation time placeholder creationTime.fromString( atimeTxt, '%Y-%m-%dT%H:%M:%S.%f') # get creation time ot = sccore.Time() # origin time placeholder ot.fromString(otTxt, '%Y-%m-%dT%H:%M:%S.%f') # get origin time self._origin = self.createOrigin( ot=ot, otu=timeu, lat=lat, lon=lon, depth=depth, mag=mag, latu=latu, lonu=lonu, depthu=depu, magu=magu, reported=Aok, creationTime=creationTime) # add origin self.addOriginQuality(self._origin, nT, nS, azspan, maxdist, mindist, rms) # add origin quality self.eparams.add(self._origin) if int(Eid) > 0: # if event has a positive id number self.addEvent(Eid, origins=[self._origin]) #add origin to event if 'E:I:T: ' in line: # Trigger #E:I:T:H: eventid ver update order sta chan net loc lat lon trigger_time log_taup taup_snr log_pd pd_snr log_pv pv_snr pa pa_snr assoc tpmag utpm pdmag updm uch ukm upd ups utp uts distkm azimuth [tterr plen sps toffset arrtime protime fndtime quetime sndtime e2time buftime alert] timeStamp, Eid, ver, update, order, sta, chn, net, loc, lat, lon, trigger_time, log_taup, taup_snr, log_pd, pd_snr, log_pv, pv_snr, pa, pa_snr, assoc, tpmag, utpm, pdmag, updm, uch, ukm, upd, ups, utp, uts, distkm, azimuth = line.strip( ).split()[:33] # parse line pTime = sccore.Time() pTime.fromString(trigger_time, '%Y-%m-%dT%H:%M:%S.%f') # get pick time if loc == '--': loc = '' # adjust location format creationTime = sccore.Time() creationTime.fromString( trigger_time.split('T')[0] + 'T' + timeStamp.split("|")[0], '%Y-%m-%dT%H:%M:%S.%f') # get creation time pick = self.addPick(pTime, net, sta, loc, chn, azimuth, distkm, latency=0, creationTime=creationTime) # add pick self.addArrival(self._origin, pick.publicID(), azimuth, distkm) # add arrival to current origin amp = self.addAmplitude(ampval=log_pd, amptype='log_pd', snr=pd_snr, pickid=pick.publicID(), timeref=pTime, starttime=0, endtime=update, creationTime=creationTime) self.addStationMagnitude(self._origin, magval=pdmag, amp=amp, weight=1) amp = self.addAmplitude(ampval=log_taup, amptype='log_taup', snr=taup_snr, pickid=pick.publicID(), timeref=pTime, starttime=0, endtime=update, creationTime=creationTime) self.addStationMagnitude(self._origin, magval=tpmag, amp=amp, weight=0)