Esempio n. 1
0
def getClosest(elat, elon, etime, eventlist):
    dmin = 9999999
    tmin = 9999999
    azmin = 9999999
    imin = -1
    for i in range(0, len(eventlist)):
        event = eventlist[i]
        lon, lat, depth = event['geometry']['coordinates']
        time = datetime.utcfromtimestamp(event['properties']['time'] / 1000)
        dd = distance.sdist(elat, elon, lat, lon) / 1000.0
        azim = distance.getAzimuth(elat, elon, lat, lon)
        if time > etime:
            dt = (time - etime).seconds
        else:
            dt = (etime - time).seconds
        if dd < dmin and dt < dmin:
            dmin = dd
            tmin = dt
            azmin = azim
            imin = i
    event = eventlist[imin]
    idlist = event['properties']['ids'].split(',')[1:-1]
    eurl = event['properties']['url']
    authid = event['id']
    idlist.remove(authid)
    idlist.append(authid)
    idlist = idlist[::-1]
    return (idlist, eurl, dmin, tmin, azmin)
Esempio n. 2
0
def getEventsInCircle(lat, lon, radius, eventlist):
    """
    Select earthquakes from a list of events using a lat/lon center and a radius in km.
    @param lat: Latitude at center of circle.
    @param lon: Longitude at center of circle.
    @param radius: Radius of search in km.
    @param eventlist: List of event dictionaries, each containing (at least) keys lat,lon,depth,mag.
    @return: Filtered list of earthquake dictionaries.
    """
    elat = np.array([
        e['lat'] for e in eventlist
    ])  #extract the latitudes from each dictionary in the list
    elon = np.array([
        e['lon'] for e in eventlist
    ])  #extract the longitudes from each dictionary in the list
    d = sdist(
        lat, lon, elat, elon
    ) / 1000.0  #do vectorized distance calculation from center point to all lat/lon pairs
    az = []
    for i in range(0, len(elat)):
        az.append(getAzimuth(lat, lon, elat[i],
                             elon[i]))  #vectorize the azimuth function someday

    for i in range(0, len(eventlist)):
        eventlist[i]['distance'] = d[
            i]  #add distance field to each dictionary in the list
        eventlist[i]['azimuth'] = az[
            i]  #add azimuth field to each dictionary in the list

    idx = (d <= radius).nonzero()[
        0]  #array of indices where distance is less than input threshold
    newlist = (np.array(eventlist)[idx]).tolist()  #return a shortened list

    return newlist
Esempio n. 3
0
def getClosest(elat,elon,etime,eventlist):
    dmin = 9999999
    tmin = 9999999
    azmin = 9999999
    imin = -1    
    for i in range(0,len(eventlist)):
        event = eventlist[i]
        lon,lat,depth = event['geometry']['coordinates']
        time = datetime.utcfromtimestamp(event['properties']['time']/1000)
        dd = distance.sdist(elat,elon,lat,lon)/1000.0
        azim = distance.getAzimuth(elat,elon,lat,lon)
        if time > etime:
            dt = (time - etime).seconds
        else:
            dt = (etime - time).seconds
        if dd < dmin and dt < dmin:
            dmin = dd
            tmin = dt
            azmin = azim
            imin = i
    event = eventlist[imin]
    idlist = event['properties']['ids'].split(',')[1:-1]
    eurl = event['properties']['url']
    authid = event['id']
    idlist.remove(authid)
    idlist.append(authid)
    idlist = idlist[::-1]
    return (idlist,eurl,dmin,tmin,azmin)
Esempio n. 4
0
def getEventsInEllipse(lat, lon, str, aval, bval, eventlist):
    """
    Select earthquakes from a list of events using dist/az from a predefined lat/lon, and axes of an ellipse
    getEventsInCircle must already have been used
    @param str: Strike of slab at center of circle.
    @param aval: Long axis of ellipse in km.
    @param bval: Short axis of ellipse in km.
    @param eventlist: List of event dictionaries, each containing (at least) keys lat,lon,depth,mag.
    @return: Filtered list of earthquake dictionaries.
    """
    elat = np.array([
        e['lat'] for e in eventlist
    ])  #extract the latitudes from each dictionary in the list
    elon = np.array([
        e['lon'] for e in eventlist
    ])  #extract the longitudes from each dictionary in the list
    d = sdist(
        lat, lon, elat, elon
    ) / 1000.0  #do vectorized distance calculation from center point to all lat/lon pairs
    az = []
    for i in range(0, len(elat)):
        az.append(getAzimuth(lat, lon, elat[i],
                             elon[i]))  #vectorize the azimuth function someday

    for i in range(0, len(eventlist)):
        eventlist[i]['distance'] = d[
            i]  #add distance field to each dictionary in the list
        eventlist[i]['azimuth'] = az[
            i]  #add azimuth field to each dictionary in the list

