Ejemplo n.º 1
0
def main():
    if len(sys.argv) < 1 or len(sys.argv) > 3:
        sys.stderr.write("Usage inv2dlsv [in_xml [out_dataless]]\n")
        return 1

    if len(sys.argv) > 1:
        inFile = sys.argv[1]
    else:
        inFile = "-"

    if len(sys.argv) > 2:
        out = sys.argv[2]
    else:
        out = ""

    sc3wrap.dbQuery = None

    ar = IO.XMLArchive()
    if ar.open(inFile) == False:
        raise IOError(inFile + ": unable to open")

    obj = ar.readObject()
    if obj is None:
        raise TypeError(inFile + ": invalid format")

    sc3inv = DataModel.Inventory.Cast(obj)
    if sc3inv is None:
        raise TypeError(inFile + ": invalid format")

    inv = Inventory(sc3inv)
    inv.load_stations("*", "*", "*", "*")
    inv.load_instruments()

    vol = SEEDVolume(inv, ORGANIZATION, "", resp_dict=False)

    for net in iterinv(inv.network):
        for sta in iterinv(net.station):
            for loc in iterinv(sta.sensorLocation):
                for strm in iterinv(loc.stream):
                    try:
                        vol.add_chan(net.code, sta.code, loc.code,
                                     strm.code, strm.start, strm.end)

                    except SEEDError as e:
                        sys.stderr.write("Error (%s,%s,%s,%s): %s\n" % (
                            net.code, sta.code, loc.code, strm.code, str(e)))

    if not out or out == "-":
        output = io.BytesIO()
        vol.output(output)
        stdout = sys.stdout.buffer if hasattr(sys.stdout, "buffer") else sys.stdout
        stdout.write(output.getvalue())
        stdout.flush()
        output.close()
    else:
        with open(sys.argv[2], "wb") as fd:
            vol.output(fd)

    return 0
Ejemplo n.º 2
0
def main():
    if len(sys.argv) < 1 or len(sys.argv) > 3:
        print "Usage inv2dlsv [in_xml [out_dataless]]"
        return 1

    if len(sys.argv) > 1:
        inFile = sys.argv[1]
    else:
        inFile = "-"

    if len(sys.argv) > 2:
        out = sys.argv[2]
    else:
        out = ""

    sc3wrap.dbQuery = None

    ar = IO.XMLArchive()
    if ar.open(inFile) == False:
        raise IOError, inFile + ": unable to open"

    obj = ar.readObject()
    if obj is None:
        raise TypeError, inFile + ": invalid format"

    sc3inv = DataModel.Inventory.Cast(obj)
    if sc3inv is None:
        raise TypeError, inFile + ": invalid format"

    inv = Inventory(sc3inv)
    inv.load_stations("*", "*", "*", "*")
    inv.load_instruments()

    vol = SEEDVolume(inv, ORGANIZATION, "", resp_dict=False)

    for net in sum([i.values() for i in inv.network.itervalues()], []):
        for sta in sum([i.values() for i in net.station.itervalues()], []):
            for loc in sum(
                [i.values() for i in sta.sensorLocation.itervalues()], []):
                for strm in sum([i.values() for i in loc.stream.itervalues()],
                                []):
                    try:
                        vol.add_chan(net.code, sta.code, loc.code, strm.code,
                                     strm.start, strm.end)

                    except SEEDError, e:
                        print >> sys.stderr, "Error (%s,%s,%s,%s):" % (
                            net.code, sta.code, loc.code, strm.code), str(e)
Ejemplo n.º 3
0
def main():
    if len(sys.argv) < 1 or len(sys.argv) > 3:
        print "Usage inv2dlsv [in_xml [out_dataless]]"
        return 1

    if len(sys.argv) > 1:
        inFile = sys.argv[1]
    else:
        inFile = "-"

    if len(sys.argv) > 2:
        out = sys.argv[2]
    else:
        out = ""

    sc3wrap.dbQuery = None

    ar = IO.XMLArchive()
    if ar.open(inFile) == False:
        raise IOError, inFile + ": unable to open"

    obj = ar.readObject()
    if obj is None:
        raise TypeError, inFile + ": invalid format"

    sc3inv = DataModel.Inventory.Cast(obj)
    if sc3inv is None:
        raise TypeError, inFile + ": invalid format"

    inv = Inventory(sc3inv)
    inv.load_stations("*", "*", "*", "*")
    inv.load_instruments()

    vol = SEEDVolume(inv, ORGANIZATION, "", resp_dict=False)

    for net in iterinv(inv.network):
        for sta in iterinv(net.station):
            for loc in iterinv(sta.sensorLocation):
                for strm in iterinv(loc.stream):
                    try:
                        vol.add_chan(net.code, sta.code, loc.code, strm.code, strm.start, strm.end)

                    except SEEDError, e:
                        print >> sys.stderr, "Error (%s,%s,%s,%s):" % (net.code, sta.code, loc.code, strm.code), str(e)