61
61
'__version__'
62
62
]
63
63
64
- def load_stochastic_event_sets (filename , type = 'csv' , format = 'native' , ** kwargs ):
64
+
65
+ def load_stochastic_event_sets (filename , type = 'csv' , format = 'native' ,
66
+ ** kwargs ):
65
67
""" General function to load stochastic event sets
66
68
67
69
This function returns a generator to iterate through a collection of catalogs.
@@ -106,7 +108,8 @@ def load_stochastic_event_sets(filename, type='csv', format='native', **kwargs):
106
108
raise ValueError ('format must be either "native" or "csep!' )
107
109
108
110
109
- def load_catalog (filename , type = 'csep-csv' , format = 'native' , loader = None , apply_filters = False , ** kwargs ):
111
+ def load_catalog (filename , type = 'csep-csv' , format = 'native' , loader = None ,
112
+ apply_filters = False , ** kwargs ):
110
113
""" General function to load single catalog
111
114
112
115
See corresponding class documentation for additional parameters.
@@ -122,9 +125,12 @@ def load_catalog(filename, type='csep-csv', format='native', loader=None, apply_
122
125
Returns (:class:`~csep.core.catalogs.AbstractBaseCatalog`)
123
126
"""
124
127
125
-
126
- if type not in ('ucerf3' , 'csep-csv' , 'zmap' , 'jma-csv' , 'ingv_horus' , 'ingv_emrcmt' , 'ndk' ) and loader is None :
127
- raise ValueError ("type must be one of the following: ('ucerf3', 'csep-csv', 'zmap', 'jma-csv', 'ndk', 'ingv_horus', 'ingv_emrcmt')." )
128
+ if type not in (
129
+ 'ucerf3' , 'csep-csv' , 'zmap' , 'jma-csv' , 'ingv_horus' ,
130
+ 'ingv_emrcmt' ,
131
+ 'ndk' ) and loader is None :
132
+ raise ValueError (
133
+ "type must be one of the following: ('ucerf3', 'csep-csv', 'zmap', 'jma-csv', 'ndk', 'ingv_horus', 'ingv_emrcmt')." )
128
134
129
135
# map to correct catalog class, at some point these could be abstracted into configuration file
130
136
# this maps a human readable string to the correct catalog class and the correct loader function
@@ -167,7 +173,8 @@ def load_catalog(filename, type='csep-csv', format='native', loader=None, apply_
167
173
if loader is None :
168
174
loader = class_loader_mapping [type ]['loader' ]
169
175
170
- catalog = catalog_class .load_catalog (filename = filename , loader = loader , ** kwargs )
176
+ catalog = catalog_class .load_catalog (filename = filename , loader = loader ,
177
+ ** kwargs )
171
178
172
179
# convert to csep format if needed
173
180
if format == 'native' :
@@ -213,12 +220,15 @@ def query_comcat(start_time, end_time, min_magnitude=2.50,
213
220
# Timezone should be in UTC
214
221
t0 = time .time ()
215
222
eventlist = readers ._query_comcat (start_time = start_time , end_time = end_time ,
216
- min_magnitude = min_magnitude ,
217
- min_latitude = min_latitude , max_latitude = max_latitude ,
218
- min_longitude = min_longitude , max_longitude = max_longitude ,
219
- max_depth = max_depth )
223
+ min_magnitude = min_magnitude ,
224
+ min_latitude = min_latitude ,
225
+ max_latitude = max_latitude ,
226
+ min_longitude = min_longitude ,
227
+ max_longitude = max_longitude ,
228
+ max_depth = max_depth )
220
229
t1 = time .time ()
221
- comcat = catalogs .CSEPCatalog (data = eventlist , date_accessed = utc_now_datetime (), ** kwargs )
230
+ comcat = catalogs .CSEPCatalog (data = eventlist ,
231
+ date_accessed = utc_now_datetime (), ** kwargs )
222
232
print ("Fetched ComCat catalog in {} seconds.\n " .format (t1 - t0 ))
223
233
224
234
if apply_filters :
@@ -229,9 +239,13 @@ def query_comcat(start_time, end_time, min_magnitude=2.50,
229
239
230
240
if verbose :
231
241
print ("Downloaded catalog from ComCat with following parameters" )
232
- print ("Start Date: {}\n End Date: {}" .format (str (comcat .start_time ), str (comcat .end_time )))
233
- print ("Min Latitude: {} and Max Latitude: {}" .format (comcat .min_latitude , comcat .max_latitude ))
234
- print ("Min Longitude: {} and Max Longitude: {}" .format (comcat .min_longitude , comcat .max_longitude ))
242
+ print ("Start Date: {}\n End Date: {}" .format (str (comcat .start_time ),
243
+ str (comcat .end_time )))
244
+ print (
245
+ "Min Latitude: {} and Max Latitude: {}" .format (comcat .min_latitude ,
246
+ comcat .max_latitude ))
247
+ print ("Min Longitude: {} and Max Longitude: {}" .format (
248
+ comcat .min_longitude , comcat .max_longitude ))
235
249
print ("Min Magnitude: {}" .format (comcat .min_magnitude ))
236
250
print (f"Found { comcat .event_count } events in the ComCat catalog." )
237
251
@@ -266,11 +280,14 @@ def query_bsi(start_time, end_time, min_magnitude=2.50,
266
280
t0 = time .time ()
267
281
eventlist = readers ._query_bsi (start_time = start_time , end_time = end_time ,
268
282
min_magnitude = min_magnitude ,
269
- min_latitude = min_latitude , max_latitude = max_latitude ,
270
- min_longitude = min_longitude , max_longitude = max_longitude ,
283
+ min_latitude = min_latitude ,
284
+ max_latitude = max_latitude ,
285
+ min_longitude = min_longitude ,
286
+ max_longitude = max_longitude ,
271
287
max_depth = max_depth )
272
288
t1 = time .time ()
273
- bsi = catalogs .CSEPCatalog (data = eventlist , date_accessed = utc_now_datetime (), ** kwargs )
289
+ bsi = catalogs .CSEPCatalog (data = eventlist ,
290
+ date_accessed = utc_now_datetime (), ** kwargs )
274
291
print ("Fetched BSI catalog in {} seconds.\n " .format (t1 - t0 ))
275
292
276
293
if apply_filters :
@@ -280,19 +297,25 @@ def query_bsi(start_time, end_time, min_magnitude=2.50,
280
297
bsi = bsi .filter ()
281
298
282
299
if verbose :
283
- print ("Downloaded catalog from Bollettino Sismico Italiano (BSI) with following parameters" )
284
- print ("Start Date: {}\n End Date: {}" .format (str (bsi .start_time ), str (bsi .end_time )))
285
- print ("Min Latitude: {} and Max Latitude: {}" .format (bsi .min_latitude , bsi .max_latitude ))
286
- print ("Min Longitude: {} and Max Longitude: {}" .format (bsi .min_longitude , bsi .max_longitude ))
300
+ print (
301
+ "Downloaded catalog from Bollettino Sismico Italiano (BSI) with following parameters" )
302
+ print ("Start Date: {}\n End Date: {}" .format (str (bsi .start_time ),
303
+ str (bsi .end_time )))
304
+ print ("Min Latitude: {} and Max Latitude: {}" .format (bsi .min_latitude ,
305
+ bsi .max_latitude ))
306
+ print (
307
+ "Min Longitude: {} and Max Longitude: {}" .format (bsi .min_longitude ,
308
+ bsi .max_longitude ))
287
309
print ("Min Magnitude: {}" .format (bsi .min_magnitude ))
288
310
print (f"Found { bsi .event_count } events in the BSI catalog." )
289
311
290
312
return bsi
291
313
314
+
292
315
def query_gns (start_time , end_time , min_magnitude = 2.950 ,
293
- min_latitude = - 47 , max_latitude = - 34 ,
294
- min_longitude = 164 , max_longitude = 180 ,
295
- max_depth = 45.5 ,
316
+ min_latitude = - 47 , max_latitude = - 34 ,
317
+ min_longitude = 164 , max_longitude = 180 ,
318
+ max_depth = 45.5 ,
296
319
verbose = True ,
297
320
apply_filters = False , ** kwargs ):
298
321
"""
@@ -338,6 +361,29 @@ def query_gns(start_time, end_time, min_magnitude=2.950,
338
361
339
362
return gns
340
363
364
+
365
+ def query_gcmt (start_time , end_time , min_magnitude = 5.0 ,
366
+ max_depth = None ,
367
+ catalog_id = None ,
368
+ min_latitude = None , max_latitude = None ,
369
+ min_longitude = None , max_longitude = None ):
370
+
371
+ eventlist = readers ._query_gcmt (start_time = start_time ,
372
+ end_time = end_time ,
373
+ min_magnitude = min_magnitude ,
374
+ min_latitude = min_latitude ,
375
+ max_latitude = max_latitude ,
376
+ min_longitude = min_longitude ,
377
+ max_longitude = max_longitude ,
378
+ max_depth = max_depth )
379
+
380
+ catalog = catalogs .CSEPCatalog (data = eventlist ,
381
+ name = 'gCMT' ,
382
+ catalog_id = catalog_id ,
383
+ date_accessed = utc_now_datetime ())
384
+ return catalog
385
+
386
+
341
387
def load_evaluation_result (fname ):
342
388
""" Load evaluation result stored as json file
343
389
@@ -361,7 +407,8 @@ def load_evaluation_result(fname):
361
407
evaluation_type = json_dict ['type' ]
362
408
except :
363
409
evaluation_type = 'default'
364
- eval_result = evaluation_result_factory [evaluation_type ].from_dict (json_dict )
410
+ eval_result = evaluation_result_factory [evaluation_type ].from_dict (
411
+ json_dict )
365
412
return eval_result
366
413
367
414
@@ -404,15 +451,18 @@ class with the region and magnitude members correctly assigned.
404
451
405
452
# sanity checks
406
453
if not os .path .exists (fname ):
407
- raise FileNotFoundError (f"Could not locate file { fname } . Unable to load forecast." )
454
+ raise FileNotFoundError (
455
+ f"Could not locate file { fname } . Unable to load forecast." )
408
456
# sanity checks
409
457
if loader is not None and not callable (loader ):
410
- raise AttributeError ("Loader must be callable. Unable to load forecast." )
458
+ raise AttributeError (
459
+ "Loader must be callable. Unable to load forecast." )
411
460
extension = os .path .splitext (fname )[- 1 ][1 :]
412
461
if extension not in forecast_loader_mapping .keys () and loader is None :
413
- raise AttributeError ("File extension should be in ('dat','xml','h5','bin') if loader not provided." )
462
+ raise AttributeError (
463
+ "File extension should be in ('dat','xml','h5','bin') if loader not provided." )
414
464
415
- if extension in ('xml' ,'h5' ,'bin' ):
465
+ if extension in ('xml' , 'h5' , 'bin' ):
416
466
raise NotImplementedError
417
467
418
468
# assign default loader
@@ -425,7 +475,8 @@ class with the region and magnitude members correctly assigned.
425
475
return forecast
426
476
427
477
428
- def load_catalog_forecast (fname , catalog_loader = None , format = 'native' , type = 'ascii' , ** kwargs ):
478
+ def load_catalog_forecast (fname , catalog_loader = None , format = 'native' ,
479
+ type = 'ascii' , ** kwargs ):
429
480
""" General function to handle loading catalog forecasts.
430
481
431
482
Currently, just a simple wrapper, but can contain more complex logic in the future.
@@ -444,10 +495,12 @@ def load_catalog_forecast(fname, catalog_loader=None, format='native', type='asc
444
495
"""
445
496
# sanity checks
446
497
if not os .path .exists (fname ):
447
- raise FileNotFoundError (f"Could not locate file { fname } . Unable to load forecast." )
498
+ raise FileNotFoundError (
499
+ f"Could not locate file { fname } . Unable to load forecast." )
448
500
# sanity checks
449
501
if catalog_loader is not None and not callable (catalog_loader ):
450
- raise AttributeError ("Loader must be callable. Unable to load forecast." )
502
+ raise AttributeError (
503
+ "Loader must be callable. Unable to load forecast." )
451
504
# factory methods for loading different types of catalogs
452
505
catalog_loader_mapping = {
453
506
'ascii' : catalogs .CSEPCatalog .load_ascii_catalogs ,
@@ -456,17 +509,18 @@ def load_catalog_forecast(fname, catalog_loader=None, format='native', type='asc
456
509
if catalog_loader is None :
457
510
catalog_loader = catalog_loader_mapping [type ]
458
511
# try and parse information from filename and send to forecast constructor
459
- if format == 'native' and type == 'ascii' :
512
+ if format == 'native' and type == 'ascii' :
460
513
try :
461
514
basename = str (os .path .basename (fname .rstrip ('/' )).split ('.' )[0 ])
462
515
split_fname = basename .split ('_' )
463
516
name = split_fname [0 ]
464
- start_time = strptime_to_utc_datetime (split_fname [1 ], format = "%Y-%m-%dT%H-%M-%S-%f" )
517
+ start_time = strptime_to_utc_datetime (split_fname [1 ],
518
+ format = "%Y-%m-%dT%H-%M-%S-%f" )
465
519
# update kwargs
466
520
_ = kwargs .setdefault ('name' , name )
467
521
_ = kwargs .setdefault ('start_time' , start_time )
468
522
except :
469
523
pass
470
524
# create observed_catalog forecast
471
- return CatalogForecast (filename = fname , loader = catalog_loader , catalog_format = format , catalog_type = type , ** kwargs )
472
-
525
+ return CatalogForecast (filename = fname , loader = catalog_loader ,
526
+ catalog_format = format , catalog_type = type , ** kwargs )
0 commit comments