本文整理汇总了Python中obspy.UTCDateTime.strftime方法的典型用法代码示例。如果您正苦于以下问题:Python UTCDateTime.strftime方法的具体用法?Python UTCDateTime.strftime怎么用?Python UTCDateTime.strftime使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类obspy.UTCDateTime
的用法示例。
在下文中一共展示了UTCDateTime.strftime方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _colormap_plot_beamforming_time
# 需要导入模块: from obspy import UTCDateTime [as 别名]
# 或者: from obspy.UTCDateTime import strftime [as 别名]
def _colormap_plot_beamforming_time(cmaps):
"""
Plot for illustrating colormaps: beamforming.
:param cmaps: list of :class:`~matplotlib.colors.Colormap`
:rtype: None
"""
import matplotlib.pyplot as plt
import matplotlib.dates as mdates
from obspy import UTCDateTime
from obspy.signal.array_analysis import array_processing
# Execute array_processing
stime = UTCDateTime("20080217110515")
etime = UTCDateTime("20080217110545")
kwargs = dict(
# slowness grid: X min, X max, Y min, Y max, Slow Step
sll_x=-3.0, slm_x=3.0, sll_y=-3.0, slm_y=3.0, sl_s=0.03,
# sliding window properties
win_len=1.0, win_frac=0.05,
# frequency properties
frqlow=1.0, frqhigh=8.0, prewhiten=0,
# restrict output
semb_thres=-1e9, vel_thres=-1e9, timestamp='mlabday',
stime=stime, etime=etime
)
st = _get_beamforming_example_stream()
out = array_processing(st, **kwargs)
# Plot
labels = ['rel.power', 'abs.power', 'baz', 'slow']
xlocator = mdates.AutoDateLocator()
for cmap in cmaps:
fig = plt.figure()
for i, lab in enumerate(labels):
ax = fig.add_subplot(4, 1, i + 1)
ax.scatter(out[:, 0], out[:, i + 1], c=out[:, 1], alpha=0.6,
edgecolors='none', cmap=cmap)
ax.set_ylabel(lab)
ax.set_xlim(out[0, 0], out[-1, 0])
ax.set_ylim(out[:, i + 1].min(), out[:, i + 1].max())
ax.xaxis.set_major_locator(xlocator)
ax.xaxis.set_major_formatter(mdates.AutoDateFormatter(xlocator))
fig.suptitle('AGFA skyscraper blasting in Munich %s' % (
stime.strftime('%Y-%m-%d'), ))
fig.autofmt_xdate()
fig.subplots_adjust(left=0.15, top=0.95, right=0.95, bottom=0.2,
hspace=0)
plt.show()
示例2: main
# 需要导入模块: from obspy import UTCDateTime [as 别名]
# 或者: from obspy.UTCDateTime import strftime [as 别名]
#.........这里部分代码省略.........
f.write('sta_id lat lon elev\n')
for stationcode,stationvals in stations.iteritems():
slat,slon,elev = stationvals
f.write('%s %.4f %.4f %.3f\n' % (stationcode,slat,slon,elev))
f.close()
arrfile = 'arrival.dat'
arrivalfile = os.path.join(eventfolder,arrfile)
f = open(arrivalfile,'wt')
f.write('ev_id sta_id phase time\n')
for arrival in arrivals:
eid,scode,phase,time = arrival
f.write('%i %s %s %.3f\n' % (eid,scode,phase,time))
f.close()
prifile = 'prior.dat' #??
priorfile = os.path.join(eventfolder,prifile)
f = open(priorfile,'wt')
f.write('ev_id lat_mean lon_mean dist_sd depth_mean depth_sd time_mean time_sd\n')
for prior in priors:
evid,plat,plon,pdepth,ptime = prior
f.write('%i %.4f %.4f 0.0 %.1f 0.0 %.3f 0.0\n' % (evid,plat,plon,pdepth,ptime))
f.close()
#write the config file
configfile = os.path.join(eventfolder,'bayesloc.cfg')
config = CONFIG.replace('BAYESLOC',BAYESLOC)
config = config.replace('EVENTFOLDER',eventfolder)
fcfg = open(configfile,'wt')
fcfg.write(config)
fcfg.close()
#Run the BayesLoc program
#change to the eventfolder
cwd = os.getcwd()
os.chdir(eventfolder)
bayesbin = os.path.join(BAYESLOC,'bin','bayesloc')
cmd = '%s %s' % (bayesbin,configfile)
print 'Running command %s...' % cmd
t1 = datetime.now()
# process = subprocess.Popen(cmd, stdout=subprocess.PIPE)
# for c in iter(lambda: process.stdout.read(1), ''):
# sys.stderr.write(c)
res,stdout,stderr = getCommandOutput(cmd)
t2 = datetime.now()
if not res:
print 'BayesLoc command "%s" failed. \n%s\n%s.' % (cmd,stdout,stderr)
sys.exit(1)
else:
dt = ((t2-t1).seconds)/60.0
print 'BayesLoc command was successful - took %.1f minutes.' % dt
os.chdir(cwd)
resultfile = os.path.join(eventfolder,'output','origins_ned_stats.out')
f = open(resultfile,'rt')
f.readline()
eventlist = []
fieldlist = ['lat','lon','depth','time','rlat','rlon','rdepth','rtime','mag','nevents']
nevents = len(priors) + len(newevents)
for line in f.readlines():
parts = line.split()
eid = int(parts[0])
lat = float(parts[1])
lon = float(parts[2])
depth = float(parts[3])
time = UTCDateTime(float(parts[4])).datetime
efmt = 'UPDATE event set rlat=%.4f,rlon=%.4f,rdepth=%.1f,rtime="%s",nevents=%i WHERE id=%i'
equery = efmt % (lat,lon,depth,time,nevents,eid)
cursor.execute(equery)
db.commit()
query = 'SELECT %s FROM event WHERE id=%i' % (','.join(fieldlist),eid)
cursor.execute(query)
row = cursor.fetchone()
eventlist.append(dict(zip(fieldlist,row)))
f.close()
#make a map of all the relocated events
fname = makeMap(eventlist,eventlat,eventlon,eventfolder)
print 'Relocated events: %s' % fname
#tell the user what happened with the relocation
fmt = 'SELECT lat,lon,depth,time,rlat,rlon,rdepth,rtime,nevents FROM event WHERE code="%s"'
query = fmt % (eventid)
cursor.execute(query)
row = cursor.fetchone()
lat,lon,depth,time,rlat,rlon,rdepth,rtime,nevents = row
time = UTCDateTime(time).datetime
rtime = UTCDateTime(rtime).datetime
if rtime >= time:
dt = (rtime-time).seconds + ((rtime-time).microseconds)/float(1e6)
else:
dt = (time-rtime).seconds + ((time-rtime).microseconds)/float(1e6)
dd,az1,az2 = gps2DistAzimuth(lat,lon,rlat,rlon)
dd /= 1000.0
print 'Event %s was relocated using %i events.' % (eventid,nevents)
print 'Starting: %s (%.4f,%.4f) %.1f km' % (time.strftime('%Y-%m-%d %H:%M:%S'),lat,lon,depth)
print 'Relocated: %s (%.4f,%.4f) %.1f km' % (rtime.strftime('%Y-%m-%d %H:%M:%S'),rlat,rlon,rdepth)
print '%.1f km (%.1f degrees), %.1f seconds' % (dd,az1,dt)
cursor.close()
db.close()