Exemplo n.º 1
0
def pf_2_cfg(pf, config_file):
    """
    Convert an Antelope .pf parameter file to a generic Python .cfg
    configuration file.

    Arguments:
    pf - Path to parameter file or None. If pf is None, the $PFPATH is searched
    for a parameter file named pyloceq.pf.
    config_file - Desired path to output configuration file.

    Returns:
    0 - Success

    Behaviour:
    This method will read in a parameter file, convert all parameters
    to .cfg configuration file format equivalent and write out a .cfg
    file.

    Example:
    In [1]: from anfseistools.ant import pf_2_cfg

    In [2]: pf_2_cfg(None, 'test_pf_2_cfg')
    Out[2]: 0

    In [3]: pf_2_cfg('/Users/mcwhite/src/3DSeisTools/location/pyloceq',
                     'test_pf_2_cfg')
    Out[3]: 0
    """
    import ConfigParser
    from antelope.stock import pfin,\
                               pfread
    config_file = '%s.cfg' % config_file
    if os.path.isfile(config_file):
        try:
            os.remove(config_file)
        except OSError:
            print 'Could not remove potentially stale configuration file - %s.'\
                    '\nPlease remove and try again.' % config_file
            sys.exit(-1)
    config = ConfigParser.RawConfigParser()
    config.add_section('misc')
    if pf:
        if os.path.splitext(pf)[1] == '.pf':
            pf = pfin(pf)
        else:
            pf = pfin('%s.pf' % pf)
    else: pf = pfread('pyloceq')
    for key1 in pf.keys():
        if isinstance(pf[key1], dict):
            config.add_section(key1)
            for key2 in pf[key1]:
                config.set(key1, key2, pf[key1][key2])
        else:
            config.set('misc', key1, pf[key1])
    with open(config_file, 'w') as config_file:
        config.write(config_file)
    return 0
Exemplo n.º 2
0
def pfile_2_cfg(pfile, config_file):
    '''
    Convert an Antelope .pf parameter file to a generic Python .cfg
    configuration file.

    Arguments:
    pfile - Path to parameter file or None. If pfile is None, the $PFPATH is searched
    for a parameter file named 3Dreloc.pf.
    config_file - Desired path to output configuration file.

    Returns:
    0 - Success

    Behaviour:
    This method will read in a parameter file, convert all parameters
    to .cfg configuration file format equivalent and write out a .cfg
    file.

    Example:
    In [1]: from loctools3D.ant import pfile_2_cfg

    In [2]: pfile_2_cfg(None, 'test_pfile_2_cfg')
    Out[2]: 0

    In [3]: pfile_2_cfg('/Users/mcwhite/src/3DSeisTools/location/pyloceq',
                     'test_pfile_2_cfg')
    Out[3]: 0
    '''
    import ConfigParser
    from antelope.stock import pfin,\
                               pfread
    config_file = '%s.cfg' % config_file
    if os.path.isfile(config_file):
        try:
            os.remove(config_file)
        except OSError:
            print 'Could not remove potentially stale configuration file - %s.'\
                    '\nPlease remove and try again.' % config_file
            sys.exit(-1)
    config = ConfigParser.RawConfigParser()
    config.add_section('misc')
    if pfile:
        if os.path.splitext(pfile)[1] != '.pf':
            pfile = '%s.pf' %pfile 
        pfile = pfin(pfile)
    else:
        pfile = pfread('3Drelocate')
    for key1 in pfile.keys():
        if isinstance(pfile[key1], dict):
            config.add_section(key1)
            for key2 in pfile[key1]:
                config.set(key1, key2, pfile[key1][key2])
        else:
            config.set('misc', key1, pfile[key1])
    config_file =  open(config_file, 'w')
    config.write(config_file)
    config_file.close()
    return 0
