예제 #1
0
def _open(database, perm='r', **kwargs):
    """
    Return a pointer to an open database from a string or Dbptr.
    Any keyword arguments not for dbopen are passed to dblookup
    """
    if isinstance(database, Dbptr):
        db = Dbptr(database)
    elif isinstance(database, str):
        db = dbopen(database, perm=perm)
    else:
        raise TypeError("Input pointer or string of valid database")
    if kwargs:
        db = dblookup(db,**kwargs)
    return db
예제 #2
0
    def __init__(self, database=None, **kwargs):
        """
        Sets the pointer.

        :type dbv: antelope.datascope.Dbptr
        :param dbv: Open pointer to an Antelope database view or table
        """
        super(AttribDbptr,self).__init__()
        if isinstance(database, Dbptr):
            self.Ptr = Dbptr(database)
        elif isinstance(database, str):
            db = dbopen(database,'r')
            self.Ptr = db
            self._opened = True
        else:
            raise TypeError("Input pointer or string of valid database")
        if kwargs:
            self.Ptr = dblookup(self.Ptr,**kwargs)
예제 #3
0
def eventfocalmech2db(event=None, database=None):
    """
    Write the preferred HASH solution to Datascope database.
    
    Writes to 'fplane', 'predmech' and 'predarr' tables
    """
    focm = event.preferred_focal_mechanism()
    o = focm.triggering_origin_id.getReferredObject()

    plane1 = focm.nodal_planes.nodal_plane_1
    plane2 = focm.nodal_planes.nodal_plane_2
    T = focm.principal_axes.t_axis
    P = focm.principal_axes.p_axis
    orid = int(o.creation_info.version)

    db = Dbptr(database, perm="r+")
    try:
        # Use the original db if in a dbloc2 'tmp/trial' db
        # db = dbloc_source_db(db)
        # save solution as a new mechid
        mechid = db.nextid("mechid")
        # in fplane...
        dbfpln = dblookup(db, table="fplane")
        dbfpln.record = dbfpln.addnull()
        dbfpln.putv(
            "orid",
            orid,
            "str1",
            round(plane1.strike, 1),
            "dip1",
            round(plane1.dip, 1),
            "rake1",
            round(plane1.rake, 1),
            "str2",
            round(plane2.strike, 1),
            "dip2",
            round(plane2.dip, 1),
            "rake2",
            round(plane2.rake, 1),
            "taxazm",
            round(T.azimuth, 1),
            "taxplg",
            round(T.plunge, 1),
            "paxazm",
            round(P.azimuth, 1),
            "paxplg",
            round(P.plunge, 1),
            "algorithm",
            focm.method_id.resource_id,
            "auth",
            focm.creation_info.author,
            "mechid",
            mechid,
        )
        dbpmec = dblookup(db, table="predmech")
        dbparr = dblookup(db, table="predarr")
        for av in o.arrivals:
            pk = av.pick_id.getReferredObject()
            if pk.polarity is "positive":
                fm = "U"
            elif pk.polarity is "negative":
                fm = "D"
            else:
                continue

            arid = int(av.creation_info.version)

            # ..and predmech
            dbpmec.record = dbpmec.addnull()
            dbpmec.putv("arid", arid, "orid", orid, "mechid", mechid, "fm", fm)
            # if there are entries for this arrival already, write over it...
            dbparr.record = dbparr.find("arid=={0} && orid=={1}".format(arid, orid))
            if dbparr.record < 0:
                dbparr.record = dbparr.addnull()
            dbparr.putv("arid", arid, "orid", orid, "esaz", av.azimuth, "dip", av.takeoff_angle)
    except Exception as e:
        raise e
    finally:
        db.close()
예제 #4
0
def output(hp, dbout=None, solution=0, schema="css3.0"):
    """Write the preferred HASH solution to Datascope database.
    
    This writes the strike, dip, rakes to 'fplane', arids used for a
    given mech in 'predmech' and the takeoffs in 'predarr'.
    
    Input
    -----
    dbout   : str or antelope.datascope.Dbptr to database
    solution : <STUB> int of desired solution.
    
    """
    from hashpy.doublecouple import DoubleCouple

    x = solution
    dc = DoubleCouple([hp.str_avg[x], hp.dip_avg[x], hp.rak_avg[x]])
    str1, dip1, rak1 = dc.plane1
    str2, dip2, rak2 = dc.plane2
    axes = dc.axis

    if dbout is not None:
        db = Dbptr(dbout, perm="r+")
    else:
        db = dbtmp(schema)

    mechid = db.nextid("mechid")

    dbfpln = dblookup(db, table="fplane")

    dbfpln.record = dbfpln.addnull()
    dbfpln.putv(
        "orid",
        hp.icusp,
        "str1",
        round(str1, 1),
        "dip1",
        round(dip1, 1),
        "rake1",
        round(rak1, 1),
        "algorithm",
        "HASH",
        "mechid",
        mechid,
        "auth",
        "hashpy:" + hp.author,
        "str2",
        round(str2, 1),
        "dip2",
        round(dip2, 1),
        "rake2",
        round(rak2, 1),
        "taxazm",
        round(axes["T"]["azimuth"], 1),
        "taxplg",
        round(axes["T"]["dip"], 1),
        "paxazm",
        round(axes["P"]["azimuth"], 1),
        "paxplg",
        round(axes["P"]["dip"], 1),
    )

    dbpmec = dblookup(db, table="predmech")
    dbparr = dblookup(db, table="predarr")
    for k in range(hp.npol):
        if hp.p_pol[k] > 0:
            fm = "U"
        else:
            fm = "D"
        dbpmec.record = dbpmec.addnull()
        dbpmec.putv("arid", int(hp.arid[k]), "orid", hp.icusp, "mechid", mechid, "fm", fm)
        dbparr.record = dbparr.addnull()
        dbparr.putv("arid", int(hp.arid[k]), "orid", hp.icusp, "esaz", hp.qazi[k], "dip", hp.p_the_mc[k, 0])
    return db
