1414TIMEOUT = 180
1515
1616
17- def query_gcmt (
18- start_time ,
19- end_time ,
20- min_magnitude = 5.0 ,
21- max_depth = None ,
22- catalog_id = None ,
23- min_latitude = None ,
24- max_latitude = None ,
25- min_longitude = None ,
26- max_longitude = None ,
27- ):
28-
29- eventlist = _query_gcmt (
30- start_time = start_time ,
31- end_time = end_time ,
32- min_magnitude = min_magnitude ,
33- min_latitude = min_latitude ,
34- max_latitude = max_latitude ,
35- min_longitude = min_longitude ,
36- max_longitude = max_longitude ,
37- max_depth = max_depth ,
38- )
39-
40- catalog = CSEPCatalog (
41- data = eventlist , name = "gCMT" , catalog_id = catalog_id , date_accessed = utc_now_datetime ()
42- )
43- return catalog
44-
45-
4617def from_zenodo (record_id , folder , force = False ):
4718 """
4819 Download data from a Zenodo repository.
49- Downloads if file does not exist, checksum has changed in local respect to
50- url or force
20+
21+ Downloads if file does not exist, checksum has changed in local respect to url or force
5122
5223 Args:
5324 record_id: corresponding to the Zenodo repository
5425 folder: where the repository files will be downloaded
5526 force: force download even if file exists and checksum passes
5627
5728 Returns:
58-
5929 """
6030 # Grab the urls and filenames and checksums
6131 r = requests .get (f"https://zenodo.org/api/records/{ record_id } " , timeout = 3 )
@@ -87,8 +57,7 @@ def from_zenodo(record_id, folder, force=False):
8757
8858def from_git (url , path , branch = None , depth = 1 , ** kwargs ):
8959 """
90-
91- Clones a shallow repository from a git url
60+ Clones a shallow repository from a git url.
9261
9362 Args:
9463 url (str): url of the repository
@@ -115,185 +84,13 @@ def from_git(url, path, branch=None, depth=1, **kwargs):
11584 return repo
11685
11786
118- def _query_gcmt (
119- start_time ,
120- end_time ,
121- min_magnitude = 3.50 ,
122- min_latitude = None ,
123- max_latitude = None ,
124- min_longitude = None ,
125- max_longitude = None ,
126- max_depth = 1000 ,
127- extra_gcmt_params = None ,
128- ):
129- """
130- Return GCMT eventlist from IRIS web service.
131- For details see "https://service.iris.edu/fdsnws/event/1/"
132- Args:
133- start_time (datetime.datetime): start time of catalog query
134- end_time (datetime.datetime): end time of catalog query
135- min_magnitude (float): minimum magnitude of query
136- min_latitude (float): minimum latitude of query
137- max_latitude (float): maximum latitude of query
138- min_longitude (float): minimum longitude of query
139- max_longitude (float): maximum longitude of query
140- max_depth (float): maximum depth of query
141- extra_gcmt_params (dict): additional parameters to pass to IRIS search
142- function
143-
144- Returns:
145- eventlist
146- """
147- extra_gcmt_params = extra_gcmt_params or {}
148-
149- eventlist = gcmt_search (
150- minmagnitude = min_magnitude ,
151- minlatitude = min_latitude ,
152- maxlatitude = max_latitude ,
153- minlongitude = min_longitude ,
154- maxlongitude = max_longitude ,
155- starttime = start_time .isoformat (),
156- endtime = end_time .isoformat (),
157- maxdepth = max_depth ,
158- ** extra_gcmt_params ,
159- )
160-
161- return eventlist
162-
163-
164- def gcmt_search (
165- format = "text" ,
166- starttime = None ,
167- endtime = None ,
168- updatedafter = None ,
169- minlatitude = None ,
170- maxlatitude = None ,
171- minlongitude = None ,
172- maxlongitude = None ,
173- latitude = None ,
174- longitude = None ,
175- maxradius = None ,
176- catalog = "GCMT" ,
177- contributor = None ,
178- maxdepth = 1000 ,
179- maxmagnitude = 10.0 ,
180- mindepth = - 100 ,
181- minmagnitude = 0 ,
182- offset = 1 ,
183- orderby = "time-asc" ,
184- host = None ,
185- verbose = False ,
186- ):
187- """Search the IRIS database for events matching input criteria.
188- This search function is a wrapper around the ComCat Web API described here:
189- https://service.iris.edu/fdsnws/event/1/
190-
191- This function returns a list of SummaryEvent objects, described elsewhere in this package.
192- Args:
193- starttime (datetime):
194- Python datetime - Limit to events on or after the specified start time.
195- endtime (datetime):
196- Python datetime - Limit to events on or before the specified end time.
197- updatedafter (datetime):
198- Python datetime - Limit to events updated after the specified time.
199- minlatitude (float):
200- Limit to events with a latitude larger than the specified minimum.
201- maxlatitude (float):
202- Limit to events with a latitude smaller than the specified maximum.
203- minlongitude (float):
204- Limit to events with a longitude larger than the specified minimum.
205- maxlongitude (float):
206- Limit to events with a longitude smaller than the specified maximum.
207- latitude (float):
208- Specify the latitude to be used for a radius search.
209- longitude (float):
210- Specify the longitude to be used for a radius search.
211- maxradius (float):
212- Limit to events within the specified maximum number of degrees
213- from the geographic point defined by the latitude and longitude parameters.
214- catalog (str):
215- Limit to events from a specified catalog.
216- contributor (str):
217- Limit to events contributed by a specified contributor.
218- maxdepth (float):
219- Limit to events with depth less than the specified maximum.
220- maxmagnitude (float):
221- Limit to events with a magnitude smaller than the specified maximum.
222- mindepth (float):
223- Limit to events with depth more than the specified minimum.
224- minmagnitude (float):
225- Limit to events with a magnitude larger than the specified minimum.
226- offset (int):
227- Return results starting at the event count specified, starting at 1.
228- orderby (str):
229- Order the results. The allowed values are:
230- - time order by origin descending time
231- - time-asc order by origin ascending time
232- - magnitude order by descending magnitude
233- - magnitude-asc order by ascending magnitude
234- host (str):
235- Replace default ComCat host (earthquake.usgs.gov) with a custom host.
236- Returns:
237- list: List of SummaryEvent() objects.
238- """
239-
240- # getting the inputargs must be the first line of the method!
241- inputargs = locals ().copy ()
242- newargs = {}
243-
244- for key , value in inputargs .items ():
245- if value is True :
246- newargs [key ] = "true"
247- continue
248- if value is False :
249- newargs [key ] = "false"
250- continue
251- if value is None :
252- continue
253- newargs [key ] = value
254-
255- del newargs ["verbose" ]
256-
257- events = _search_gcmt (** newargs )
258-
259- return events
260-
261-
262- def _search_gcmt (** _newargs ):
263- """
264- Performs de-query at ISC API and returns event list and access date
265-
266- """
267- paramstr = urlencode (_newargs )
268- url = HOST_CATALOG + paramstr
269- fh = request .urlopen (url , timeout = TIMEOUT )
270- data = fh .read ().decode ("utf8" ).split ("\n " )
271- fh .close ()
272- eventlist = []
273- for line in data [1 :]:
274- line_ = line .split ("|" )
275- if len (line_ ) != 1 :
276- id_ = line_ [0 ]
277- time_ = datetime .fromisoformat (line_ [1 ])
278- dt = datetime_to_utc_epoch (time_ )
279- lat = float (line_ [2 ])
280- lon = float (line_ [3 ])
281- depth = float (line_ [4 ])
282- mag = float (line_ [10 ])
283- eventlist .append ((id_ , dt , lat , lon , depth , mag ))
284-
285- return eventlist
286-
287-
28887def _download_file (url : str , filename : str ) -> None :
28988 """
290-
291- Downloads files (from zenodo)
89+ Downloads files (from zenodo).
29290
29391 Args:
29492 url (str): the url where the file is located
29593 filename (str): the filename required.
296-
29794 """
29895 progress_bar_length = 72
29996 block_size = 1024
@@ -331,9 +128,7 @@ def _download_file(url: str, filename: str) -> None:
331128
332129
333130def _check_hash (filename , checksum ):
334- """
335- Checks if existing file hash matches checksum from url
336- """
131+ """Checks if existing file hash matches checksum from url."""
337132 algorithm , value = checksum .split (":" )
338133 if not os .path .exists (filename ):
339134 return value , "invalid"
0 commit comments