Exemplo n.º 3
0
def pfile_2_cfg(pfile, config_file):
    """
    Convert an Antelope .pf parameter file to a generic Python .cfg
    configuration file.

    Arguments:
    pfile - Path to parameter file or None. If pfile is None, the $PFPATH is searched
    for a parameter file named 3Dreloc.pf.
    config_file - Desired path to output configuration file.

    Returns:
    0 - Success

    Behaviour:
    This method will read in a parameter file, convert all parameters
    to .cfg configuration file format equivalent and write out a .cfg
    file.

    Example:
    In [1]: from loctools3D.ant import pfile_2_cfg

    In [2]: pfile_2_cfg(None, 'test_pfile_2_cfg')
    Out[2]: 0

    In [3]: pfile_2_cfg('/Users/mcwhite/src/3DSeisTools/location/pyloceq',
                     'test_pfile_2_cfg')
    Out[3]: 0
    """
    import ConfigParser
    from antelope.stock import pfin, pfread

    config_file = "%s.cfg" % config_file
    if os.path.isfile(config_file):
        try:
            os.remove(config_file)
        except OSError:
            print "Could not remove potentially stale configuration file - %s." "\nPlease remove and try again." % config_file
            sys.exit(-1)
    config = ConfigParser.RawConfigParser()
    config.add_section("misc")
    if pfile:
        if os.path.splitext(pfile)[1] != ".pf":
            pfile = "%s.pf" % pfile
        pfile = pfin(pfile)
    else:
        pfile = pfread("3Dreloc")
    for key1 in pfile.keys():
        if isinstance(pfile[key1], dict):
            config.add_section(key1)
            for key2 in pfile[key1]:
                config.set(key1, key2, pfile[key1][key2])
        else:
            config.set("misc", key1, pfile[key1])
    config_file = open(config_file, "w")
    config.write(config_file)
    config_file.close()
    return 0
Exemplo n.º 4
0
def pf_2_cfg(pf, config_file):
    import ConfigParser
    config_file = '%s.cfg' % config_file
    pf = '%s.pf' % pf
    if os.path.isfile(config_file):
        try:
            os.remove(config_file)
        except Exception:
            print 'Could not remove potentially stale configuration file - %s.\n'\
                    'Please remove and try again.' % config_file
            sys.exit(-1)
    config = ConfigParser.RawConfigParser()
    config.add_section('misc')
    pf = pfin('%s' % pf)
    for key1 in pf.keys():
        if isinstance(pf[key1], dict):
            config.add_section(key1)
            for key2 in pf[key1]:
                config.set(key1, key2, pf[key1][key2])
        else:
            config.set('misc', key1, pf[key1])
    with open(config_file, 'w') as config_file:
        config.write(config_file)
Exemplo n.º 5
0
import misc_tools
from mtools import *
from numpy import arange, asarray
from antelope.stock import pfread, pfin
from antelope.datascope import closing, dbopen
params = pfin('eqloc3d.pf')
loc_params = params['location_parameters']
#These should go in parameter file.
#nr = int(loc_params['nr'])
#nlat = int(loc_params['nlat'])
#nlon = int(loc_params['nlon'])
#nx, ny, nz = nlon, nlat, nr
earth_rad = 6371

#Load events
print 'Reading db'
with closing(dbopen('/Users/mcwhite/staging/dbs/anza_sub/anza')) as db:
    tbl_event = db.schema_tables['event']
    tbl_event = tbl_event.join('origin')
    tbl_event = tbl_event.subset('time >= _2013319 00:00:00_')
    tbl_event = tbl_event.separate('event')
    event_list = misc_tools.create_event_list(tbl_event, 'CSS3.0')
print 'Done reading db'

for ev in event_list:
    origin = ev.preferred_origin
    if origin.lon < -117 or origin.lon > -116 or origin.lat < 33.0 or origin.lat > 34.0:
        continue
    misc_tools.locate_eq(origin)
    sys.exit()
Exemplo n.º 6
0
import misc_tools
from mtools import *
from numpy import arange,asarray
from antelope.stock import pfread, pfin
params=pfin('eqloc3d.pf')
loc_params = params['location_parameters']
#These should go in parameter file.
#nr = int(loc_params['nr'])
#nlat = int(loc_params['nlat'])
#nlon = int(loc_params['nlon'])
#nx, ny, nz = nlon, nlat, nr
earth_rad=6371

#Load events
fnam='pha.phase_210to9_july2011.dat'
pha=Phalist(fnam,'scedc')

