本文整理匯總了Python中obspy.read方法的典型用法代碼示例。如果您正苦於以下問題:Python obspy.read方法的具體用法?Python obspy.read怎麽用?Python obspy.read使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類obspy
的用法示例。
在下文中一共展示了obspy.read方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: read_coal4D
# 需要導入模塊: import obspy [as 別名]
# 或者: from obspy import read [as 別名]
def read_coal4D(self, fname):
"""
Reads a binary numpy file containing 4-D coalescence grid output by
_compute() .
Parameters
----------
fname : str or pathlib.Path object
Location of file to be read
Returns
-------
map_4d : array-like
4-D coalescence grid
"""
map_4d = np.load(fname)
return map_4d
示例2: test_process_obsd
# 需要導入模塊: import obspy [as 別名]
# 或者: from obspy import read [as 別名]
def test_process_obsd():
st = testobs.copy()
inv = deepcopy(teststaxml)
event = obspy.readEvents(testquakeml)[0]
origin = event.preferred_origin() or event.origins[0]
event_lat = origin.latitude
event_lon = origin.longitude
event_time = origin.time
pre_filt = [1/90., 1/60., 1/27.0, 1/22.5]
t1 = event_time
t2 = event_time + 6000.0
st_new = proc.process_stream(
st, remove_response_flag=True, water_level=60, inventory=inv,
filter_flag=True, pre_filt=pre_filt,
starttime=t1, endtime=t2, resample_flag=True,
sampling_rate=2.0, taper_type="hann",
taper_percentage=0.05, rotate_flag=True,
event_latitude=event_lat,
event_longitude=event_lon)
bmfile = os.path.join(DATA_DIR, "proc", "IU.KBL.obs.proc.mseed")
st_compare = obspy.read(bmfile)
assert compare_stream_kernel(st_new, st_compare)
示例3: test_process_synt
# 需要導入模塊: import obspy [as 別名]
# 或者: from obspy import read [as 別名]
def test_process_synt():
staxmlfile = os.path.join(DATA_DIR, "stationxml", "IU.KBL.syn.xml")
inv = obspy.read_inventory(staxmlfile)
st = testsyn.copy()
event = obspy.readEvents(testquakeml)[0]
origin = event.preferred_origin() or event.origins[0]
event_lat = origin.latitude
event_lon = origin.longitude
event_time = origin.time
pre_filt = [1/90., 1/60., 1/27.0, 1/22.5]
t1 = event_time
t2 = event_time + 6000.0
st_new = proc.process_stream(
st, remove_response_flag=False, inventory=inv,
filter_flag=True, pre_filt=pre_filt,
starttime=t1, endtime=t2, resample_flag=True,
sampling_rate=2.0, taper_type="hann",
taper_percentage=0.05, rotate_flag=True,
event_latitude=event_lat,
event_longitude=event_lon)
bmfile = os.path.join(DATA_DIR, "proc", "IU.KBL.syn.proc.mseed")
st_compare = obspy.read(bmfile)
assert compare_stream_kernel(st_new, st_compare)
示例4: test_update_user_levels
# 需要導入模塊: import obspy [as 別名]
# 或者: from obspy import read [as 別名]
def test_update_user_levels():
obs_tr = read(obsfile)[0]
syn_tr = read(synfile)[0]
config_file = os.path.join(DATA_DIR, "window", "27_60.BHZ.config.yaml")
config = wio.load_window_config_yaml(config_file)
cat = readEvents(quakeml)
inv = read_inventory(staxml)
user_module = "pytomo3d.window.tests.user_module_example"
config = win.update_user_levels(user_module, config, inv, cat,
obs_tr, syn_tr)
npts = obs_tr.stats.npts
assert isinstance(config.stalta_waterlevel, np.ndarray)
assert len(config.stalta_waterlevel) == npts
assert isinstance(config.tshift_acceptance_level, np.ndarray)
assert len(config.tshift_acceptance_level) == npts
assert isinstance(config.dlna_acceptance_level, np.ndarray)
assert len(config.dlna_acceptance_level) == npts
assert isinstance(config.cc_acceptance_level, np.ndarray)
assert len(config.cc_acceptance_level) == npts
assert isinstance(config.s2n_limit, np.ndarray)
assert len(config.s2n_limit) == npts
示例5: test_window_on_trace
# 需要導入模塊: import obspy [as 別名]
# 或者: from obspy import read [as 別名]
def test_window_on_trace():
obs_tr = read(obsfile).select(channel="*R")[0]
syn_tr = read(synfile).select(channel="*R")[0]
config_file = os.path.join(DATA_DIR, "window", "27_60.BHZ.config.yaml")
config = wio.load_window_config_yaml(config_file)
cat = readEvents(quakeml)
inv = read_inventory(staxml)
windows = win.window_on_trace(obs_tr, syn_tr, config, station=inv,
event=cat, _verbose=False,
figure_mode=False)
assert len(windows) == 5
winfile_bm = os.path.join(DATA_DIR, "window",
"IU.KBL..BHR.window.json")
with open(winfile_bm) as fh:
windows_json = json.load(fh)
for _win, _win_json_bm in zip(windows, windows_json):
_win_bm = Window._load_from_json_content(_win_json_bm)
assert _win == _win_bm
示例6: test_window_on_trace_with_none_user_levels
# 需要導入模塊: import obspy [as 別名]
# 或者: from obspy import read [as 別名]
def test_window_on_trace_with_none_user_levels():
obs_tr = read(obsfile).select(channel="*R")[0]
syn_tr = read(synfile).select(channel="*R")[0]
config_file = os.path.join(DATA_DIR, "window", "27_60.BHZ.config.yaml")
config = wio.load_window_config_yaml(config_file)
cat = readEvents(quakeml)
inv = read_inventory(staxml)
windows = win.window_on_trace(obs_tr, syn_tr, config, station=inv,
event=cat, user_module="None",
_verbose=False, figure_mode=False)
winfile_bm = os.path.join(DATA_DIR, "window",
"IU.KBL..BHR.window.json")
with open(winfile_bm) as fh:
windows_json = json.load(fh)
for _win, _win_json_bm in zip(windows, windows_json):
_win_bm = Window._load_from_json_content(_win_json_bm)
assert _win == _win_bm
示例7: test_window_on_stream
# 需要導入模塊: import obspy [as 別名]
# 或者: from obspy import read [as 別名]
def test_window_on_stream():
obs_tr = read(obsfile)
syn_tr = read(synfile)
config_file = os.path.join(DATA_DIR, "window", "27_60.BHZ.config.yaml")
config = wio.load_window_config_yaml(config_file)
config_dict = {"Z": config, "R": config, "T": config}
config_file = os.path.join(DATA_DIR, "window", "27_60.BHZ.config.yaml")
config = wio.load_window_config_yaml(config_file)
cat = readEvents(quakeml)
inv = read_inventory(staxml)
windows = win.window_on_stream(obs_tr, syn_tr, config_dict, station=inv,
event=cat, _verbose=False,
figure_mode=False)
assert len(windows) == 3
nwins = dict((_w, len(windows[_w])) for _w in windows)
assert nwins == {"IU.KBL..BHR": 5, "IU.KBL..BHZ": 2, "IU.KBL..BHT": 4}
示例8: test_window_on_stream_user_levels
# 需要導入模塊: import obspy [as 別名]
# 或者: from obspy import read [as 別名]
def test_window_on_stream_user_levels():
obs_tr = read(obsfile)
syn_tr = read(synfile)
config_file = os.path.join(DATA_DIR, "window", "27_60.BHZ.config.yaml")
config = wio.load_window_config_yaml(config_file)
config_dict = {"Z": config, "R": config, "T": config}
config_file = os.path.join(DATA_DIR, "window", "27_60.BHZ.config.yaml")
config = wio.load_window_config_yaml(config_file)
cat = readEvents(quakeml)
inv = read_inventory(staxml)
_mod = "pytomo3d.window.tests.user_module_example"
user_modules = {"BHZ": _mod, "BHR": _mod, "BHT": _mod}
windows = win.window_on_stream(obs_tr, syn_tr, config_dict, station=inv,
event=cat, user_modules=user_modules,
_verbose=False,
figure_mode=False)
assert len(windows) == 3
nwins = dict((_w, len(windows[_w])) for _w in windows)
assert nwins == {"IU.KBL..BHR": 5, "IU.KBL..BHZ": 2, "IU.KBL..BHT": 4}
示例9: test_plot_window_figure
# 需要導入模塊: import obspy [as 別名]
# 或者: from obspy import read [as 別名]
def test_plot_window_figure(tmpdir):
reset_matplotlib()
obs_tr = read(obsfile).select(channel="*R")[0]
syn_tr = read(synfile).select(channel="*R")[0]
config_file = os.path.join(DATA_DIR, "window", "27_60.BHZ.config.yaml")
config = wio.load_window_config_yaml(config_file)
cat = readEvents(quakeml)
inv = read_inventory(staxml)
ws = WindowSelector(obs_tr, syn_tr, config, event=cat, station=inv)
windows = ws.select_windows()
assert len(windows) > 0
win.plot_window_figure(str(tmpdir), obs_tr.id, ws, True,
figure_format="png")
示例10: test_stationxml_is_invalid_tag_name
# 需要導入模塊: import obspy [as 別名]
# 或者: from obspy import read [as 別名]
def test_stationxml_is_invalid_tag_name(tmpdir):
"""
StationXML is an invalid waveform path.
"""
filename = os.path.join(tmpdir.strpath, "example.h5")
data_set = ASDFDataSet(filename)
st = obspy.read()
with pytest.raises(ValueError):
data_set.add_waveforms(st, tag="StationXML")
with pytest.raises(ValueError):
data_set.add_waveforms(st, tag="stationxml")
# Adding with a proper path works just fine.
data_set.add_waveforms(st, tag="random_waveform")
示例11: test_adding_a_provenance_record
# 需要導入模塊: import obspy [as 別名]
# 或者: from obspy import read [as 別名]
def test_adding_a_provenance_record(tmpdir):
"""
Tests adding a provenance record.
"""
asdf_filename = os.path.join(tmpdir.strpath, "test.h5")
data_set = ASDFDataSet(asdf_filename)
filename = os.path.join(data_dir, "example_schematic_processing_chain.xml")
# Add it as a document.
doc = prov.read(filename, format="xml")
data_set.add_provenance_document(doc, name="test_provenance")
del data_set
# Read it again.
data_set = ASDFDataSet(asdf_filename)
assert data_set.provenance.test_provenance == doc
示例12: test_provenance_dicionary_behaviour
# 需要導入模塊: import obspy [as 別名]
# 或者: from obspy import read [as 別名]
def test_provenance_dicionary_behaviour(tmpdir):
asdf_filename = os.path.join(tmpdir.strpath, "test.h5")
data_set = ASDFDataSet(asdf_filename)
filename = os.path.join(data_dir, "example_schematic_processing_chain.xml")
# Add it as a document.
doc = prov.read(filename, format="xml")
# Setting via setitem.
data_set.provenance["test_provenance"] = doc
data_set.__del__()
del data_set
new_data_set = ASDFDataSet(asdf_filename)
assert new_data_set.provenance.list() == ["test_provenance"]
assert new_data_set.provenance["test_provenance"] == doc
assert getattr(new_data_set.provenance, "test_provenance") == doc
assert list(new_data_set.provenance.keys()) == ["test_provenance"]
assert list(new_data_set.provenance.values()) == [doc]
assert list(new_data_set.provenance.items()) == [("test_provenance", doc)]
示例13: test_deleting_provenance_records
# 需要導入模塊: import obspy [as 別名]
# 或者: from obspy import read [as 別名]
def test_deleting_provenance_records(tmpdir):
"""
Tests the deletion of provenance records.
"""
asdf_filename = os.path.join(tmpdir.strpath, "test.h5")
ds = ASDFDataSet(asdf_filename)
filename = os.path.join(data_dir, "example_schematic_processing_chain.xml")
doc = prov.read(filename, format="xml")
# Delete via attribute access.
ds.add_provenance_document(doc, name="test_provenance")
assert ds.provenance.test_provenance
del ds.provenance.test_provenance
with pytest.raises(AttributeError):
ds.provenance.test_provenance
# Delete via key access.
ds.add_provenance_document(doc, name="test_provenance")
assert ds.provenance["test_provenance"]
del ds.provenance["test_provenance"]
with pytest.raises(KeyError):
ds.provenance["test_provenance"]
示例14: test_warning_that_data_exists_shows_up_every_time
# 需要導入模塊: import obspy [as 別名]
# 或者: from obspy import read [as 別名]
def test_warning_that_data_exists_shows_up_every_time(tmpdir):
asdf_filename = os.path.join(tmpdir.strpath, "test.h5")
ds = ASDFDataSet(asdf_filename)
tr = obspy.read()[0]
# Make sure hash is unique.
tr.stats.starttime += 12345.789
# No warning for first time.
with warnings.catch_warnings(record=True) as w:
ds.add_waveforms(tr, tag="a")
assert len(w) == 0
# Warning for all subsequent times.
for _i in range(10):
_i += 1
with warnings.catch_warnings(record=True) as w:
ds.add_waveforms(tr, tag="a")
assert len(w) == 1, "Run %i" % _i
assert w[0].category is ASDFWarning, "Run %i" % _i
assert "already exists in file" in str(w[0].message), "Run %i" % _i
示例15: save_waveforms_iter
# 需要導入模塊: import obspy [as 別名]
# 或者: from obspy import read [as 別名]
def save_waveforms_iter(self, base_output_path, output_format, waveforms):
"""
Save waveforms, returning an iterator of WaveformResult objects whose values are
True (saved), False (already saved), or Exception (error)
This is so the GUI layer can handle save progress and errors in its own fashion
"""
if not os.path.exists(base_output_path):
try:
os.makedirs(base_output_path, 0o700)
except Exception as e:
raise Exception("Could not create the output path: %s" % str(e))
# Get the file extension to use
extension = OUTPUT_FORMAT_EXTENSIONS[output_format]
for waveform in waveforms:
waveform_id = waveform.waveform_id
try:
output_file = os.path.extsep.join((waveform.base_filename, extension))
output_path = os.path.join(base_output_path, output_file)
# Don't repeat any work that has already been done
if not os.path.exists(output_path):
LOGGER.debug('reading %s', waveform.mseed_path)
st = obspy.read(waveform.mseed_path)
self.save_waveform(st, output_path, output_format, waveform)
yield WaveformResult(waveform_id, True)
else:
yield WaveformResult(waveform_id, False)
except Exception as e:
yield WaveformResult(waveform_id, e)