11# stdlib imports
2- from xml .dom import minidom
3- import warnings
42import json
5- from io import StringIO
6- from datetime import datetime , timedelta
73import logging
4+ import time
5+ import warnings
6+ from datetime import datetime , timedelta
7+ from io import StringIO
8+ from xml .dom import minidom
89
910# third party imports
1011import numpy as np
1112import pandas as pd
12- from obspy .io .quakeml .core import Unpickler
1313import requests
14- from scipy .special import erfcinv
15- from obspy .geodetics .base import gps2dist_azimuth
1614from impactutils .mapping .compass import get_compass_dir_azimuth
15+ from obspy .geodetics .base import gps2dist_azimuth
16+ from obspy .io .quakeml .core import Unpickler
17+ from scipy .special import erfcinv
1718
1819# local imports
1920from libcomcat import search
5455 "ZIP/Location" : "station" ,
5556}
5657
58+ MIN_API_TIME = (
59+ 0.7 # required number of seconds between calls (with a little safety factor)
60+ )
5761
5862PRODUCT_COLUMNS = [
5963 "Update Time" ,
@@ -441,6 +445,7 @@ def get_detail_data_frame(
441445 fmt = "Getting detailed event info - reporting every %i events."
442446 logging .debug (fmt % inc )
443447 for event in events :
448+ t1 = time .time ()
444449 try :
445450 detail = event .getDetailEvent ()
446451 except Exception :
@@ -457,6 +462,15 @@ def get_detail_data_frame(
457462 msg = "Getting detailed information for %s, %i of %i events.\n "
458463 logging .debug (msg % (event .id , ic , len (events )))
459464 ic += 1
465+
466+ # there are limits on the number of ComCat API calls that can be made. To stay under this,
467+ # we'll sleep as long as necessary between calls.
468+ t2 = time .time ()
469+ dt = t2 - t1
470+ sleep_time = MIN_API_TIME - dt
471+ if sleep_time < 0 :
472+ continue
473+ time .sleep (sleep_time )
460474 df = pd .DataFrame (elist )
461475 first_columns = ["id" , "time" , "latitude" , "longitude" , "depth" , "magnitude" ]
462476 all_columns = df .columns
@@ -1851,7 +1865,7 @@ def find_nearby_events(time, lat, lon, twindow, radius):
18511865 df .loc [idx , "azimuth(deg)" ] = az
18521866 dt_norm = dt / twindow
18531867 dd_norm = distance_km / radius
1854- norm_vec = np .sqrt (dt_norm ** 2 + dd_norm ** 2 )
1868+ norm_vec = np .sqrt (dt_norm ** 2 + dd_norm ** 2 )
18551869 df .loc [idx , "normalized_time_dist_vector" ] = norm_vec
18561870
18571871 # reorder the columns so that url is at the end
0 commit comments