Пример #1
0
def main(args=None):

    # get options
    (opts, inpickle) = get_options()

    # check output
    wtf = False
    if len(opts.ofile) > 0:
        wtf = True
        if opts.ofile.find('.csv') > 0:
            ofile = opts.ofile
        else:
            ofile = opts.ofile + ".csv"
        fout = open(ofile, 'w')

    # Check input extension extension
    ext = osp.splitext(inpickle)[1]
    if ext == ".pkl":

        # Pickle Already Created...
        db, stkeys = load_db(inpickle, binp=opts.use_binary, keys=opts.keys)

        # # construct station key loop
        # allkeys = db.keys()
        # sorted(allkeys)

        # # Extract key subset
        # if len(opts.keys) > 0:
        #     stkeys = []
        #     for skey in opts.keys:
        #         stkeys.extend([s for s in allkeys if skey in s] )
        # else:
        #     stkeys = db.keys()
        #     sorted(stkeys)

        ikey = 0
        nout = 0
        for key in stkeys:
            ikey += 1

            # generate csvline
            csvline = tocsv(db[key])

            # StdOut
            print(csvline)

            # Save to File
            if wtf:
                fout.writelines(csvline + "\n")
                nout = nout + 1

        # Did we make any changes?
        if wtf and nout == 0:
            remove(ofile)

    else:
        print("Error: Must Enter a .pkl station database pickle file")
        sys.exit()
Пример #2
0
def main(args=None):

    # get options
    (opts, inpickles) = get_options()

    # Loop through inputs
    for inpickle in inpickles:

        # Pickle Already Created...
        print("Listing Station Pickle: {0:s}".format(inpickle))
        db, stkeys = load_db(inpickle, binp=opts.use_binary, keys=opts.keys)

        # Networks only?
        if opts.networks:
            nets = []

        # # construct station key loop
        # allkeys = db.keys()
        # sorted(allkeys)

        # # Extract key subset
        # if len(opts.keys) > 0:
        #     stkeys = []
        #     for skey in opts.keys:
        #         stkeys.extend([s for s in allkeys if skey in s] )
        # else:
        #     stkeys = db.keys()
        #     sorted(stkeys)

        ikey = 0
        for key in stkeys:
            #print(key)
            ikey += 1
            if opts.networks:
                nets.append(db[key].network)
                continue
            print(
                "--------------------------------------------------------------------------"
            )
            print("{0:.0f}) {1:s}".format(ikey, key))
            print(db[key](5))
            print("")

        if opts.networks:
            nets = list(set(nets))
            nets.sort()
            print("Networks: ")
            for net in nets:
                print(net)
Пример #3
0
def main(args=None):

    # get options
    (opts, inpickle) = get_options()

    # Check extension
    ext = osp.splitext(inpickle)[1]
    if ext == ".pkl":

        # Pickle Already Created...
        print("Listing Station Pickle: {0:s}".format(inpickle))
        db, stkeys = load_db(inpickle, binp=opts.use_binary, keys=opts.keys)

        # # construct station key loop
        # allkeys = db.keys()
        # sorted(allkeys)

        # Do we make any changes
        tfEdit = False

        # # Extract key subset
        # if len(opts.keys) > 0:
        #     stkeys = []
        #     for skey in opts.keys:
        #         stkeys.extend([s for s in allkeys if skey in s])
        # else:
        #     stkeys = db.keys()
        #     sorted(stkeys)

        ikey = 0
        for key, val in db.items():
            if key not in stkeys: continue
            ikey += 1

            print(
                "--------------------------------------------------------------------------"
            )
            print(" Original ")
            print("{0:.0f}) {1:s}".format(ikey, key))
            print(db[key](5))
            print(
                "**************************************************************************"
            )
            newline = EditMsgBox(ststr=stdb.convert.tocsv(db[key]), title=key)
            if len(newline) > 0:
                nkey, nel = stdb.convert.fromcsv(newline, lkey=opts.lkey)
                if nel == val:
                    print(" No Changes Made...")
                    continue
                if nkey is not None and nel is not None:
                    if key == nkey:
                        db[key] = nel
                        print(" Replaced " + key + ": ")
                        print(db[key](5))
                        tfEdit = True
                    else:
                        if nkey not in db:
                            del db[key]
                            db[nkey] = nel
                            print(" Added " + nkey + ":")
                            print(db[nkey](5))
                            tfEdit = True
                        else:
                            print(" Database already has key " + nkey +
                                  ". No changes made")
                            print(db[nkey](5))
                else:
                    print(" Error parsing: ")
                    print("  " + newline)
            else:
                print(" No Changes Made...")

        # Did we make any changes?
        if tfEdit:

            # Changes Made... Save Database
            if len(opts.ofile) > 0:
                if opts.ofile.find('.pkl') > 0:
                    fname = opts.ofile
                else:
                    fname = opts.ofile + ".pkl"
                write_db(fname=fname, stdb=db, binp=opts.use_binary)
            else:
                write_db(fname=inpickle, stdb=db, binp=opts.use_binary)

    else:
        print("Error: Must Enter a .pkl station database pickle file")
        sys.exit()