#   print 'Eventlist[1] = %.4f, %.4f, %.4f, %.4f' % (elat[1],elon[1],d[1],az[1])

    mdist = []
    erta = math.sqrt(1 - ((math.pow(bval, 2)) / (math.pow(aval, 2))))

    #    print 'ERTA = %.4f' % (erta)

    for i in range(0, len(elat)):
        mdist.append(getEllipseRad(aval, erta, az[i], str))


#    print 'Lon:', (elon[1:-1])
#    print 'Lat:', (elat[1:-1])
#    print 'Dist:', (d[1:-1])
#    print 'Azi:', (az[1:-1])
#    print 'Edist:', (mdist[1:-1])

    idx = (d <= mdist).nonzero()[
        0]  #array of indices where distance is less than input threshold

    #    print 'Indexes:'
    #    print (idx)[1:-1]

    newerlist = (np.array(eventlist)[idx]).tolist()  #return a shortened list

    return newerlist
Esempio n. 5
0
def getEventsInEllipse(lat,lon,str,aval,bval,eventlist):
    """
    Select earthquakes from a list of events using dist/az from a predefined lat/lon, and axes of an ellipse
    getEventsInCircle must already have been used
    @param str: Strike of slab at center of circle.
    @param aval: Long axis of ellipse in km.
    @param bval: Short axis of ellipse in km.
    @param eventlist: List of event dictionaries, each containing (at least) keys lat,lon,depth,mag.
    @return: Filtered list of earthquake dictionaries.
    """
    elat = np.array([e['lat'] for e in eventlist]) #extract the latitudes from each dictionary in the list
    elon = np.array([e['lon'] for e in eventlist]) #extract the longitudes from each dictionary in the list
    d = sdist(lat,lon,elat,elon)/1000.0 #do vectorized distance calculation from center point to all lat/lon pairs
    az = []
    for i in range(0,len(elat)):
        az.append(getAzimuth(lat,lon,elat[i],elon[i]))  #vectorize the azimuth function someday

    for i in range(0,len(eventlist)):
        eventlist[i]['distance'] = d[i] #add distance field to each dictionary in the list
        eventlist[i]['azimuth'] = az[i] #add azimuth field to each dictionary in the list

#   print 'Eventlist[1] = %.4f, %.4f, %.4f, %.4f' % (elat[1],elon[1],d[1],az[1]) 

    mdist = []
    erta = math.sqrt(1-((math.pow(bval,2))/(math.pow(aval,2))))

#    print 'ERTA = %.4f' % (erta)

    for i in range(0,len(elat)):
        mdist.append(getEllipseRad(aval,erta,az[i],str))

#    print 'Lon:', (elon[1:-1])
#    print 'Lat:', (elat[1:-1])
#    print 'Dist:', (d[1:-1])
#    print 'Azi:', (az[1:-1])
#    print 'Edist:', (mdist[1:-1])

    idx = (d <= mdist).nonzero()[0]  #array of indices where distance is less than input threshold

#    print 'Indexes:'
#    print (idx)[1:-1]

    newerlist = (np.array(eventlist)[idx]).tolist() #return a shortened list

    return newerlist
Esempio n. 6
0
def getEventsInCircle(lat,lon,radius,eventlist):
    """
    Select earthquakes from a list of events using a lat/lon center and a radius in km.
    @param lat: Latitude at center of circle.
    @param lon: Longitude at center of circle.
    @param radius: Radius of search in km.
    @param eventlist: List of event dictionaries, each containing (at least) keys lat,lon,depth,mag.
    @return: Filtered list of earthquake dictionaries.
    """
    elat = np.array([e['lat'] for e in eventlist]) #extract the latitudes from each dictionary in the list
    elon = np.array([e['lon'] for e in eventlist]) #extract the longitudes from each dictionary in the list
    d = sdist(lat,lon,elat,elon)/1000.0 #do vectorized distance calculation from center point to all lat/lon pairs
    az = []
    for i in range(0,len(elat)):
        az.append(getAzimuth(lat,lon,elat[i],elon[i]))  #vectorize the azimuth function someday

    for i in range(0,len(eventlist)):
        eventlist[i]['distance'] = d[i] #add distance field to each dictionary in the list
        eventlist[i]['azimuth'] = az[i] #add azimuth field to each dictionary in the list

    idx = (d <= radius).nonzero()[0] #array of indices where distance is less than input threshold
    newlist = (np.array(eventlist)[idx]).tolist() #return a shortened list
    
    return newlist