本文整理汇总了Python中pyrocko.util.setup_logging函数的典型用法代码示例。如果您正苦于以下问题:Python setup_logging函数的具体用法?Python setup_logging怎么用?Python setup_logging使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了setup_logging函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: make_targets
import sys
import matplotlib
matplotlib.use('Qt4Agg')
import logging
import os.path as op
import numpy as num
import progressbar
from pyrocko import model, trace, util, orthodrome, cake, gui_util
from pyrocko.gf.seismosizer import Target, SeismosizerTrace
from pyrocko.snuffling import Snuffling, Choice, Param, Switch
from similarity import SimilarityMatrix, Similarity
import matplotlib.pyplot as plt
util.setup_logging('cc.py')
logger = logging.getLogger('cc-snuffling')
def make_targets(pile, stations):
targets = []
for nslc_id in pile.nslc_ids.keys():
for s in stations:
if util.match_nslc('%s.*'%(s.nsl_string()), nslc_id):
targets.append(Target(lat=s.lat,
lon=s.lon,
depth=s.depth,
elevation=s.elevation,
codes=nslc_id))
else:
continue
return targets
示例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)
if __name__ == "__main__":
util.setup_logging('test_catalog', 'debug')
unittest.main()
示例3: CPT
for level in dry.levels:
if level.vmax > 0.0:
if level.vmin < 0.0:
level.vmin = 0.0
levels.append(level)
combi = CPT(color_below=wet.color_below, color_above=dry.color_above, color_nan=dry.color_nan, levels=levels)
return combi
if __name__ == "__main__":
from pyrocko import util
util.setup_logging("pyrocko.automap", "info")
m = Map(
lat=rand(40, 70.0),
lon=rand(0.0, 20.0),
radius=math.exp(rand(math.log(10 * km), math.log(2000 * km))),
width=rand(10, 20),
height=rand(10, 20),
show_grid=True,
show_topo=True,
illuminate=True,
)
m.draw_cities()
print m
m.save("map.pdf")
示例4: template
dest='markers_filename',
metavar='FILENAME',
help='Read markers from FILENAME')
parser.add_option(
'--output',
dest='out_filename',
default=default_output_filename,
metavar='FILENAME',
help='set output filename template (default="%s")' % default_output_filename)
def __snufflings__():
return [ExtractEvents()]
if __name__ == '__main__':
import logging
logger = logging.getLogger()
util.setup_logging('extract_events.py', 'info')
s = ExtractEvents()
options, args, parser = s.setup_cli()
s.markers_filename = options.markers_filename
s.out_filename = options.out_filename
if not options.markers_filename:
logger.critical('no markers file given; use the --markers=FILENAME option')
sys.exit(1)
s.call()
示例5: min
widget = layout.get_widget()
# widget['J'] = ('-JT%g/%g' % (lon, lat)) + '/%(width)gp'
widget['J'] = ('-JE%g/%g/%g' % (lon, lat, min(lat_delta/2.,180.))) + '/%(width)gp'
aspect = gmtpy.aspect_for_projection( *(widget.J() + scaler.R()) )
widget.set_aspect(aspect)
if lat > 0:
axes_layout = 'WSen'
else:
axes_layout = 'WseN'
gmt.psbasemap( #B=('%(xinc)gg%(xinc)g:%(xlabel)s:/%(yinc)gg%(yinc)g:%(ylabel)s:' % scaler.get_params())+axes_layout,
B='5g5',
L=('x%gp/%gp/%g/%g/%gk' % (widget.width()/2., widget.height()/7.,lon,lat,scale_km) ),
*(widget.JXY()+scaler.R()) )
gmt.psxy( in_columns=(lon_grid,lat_grid), S='x10p', W='1p/200/0/0', *(widget.JXY()+scaler.R()) )
gmt.psxy( in_columns=(lon_grid_alt,lat_grid_alt), S='c10p', W='1p/0/0/200', *(widget.JXY()+scaler.R()) )
gmt.save('orthodrome.pdf')
subprocess.call( [ 'xpdf', '-remote', 'ortho', '-reload' ] )
time.sleep(2)
else:
print 'ok', gsize, lat, lon
if __name__ == "__main__":
util.setup_logging('test_orthodrome', 'warning')
unittest.main()
示例6: produce
def produce(deltat, duration):
logging.debug('rate %g Hz, duration %g s' % (1./deltat, duration))
tbegin = time.time()
n = 0
while True:
t = time.time() - tbegin
nt = int(t/deltat)
while n < nt:
d = random.randint(-127, 128)
sys.stdout.write("%i\n" % d)
n += 1
sys.stdout.flush()
tsleep = 0.01
time.sleep(tsleep)
if t > duration:
break
util.setup_logging('producer', 'debug')
produce(0.0025, 20.)
logging.debug('sleep 2 s')
time.sleep(2.)
produce(0.0025, 20.)
produce(0.005, 20.)
produce(0.005005, 20.)
示例7: range
for x in range(nx):
strike = fuzz_angle(0., 360.)
dip = fuzz_angle(0., 90.)
rake = fuzz_angle(-180., 180.)
mt = mtm.MomentTensor(
strike=strike,
dip=dip,
rake=rake)
self.compare_beachball(mt)
def test_specific_dcs(self):
for strike, dip, rake in [
[270., 0.0, 0.01],
[360., 28.373841741182012, 90.],
[0., 0., 0.]]:
mt = mtm.MomentTensor(
strike=strike,
dip=dip,
rake=rake)
self.compare_beachball(mt)
if __name__ == "__main__":
util.setup_logging('test_moment_tensor', 'warning')
unittest.main()
示例8: enumerate
emarker.set_alerted(True)
markers = [_marker, emarker, pmarker]
fn = tempfile.mkstemp()[1]
marker.save_markers(markers, fn)
in_markers = marker.load_markers(fn)
in__marker, in_emarker, in_pmarker = in_markers
for i, m in enumerate(in_markers):
if not isinstance(m, marker.EventMarker):
assert (m.tmax - m.tmin) == 9.
else:
assert not m.is_alerted()
marker.associate_phases_to_events([in_pmarker, in_emarker])
in_event = in_pmarker.get_event()
assert all((in_event.lat == 111., in_event.lon == 111.,
in_event.depth == 111., in_event.time == 111.))
assert in_pmarker.get_event_hash() == in_event.get_hash()
assert in_pmarker.get_event_time() == 111.
if __name__ == "__main__":
util.setup_logging('test_marker', 'warning')
unittest.main()
示例9: len
if tn not in self.available_tilenames():
return None
else:
fpath = self.tilepath(tn)
if not op.exists(fpath):
self.download_tile(tn)
zipf = zipfile.ZipFile(fpath, 'r')
rawdata = zipf.read(tn + '.hgt')
zipf.close()
data = num.fromstring(rawdata, dtype=self.dtype)
assert data.size == self.ntx * self.nty
data = data.reshape(self.nty, self.ntx)[::-1, ::]
return tile.Tile(
self.xmin + itx*self.stx,
self.ymin + ity*self.sty,
self.dx, self.dx, data)
if __name__ == '__main__':
import sys
util.setup_logging('pyrocko.topo.srtmgl3', 'info')
if len(sys.argv) != 2:
sys.exit('usage: python -m pyrocko.topo.srtmgl3 download')
if sys.argv[1] == 'download':
srtmgl3 = SRTMGL3()
srtmgl3.download()
示例10: save_as
def save_as(self):
if self.fig:
fn = self.output_filename()
self.fig.savefig(fn,
pad_inches=0.05,
bbox_inches='tight')
def configure_cli_parser(self, parser):
parser.add_option(
'--events',
dest='events_filename',
default=None,
metavar='FILENAME',
help='Read events from FILENAME')
def __snufflings__():
'''Returns a list of snufflings to be exported by this module.'''
return [ TimeLine() ]
if __name__=='__main__':
import matplotlib.pyplot as plt
util.setup_logging('time_line.py', 'info')
s = TimeLine()
options, args, parser = s.setup_cli()
s.cli_mode = True
if options.events_filename:
s.make_time_line(list(model.Event.load_catalog(options.events_filename)))
示例11: test_new_zealand
replace_topo_color_only=tile,
illuminate=True)
m.draw_cities()
fname = 'automap_test_fidshi.png'
fpath = self.fpath(fname)
m.save(fpath)
self.compare_with_ref(fname, 0.01, show=False)
def test_new_zealand(self):
m = automap.Map(
lat=-42.57,
lon=173.01,
radius=1000.*km,
width=20.,
height=20.,
color_dry=gmtpy.color_tup('aluminium1'),
show_topo=False,
show_rivers=False,
show_plates=True)
m.draw_cities()
fname = 'new_zealand.pdf'
fpath = self.fpath(fname)
m.save(fpath)
if __name__ == "__main__":
util.setup_logging('test_automap', 'warning')
unittest.main()
示例12: range
for n in range(nsrc):
src = gf.RectangularSource(
lat=0., lon=0.,
anchor='bottom',
north_shift=5000., east_shift=9000., depth=4.*km,
width=2.*km, length=8.*km,
dip=0., rake=0., strike=(180./nsrc + 1) * n,
slip=1.)
rect_sources.append(src)
@staticmethod
def plot_rectangular_source(src, store):
from matplotlib import pyplot as plt
from matplotlib.patches import Polygon
ax = plt.gca()
ne = src.outline(cs='xy')
p = Polygon(num.fliplr(ne), fill=False, color='r', alpha=.7)
ax.add_artist(p)
mt = src.discretize_basesource(store)
ax.scatter(mt.east_shifts, mt.north_shifts, alpha=1)
ax.scatter(src.east_shift, src.north_shift, color='r')
plt.axis('equal')
plt.show()
if __name__ == '__main__':
util.setup_logging('test_gf_source_types', 'warning')
unittest.main(defaultTest='GFSourceTypesTestCase')
示例13: range
import random
import logging
from matplotlib import pyplot as plt
from pyrocko import moment_tensor as pmt
from pyrocko import util
from pyrocko.plot import beachball
''' Beachball Copacabana '''
logger = logging.getLogger('pyrocko.examples.beachball_example01')
util.setup_logging()
fig = plt.figure(figsize=(10., 4.))
fig.subplots_adjust(left=0., right=1., bottom=0., top=1.)
axes = fig.add_subplot(1, 1, 1)
for i in range(200):
# create random moment tensor
mt = pmt.MomentTensor.random_mt()
try:
# create beachball from moment tensor
beachball.plot_beachball_mpl(
mt, axes,
# type of beachball: deviatoric, full or double couple (dc)
beachball_type='full',
size=random.random()*120.,
position=(random.random()*10., random.random()*10.),
alpha=random.random(),
示例14: len
s = collection.get_scenario('gnss')
assert len(s.get_gnss_campaigns()) == 1
@unittest.skipUnless(
gmtpy.have_gmt(), 'GMT not available')
@unittest.skipUnless(
have_srtm_credentials(),
'No Earthdata credentials in config.')
def test_scenario_map(self):
tempdir = mkdtemp(prefix='pyrocko-scenario')
self.tempdirs.append(tempdir)
generator = self.generator
engine = gf.get_engine()
collection = scenario.ScenarioCollection(tempdir, engine)
collection.add_scenario('plot', generator)
s = collection.get_scenario('plot')
s.get_map()
def assert_traces_almost_equal(self, trs1, trs2):
assert len(trs1) == len(trs2)
for (tr1, tr2) in zip(trs1, trs2):
tr1.assert_almost_equal(tr2)
if __name__ == '__main__':
util.setup_logging('test_scenario', 'warning')
unittest.main()
示例15: open
except IOError as e:
if e.errno == errno.ENOLCK:
time.sleep(0.01)
pass
else:
raise
f.seek(0)
assert '' == f.read()
f.write('%s' % x)
f.flush()
# time.sleep(0.01)
f.seek(0)
f.truncate(0)
fcntl.lockf(f, fcntl.LOCK_UN)
fos, fn = tempfile.mkstemp() # (dir='/try/with/nfs/mounted/dir')
f = open(fn, 'w')
f.close()
for x in parimap(work, range(100), nprocs=10, eprintignore=()):
pass
os.close(fos)
os.remove(fn)
if __name__ == '__main__':
util.setup_logging('test_parimap', 'warning')
unittest.main()