Exemplo n.º 1
0
def convert_to_sac(asdf_fn, outputdir, tag=None, type="sac"):
    """
    Convert asdf to different types of file
    """
    if not os.path.exists(asdf_fn):
        raise ValueError("No asdf file: %s" % asdf_fn)

    if not os.path.exists(outputdir):
        raise ValueError("No output dir: %s" % outputdir)

    ds = ASDFDataSet(asdf_fn)

    sta_list = ds.get_station_list()
    print sta_list
    print "tag", tag

    for sta_tag in sta_list:
        station_name = sta_tag.replace(".", "_")
        station = getattr(ds.waveforms, station_name)
        attr_list = dir(station)
        attr_list.remove('StationXML')
        print station_name, attr_list
        if tag is None or tag == "":
            if len(attr_list) == 1:
                stream = getattr(station, attr_list[0])
        else:
            stream = getattr(station, tag)
        #print sta_tag, stream
        for tr in stream:
            network = tr.stats.network
            station = tr.stats.station
            location = tr.stats.location
            channel = tr.stats.channel
            filename = ".".join([network, station, location, channel, type])
            filename = os.path.join(outputdir, filename)
            print "output filename:", filename
            tr.write(filename, format=type)
Exemplo n.º 2
0
def convert_to_sac(asdf_fn, outputdir, tag=None, type="sac"):
    """
    Convert asdf to different types of file
    """
    if not os.path.exists(asdf_fn):
        raise ValueError("No asdf file: %s" % asdf_fn)

    if not os.path.exists(outputdir):
        raise ValueError("No output dir: %s" % outputdir)

    ds = ASDFDataSet(asdf_fn)

    sta_list = ds.get_station_list()
    print sta_list
    print "tag",tag

    for sta_tag in sta_list:
        station_name = sta_tag.replace(".", "_")
        station = getattr(ds.waveforms, station_name)
        attr_list = dir(station)
        attr_list.remove('StationXML')
        print station_name, attr_list
        if tag is None or tag == "":
            if len(attr_list) == 1:
                stream = getattr(station, attr_list[0])
        else:
            stream = getattr(station, tag)
        #print sta_tag, stream
        for tr in stream:
            network = tr.stats.network
            station = tr.stats.station
            location = tr.stats.location
            channel = tr.stats.channel
            filename = ".".join([network, station, location, channel, type])
            filename = os.path.join(outputdir, filename)
            print "output filename:", filename
            tr.write(filename, format=type)