예제 #5
0
def eventfocalmech2db(event=None, database=None):
    """
    Write the preferred HASH solution to Datascope database.
    
    Writes to 'fplane', 'predmech' and 'predarr' tables
    """
    focm = event.preferred_focal_mechanism()
    o = focm.triggering_origin_id.getReferredObject()
    
    plane1 = focm.nodal_planes.nodal_plane_1
    plane2 = focm.nodal_planes.nodal_plane_2
    T = focm.principal_axes.t_axis
    P = focm.principal_axes.p_axis
    orid = int(o.creation_info.version)
    
    db = Dbptr(database, perm='r+')
    try:
        # Use the original db if in a dbloc2 'tmp/trial' db
        #db = dbloc_source_db(db)
        # save solution as a new mechid
        mechid = db.nextid('mechid')
        # in fplane...
        dbfpln = dblookup(db,table='fplane')
        dbfpln.record = dbfpln.addnull()
        dbfpln.putv('orid', orid,
            'str1', round(plane1.strike,1) ,
            'dip1', round(plane1.dip,1) ,
            'rake1',round(plane1.rake,1),
            'str2', round(plane2.strike,1) ,
            'dip2', round(plane2.dip,1) ,
            'rake2',round(plane2.rake,1),
            'taxazm',round(T.azimuth,1),
            'taxplg',round(T.plunge,1),
            'paxazm',round(P.azimuth,1),
            'paxplg',round(P.plunge,1),
            'algorithm', focm.method_id.resource_id,
            'auth', focm.creation_info.author,
            'mechid', mechid,
            )
        dbpmec = dblookup(db,table='predmech')
        dbparr = dblookup(db,table='predarr')
        for av in o.arrivals:
            pk = av.pick_id.getReferredObject()
            if pk.polarity is 'positive':
                fm = 'U'
            elif pk.polarity is 'negative':
                fm = 'D'
            else:
                continue
            
            arid = int(av.creation_info.version)
            
            # ..and predmech
            dbpmec.record = dbpmec.addnull()
            dbpmec.putv('arid', arid,
                        'orid', orid,
                        'mechid', mechid,
                        'fm', fm,
                        )
            # if there are entries for this arrival already, write over it...
            dbparr.record = dbparr.find('arid=={0} && orid=={1}'.format(arid, orid))
            if dbparr.record < 0:
                dbparr.record = dbparr.addnull()
            dbparr.putv('arid', arid,
                        'orid', orid, 
                        'esaz', av.azimuth, 
                        'dip' , av.takeoff_angle,
                        )
    except Exception as e:
        raise e
    finally:
        db.close()
예제 #6
0
def output(hp, dbout=None, solution=0, schema="css3.0"):
    '''Write the preferred HASH solution to Datascope database.
    
    This writes the strike, dip, rakes to 'fplane', arids used for a
    given mech in 'predmech' and the takeoffs in 'predarr'.
    
    Input
    -----
    dbout   : str or antelope.datascope.Dbptr to database
    solution : <STUB> int of desired solution.
    
    '''
    from hashpy.doublecouple import DoubleCouple

    x = solution
    dc = DoubleCouple([hp.str_avg[x], hp.dip_avg[x], hp.rak_avg[x]])
    str1, dip1, rak1 = dc.plane1 
    str2, dip2, rak2 = dc.plane2
    axes = dc.axis
    
    if dbout is not None:
        db = Dbptr(dbout, perm='r+')
    else:
        db = dbtmp(schema)

    mechid = db.nextid('mechid')
    
    dbfpln = dblookup(db,table='fplane')
    
    dbfpln.record = dbfpln.addnull()
    dbfpln.putv(
            'orid' , hp.icusp,
            'str1' , round(str1,1) ,
            'dip1' , round(dip1,1) ,
            'rake1', round(rak1,1),
            'algorithm', "HASH",
            'mechid', mechid,
            'auth', 'hashpy:'+ hp.author,
            'str2' , round(str2,1) ,
            'dip2' , round(dip2,1) ,
            'rake2', round(rak2,1),
            'taxazm', round(axes['T']['azimuth'],1),
            'taxplg', round(axes['T']['dip'],1),
            'paxazm', round(axes['P']['azimuth'],1),
            'paxplg', round(axes['P']['dip'],1),
            )
    
    dbpmec = dblookup(db,table='predmech')
    dbparr = dblookup(db,table='predarr')
    for k in range(hp.npol):
        if hp.p_pol[k] > 0:
            fm = 'U'
        else:
            fm = 'D'
        dbpmec.record = dbpmec.addnull()
        dbpmec.putv('arid', int(hp.arid[k]) ,
                    'orid', hp.icusp,
                    'mechid', mechid,
                    'fm', fm,
                    )
        dbparr.record = dbparr.addnull()
        dbparr.putv('arid', int(hp.arid[k]),
                    'orid', hp.icusp, 
                    'esaz', hp.qazi[k], 
                    'dip' , hp.p_the_mc[k,0],
                    )
    return db