本文整理汇总了Python中pyrocko.io.save函数的典型用法代码示例。如果您正苦于以下问题:Python save函数的具体用法?Python save怎么用?Python save使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了save函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: save_traces_mseed
def save_traces_mseed(self, filename_tmpl='%(whichset)s_%(network)s_%(station)s_%(location)s_%(channel)s.mseed',
overwrite_network=None, component_to_channel={}, location_map={}):
station, network = self.get_station(), self.get_network()
if overwrite_network is not None:
network = overwrite_network
fns = []
for icomp, comp in enumerate(self.components):
channel = component_to_channel.get(comp, comp)
for (whichset, sgram) in zip(('references', 'synthetics'),
(self.ref_seismograms[icomp], self.syn_seismograms[icomp])):
if sgram and len(sgram[0]) > 1:
starttime = sgram[0][0]
endtime = sgram[0][-1]
deltat = (endtime-starttime)/(len(sgram[0])-1)
data = sgram[1]
location = location_map.get(whichset, whichset)
tr = trace.Trace(network[:2], station[:5], location[:2], channel[:3],
tmin = starttime, tmax=endtime, deltat=deltat, ydata=data)
fn = filename_tmpl % { 'whichset': whichset,
'network': network,
'station': station,
'location': location,
'channel': channel }
io.save([tr], fn)
fns.append(fn)
return fns
开发者ID:alirezaniki,项目名称:kiwi,代码行数:30,代码来源:receiver.py
示例2: call
def call(self):
template = 'trace_%(network)s.%(station)s.%(location)s.%(channel)s'
try:
if self.format == 'text':
default_output_filename = template + '.dat'
else:
default_output_filename = template + '.' + self.format
out_filename = self.output_filename('Template for output files',
default_output_filename)
except NoViewerSet:
out_filename = self.out_filename
traces = self.chopper_selected_traces(fallback=True)
for trs in traces:
for tr in trs:
if self.format == 'mseed':
if len(tr.network) > 2:
tr.set_network(tr.network[:2])
if len(tr.station) > 5:
tr.set_station(tr.station[:5])
if len(tr.location) > 2:
tr.set_location(tr.location[:2])
if len(tr.channel) > 3:
tr.set_channel(tr.channel[:3])
io.save(tr, out_filename, format=self.format)
开发者ID:khannema,项目名称:contrib-snufflings,代码行数:28,代码来源:export_waveforms.py
示例3: call
def call(self):
p = self.get_pile()
try:
markers = self.get_selected_event_markers()
except NoViewerSet:
markers = load_markers(self.markers_filename)
try:
out_filename = self.output_filename('Template for output files',
default_output_filename)
except NoViewerSet:
out_filename = self.out_filename
for m in markers:
event = m.get_event()
eventname = event.name
if not eventname:
eventname = util.time_to_str(event.time, format='%Y-%m-%d_%H-%M-%S')
traces = p.all(tmin=event.time + self.tbeg,
tmax=event.time + self.tend)
io.save(traces, out_filename, additional=dict(
eventname=eventname))
开发者ID:HerrMuellerluedenscheid,项目名称:contrib-snufflings,代码行数:26,代码来源:extract_events.py
示例4: write_container_to_dirs
def write_container_to_dirs(container, base_dir, pad_traces=True):
sources = container.sources
targets = container.targets
if not os.path.exists(base_dir):
os.makedirs(base_dir)
p = progressbar.ProgressBar(widgets=['writing: ',
progressbar.Percentage(),
progressbar.Bar()],
maxval=len(sources)).start()
for i_s, s in enumerate(sources):
_trs = [container[s][t] for t in targets]
if pad_traces:
_trs = do_pad_traces(_trs)
e = s.pyrocko_event()
e.set_name(str(i_s))
out_dir = os.path.join(base_dir, dir_from_event(e))
if not os.path.exists(out_dir):
os.makedirs(out_dir)
for tr in _trs:
io.save(tr, filename_template=out_dir+'/tr_%(network)s.%(station)s.%(location)s.%(channel)s.mseed')
e.dump(os.path.join(out_dir, 'event.pf'))
p.update(i_s)
p.finish()
开发者ID:HerrMuellerluedenscheid,项目名称:swarming,代码行数:28,代码来源:synthi.py
示例5: restitute_evalresp
def restitute_evalresp(tr_fn):
traces = io.load(tr_fn)
out_traces = []
for tr in traces:
try:
try:
evalresp = trace.Evalresp(respfile=evalresps['%s.%s'%(tr.station, tr.channel)],
nslc_id=tr.nslc_id,
target='dis')
except KeyError:
print 'skip ', '.'.join(tr.nslc_id[1:])
continue
if tr.station=='nkc' or tr.station=='zhc':
t_taper = 30
f_taper = (0.05, 0.08, 50., 75.), # frequency domain taper in [hz]
else:
t_taper = 5.
f_taper = (0.3, 0.6, 50., 75.), # frequency domain taper in [hz]
displacement = tr.transfer(
t_taper, # rise and fall of time domain taper in [s]
*f_taper, # frequency domain taper in [hz]
transfer_function=evalresp,
invert=True)
except trace.TraceTooShort:
continue
out_traces.append(displacement)
tr_fn = tr_fn.replace(inputdir, outputdir)
print tr_fn
io.save(out_traces, tr_fn)
del traces
开发者ID:HerrMuellerluedenscheid,项目名称:seismerize,代码行数:35,代码来源:restitute.py
示例6: make_noise_trace
def make_noise_trace(
self, tmin, tmax, nslc_id, target_nslc_id=None, merge_traces=None,
outdir='noise_concat', template='tr_%n.%s.%l.%c.-%(tmin)s.mseed'):
if target_nslc_id is None:
target_nslc_id = nslc_id
n, s, l, c = target_nslc_id
noise_tr = self.noise[(n, s, l, c)]
deltat = noise_tr.deltat
self.resample_many(merge_traces, deltat)
overlap = 0.2 # 20 percent of sample length
sample_length = 60. # seconds
ns = int(sample_length/deltat) # number of samples
fader = trace.CosFader(xfrac=overlap)
noisey = noise_tr.get_ydata()
buffer_size = num.int(sample_length*60./deltat)
i_dumped = 0.
buffer_y = num.zeros(buffer_size)
ioverflow = 0
overflow = None
taper = trace.costaper(
0., overlap/2.*sample_length, sample_length*(1.0-overlap/2.),
sample_length, ns, deltat)
for i, istart in enumerate(num.arange(0, int(num.ceil((tmax-tmin)/deltat)), int(ns*(1.0 - overlap/2.0)))):
istart = int(num.floor((istart+ioverflow) % buffer_size))
istop = istart + ns
nmissing = buffer_size - istop
isample_start = int(num.floor(num.random.uniform(0, len(noisey)-ns)))
isample_stop = isample_start + ns
noise_sample = num.zeros(ns)
noise_sample[:] = noisey[isample_start:isample_stop]
noise_sample *= taper
if nmissing<0:
isample_stop = ns + nmissing
istop = istart + ns + nmissing
ioverflow = isample_stop
overflow = noise_sample[ioverflow:]
noise_sample = noise_sample[:ioverflow]
buffer_y[istart: istop] += noise_sample
# Problem mit ioverlap.
if overflow is not None:
tmin_tr = tmin+i_dumped*buffer_size*deltat
tmax_tr = tmin_tr+(buffer_size-1)*deltat
buff_tr = trace.Trace(network=n, station=s, location=l, channel=c,
tmin=tmin_tr, tmax=tmax_tr,
deltat=noise_tr.deltat, ydata=buffer_y)
if merge_traces is not None:
for mtr in merge_traces:
if buff_tr.is_relevant(mtr.tmin, mtr.tmax):
mtr = mtr.taper(self.merge_fader, inplace=False)
buff_tr.add(mtr)
#print max(num.abs(mtr.ydata))
#trace.snuffle([mtr, buff_tr])
io.save(buff_tr, pjoin(outdir, template))
buffer_y = num.zeros(buffer_size)
buffer_y[0:ns-ioverflow] = overflow
i_dumped += 1.
overflow = None
开发者ID:HerrMuellerluedenscheid,项目名称:swarming,代码行数:59,代码来源:noisify.py
示例7: testLongCode
def testLongCode(self):
c = '1234567'
tr = trace.Trace(c, c, c, c, ydata=num.zeros(10))
e = None
try:
io.save(tr, 'test.mseed')
except mseed.CodeTooLong as e:
assert isinstance(e, mseed.CodeTooLong)
开发者ID:emolch,项目名称:pyrocko,代码行数:8,代码来源:test_io.py
示例8: testLongCode
def testLongCode(self):
c = '1234567'
tr = trace.Trace(c,c,c,c, ydata=num.zeros(10))
e = None
try:
io.save(tr, 'test.mseed')
except mseed.CodeTooLong, e:
pass
开发者ID:gladkovvalery,项目名称:pyrocko,代码行数:8,代码来源:test_io.py
示例9: command_extract
def command_extract(args):
def setup(parser):
parser.add_option(
'--format', dest='format', default='mseed',
choices=['mseed', 'sac', 'text', 'yaff'],
help='export to format "mseed", "sac", "text", or "yaff". '
'Default is "mseed".')
fndfl = 'extracted/%(irecord)s_%(args)s.%(extension)s'
parser.add_option(
'--output', dest='output_fn', default=fndfl, metavar='TEMPLATE',
help='output path template [default: "%s"]' % fndfl)
parser, options, args = cl_parse('extract', args, setup=setup)
try:
sdef = args.pop()
except Exception:
parser.error('cannot get <selection> argument')
try:
gdef = gf.meta.parse_grid_spec(sdef)
except gf.meta.GridSpecError as e:
die(e)
store_dir = get_store_dir(args)
extensions = {
'mseed': 'mseed',
'sac': 'sac',
'text': 'txt',
'yaff': 'yaff'}
try:
store = gf.Store(store_dir)
for args in store.config.iter_extraction(gdef):
gtr = store.get(args)
if gtr:
tr = trace.Trace(
'', '', '', util.zfmt(store.config.ncomponents) % args[-1],
ydata=gtr.data,
deltat=gtr.deltat,
tmin=gtr.deltat * gtr.itmin)
additional = dict(
args='_'.join('%g' % x for x in args),
irecord=store.str_irecord(args),
extension=extensions[options.format])
io.save(
tr,
options.output_fn,
format=options.format,
additional=additional)
except (gf.meta.GridSpecError, gf.StoreError, gf.meta.OutOfBounds) as e:
die(e)
开发者ID:emolch,项目名称:pyrocko,代码行数:56,代码来源:fomosto.py
示例10: save
def save(self):
if not self.current_stuff:
self.fail('Nothing to save.')
data_fn = self.output_filename(caption='Save Data', dir='data-%(network)s-%(station)s-%(location)s-%(channel)s-%(tmin)s.mseed')
stations_fn = self.output_filename(caption='Save Stations File', dir='stations.txt')
all_traces, stations = self.current_stuff
io.save(all_traces, data_fn)
model.dump_stations(stations, stations_fn)
开发者ID:kshramt,项目名称:pyrocko,代码行数:10,代码来源:iris_data.py
示例11: dump_waveforms
def dump_waveforms(self, engine, sources, path,
tmin=None, tmax=None, overwrite=False):
path_waveforms = op.join(path, 'waveforms')
gf.store.remake_dir(path_waveforms, force=overwrite)
path_traces = op.join(
path_waveforms,
'%(wmin_year)s',
'%(wmin_month)s',
'%(wmin_day)s',
'waveform_%(network)s_%(station)s_' +
'%(location)s_%(channel)s_%(tmin)s_%(tmax)s.mseed')
tmin_all, tmax_all = self.get_time_range(sources)
tmin = tmin if tmin is not None else tmin_all
tmax = tmax if tmax is not None else tmax_all
tts = util.time_to_str
tinc = self.tinc or self.get_useful_time_increment(engine, sources)
tmin = math.floor(tmin / tinc) * tinc
tmax = math.ceil(tmax / tinc) * tinc
nwin = int(round((tmax - tmin) / tinc))
pbar = util.progressbar('Generating waveforms', nwin)
for iwin in range(nwin):
pbar.update(iwin)
tmin_win = max(tmin, tmin + iwin*tinc)
tmax_win = min(tmax, tmin + (iwin+1)*tinc)
if tmax_win <= tmin_win:
continue
trs = self.get_waveforms(engine, sources, tmin_win, tmax_win)
try:
io.save(
trs, path_traces,
additional=dict(
wmin_year=tts(tmin_win, format='%Y'),
wmin_month=tts(tmin_win, format='%m'),
wmin_day=tts(tmin_win, format='%d'),
wmin=tts(tmin_win, format='%Y-%m-%d_%H-%M-%S'),
wmax_year=tts(tmax_win, format='%Y'),
wmax_month=tts(tmax_win, format='%m'),
wmax_day=tts(tmax_win, format='%d'),
wmax=tts(tmax_win, format='%Y-%m-%d_%H-%M-%S')),
overwrite=overwrite)
except FileSaveError as e:
logger.debug('Waveform exists %s' % e)
pbar.finish()
return [path_waveforms]
开发者ID:emolch,项目名称:pyrocko,代码行数:54,代码来源:waveform.py
示例12: call
def call(self):
self.cleanup()
if self.tinc is not None:
template = \
'trace_%n.%s.%l.%c_%(tmin_us)s'
else:
template = 'trace_%n.%s.%l.%c'
if self.format == 'text':
default_output_filename = template + '.dat'
else:
default_output_filename = template + '.' + self.format
out_filename = self.output_filename('Template for output files',
default_output_filename)
viewer = self.get_viewer()
for trs in self.chopper_selected_traces(fallback=True, tinc=self.tinc):
trs2save = []
for tr in trs:
if self.format == 'mseed':
if len(tr.network) > 2:
tr.set_network(tr.network[:2])
if len(tr.station) > 5:
tr.set_station(tr.station[:5])
if len(tr.location) > 2:
tr.set_location(tr.location[:2])
if len(tr.channel) > 3:
tr.set_channel(tr.channel[:3])
if viewer.lowpass:
if viewer.lowpass < 0.5/tr.deltat:
tr.lowpass(4, viewer.lowpass, demean=False)
if viewer.highpass:
if viewer.highpass < 0.5/tr.deltat:
tr.highpass(4, viewer.highpass, demean=False)
trs2save.append(tr)
try:
io.save(
trs2save, out_filename,
format=self.format,
overwrite=True)
except io.io_common.FileSaveError as e:
self.fail(str(e))
if self.save_stations:
stations = viewer.stations.values()
fn = self.output_filename('Save Stations', 'stations.pf')
model.dump_stations(list(stations), fn)
开发者ID:HerrMuellerluedenscheid,项目名称:contrib-snufflings,代码行数:54,代码来源:export_waveforms.py
示例13: save
def save(self):
if not self.current_stuff:
self.fail("Nothing to save.")
data_fn = self.output_filename(
caption="Save Data", dir="data-%(network)s-%(station)s-%(location)s-%(channel)s-%(tmin)s.mseed"
)
stations_fn = self.output_filename(caption="Save Stations File", dir="stations.txt")
all_traces, stations = self.current_stuff
io.save(all_traces, data_fn)
model.dump_stations(stations, stations_fn)
开发者ID:trokia,项目名称:pyrocko,代码行数:12,代码来源:iris_data.py
示例14: testDownsampling
def testDownsampling(self):
n = 1024
dt1 = 1./125.
dt2 = 1./10.
dtinter = 1./util.lcm(1./dt1,1./dt2)
upsratio = dt1/dtinter
xdata = num.arange(n,dtype=num.float)
ydata = num.exp(-((xdata-n/2)/10.)**2)
t = trace.Trace(ydata=ydata, tmin=sometime, deltat=dt1, location='1')
t2 = t.copy()
t2.set_codes(location='2')
t2.downsample_to(dt2, allow_upsample_max = 10)
io.save([t,t2], 'test.mseed')
开发者ID:carinaj,项目名称:pyrocko,代码行数:14,代码来源:test_trace.py
示例15: testWriteText
def testWriteText(self):
networks = [rn(2) for i in range(5)]
deltat = 0.1
tr = trace.Trace(
rc(networks), rn(4), rn(2), rn(3),
tmin=time.time()+deltat,
deltat=deltat,
ydata=num.arange(100, dtype=num.int32),
mtime=time.time())
io.save(
tr,
pjoin(
self.tmpdir,
'%(network)s_%(station)s_%(location)s_%(channel)s'),
format='text')
开发者ID:emolch,项目名称:pyrocko,代码行数:15,代码来源:test_io.py
示例16: put_ref_seismograms
def put_ref_seismograms(self):
traces_path = self._ref_seismogram_stem+ '-%(ireceiver)i-%(component)s.mseed'
for irec, (station, receiver, traces) in enumerate(self._dataset):
for tr in traces:
fn = traces_path % {
'ireceiver': irec+1,
'component': self._kiwi_component_map[tr.channel]}
tr = tr.copy()
if self._zero_time != 0.0:
tr.shift(-self._zero_time)
ydata = tr.get_ydata()
if self._trace_factor != 1.0:
ydata *= self._trace_factor
io.save([tr], fn)
开发者ID:alirezaniki,项目名称:kiwi,代码行数:15,代码来源:glue.py
示例17: makeManyFiles
def makeManyFiles( nfiles, nsamples, networks, stations, channels, tmin):
datadir = tempfile.mkdtemp()
traces = []
deltat=1.0
for i in xrange(nfiles):
ctmin = tmin+i*nsamples*deltat # random.randint(1,int(time.time()))
data = num.ones(nsamples)
traces.append(trace.Trace(rc(networks), rc(stations),'',rc(channels), ctmin, None, deltat, data))
fnt = pjoin( datadir, '%(network)s-%(station)s-%(location)s-%(channel)s-%(tmin)s.mseed')
io.save(traces, fnt, format='mseed')
return datadir
开发者ID:gladkovvalery,项目名称:pyrocko,代码行数:15,代码来源:test_pile.py
示例18: __call__
def __call__(self):
# Change strike within Snuffler with the added scroll bar.
#strike = 0
#dip = 90
#rake = 0
#moment = 7.00e20
depth = 3000
rise_time = 1
scale = 1E21
mxx = 1.*scale
mxy = 1.*scale
myz = 1.*scale
mxz = 1.*scale
#explosion source
source_params = dict(zip(['mxx', 'myy', 'mzz', 'mxy', 'mxz',
'myz', 'depth', 'rise-time'],
[mxx, mxx, mxx, mxy, mxz, myz,
depth, rise_time]))
s = source.Source(sourcetype='moment_tensor', sourceparams=source_params)
#strike dip rake
#s = source.Source('bilateral',
#sourceparams_str ='0 0 0 %g %g %g %g %g 0 0 0 0 1 %g' % (depth, moment, strike, dip, rake, rise_time))
self.seis.set_source(s)
recs = self.seis.get_receivers_snapshot(which_seismograms=('syn',),
which_spectra=(),
which_processing='tapered')
trs = []
for rec in recs:
for t in rec.get_traces():
t.shift(rise_time*0.5)
trs.append(t)
io.save(trs, 'mseeds/%(network)s_%(station)s_%(location)s_%(channel)s.mseed')
# Create event:
ref_event = model.Event(lat=self.olat,
lon=self.olon,
depth=depth,
time=self.otime,
name='Reference Event')
synthetic_event_marker = gui_util.EventMarker(event=ref_event)
gui_util.Marker.save_markers([synthetic_event_marker], 'reference_marker.txt')
开发者ID:HerrMuellerluedenscheid,项目名称:derec,代码行数:48,代码来源:make-test-traces.py
示例19: testWriteRead
def testWriteRead(self):
now = time.time()
n = 10
deltat = 0.1
networks = [ rn(2) for i in range(5) ]
traces1 = [ trace.Trace(rc(networks), rn(4), rn(2), rn(3), tmin=now+i*deltat*n*2, deltat=deltat, ydata=num.arange(n, dtype=num.int32), mtime=now)
for i in range(3) ]
tempdir = tempfile.mkdtemp()
for format in ('mseed', 'sac', 'yaff'):
fns = io.save(traces1, pjoin(tempdir, '%(network)s_%(station)s_%(location)s_%(channel)s'), format=format)
for fn in fns:
assert io.detect_format(fn) == format
traces2 = []
for fn in fns:
traces2.extend(io.load(fn, format='detect'))
for tr in traces1:
assert tr in traces2, 'failed for format %s' % format
for fn in fns:
os.remove(fn)
shutil.rmtree(tempdir)
开发者ID:kshramt,项目名称:pyrocko,代码行数:29,代码来源:test_io.py
示例20: _fixate
def _fixate(self, buf):
if self._path:
trbuf = buf.get_traces()[0]
fns = io.save([trbuf], self._path, format=self._format)
self.remove_file(buf)
if not self._forget_fixed:
self.load_files(fns, show_progress=False, fileformat=self._format)
开发者ID:gladkovvalery,项目名称:pyrocko,代码行数:8,代码来源:hamster_pile.py
注:本文中的pyrocko.io.save函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论