本文整理汇总了Python中pyrocko.util.str_to_time函数的典型用法代码示例。如果您正苦于以下问题:Python str_to_time函数的具体用法?Python str_to_time怎么用?Python str_to_time使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了str_to_time函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: read_enhanced_sac_pz
def read_enhanced_sac_pz(filename):
zeros, poles, constant, comments = pz.read_sac_zpk(filename=filename, get_comments=True)
d = {}
for line in comments:
toks = line.split(':', 1)
if len(toks) == 2:
temp = toks[0].strip('* \t')
for k in ('network', 'station', 'location', 'channel', 'start', 'end',
'latitude', 'longitude', 'depth', 'elevation', 'dip', 'azimuth',
'input unit', 'output unit'):
if temp.lower().startswith(k):
d[k] = toks[1].strip()
response = trace.PoleZeroResponse(zeros, poles, constant)
try:
channel = Channel(
nslc=(d['network'], d['station'], d['location'], d['channel']),
tmin=util.str_to_time(d['start'], format='%Y-%m-%dT%H:%M:%S'),
tmax=util.str_to_time(d['end'], format='%Y-%m-%dT%H:%M:%S'),
lat=float(d['latitude']),
lon=float(d['longitude']),
elevation=float(d['elevation']),
depth=float(d['depth']),
dip=float(d['dip']),
azimuth=float(d['azimuth']),
input_unit=d['input unit'],
output_unit=d['output unit'],
response=response)
except:
raise EnhancedSacPzError('cannot get all required information from file %s' % filename)
return channel
示例2: testUSGS
def testUSGS(self):
def is_the_haiti_event(ev):
assert near(ev.magnitude, 7.0, 0.1)
assert near(ev.lat, 18.443, 0.01)
assert near(ev.lon, -72.571, 0.01)
assert near(ev.depth, 13000., 1.)
cat = catalog.USGS()
tmin = util.str_to_time('2010-01-12 21:50:00')
tmax = util.str_to_time('2010-01-13 03:17:00')
names = cat.get_event_names(time_range=(tmin, tmax), magmin=5.)
assert len(names) == 13
for name in names:
ev = cat.get_event(name)
if ev.magnitude >= 7.:
is_the_haiti_event(ev)
ident = ev.name
assert ident is not None
cat.flush()
ev = cat.get_event(ident)
is_the_haiti_event(ev)
示例3: read_data
def read_data(fn):
"""Read a buletin from the IG CAS website.
Creates objects of type ResidualMarker (subclass of pyrocko.gui_util.PhaseMarker) and pyrocko.model.Event.
"""
picks = []
events = []
with open(fn, 'r') as f:
for line in f.readlines():
odate, eventid, otime, lon, _, lat, _, _, depth, _, _, mag, stat, phase_id, polarity, date, t, a = line.split()
otime = util.str_to_time('%s %s'%(odate, otime))
event = model.Event(lat=float(lat),
lon=float(lon),
depth=float(depth),
time=otime)
t_pick = util.str_to_time('%s %s'%(date, t))
pick = ResidualMarker(event=event,
tmin=float(t_pick),
tmax=float(t_pick),
nslc_ids=[('', stat, '', '*'),],
phasename=phase_id,
polarity=int(polarity),
event_time=otime,
event_hash=event.get_hash())
if abs(t_pick-otime)>30:
continue
picks.append(pick)
events.append(event)
return picks, events
示例4: readandsplit
def readandsplit(infile, box, stations):
'''
Load phase files and store data in a myStation.
Phasename is retrieved from file name: *_*_Phasename,
where * can be anything.
:param infile: name of the file which is to be read as string.
:param box: instance of myStationBox, containing myStation instances.
:param stations: File as used with snuffler to import station information.
'''
refevent = str_to_time("2010-04-11 22:08:15.500")
phasename = infile.split('_')[2]
phasename = phasename.split('.')[0]
phases = open(infile,'r').readlines()[1::]
for phase in phases:
date,time,length,NSLC = phase.split()
arrival = str_to_time(date+' '+time)-refevent
netw,stat,loc,comp = NSLC.split('.')
# check if card exists, and if it does, add phase to that card:
if(box.stationInBox(netw,stat)):
tmpCard = box.getStationCardForNetworkStation(netw,stat)
tmpCard.setPhase(phasename,arrival)
# if not, create a new card:
else:
newCard=myStation(network=netw,station=stat)
newCard.setPhase(phasename,arrival)
newCard.setLatLonEleFromStation(stations)
box.addStationCard(newCard)
示例5: testGlobalCMT
def testGlobalCMT(self):
def is_the_haiti_event(ev):
assert near(ev.magnitude, 7.0, 0.1)
assert near(ev.lat, 18.61, 0.01)
assert near(ev.lon, -72.62, 0.01)
assert near(ev.depth, 12000., 1.)
assert ev.region.lower() == 'haiti region'
cat = catalog.GlobalCMT()
tmin = util.str_to_time('2010-01-12 21:50:00')
tmax = util.str_to_time('2010-01-13 03:17:00')
names = cat.get_event_names(time_range=(tmin, tmax), magmin=5.)
ident = None
for name in names:
ev = cat.get_event(name)
if ev.magnitude > 7:
is_the_haiti_event(ev)
ident = ev.name
assert ident is not None
cat.flush()
ev = cat.get_event(ident)
is_the_haiti_event(ev)
示例6: testTimeError
def testTimeError(self):
ok = False
try:
util.str_to_time('abc')
except util.TimeStrError:
ok = True
assert ok
示例7: testGeofonMT
def testGeofonMT(self):
cat = catalog.Geofon()
tmin = util.str_to_time('2014-01-01 00:00:00')
tmax = util.str_to_time('2017-01-01 00:00:00')
events = cat.get_events((tmin, tmax), magmin=8)
self.assertEqual(len(events), 2)
mt1, mt2 = [ev.moment_tensor for ev in events]
angle = moment_tensor.kagan_angle(mt1, mt2)
self.assertEqual(round(angle - 7.7, 1), 0.0)
示例8: dummy_aware_str_to_time
def dummy_aware_str_to_time(s, time_format='%Y-%m-%dT%H:%M:%S'):
try:
util.str_to_time(s, format=time_format)
except util.TimeStrError:
year = int(s[:4])
if year > this_year + 100:
return None # StationXML contained a dummy end date
raise
示例9: testTime
def testTime(self):
for fmt, accu in zip(
[ '%Y-%m-%d %H:%M:%S.3FRAC', '%Y-%m-%d %H:%M:%S.2FRAC', '%Y-%m-%d %H:%M:%S.1FRAC', '%Y-%m-%d %H:%M:%S' ],
[ 0.001, 0.01, 0.1, 1.] ):
ta = util.str_to_time('1960-01-01 10:10:10')
tb = util.str_to_time('2020-01-01 10:10:10')
for i in xrange(10000):
t1 = ta + random() * (tb-ta)
s = util.time_to_str(t1, format=fmt)
t2 = util.str_to_time(s, format=fmt)
assert abs( t1 - t2 ) < accu
示例10: testIterTimes
def testIterTimes(self):
tmin = util.str_to_time('1999-03-20 20:10:10')
tmax = util.str_to_time('2001-05-20 10:00:05')
ii = 0
for ymin, ymax in util.iter_years(tmin, tmax):
for mmin, mmax in util.iter_months(ymin, ymax):
ii += 1
s1 = util.time_to_str(mmin)
s2 = util.time_to_str(mmax)
assert ii == 12*3
assert s1 == '2001-12-01 00:00:00.000'
assert s2 == '2002-01-01 00:00:00.000'
示例11: __init__
def __init__(self):
# Set up receiver configuration.
tab = '''
HH1 58.500 12.5000 0
HH2 48.500 12.5000 0
HH3 48.500 3.5000 0
HH4 58.500 3.5000 0
'''.strip()
receivers = []
for line_tab in tab.split('\n'):
station, lat, lon, depth = line_tab.split()
r = receiver.Receiver(lat, lon, components='neu', name='.%s.' % station)
receivers.append(r)
stations = receivers_to_stations(receivers)
model.dump_stations(stations, 'reference_stations.txt')
# Composition of the source
self.olat, self.olon = 52.0000, 9.00000
self.otime = util.str_to_time('1986-08-22 07:00:00')
# The gfdb can be chosen within snuffler.
# This refers to the 'add_parameter' method.
db = gfdb.Gfdb('fomostos/local1/local1')
seis = seismosizer.Seismosizer(hosts=['localhost'])
seis.set_database(db)
seis.set_effective_dt(db.dt)
seis.set_local_interpolation('bilinear')
seis.set_receivers(receivers)
seis.set_source_location(self.olat, self.olon, self.otime)
seis.set_source_constraints(0, 0, 0, 0, 0, -1)
self.seis = seis
示例12: test_evalresp
def test_evalresp(self, plot=False):
resp_fpath = common.test_data_file('test2.resp')
freqs = num.logspace(num.log10(0.001), num.log10(10.), num=1000)
transfer = evalresp.evalresp(
sta_list='BSEG',
cha_list='BHZ',
net_code='GR',
locid='',
instant=util.str_to_time('2012-01-01 00:00:00'),
freqs=freqs,
units='DIS',
file=resp_fpath,
rtype='CS')[0][4]
pz_fpath = common.test_data_file('test2.sacpz')
zeros, poles, constant = pz.read_sac_zpk(pz_fpath)
resp = trace.PoleZeroResponse(zeros, poles, constant)
transfer2 = resp.evaluate(freqs)
if plot:
plot_tfs(freqs, [transfer, transfer2])
assert numeq(transfer, transfer2, 1e-4)
示例13: pdate
def pdate(s):
if s.startswith('2599') or s.startswith('2999'):
return None
elif s.lower().startswith('no'):
return None
else:
return util.str_to_time(s, format='%Y,%j,%H:%M:%S.OPTFRAC')
示例14: test_evalresp
def test_evalresp(self, plot=False):
testdir = os.path.dirname(__file__)
freqs = num.logspace(num.log10(0.001), num.log10(10.), num=1000)
transfer = evalresp.evalresp(sta_list='BSEG',
cha_list='BHZ',
net_code='GR',
locid='',
instant=util.str_to_time('2012-01-01 00:00:00'),
freqs=freqs,
units='DIS',
file=os.path.join(testdir, 'response', 'RESP.GR.BSEG..BHZ'),
rtype='CS')[0][4]
pzfn = 'SAC_PZs_GR_BSEG_BHZ__2008.254.00.00.00.0000_2599.365.23.59.59.99999'
zeros, poles, constant = pz.read_sac_zpk(filename=os.path.join(
testdir, 'response', pzfn))
resp = trace.PoleZeroResponse(zeros, poles, constant)
transfer2 = resp.evaluate(freqs)
if plot:
import pylab as lab
lab.plot(freqs, num.imag(transfer))
lab.plot(freqs, num.imag(transfer2))
lab.gca().loglog()
lab.show()
assert numeq(transfer, transfer2, 1e-4)
示例15: window
def window(lat, lon, lat_source, lon_source, depth_source, nsta, store):
center = Array_center(lat, lon)
source_reciever_dis = orthodrome.distance_accurate50m_numpy(
lat_source, lon_source, lat, lon)
t_p = np.array([
store.t("first(p|P)", (depth_source, int(source_reciever_dis[i])))
for i in range(0, nsta)])
t_s = np.array([
store.t("first(s|S)", (depth_source, int(source_reciever_dis[i])))
for i in range(0, nsta)])
t_origin = util.str_to_time('2008-02-17 11:06:01.10')
def win_(t_, t_l , t_r, center):
wind_i = t_origin + t_ - t_l
wind_e = t_origin + t_ + t_r
t_o = - t_ + t_[center]
return wind_i, wind_e, t_o
P_wind_i, P_wind_e, t_op = win_(t_p, 5.0 , 20.0, center)
S_wind_i, S_wind_e, t_os = win_(t_s, 2.0 , 18.0, center)
return P_wind_i, P_wind_e, t_op , center#, S_wind_i, S_wind_e, t_os