for ev in pha:
    if ev.lon<-117 or ev.lon>-116 or ev.lat<33.0 or ev.lat>34.0:
        continue
    misc_tools.locate_eq(ev)
Exemplo n.º 7
0
def locate_eq(ev):
    #Locate an earthquake based on the arrivals in ev, traveltime files which are already saved
    from antelope.stock import pfread, pfin
    from mtools import Phalist,Stalist
    params=pfin('eqloc3d.pf')
    loc_params = params['location_parameters']
    prop_params= params['propagation_grid']
    earth_rad=6371.0

    #Get Propagation grid paramters
    nlat=int(prop_params['nlat'])
    nlon=int(prop_params['nlon'])
    nz=int(prop_params['nr'])
    li = Linear_index(nlon, nlat, nz)
    olon=float(prop_params['minlon'])
    olat=float(prop_params['minlat'])
    oz=float(prop_params['minz'])
    dlon=float(prop_params['dlon'])
    dlat=float(prop_params['dlat'])
    dz=  float(prop_params['dr'])

    #Build vectors of geographic coordinates
    qlon = arange(olon, dlon * nlon + olon, dlon)
    qlat = arange(olat, dlat * nlat + olat, dlat)
    qdep = arange(earth_rad-dz*nz,earth_rad,dz)+oz+dz

    #Grid search for best location
    start_time=time.time()
    absvec=[]
    arrvec=[]
    arrsta=[]        #a list of station names
    for arrival in ev.arrivals:
        if arrival.phase is 'P':
            arrvec.append(arrival.time - ev.time)
            absvec.append(arrival.time)
            arrsta.append(arrival.sta)
        if not os.path.isfile(arrival.sta+'traveltime'):
            continue
    if len(arrvec)<6: #About this many phases are needed to get a decent result
        return None
    absvec=asarray(absvec)
    arrvec=asarray(arrvec)
    #print 'Number of phases used: ',len(arrvec)

    #Search coarsely
    #dstep should go in parameter file.
    dstep = int(loc_params['dstep2'])
    dx, dy, dz = nlon / dstep, nlat / dstep, nz / dstep
    #dx, dy, dz = 1,1,1 #Remove this later
    qx, qy, qz = range(1, nlon, dx), range(1, nlat, dy), range(1, nz, dz);
    minx, miny, minz, orgmin = grid_search_traveltimes_origin(arrsta, qx, qy,
                                                                qz, absvec, li)
    #minx, miny, minz, orgmin = exp_grid_search(arrsta,qx,qy,qz, absvec, li,ev.time)
    #Finer search
#    minx, miny, minz = grid_search_traveltimes_rms(arrsta, qx, qy, qz,
#                                                            arrvec,li)
    buff = int(loc_params['buff2'])
    qx = range(minx - buff, minx + buff)
    qy = range(miny - buff, miny + buff)
    qz = range(minz - buff, minz + buff);
    qx = fix_boundary_search(qx, li.nx)
    qy = fix_boundary_search(qy, li.ny)
    qz = fix_boundary_search(qz, li.nz)
    minx, miny, minz, orgmin = grid_search_traveltimes_origin(arrsta, qx, qy,
                                                                qz, absvec, li)
    #minx, miny, minz, orgmin = exp_grid_search(arrsta,qx,qy,qz, absvec, li,ev.time)
#    minx, miny, minz = grid_search_traveltimes_rms(arrsta, qx, qy, qz,
#                                                            arrvec,li)
    orgmin=0

    #Find the best subgrid location
    c,resid=get_subgrid_loc(minx,miny,minz,arrvec,arrsta,li)
    delta_x=qlon[1]-qlon[0]
    delta_y=qlat[1]-qlat[0]
    delta_z=qdep[1]-qdep[0]
    loc_change=c*[delta_x,delta_y,delta_z] #Subgrid location change in lon/lat/depth

    #Find the best-fit source location in geographic coordinates
    newloc=[newlon,newlat,newz]=[ qlon[minx],qlat[miny],qdep[minz] ] #+loc_change
    elapsed_time=time.time()-start_time
    print ev.orid,len(arrvec),newlon,newlat,earth_rad-newz,ev.lon,ev.lat,ev.depth,ev.time-orgmin,elapsed_time,resid