本文整理匯總了Python中pyasdf.ASDFDataSet.get_data_for_tag方法的典型用法代碼示例。如果您正苦於以下問題:Python ASDFDataSet.get_data_for_tag方法的具體用法?Python ASDFDataSet.get_data_for_tag怎麽用?Python ASDFDataSet.get_data_for_tag使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類pyasdf.ASDFDataSet
的用法示例。
在下文中一共展示了ASDFDataSet.get_data_for_tag方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: convert_from_asdf
# 需要導入模塊: from pyasdf import ASDFDataSet [as 別名]
# 或者: from pyasdf.ASDFDataSet import get_data_for_tag [as 別名]
def convert_from_asdf(asdf_fn, outputdir, tag=None, filetype="sac",
output_staxml=True, output_quakeml=True,
_verbose=True):
"""
Convert the waveform in asdf to different types of file
"""
filetype = filetype.upper()
if filetype not in ["SAC", "MSEED"]:
raise ValueError("Supported filetype: 1) sac; 2) mseed")
if not os.path.exists(asdf_fn):
raise ValueError("No asdf file: %s" % asdf_fn)
if not os.path.exists(outputdir):
os.makedirs(outputdir)
if isinstance(tag, str):
tag_list = [tag]
print("Input ASDF: %s" % asdf_fn)
print("Output dir: %s" % outputdir)
print("Output StationXML and Quakeml: [%s, %s]" % (output_staxml,
output_quakeml))
ds = ASDFDataSet(asdf_fn, mode='r')
if output_quakeml:
if len(ds.events) >= 1:
filename = os.path.join(outputdir, "Quakeml.xml")
if _verbose:
print("Quakeml file: %s" % filename)
ds.events.write(filename, format="QUAKEML")
sta_list = ds.waveforms.list()
for station_name in sta_list:
if _verbose:
print("Convert station: %s" % station_name)
station_name2 = station_name.replace(".", "_")
station = getattr(ds.waveforms, station_name2)
default_tag_list = station.get_waveform_tags()
if tag is None:
tag_list = default_tag_list
for _tag in tag_list:
if _tag not in default_tag_list:
print("Tag(%s) not in Station(%s) taglist(%s)" %
(_tag, station_name2, default_tag_list))
continue
try:
stream, inv = ds.get_data_for_tag(station_name2, _tag)
except:
print("Error for station:", station_name2)
if filetype == "SAC":
write_stream_to_sac(stream, outputdir, _tag)
elif filetype == "MSEED":
filename = os.path.join(outputdir, "%s.%s.mseed"
% (station_name, _tag))
stream.write(filename, format="MSEED")
if output_staxml:
filename = os.path.join(outputdir, "%s.%s.xml"
% (station_name, _tag))
try:
inv.write(filename, format="STATIONXML")
except:
print("Error creating STATIONXML: %f" % filename)
del ds