Пример #4
0
    # return options
    return opts, args[0]


if __name__=='__main__':

    # get options
    (opts, inpickle) = get_options()

    # Check extension
    ext = osp.splitext(inpickle)[1]
    if ext == ".pkl":
        
        # Pickle Already Created...
        print ("Listing Station Pickle: {0:s}".format(inpickle))
        db,stkeys = load_db(inpickle, binp=opts.use_binary, keys=opts.keys)
        
        # # construct station key loop
        # allkeys = db.keys()
        # sorted(allkeys)
    
        # Do we make any changes
        tfEdit = False
    
        # # Extract key subset
        # if len(opts.keys) > 0:
        #     stkeys = []
        #     for skey in opts.keys:
        #         stkeys.extend([s for s in allkeys if skey in s])
        # else:
        #     stkeys = db.keys()
Пример #5
0
def main(args=None):

    # get options
    (opts, args) = get_options()

    # Check Output File
    if osp.exists(opts.oname) and not opts.ovr:
        print("Error: Output File exists " + opts.oname)
        print("  Run using --overwrite to replace existing file")
        sys.exit()

    # Load First Database
    if opts.verb: print("Loading " + args[0])
    tdb = load_db(args[0], binp=opts.use_binary)

    # construct station key loop
    allkeys = tdb.keys()
    sorted(allkeys)

    # Any added?
    stadd = False

    # Loop adding additional databases
    for ndb in args[1:]:

        # load database
        if opts.verb: print(" Adding " + ndb)
        db = load_db(ndb, binp=opts.use_binary)

        # Get new keys
        nkeys = db.keys()
        sorted(nkeys)

        # Loop through new keys
        for nkey in nkeys:
            if nkey not in tdb:
                tdb[nkey] = db[nkey]
                stadd = True
            else:
                if opts.verb:
                    print("")
                    print(
                        "*********************************************************"
                    )
                    print("! Duplicate Entry: " + nkey)
                    print("  Retaining: ")
                    print(tdb[nkey](5))
                    print("  Discarding: ")
                    print(db[nkey](5))
                    print(
                        "*********************************************************"
                    )

    # Were any new stations added?
    if stadd:
        if opts.verb:
            print("")
            print("Saving merged database: " + opts.oname)
        write_db(fname=opts.oname, stdb=tdb, binp=opts.use_binary)
    else:
        if opts.verb:
            print("")
            print("No actual merges performed...")
Пример #6
0
    # return options
    return opts, args[0]

if __name__ == '__main__':

    # get options
    (opts, inpickle) = get_options()

    # Check Output File
    if osp.exists(opts.oname):
        print("Error: Output File exists ", opts.oname)
        sys.exit()

    # Load Database
    db = load_db(inpickle, binp=opts.use_binary)

    # construct station key loop
    allkeys = db.keys()
    sorted(allkeys)

    # Loop adding new stations
    newstn = ""
    addnew = False
    while len(newstn) == 0 or newstn.lower()[0] == "y":

        print("********************************")
        print("* New Station")

        # Get Basic Info
        net = input("*    Network:   ")
