当前位置: 首页>>代码示例>>Python>>正文


Python ASDFDataSet.get_data_for_tag方法代码示例

本文整理汇总了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
开发者ID:wjlei1990,项目名称:pypaw,代码行数:68,代码来源:convert.py


注:本文中的pyasdf.ASDFDataSet.get_data_for_tag方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。