Пример #7
0
def main(args=None):

    # get options
    (opts, inpickle) = get_options()

    # Check Output File
    if osp.exists(opts.oname):
        print("Error: Output File exists ", opts.oname)
        sys.exit()

    # Load Database
    db = load_db(inpickle, binp=opts.use_binary)

    # construct station key loop
    allkeys = db.keys()
    sorted(allkeys)

    # Loop adding new stations
    newstn = ""
    addnew = False
    while len(newstn) == 0 or newstn.lower()[0] == "y":

        print("********************************")
        print("* New Station")

        # Get Basic Info
        net = input("*    Network:   ")
        stn = input("*    Station:   ")
        chn = input("*    Channel:   ")[0:2]
        loc = input("*    LocId:     ")
        lon = float(input("*    Longitude: "))
        lat = float(input("*    Latitude:  "))
        std = UTCDateTime(input("*    Start:     "))
        edd = UTCDateTime(input("*    End:       "))

        # Advanced Info
        if opts.complex:
            altnet = input("*    Alternate Networks: ")
            addloc = input("*    Additional LocIDs: ")
            pol = float(input("*    Polarity: "))
            azcor = float(input("*    Azimuth Correction: "))
            elev = float(input("*    Elevation: "))
            res_stat = input("*    Restricted Status: ")
            loc = [loc]
            loc.extend(addloc.split(','))
            altnet = altnet.split(',')
        else:
            altnet = []
            loc = [loc]
            pol = 1.
            azcor = 0.
            elev = 0.
            res_stat = "?"

        nloc = []
        for al in loc:
            if len(al) == 0:
                nloc.append('--')
            else:
                nloc.append(al)
        loc = nloc

        # Contruct Key
        if opts.lkey:
            nkey = net.upper() + "." + stn.upper() + "." + chn.upper()
        else:
            nkey = net.upper() + "." + stn.upper()

        #- New DBElement
        NewDbEntry = StDbElement(network=net, altnet=altnet, station=stn, channel=chn, \
                         location=loc, latitude=lat, longitude=lon, elevation=elev, \
                         polarity=pol, azcorr=azcor, startdate=std, enddate=edd)

        # Add key if not present
        if nkey not in db:
            db[nkey] = NewDbEntry
            addnew = True
            print("* Added to DB")
        else:
            print("*")
            print("* Key Exists: " + nkey)
            print("* Existing: ")
            print(db[nkey](10))
            print("* New:")
            print(NewDbEntry(10))
            print("--------------")
            ovr = input("Overwrite Existing? [Y]/N: ")
            if ovr.lower() == "n":
                print("* Retaining Original")
            else:
                db[nkey] = NewDBEntry
                addnew = True
                print("* Added to DB")
        print("")
        newstn = input("* Another Station? [Y]/N: ")

    # Were any new stations added?
    if addnew:
        print("")
        print("Saving new database: " + opts.oname)
        write_db(fname=opts.oname, stdb=db, binp=opts.use_binary)
    else:
        print("")
        print("No changes made...")
Пример #8
0

if __name__ == '__main__':

    # get options
    (opts, args) = get_options()

    # Check Output File
    if osp.exists(opts.oname) and not opts.ovr:
        print("Error: Output File exists " + opts.oname)
        print("  Run using --overwrite to replace existing file")
        sys.exit()

    # Load First Database
    if opts.verb: print("Loading " + args[0])
    tdb = load_db(args[0], binp=opts.use_binary)

    # construct station key loop
    allkeys = tdb.keys()
    sorted(allkeys)

    # Any added?
    stadd = False

    # Loop adding additional databases
    for ndb in args[1:]:

        # load database
        if opts.verb: print(" Adding " + ndb)
        db = load_db(ndb, binp=opts.use_binary)